Skip to content
This repository has been archived by the owner on Aug 24, 2021. It is now read-only.

Commit

Permalink
feat: parse mergetags
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k authored and vmx committed Oct 12, 2018
1 parent 4abebbf commit f2010df
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/util/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ exports.serialize = (dagNode, callback) => {
if (dagNode.encoding) {
lines.push('encoding ' + dagNode.encoding)
}
if (dagNode.mergetag) {
dagNode.mergetag.forEach(tag => {
lines.push('mergetag object ' + gitUtil.cidToSha(tag.object['/']).toString('hex'))
lines.push(tag.text)
})
}
if (dagNode.signature) {
lines.push('gpgsig -----BEGIN PGP SIGNATURE-----')
lines.push(dagNode.signature.text)
Expand Down Expand Up @@ -78,6 +84,30 @@ exports.deserialize = (data, callback) => {
}
break
}
case 'mergetag': {
let mt = value.match(/^object ([0-9a-f]{40})$/)
if (!mt) {
setImmediate(() => callback(new Error('Invalid commit line ' + line)))
}

let tag = {object: {'/': gitUtil.shaToCid(Buffer.from(mt[1], 'hex'))}}

let startLine = line
for (; line < lines.length - 1; line++) {
if (lines[line + 1][0] !== ' ') {
tag.text = lines.slice(startLine + 1, line + 1).join('\n')
break
}
}

if (!res.mergetag) {
res.mergetag = []
}

res.mergetag.push(tag)
}

break
default:
res[key] = value
}
Expand Down

0 comments on commit f2010df

Please sign in to comment.