aboutsummaryrefslogtreecommitdiff
path: root/lib/git.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/git.js')
-rw-r--r--lib/git.js74
1 files changed, 74 insertions, 0 deletions
diff --git a/lib/git.js b/lib/git.js
index 048e2b3..07061e2 100644
--- a/lib/git.js
+++ b/lib/git.js
@@ -10,6 +10,12 @@ var zlib = require('zlib')
var ObjectNotFoundError = u.customError('ObjectNotFoundError')
+var types = {
+ blob: true,
+ commit: true,
+ tree: true,
+}
+
module.exports = Git
function Git(app) {
@@ -456,3 +462,71 @@ Git.prototype.getCommit = function (obj, cb) {
cb(null, commit)
}))
}
+
+Git.prototype.getTag = function (obj, cb) {
+ pull(this.readObject(obj), u.pullConcat(function (err, buf) {
+ if (err) return cb(err)
+ var tag = {
+ msg: obj.msg,
+ }
+ var authorLine, tagterLine
+ var lines = buf.toString('utf8').split('\n')
+ for (var line; (line = lines.shift()); ) {
+ var parts = line.split(' ')
+ var prop = parts.shift()
+ var value = parts.join(' ')
+ switch (prop) {
+ case 'object':
+ tag.object = value
+ break
+ case 'type':
+ if (!types[value])
+ return cb(new TypeError('unknown git object type ' + type))
+ tag.type = value
+ break
+ case 'tag':
+ tag.tag = value
+ break
+ case 'tagger':
+ tag.tagger = parseName(value)
+ break
+ default:
+ return cb(new TypeError('unknown git object property ' + prop))
+ }
+ }
+ tag.body = lines.join('\n')
+ cb(null, tag)
+ }))
+}
+
+function readCString(reader, cb) {
+ var chars = []
+ reader.read(1, function next(err, ch) {
+ if (err) return cb(err)
+ if (ch[0] === 0) return cb(null, Buffer.concat(chars).toString('utf8'))
+ chars.push(ch)
+ reader.read(1, next)
+ })
+}
+
+Git.prototype.readTree = function (obj) {
+ var reader = Reader()
+ reader(this.readObject(obj))
+ return function (abort, cb) {
+ if (abort) return reader.abort(abort, cb)
+ readCString(reader, function (err, str) {
+ if (err) return cb(err)
+ var parts = str.split(' ')
+ var mode = parseInt(parts[0], 8)
+ var name = parts.slice(1).join(' ')
+ reader.read(20, function (err, hash) {
+ if (err) return cb(err)
+ cb(null, {
+ name: name,
+ mode: mode,
+ hash: hash.toString('hex')
+ })
+ })
+ })
+ }
+}