pull-git-repo
Advanced tools
Comparing version 1.0.1 to 1.1.1
69
index.js
@@ -427,29 +427,27 @@ var buffered = require('pull-buffered') | ||
R.readTree = function (hash) { | ||
var b, readStr, readHash, ended | ||
var self = this | ||
if (!hash) return pull.empty() | ||
Repo.parseTree = function (object) { | ||
var hasher = createGitHash(object, function () {}) | ||
var b = buffered(hasher(object.read)) | ||
var readStr = b.delimited(0) | ||
var readHash = b.chunks(20) | ||
var ended | ||
return function (end, cb) { | ||
if (ended) return cb(ended) | ||
if (b) return next(end, cb) | ||
self.getTree(hash, function gotObject(err, object) { | ||
if (err) return cb(err) | ||
b = buffered(object.read) | ||
readStr = b.delimited(0) | ||
readHash = b.chunks(20) | ||
next(null, cb) | ||
}) | ||
} | ||
function next(end, cb) { | ||
readStr(end, function (err, fileInfo) { | ||
if (err === true) { | ||
ended = true | ||
return cb(null, {name: 'id', value: hasher.digest}) | ||
} | ||
if (err) return cb(err) | ||
readHash(end, function (err, hash) { | ||
readHash(null, function (err, hash) { | ||
if (err) return cb(err) | ||
var s = split2(fileInfo) | ||
cb(null, { | ||
id: hash.toString('hex'), | ||
mode: parseInt(s[0], 8), | ||
name: s[1] | ||
name: 'entry', | ||
value: { | ||
id: hash.toString('hex'), | ||
mode: parseInt(s[0], 8), | ||
name: s[1] | ||
} | ||
}) | ||
@@ -461,2 +459,34 @@ }) | ||
Repo.getTreeParsed = function (object, cb) { | ||
var tree = { | ||
entries: [] | ||
} | ||
return pull( | ||
Repo.parseTree(object), | ||
pull.drain(function (field) { | ||
if (field.name === 'entry') | ||
tree.entries.push(field.value) | ||
else | ||
tree[field.name] = field.value | ||
}, function (err) { | ||
cb(err, tree) | ||
}) | ||
) | ||
} | ||
R.readTree = function (hash) { | ||
if (!hash) return pull.empty() | ||
var self = this | ||
return readNext(function (cb) { | ||
self.getTree(hash, function (err, object) { | ||
if (err) return cb(err) | ||
cb(null, pull( | ||
Repo.parseTree(object), | ||
pull.filter(function (field) { return field.name === 'entry' }), | ||
pull.map(function (field) { return field.value }) | ||
)) | ||
}) | ||
}) | ||
} | ||
R.readDir = function (rev, path) { | ||
@@ -600,2 +630,3 @@ var readTree = this.readTree(rev) | ||
offset.packId = pack.packId | ||
offset.msgId = pack.msgId | ||
cb(null, offset) | ||
@@ -602,0 +633,0 @@ }) |
{ | ||
"name": "pull-git-repo", | ||
"version": "1.0.1", | ||
"version": "1.1.1", | ||
"description": "utility methods for git repos using pull streams", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -19,2 +19,8 @@ # pull-git-repo | ||
#### `Repo.parseTree(object): source({id, mode, name})` | ||
Read a tree and transform it into a stream of `{name, value}` properties. | ||
`name` may be `id` for the tree object id, or `entry` for a file entry in the | ||
tree. | ||
#### `repo.getRefNames([pretty, ]cb(err, refs)) | ||
@@ -165,2 +171,12 @@ | ||
#### `Repo.getTreeParsed(object, cb(err, tree))` | ||
Read a tree object and parse it an object. | ||
- `tree.id`: ID of the tree | ||
- `tree.entries`: array of entries in the tree | ||
- `entry.id`: ID of the item object | ||
- `entry.mode`: permission mode of the file | ||
- `entry.name`: name of the file in the directory | ||
#### `repo.getFile(rev, path, cb(err, {length, mode, read)` | ||
@@ -167,0 +183,0 @@ |
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
35516
985
231