pull-git-repo
Advanced tools
Comparing version 0.3.0 to 0.3.1
87
index.js
@@ -11,2 +11,4 @@ var buffered = require('pull-buffered') | ||
var cache = require('pull-cache') | ||
var kvdiff = require('pull-kvdiff') | ||
var cat = require('pull-cat') | ||
@@ -217,2 +219,8 @@ var R = {} | ||
if (/^[A-Z_]+$/.test(name)) | ||
return this.getSymRef(name, function (err, ref) { | ||
if (err) return cb(err) | ||
this.resolveRef(ref, cb) | ||
}.bind(this)) | ||
var readRef = this.refs() | ||
@@ -351,2 +359,3 @@ readRef(null, function next(end, ref) { | ||
var self = this | ||
if (!hash) return pull.empty() | ||
@@ -401,3 +410,4 @@ return function (end, cb) { | ||
var file = files[0] | ||
if (!file) return cb(new Error('File \'' + path[0] + '\' not found')) | ||
if (!file) | ||
return cb(new NotFoundError('File \'' + path[0] + '\' not found')) | ||
path.shift() | ||
@@ -426,3 +436,3 @@ readTree = self.readTree(file.id) | ||
if (!file) | ||
return cb(new Error('File not found')) | ||
return cb(new NotFoundError('File not found')) | ||
self.getObjectFromAny(file.id, function (err, object) { | ||
@@ -632,1 +642,74 @@ if (err) return cb(err) | ||
} | ||
R.getSymRef = function (name, short, cb) { | ||
if (typeof short == 'function') cb = short, short = false | ||
var symrefs = this.symrefs() | ||
symrefs(null, function next(end, ref) { | ||
if (end === true) return cb(null, null) | ||
if (end) return cb(end) | ||
if (ref.name != name) return symrefs(null, next) | ||
symrefs(true, function (err) { | ||
var value = ref.ref | ||
if (value && short) | ||
value = String(value).replace(/^refs\/(?:heads|tags)\//, '') | ||
cb(err === true ? null : err, value) | ||
}) | ||
}) | ||
} | ||
function isTree(file) { | ||
return file.mode == 040000 | ||
} | ||
function R_diffTrees2(treeIds, recursive, pathPrefix) { | ||
var self = this | ||
var treeDiff = kvdiff(treeIds.map(this.readTree.bind(this)), 'name') | ||
return !recursive ? treeDiff : pull( | ||
treeDiff, | ||
pull.map(function (item) { | ||
item.path = pathPrefix.concat(item.key) | ||
if (!item.diff.id) return [item] | ||
// split diff item into file diff and tree diff | ||
// in case the filename is a file in one tree and a subtree in another | ||
var subtreeIds = [] | ||
var hasSubtree, hasNonSubtree | ||
for (var i = 0; i < item.values.length; i++) { | ||
var val = item.values[i] | ||
if (!val) { | ||
subtreeIds[i] = null | ||
} else if (val.mode == 040000) { | ||
hasSubtree = true | ||
subtreeIds[i] = val.id | ||
if (item.diff.id) | ||
delete item.diff.id[i] | ||
if (item.diff.mode) | ||
delete item.diff.mode[i] | ||
delete item.values[i] | ||
} else { | ||
hasNonSubtree = true | ||
subtreeIds[i] = null | ||
} | ||
} | ||
var nonSubtreeDiff = hasNonSubtree && pull.once(item) | ||
var subtreeDiff = hasSubtree && | ||
R_diffTrees2.call(self, subtreeIds, true, item.path) | ||
return cat([nonSubtreeDiff, subtreeDiff]) | ||
}), | ||
pull.flatten() | ||
) | ||
} | ||
R.diffTrees = function (treeIds, recursive) { | ||
console.error('tree ids', treeIds) | ||
return pull( | ||
R_diffTrees2.call(this, treeIds, recursive, []), | ||
pull.map(function (item) { | ||
return { | ||
name: item.key, | ||
path: item.path, | ||
id: item.diff && item.diff.id, | ||
mode: item.diff && item.diff.mode | ||
} | ||
}) | ||
) | ||
} |
{ | ||
"name": "pull-git-repo", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "utility methods for git repos using pull streams", | ||
@@ -26,5 +26,7 @@ "main": "index.js", | ||
"pull-buffered": "^0.3.1", | ||
"pull-cat": "^1.1.8", | ||
"pull-git-pack": "^0.1.1", | ||
"pull-hash": "^0.0.0", | ||
"pull-cache": "^0.0.0", | ||
"pull-kvdiff": "^0.0.0", | ||
"stream-to-pull-stream": "^1.6.6" | ||
@@ -31,0 +33,0 @@ }, |
@@ -27,2 +27,12 @@ # pull-git-repo | ||
#### `repo.getSymRef(name[, short], cb(err, value))` | ||
Get a symref of a repo. | ||
- `name`: the symref to resolve. e.g. `"HEAD"` | ||
- `short`: whether to shorten the value, e.g. from `"refs/heads/master"` | ||
to `"master"`. | ||
- `value`: head pointed to by name. e.g. `"refs/heads/master"` | ||
#### `repo.readCommit(rev): source({name, value})` | ||
@@ -66,3 +76,3 @@ | ||
Get the hash that a ref points to. Errors if the ref is not found. | ||
Get the hash that a ref (or symref) points to. Errors if the ref is not found. | ||
@@ -165,2 +175,6 @@ #### `repo.getRef(name, cb(err, object, id))` | ||
#### `repo.diffTrees(treeIds, recursive): source({key, values, diff})` | ||
Get a diff of changed files between two trees | ||
## License | ||
@@ -167,0 +181,0 @@ |
26034
708
186
10
+ Addedpull-cat@^1.1.8
+ Addedpull-kvdiff@^0.0.0
+ Addedpull-kvdiff@0.0.0(transitive)