Created
November 13, 2013 02:42
-
-
Save aaronpowell/7442765 to your computer and use it in GitHub Desktop.
Single-level tree walker for js-git
This file contains hidden or 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
//assumes that the hash you want and the repo are obtainable via closure scope | |
function findPrevious(commit, previousCommit) { | |
repo.load(commit.parents[0], function (err, obj) { | |
if (obj.type !== 'commit') { | |
console.error(obj); | |
throw 'Unexpected type returned'; | |
} | |
repo.load(obj.body.tree, function (err, tree) { | |
if (tree.type !== 'tree') { | |
console.error(tree); | |
throw 'Object is not a tree'; | |
} | |
var match = tree.body.filter(function (obj) { return obj.hash == hash; }); | |
if (match.length) { | |
console.dir(match); | |
findPrevious(obj.body, commit); | |
} else { | |
console.log('we have a winner!'); | |
console.dir(obj); | |
} | |
}) | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment