summaryrefslogtreecommitdiff
path: root/rev-parse.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@g5.osdl.org>2005-07-12 01:27:25 (GMT)
committerLinus Torvalds <torvalds@g5.osdl.org>2005-07-12 01:27:25 (GMT)
commit79162bb8ad43aefb23172b9f164ea13ac2b60744 (patch)
tree411e665b69eef158141fe511470c6f724ed4bee8 /rev-parse.c
parente33b2ef8f59a136402ae434cc743408300d69e9a (diff)
downloadgit-79162bb8ad43aefb23172b9f164ea13ac2b60744.zip
git-79162bb8ad43aefb23172b9f164ea13ac2b60744.tar.gz
git-79162bb8ad43aefb23172b9f164ea13ac2b60744.tar.bz2
git-rev-parse: Allow a "zeroth" parent of a commit - the commit itself.
This sounds nonsensical, but it's useful to make sure that the result is a commit. For example, "git-rev-parse v2.6.12" will return the _tag_ object for v2.6.12, but "git-rev-parse v2.6.12^0" will return the _commit_ object associated with that tag (and v2.6.12^1 will return the first parent). Also, since the "parent" code will actually parse the commit, this, together with the "--verify" flag, will verify not only that the result is a single SHA1, but will also have verified that it's a proper commit that we can see.
Diffstat (limited to 'rev-parse.c')
-rw-r--r--rev-parse.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/rev-parse.c b/rev-parse.c
index 4c307cd..43af88b 100644
--- a/rev-parse.c
+++ b/rev-parse.c
@@ -97,6 +97,10 @@ static int get_parent(char *name, unsigned char *result, int idx)
return -1;
if (parse_commit(commit))
return -1;
+ if (!idx) {
+ memcpy(result, commit->object.sha1, 20);
+ return 0;
+ }
p = commit->parents;
while (p) {
if (!--idx) {
@@ -238,7 +242,7 @@ static int get_extended_sha1(char *name, unsigned char *sha1)
int len = strlen(name);
parent = 1;
- if (len > 2 && name[len-1] >= '1' && name[len-1] <= '9') {
+ if (len > 2 && name[len-1] >= '0' && name[len-1] <= '9') {
parent = name[len-1] - '0';
len--;
}