From: Jeff King <peff@peff.net>
To: sverre@rabbelier.nl
Cc: Michael J Gruber <git@drmicha.warpmail.net>,
Anatol Pomozov <anatol.pomozov@gmail.com>,
Git Mailing List <git@vger.kernel.org>
Subject: Re: Diff-tree does not work for initial commit
Date: Mon, 15 Sep 2008 18:34:43 -0400 [thread overview]
Message-ID: <20080915223442.GD20677@sigill.intra.peff.net> (raw)
In-Reply-To: <bd6139dc0809151411p49f5adeaq4beff452574ca980@mail.gmail.com>
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,
next prev parent reply other threads:[~2008-09-15 22:36 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-15 20:01 Diff-tree does not work for initial commit Anatol Pomozov
2008-09-15 20:49 ` Michael J Gruber
2008-09-15 20:54 ` Junio C Hamano
2008-09-15 21:48 ` Anatol Pomozov
2008-09-15 21:09 ` Michael J Gruber
2008-09-15 21:11 ` Sverre Rabbelier
2008-09-15 22:34 ` Jeff King [this message]
2008-09-16 6:19 ` Sverre Rabbelier
2008-09-16 6:21 ` Jeff King
2008-09-18 9:21 ` [RFC/PATCH] extend meaning of "--root" option to index comparisons Jeff King
2008-09-18 16:31 ` Anatol Pomozov
2008-09-18 16:51 ` Sverre Rabbelier
2008-09-19 14:25 ` Jeff King
2008-09-19 16:54 ` Anatol Pomozov
2008-09-19 17:39 ` Jeff King
2008-09-19 20:27 ` Re* " Junio C Hamano
2008-09-21 13:56 ` Jeff King
2008-09-21 15:58 ` Anatol Pomozov
2008-09-21 17:04 ` Jakub Narebski
2008-09-22 13:15 ` Jeff King
2008-09-21 18:48 ` Junio C Hamano
2008-09-22 13:32 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080915223442.GD20677@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=anatol.pomozov@gmail.com \
--cc=git@drmicha.warpmail.net \
--cc=git@vger.kernel.org \
--cc=sverre@rabbelier.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).