Charles E. Lehner committed 1.2.0Latest: 851db48 on 3/3/2022, 12:47:16 AM | |
📄 | README.md |
📄 | index.js |
📁 | lib |
📄 | package-lock.json |
📄 | package.json |
📁 | test |
ssb-git
Functions for working with git-ssb messages.
API
var SSBGit = require('ssb-git')
var ssbGit = new SSBGit(sbot, config)
type: Author
Author: {
name: string,
email: string,
localpart: string,
feed: FeedID,
date: Date,
tz: string,
}
ssbGit.openObject(opts, cb(err, obj))
opts.msg
: MsgIdopts.obj
: sha1opts.type
: type of git object (optional)opts.length
: length of the git object (optional)obj
: git object
ssbGit.readObject(obj)
: source
obj
: git object, fromopenObject
ssbGit.statObject(obj), cb(err, stat)
stat.type
: type of git objectstat.length
: length of git objectobj
: git object, fromopenObject
ssbGit.getObjectMsg(opts, cb(err, msg))
opts.obj
: git object, fromopenObject
opts.headMsgId
: MsgIdopts.type
: MsgIdmsg
: message
ssbGit.getCommit(obj, cb(err, commit))
obj
: git object, fromopenObject
commit
:{ tree: sha1, parents: [sha1], author: Author?, committer: Author?, gpgsig: string?, signatureVersion: string?, }
ssbGit.getTag(obj, cb(err, tag))
obj
: git object, fromopenObject
tag
:{ object: sha1?, type: "tree" | "commit" | "blob" ?, tag: string?, tagger: Author?, gpgsig: string?, signatureVersion: string?, }
ssbGit.readTree(obj)
: source
obj
: git object, fromopenObject
tree entry:
{
name: string,
mode: number,
hash: sha1,
type: "tree" | "commit" | "blob",
}
ssbGit.readTreeFull(obj)
: source
Same as readTree
except each tree entry also has a msg
property which
is a ssb message that pushed the tree entry
ssbGit.readCommitChanges(obj, cb)
opts.obj
opts.headMsgId
opts.type
ssbGit.getObjectAtPath(opts, cb(err, info))
opts.msg
: id of git-update messageopts.obj
: id of git commitopts.path
: path of file in the tree of the commitinfo.obj
: object fromopenObject
info.hash
: id of the git objectinfo.msg
: message that pushed the object
ssbGit.diffFile(opts, cb(err, info))
for a commit and file path, get info about the changes to the file in that commit.
opts.msg
: id of git-update message for the commitopts.commit
: id of git commitopts.path
: path name of file in commitfile.created
: boolean true if the file was created in this commitfile.hash
: array of git object ids, where the last one is the new one, and previous ones are from the file in the parents of the commit
ssbGit.extractSignature(obj, cb(err, parts))
obj
: git object, fromopenObject
parts.signature
: buffer of signature data from the obejctparts.payload
: buffer of payload (the rest of the data besides the signature) from the object
More API
Various utility functions
mergeUpdates
var mergeUpdates = SSBGit.merge
var KVGraph = require('kvgraph')
mergeUpdates
is a reduce function, for use with kvgraph's
reduceRight
function.
The state reduced is as follows:
{
refs: [{name: ref, hash: string, link: Msg, title: string},
refUpdates: {<ref>: integer},
}
refs
: list of current refs and their valuesrefUpdates
: index inrefs
of which refs are updated. index is -1 if the ref is deleted.head
: ref name for symbolic refHEAD
(the repo's default branch)
linearize
var linearize = SSBGit.linearize()
Call to produce a reduce function, to be used with kvgraph's reduceLeft
function to get an array of the updates to a repo.
NOTE: Each reduce operation has to maintain a small amount of state to stay
efficient; call linearize()
anew for each reduce operation you wish to do.
License
Copyright (c) 2016-2019 Charles Lehner and contributors
Usage of the works is permitted provided that this instrument is retained with the works, so that any entity that uses the works is notified of this instrument.
DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
Built with git-ssb-web