git-diff-tree
Advanced tools
Comparing version 0.1.2 to 1.0.0
@@ -1,2 +0,3 @@ | ||
"use strict"; | ||
/* eslint-disable no-console, func-names */ | ||
'use strict'; | ||
@@ -10,3 +11,3 @@ var gitDiffTree = require('../'); | ||
gitDiffTree(repoPath, { | ||
rev : process.env.REV || null, // defaults to 'HEAD' | ||
rev: process.env.REV || null // defaults to 'HEAD' | ||
// originalRev : 'HEAD^^^^^' // defaults to --root | ||
@@ -39,3 +40,3 @@ // don't output data for files that have more lines changed than allowed | ||
console.log('-----------------'); | ||
console.log("That's all folks"); | ||
console.log('That\'s all folks'); | ||
}); |
10
index.js
@@ -1,2 +0,2 @@ | ||
"use strict"; | ||
'use strict'; | ||
@@ -6,4 +6,4 @@ var gitSpawnedStream = require('git-spawned-stream'); | ||
function diffTree(repoPath, opts) { | ||
var opts = opts || {}; | ||
function diffTree(repoPath, ops) { | ||
var opts = ops || {}; | ||
var rev = opts.rev || 'HEAD'; | ||
@@ -13,4 +13,4 @@ var revParent = opts.originalRev || '--root'; | ||
var args = []; | ||
args.push("diff-tree", "--patch-with-raw", "--numstat"); | ||
args.push("--full-index", "--no-commit-id", "-M", revParent, rev, "--"); | ||
args.push('diff-tree', '--patch-with-raw', '--numstat'); | ||
args.push('--full-index', '--no-commit-id', '-M', revParent, rev, '--'); | ||
@@ -17,0 +17,0 @@ // when the diff output is bigger than the limit destroy the stream |
@@ -1,8 +0,8 @@ | ||
"use strict"; | ||
'use strict'; | ||
function parseRawDiffLine(text) { | ||
var res = {}; | ||
var matched = null; | ||
var matched = text.match(/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/); | ||
if (matched = text.match(/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) { | ||
if (matched) { | ||
res.fromMode = matched[1]; | ||
@@ -26,4 +26,9 @@ res.toMode = matched[2]; | ||
return res; | ||
} | ||
// combined diff (for merge commit) | ||
} else if (matched = text.match(/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$/)) { | ||
matched = text.match(/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$/); | ||
if (matched) { | ||
res.nparents = matched[1].length; | ||
@@ -37,3 +42,8 @@ res.fromMode = matched[2].split(' '); | ||
} else if (matched = text.match(/^([0-9a-fA-F]{40})$/)) { | ||
return res; | ||
} | ||
matched = text.match(/^([0-9a-fA-F]{40})$/); | ||
if (matched) { | ||
res.commit = matched[1]; | ||
@@ -40,0 +50,0 @@ } |
@@ -1,2 +0,2 @@ | ||
"use strict"; | ||
'use strict'; | ||
@@ -8,6 +8,8 @@ var splitStream = require('split-transform-stream'); | ||
module.exports = function parseStream(inputStream, opts) { | ||
var patchStream, patchStreamRes; | ||
module.exports = function parseStream(inputStream, ops) { | ||
var patchStream; | ||
var patchStreamRes; | ||
var outStream; | ||
opts = opts || {}; | ||
var opts = ops || {}; | ||
@@ -24,3 +26,3 @@ // don't output data for files that have more lines changed than allowed | ||
inputStream.on('end', function(limitExceeded) { | ||
inputStream.on('end', function handleStreamEnd(limitExceeded) { | ||
if (limitExceeded) { isCut = true; } | ||
@@ -33,5 +35,5 @@ }); | ||
patchStreamRes.on('data', function(data) { | ||
patchStreamRes.on('data', function processPatchChunk(data) { | ||
outStream.emit('data', 'patch', data); | ||
}).on('error', function(err) { | ||
}).on('error', function handlePatchStreamError(err) { | ||
outStream.emit(err); | ||
@@ -48,3 +50,3 @@ }); | ||
if (parsed.status === 'D' || parsed.similarity == '100') { | ||
if (parsed.status === 'D' || parsed.similarity === 100) { | ||
noShow.push(parsed.toFile || parsed.fromFile); | ||
@@ -66,8 +68,6 @@ } | ||
function writeStats(stats) { | ||
var tmp, added, deleted; | ||
var tmp = stats[3].split(' => '); | ||
var added = parseInt(stats[1], 10); | ||
var deleted = parseInt(stats[2], 10); | ||
tmp = stats[3].split(' => '); | ||
added = parseInt(stats[1], 10); | ||
deleted = parseInt(stats[2], 10); | ||
if ((added + deleted) > MAX_DIFF_LINES_PER_FILE) { | ||
@@ -79,10 +79,10 @@ noShow.push(tmp[1] || tmp[0]); | ||
this.emit('data', 'stats', { | ||
added : added, | ||
deleted : deleted, | ||
fileA : tmp[0], | ||
fileB : tmp[1] | ||
added: added, | ||
deleted: deleted, | ||
fileA: tmp[0], | ||
fileB: tmp[1] | ||
}); | ||
} | ||
function end(cb) { | ||
var end = function end(cb) { | ||
patchStream.emit('end'); | ||
@@ -95,13 +95,13 @@ | ||
cb(); | ||
} | ||
}; | ||
var type = 'raw'; | ||
var write = function(line, enc, cb) { | ||
var stats, tmp; | ||
var write = function write(line, enc, cb) { | ||
if (type === 'patch') { | ||
writePatch.call(this, line); | ||
} else { | ||
if (type !== 'patch' && (stats = line.match(/^(\d+)\t(\d+)\t(.*)( => (.*))?/))) { | ||
var stats = line.match(/^(\d+)\t(\d+)\t(.*)( => (.*))?/); | ||
if (type !== 'patch' && stats) { | ||
writeStats.call(this, stats); | ||
@@ -121,5 +121,5 @@ } else if (type !== 'patch' && /^-\t-\t/.test(line)) { | ||
var outStream = splitStream(inputStream, write, end); | ||
outStream = splitStream(inputStream, write, end); | ||
return outStream; | ||
}; |
@@ -1,18 +0,21 @@ | ||
"use strict"; | ||
'use strict'; | ||
var bubbleError = require('bubble-stream-error').bubble; | ||
var pump = require('pump-chain'); | ||
var through = require('through2'); | ||
function streamDiff(inputStream, blacklist) { | ||
function streamDiff(inputStream, blackList) { | ||
var diff = null; | ||
blacklist = blacklist || []; | ||
var blacklist = blackList || []; | ||
function prepareDiff(diff) { | ||
if (diff.lines.length) { | ||
var tmp = diff.lines.pop(); | ||
if (tmp !== '') { diff.lines.push(tmp); } | ||
function prepareDiff(diffData) { | ||
if (diffData.lines.length) { | ||
var tmp = diffData.lines.pop(); | ||
if (tmp !== '') { | ||
diffData.lines.push(tmp); | ||
} | ||
} | ||
return diff; | ||
return diffData; | ||
} | ||
@@ -25,6 +28,6 @@ | ||
function write(line, enc, cb) { | ||
var tmp = null; | ||
var tmp = line.match(/^diff --git a\/(.+?) b\/(.+)$/); | ||
// new diff, must emit previous diff | ||
if (tmp = line.match(/^diff --git a\/(.+?) b\/(.+)$/)) { | ||
if (tmp) { | ||
if (diff && !diff.isBlacklisted) { | ||
@@ -35,5 +38,5 @@ this.push(prepareDiff(diff)); | ||
diff = { | ||
aPath : tmp[1], | ||
bPath : tmp[2], | ||
lines : [], | ||
aPath: tmp[1], | ||
bPath: tmp[2], | ||
lines: [], | ||
isBlacklisted: isBlacklisted(tmp[2] || tmp[1]) | ||
@@ -67,11 +70,7 @@ }; | ||
var outStream = through({ | ||
return pump(inputStream, through({ | ||
objectMode: true | ||
}, write, end); | ||
bubbleError(outStream, [inputStream]); | ||
inputStream.pipe(outStream); | ||
return outStream; | ||
}, write, end)); | ||
} | ||
module.exports = streamDiff; |
{ | ||
"name": "git-diff-tree", | ||
"version": "0.1.2", | ||
"version": "1.0.0", | ||
"description": "Shelling out to git-diff-tree(1) in a Node streamy fashion", | ||
"main": "index.js", | ||
"dependencies": { | ||
"bubble-stream-error": "~0.0.1", | ||
"git-spawned-stream": "~0.1.0", | ||
"pump-chain": "^1.0.0", | ||
"split-transform-stream": "~0.1.1", | ||
"through2": "~0.5.1" | ||
"through2": "~2.0.0" | ||
}, | ||
"devDependencies": { | ||
"proxyquire": "~1.0.1", | ||
"should": "~4.0.4", | ||
"mocha": "~1.20.1" | ||
"alessioalex-standard": "^1.1.0", | ||
"husky": "^0.10.2", | ||
"mocha": "^2.3.4", | ||
"proxyquire": "^1.7.3", | ||
"should": "^7.1.1" | ||
}, | ||
"scripts": { | ||
"test": "mocha" | ||
"test": "mocha", | ||
"lint": "alessioalex-standard", | ||
"precommit": "npm run lint && npm test" | ||
}, | ||
@@ -20,0 +24,0 @@ "repository": { |
@@ -5,2 +5,4 @@ # git-diff-tree | ||
[![build status](https://secure.travis-ci.org/alessioalex/git-diff-tree.png)](http://travis-ci.org/alessioalex/git-diff-tree) | ||
## Usage | ||
@@ -7,0 +9,0 @@ |
@@ -1,5 +0,6 @@ | ||
"use strict"; | ||
/* eslint-disable func-names */ | ||
'use strict'; | ||
should = require('should'); | ||
var proxyquire = require('proxyquire'); | ||
var should = require('should'); | ||
var fs = require('fs'); | ||
@@ -6,0 +7,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
26311
13
375
0
68
5
+ Addedpump-chain@^1.0.0
+ Addedbubble-stream-error@1.0.0(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedpump@1.0.3(transitive)
+ Addedpump-chain@1.0.0(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedsliced@1.0.1(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedthrough2@2.0.5(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedxtend@4.0.2(transitive)
- Removedbubble-stream-error@~0.0.1
- Removedthrough2@0.5.1(transitive)
- Removedxtend@3.0.0(transitive)
Updatedthrough2@~2.0.0