On Mon, Sep 15, 2008 at 11:11:30PM +0200, Sverre Rabbelier wrote: > Some of my code uses "git rev-parse" on "HEAD^" to see if a commit has > a parent; I wouldn't be surprised if someone else has a script that > uses "git diff-tree" or such for that purpose, or at least assumes > that for a root commit it will complain. Anyway, as Junio said, for > "diff-tree" you can use the "--root" option. A better RFE would > perhaps be that "--root" be supported in more places. I posted this a week or so ago, but I am sure it is incomplete. If there is interest I can clean it up and do a proper submission. --- diff --git a/builtin-diff.c b/builtin-diff.c index 76651bd..4151900 100644 --- a/builtin-diff.c +++ b/builtin-diff.c @@ -332,8 +332,11 @@ int cmd_diff(int argc, const char **argv, const char *prefix) break; else if (!strcmp(arg, "--cached")) { add_head_to_pending(&rev); - if (!rev.pending.nr) - die("No HEAD commit to compare with (yet)"); + if (!rev.pending.nr) { + if (!rev.show_root_diff) + die("No HEAD commit to compare with (yet)"); + add_empty_to_pending(&rev); + } break; } } diff --git a/revision.c b/revision.c index 2f646de..7ec3990 100644 --- a/revision.c +++ b/revision.c @@ -145,16 +145,27 @@ void add_pending_object(struct rev_info *revs, struct object *obj, const char *n add_pending_object_with_mode(revs, obj, name, S_IFINVALID); } -void add_head_to_pending(struct rev_info *revs) +static void add_to_pending_by_name(struct rev_info *revs, const char *name) { unsigned char sha1[20]; struct object *obj; - if (get_sha1("HEAD", sha1)) + if (get_sha1(name, sha1)) return; obj = parse_object(sha1); if (!obj) return; - add_pending_object(revs, obj, "HEAD"); + add_pending_object(revs, obj, name); +} + +void add_head_to_pending(struct rev_info *revs) +{ + add_to_pending_by_name(revs, "HEAD"); +} + +void add_empty_to_pending(struct rev_info *revs) +{ + add_to_pending_by_name(revs, + "4b825dc642cb6eb9a060e54bf8d69288fbee4904"); } static struct object *get_reference(struct rev_info *revs, const char *name, const unsigned char *sha1, unsigned int flags) diff --git a/revision.h b/revision.h index 2fdb2dd..8c990d5 100644 --- a/revision.h +++ b/revision.h @@ -152,6 +152,7 @@ extern void add_object(struct object *obj, extern void add_pending_object(struct rev_info *revs, struct object *obj, const char *name); extern void add_head_to_pending(struct rev_info *); +extern void add_empty_to_pending(struct rev_info *); enum commit_action { commit_ignore, -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html