Last active
August 29, 2015 14:06
-
-
Save legokichi/8c89cd4314d9207952bc to your computer and use it in GitHub Desktop.
js-gitの使い方 ref: http://qiita.com/DUxCA/items/7653b826339c82acd64d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This provides symbolic names for the octal modes used by git trees. | |
window.modes = require('./lib/modes'); | |
// Create a repo by creating a plain object. | |
window.repo = {}; | |
// This provides an in-memory storage backend that provides the following APIs: | |
// - saveAs(type, value) => hash | |
// - loadAs(type, hash) => hash | |
// - saveRaw(hash, binary) => | |
// - loadRaw(hash) => binary | |
require('./mixins/mem-db')(repo); | |
// This adds a high-level API for creating multiple git objects by path. | |
// - createTree(entries) => hash | |
require('./mixins/create-tree')(repo); | |
// This provides extra methods for dealing with packfile streams. | |
// It depends on | |
// - unpack(packStream, opts) => hashes | |
// - pack(hashes, opts) => packStream | |
require('./mixins/pack-ops')(repo); | |
// This adds in walker algorithms for quickly walking history or a tree. | |
// - logWalk(ref|hash) => stream<commit> | |
// - treeWalk(hash) => stream<object> | |
require('./mixins/walkers')(repo); | |
// This combines parallel requests for the same resource for effeciency under load. | |
require('./mixins/read-combiner')(repo); | |
// This makes the object interface less strict. See it's docs for details | |
require('./mixins/formats')(repo); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="bundle.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ browserify main.js -o bundle.js | |
$ open index.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// First we create a blob from a string. The `formats` mixin allows us to | |
// use a string directly instead of having to pass in a binary buffer. | |
repo.saveAs("blob", "Hello World\n", function(err, blobHash){ | |
console.log(err, blobHash); | |
// Now we create a tree that is a folder containing the blob as `greeting.txt` | |
repo.saveAs("tree", { | |
"greeting.txt": { mode: modes.file, hash: blobHash } | |
}, function(err, treeHash){ | |
console.log(err, treeHash); | |
// With that tree, we can create a commit. | |
// Again the `formats` mixin allows us to omit details like committer, date, | |
// and parents. It assumes sane defaults for these. | |
repo.saveAs("commit", { | |
author: { | |
name: "Tim Caswell", | |
email: "[email protected]" | |
}, | |
tree: treeHash, | |
message: "Test commit\n" | |
}, function(err, commitHash){ | |
console.log(err, commitHash); | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
repo.saveAs("blob", "Hello World\n", function(err, blobHash){ | |
console.dir(blobHash); | |
repo.loadAs("blob", blobHash, function(err, byteArray){ | |
console.log(byteArray);// -> [72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 10] | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment