aboutsummaryrefslogtreecommitdiff
path: root/sha1_name.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2008-03-15 00:05:40 -0700
committerJunio C Hamano <gitster@pobox.com>2008-03-15 00:05:40 -0700
commit2a2ad0c0007b9f79768b4564644ac9eaaa7310b6 (patch)
tree1c0d7de9a2be2891718df0a5a443af4ff51208e4 /sha1_name.c
parentfac4b328874ccf515a42e30173d0e008382ac276 (diff)
parenta0b54e7b73415f92225ddf29fe655399bafd4938 (diff)
downloadgit-2a2ad0c0007b9f79768b4564644ac9eaaa7310b6.tar.gz
git-2a2ad0c0007b9f79768b4564644ac9eaaa7310b6.tar.xz
Merge branch 'maint'
* maint: Make man page building quiet when DOCBOOK_XSL_172 is defined git-new-workdir: Share SVN meta data between work dirs and the repository rev-parse: fix meaning of rev~ vs rev~0. git-svn: don't blindly append '*' to branch/tags config
Diffstat (limited to 'sha1_name.c')
-rw-r--r--sha1_name.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/sha1_name.c b/sha1_name.c
index 8b6c76f68..491d2e7eb 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -407,18 +407,22 @@ static int get_nth_ancestor(const char *name, int len,
unsigned char *result, int generation)
{
unsigned char sha1[20];
- int ret = get_sha1_1(name, len, sha1);
+ struct commit *commit;
+ int ret;
+
+ ret = get_sha1_1(name, len, sha1);
if (ret)
return ret;
+ commit = lookup_commit_reference(sha1);
+ if (!commit)
+ return -1;
while (generation--) {
- struct commit *commit = lookup_commit_reference(sha1);
-
- if (!commit || parse_commit(commit) || !commit->parents)
+ if (parse_commit(commit) || !commit->parents)
return -1;
- hashcpy(sha1, commit->parents->item->object.sha1);
+ commit = commit->parents->item;
}
- hashcpy(result, sha1);
+ hashcpy(result, commit->object.sha1);
return 0;
}
@@ -544,9 +548,8 @@ static int get_sha1_1(const char *name, int len, unsigned char *sha1)
int ret, has_suffix;
const char *cp;
- /* "name~3" is "name^^^",
- * "name~" and "name~0" are name -- not "name^0"!
- * "name^" is not "name^0"; it is "name^1".
+ /*
+ * "name~3" is "name^^^", "name~" is "name~1", and "name^" is "name^1".
*/
has_suffix = 0;
for (cp = name + len - 1; name <= cp; cp--) {
@@ -564,11 +567,10 @@ static int get_sha1_1(const char *name, int len, unsigned char *sha1)
cp++;
while (cp < name + len)
num = num * 10 + *cp++ - '0';
- if (has_suffix == '^') {
- if (!num && len1 == len - 1)
- num = 1;
+ if (!num && len1 == len - 1)
+ num = 1;
+ if (has_suffix == '^')
return get_parent(name, len1, sha1, num);
- }
/* else if (has_suffix == '~') -- goes without saying */
return get_nth_ancestor(name, len1, sha1, num);
}