aboutsummaryrefslogtreecommitdiff
path: root/diff-tree.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2005-04-20 18:06:50 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-20 18:06:50 -0700
commitc1fdf2a6abb6a7c5b8092d72514264ae378d60ee (patch)
treed32447a96642a513e7ba83d8c88d86a33061db78 /diff-tree.c
parent38357e6703db9f2c1bff31de1ce7c7503c6db96a (diff)
downloadgit-c1fdf2a6abb6a7c5b8092d72514264ae378d60ee.tar.gz
git-c1fdf2a6abb6a7c5b8092d72514264ae378d60ee.tar.xz
[PATCH] Teach diff-tree about commit objects
Updates diff-tree.c to use read_tree_with_tree_or_commit_sha1() function. The command can take either tree or commit IDs with this patch. Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'diff-tree.c')
-rw-r--r--diff-tree.c25
1 files changed, 4 insertions, 21 deletions
diff --git a/diff-tree.c b/diff-tree.c
index 65bb9d66c..222591936 100644
--- a/diff-tree.c
+++ b/diff-tree.c
@@ -164,14 +164,13 @@ static int diff_tree_sha1(const unsigned char *old, const unsigned char *new, co
{
void *tree1, *tree2;
unsigned long size1, size2;
- char type[20];
int retval;
- tree1 = read_sha1_file(old, type, &size1);
- if (!tree1 || strcmp(type, "tree"))
+ tree1 = read_tree_with_tree_or_commit_sha1(old, &size1, 0);
+ if (!tree1)
die("unable to read source tree (%s)", sha1_to_hex(old));
- tree2 = read_sha1_file(new, type, &size2);
- if (!tree2 || strcmp(type, "tree"))
+ tree2 = read_tree_with_tree_or_commit_sha1(new, &size2, 0);
+ if (!tree2)
die("unable to read destination tree (%s)", sha1_to_hex(new));
retval = diff_tree(tree1, size1, tree2, size2, base);
free(tree1);
@@ -179,20 +178,6 @@ static int diff_tree_sha1(const unsigned char *old, const unsigned char *new, co
return retval;
}
-static void commit_to_tree(unsigned char *sha1)
-{
- void *buf;
- char type[20];
- unsigned long size;
-
- buf = read_sha1_file(sha1, type, &size);
- if (buf) {
- if (!strcmp(type, "commit"))
- get_sha1_hex(buf+5, sha1);
- free(buf);
- }
-}
-
int main(int argc, char **argv)
{
unsigned char old[20], new[20];
@@ -214,7 +199,5 @@ int main(int argc, char **argv)
if (argc != 3 || get_sha1_hex(argv[1], old) || get_sha1_hex(argv[2], new))
usage("diff-tree <tree sha1> <tree sha1>");
- commit_to_tree(old);
- commit_to_tree(new);
return diff_tree_sha1(old, new, "");
}