summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-05-19 20:44:29 (GMT)
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-05-19 20:44:29 (GMT)
commitdc26bd890d0a8571c38397e2ab33c0f3963c01a7 (patch)
tree87a23d545ffe40ae3be9482b8f04b68991f31371
parent667bb59b2d5b0a2e7fca5970d6f757790a6edd74 (diff)
downloadgit-dc26bd890d0a8571c38397e2ab33c0f3963c01a7.zip
git-dc26bd890d0a8571c38397e2ab33c0f3963c01a7.tar.gz
git-dc26bd890d0a8571c38397e2ab33c0f3963c01a7.tar.bz2
diff-tree: add "--root" flag to show a root commit as a big creation event.
"Let there be light"
-rw-r--r--diff-tree.c41
1 files changed, 35 insertions, 6 deletions
diff --git a/diff-tree.c b/diff-tree.c
index d3d83bd..9d94e0c 100644
--- a/diff-tree.c
+++ b/diff-tree.c
@@ -3,6 +3,7 @@
#include "diff.h"
static int silent = 0;
+static int show_root_diff = 0;
static int verbose_header = 0;
static int ignore_merges = 1;
static int recursive = 0;
@@ -294,6 +295,24 @@ static int diff_tree_sha1_top(const unsigned char *old,
return ret;
}
+static int diff_root_tree(const unsigned char *new, const char *base)
+{
+ int retval;
+ void *tree;
+ unsigned long size;
+
+ if (generate_patch)
+ diff_setup(detect_rename, 0, 0, 0, 0);
+ tree = read_object_with_reference(new, "tree", &size, 0);
+ if (!tree)
+ die("unable to read root tree (%s)", sha1_to_hex(new));
+ retval = diff_tree("", 0, tree, size, base);
+ free(tree);
+ if (generate_patch)
+ diff_flush();
+ return retval;
+}
+
static int get_one_line(const char *msg, unsigned long len)
{
int ret = 0;
@@ -372,18 +391,24 @@ static int diff_tree_commit(const unsigned char *commit, const char *name)
if (!buf)
return -1;
- /* More than one parent? */
- if (ignore_merges) {
- if (!memcmp(buf + 46 + 48, "parent ", 7))
- return 0;
- }
-
if (!name) {
static char commit_name[60];
strcpy(commit_name, sha1_to_hex(commit));
name = commit_name;
}
+ /* Root commit? */
+ if (show_root_diff && memcmp(buf + 46, "parent ", 7)) {
+ header = generate_header(name, "root", buf, size);
+ diff_root_tree(commit, "");
+ }
+
+ /* More than one parent? */
+ if (ignore_merges) {
+ if (!memcmp(buf + 46 + 48, "parent ", 7))
+ return 0;
+ }
+
offset = 46;
while (offset + 48 < size && !memcmp(buf + offset, "parent ", 7)) {
unsigned char parent[20];
@@ -485,6 +510,10 @@ int main(int argc, char **argv)
read_stdin = 1;
continue;
}
+ if (!strcmp(arg, "--root")) {
+ show_root_diff = 1;
+ continue;
+ }
usage(diff_tree_usage);
}