summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e33b2ef)
raw | patch | inline | side by side (parent: e33b2ef)
author | Linus Torvalds <torvalds@g5.osdl.org> | |
Tue, 12 Jul 2005 01:27:25 +0000 (18:27 -0700) | ||
committer | Linus Torvalds <torvalds@g5.osdl.org> | |
Tue, 12 Jul 2005 01:27:25 +0000 (18:27 -0700) |
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.
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.
rev-parse.c | patch | blob | history |
diff --git a/rev-parse.c b/rev-parse.c
index 4c307cd801b5c6f104e5dd517de6a3605bd94213..43af88b5a8f4414056a1a775c9d7e1de452f06c7 100644 (file)
--- a/rev-parse.c
+++ b/rev-parse.c
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) {
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--;
}