node-git-core
Library that provides simple object-oriented api for working with git data at a lower level, see git internals for more info:
Installation
npm install git-core
Usage
git = ;Blob = gitBlob;Tree = gitTree;Commit = gitCommit;Tag = gitTag;Pack = gitPack; b1 = 'Some file'; b2 = 12345; // blob with binary data b3 = 'Another file\n'; // (For now file modes are not supported on trees, all blobs have mode 100644 and// subtrees have mode 040000) t1 = 'file-under-tree': b3; t2 = 'some-file.txt': b2 'some-file2.txt': b1 'sub-directory.d': t1; t3 = 'another-file.txt': b1; // Lets create some commmits c1 = tree: t1 author: name: 'Git Author' email: 'author@git.com' date: d1 message: 'Artificial commit 1'; c2 = tree: t2 author: name: 'Git Author' email: 'author@git.com' date: d2 message: 'Artificial commit 2' parents: c1; c3 = tree: t3 author: name: 'Git User' email: 'user@domain.com' date: d3 committer: name: 'Git Commiter' email: 'committer@git.com' date: d4 message: 'Artificial commit 3' parents: c2; tag = object: c2 name: 'v0.0.1' tagger: name: 'Git Tagger' email: 'tagger@git.com' date: d2 message: 'Tag second commit'; // Lets pack everything toguether pack = c3 tag;serializedPack = pack; // this is a git packfile // We only need to add a head to the pack, all other will be added// automatically when serializing
This library is all about working with git data in-memory, no repositories are needed. Above is an example on how git objects can be created, connected and serialized, the inverse is also supported:
// Lets say 'buffer' contains a packfile data that you read from disk or// received from 'git-fetch-pack' pack = Pack; // pack now contains a ready-to-use git object graph // print all blobs in the packfor var i = 0;i < packobjectslength;i++ var obj = packobjectsi; if obj instanceof Blob console); // deserialization of 'thin packs' is also supported, you just have to pass a// callback as a second argument to 'deserialize', which will be called with// the sha1 id whenever a base object is required pack = Pack;
Delta compression is only fully supported on 'deserialization. If you need to encode objects using delta compression then add the deltas manually:
str = '';for i = _i = 0; _i < 1000; i = ++_i str += 'test content/test content2/test content3\n'; b1 = str;b2 = str + 'append\n';b3 = str + 'append\nappend2\n';b4 = str + 'append\nappend2\nappend3\n'; pack = b1 b2 b3 b4;pack;