Make "parse_commit" return the "struct revision" for the commit.
Also, make it a fatal error to pass in a non-commit object. The callers never checked, so better check here. This simplifies merge-base further. It's now so trivial that it's almost ridiculous.
This commit is contained in:
parent
6683463ed6
commit
7d60ad7cc9
@ -46,10 +46,7 @@ int main(int argc, char **argv)
|
|||||||
* That's some time off, though, and in the meantime we know
|
* That's some time off, though, and in the meantime we know
|
||||||
* that we have a solution to the eventual expense.
|
* that we have a solution to the eventual expense.
|
||||||
*/
|
*/
|
||||||
parse_commit(rev1);
|
common = common_parent(parse_commit(rev1), parse_commit(rev2));
|
||||||
parse_commit(rev2);
|
|
||||||
|
|
||||||
common = common_parent(lookup_rev(rev1), lookup_rev(rev2));
|
|
||||||
if (!common)
|
if (!common)
|
||||||
die("no common parent found");
|
die("no common parent found");
|
||||||
printf("%s\n", sha1_to_hex(common->sha1));
|
printf("%s\n", sha1_to_hex(common->sha1));
|
||||||
|
@ -129,7 +129,7 @@ static unsigned long parse_commit_date(const char *buf)
|
|||||||
return date;
|
return date;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int parse_commit(unsigned char *sha1)
|
static struct revision * parse_commit(unsigned char *sha1)
|
||||||
{
|
{
|
||||||
struct revision *rev = lookup_rev(sha1);
|
struct revision *rev = lookup_rev(sha1);
|
||||||
|
|
||||||
@ -142,7 +142,7 @@ static int parse_commit(unsigned char *sha1)
|
|||||||
rev->flags |= SEEN;
|
rev->flags |= SEEN;
|
||||||
buffer = bufptr = read_sha1_file(sha1, type, &size);
|
buffer = bufptr = read_sha1_file(sha1, type, &size);
|
||||||
if (!buffer || strcmp(type, "commit"))
|
if (!buffer || strcmp(type, "commit"))
|
||||||
return -1;
|
die("%s is not a commit object", sha1_to_hex(sha1));
|
||||||
bufptr += 46; /* "tree " + "hex sha1" + "\n" */
|
bufptr += 46; /* "tree " + "hex sha1" + "\n" */
|
||||||
while (!memcmp(bufptr, "parent ", 7) && !get_sha1_hex(bufptr+7, parent)) {
|
while (!memcmp(bufptr, "parent ", 7) && !get_sha1_hex(bufptr+7, parent)) {
|
||||||
add_relationship(rev, parent);
|
add_relationship(rev, parent);
|
||||||
@ -152,7 +152,7 @@ static int parse_commit(unsigned char *sha1)
|
|||||||
rev->date = parse_commit_date(bufptr);
|
rev->date = parse_commit_date(bufptr);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
}
|
}
|
||||||
return 0;
|
return rev;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* REVISION_H */
|
#endif /* REVISION_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user