From: Jeff King <peff@peff.net>
To: "Rhodes, Kate" <masukomi@gmail.com>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH] add--interactive: handle initial commit better
Date: Wed, 13 Feb 2008 06:25:04 -0500 [thread overview]
Message-ID: <20080213112504.GA26627@coredump.intra.peff.net> (raw)
In-Reply-To: <20080213105051.GA26522@coredump.intra.peff.net>
On Wed, Feb 13, 2008 at 05:50:51AM -0500, Jeff King wrote:
> And here it is. I think this is a more sane approach in general than the
> last patch. The only ugly thing is the empty tree hack, but that can be
> addressed with a patch to allow referencing the empty tree without it
> existing in the object db.
And this patch hard-codes the empty tree. I _think_ this shouldn't cause
us any problems, as it just reuses the existing pretend_sha1_file
infrastructure. However that infrastructure is very rarely used.
This patch also contains the matching fix to git-add--interactive (on
top of my last patch). They should probably just be squashed together,
but I can submit a cleaned up 2-patch series if people agree that this
is a good idea.
-- >8 --
hard-code the empty tree object
Now any commands may reference the empty tree object by its
sha1 (4b825dc642cb6eb9a060e54bf8d69288fbee4904). This is
useful for showing some diffs, especially for initial
commits.
Signed-off-by: Jeff King <peff@peff.net>
---
git-add--interactive.perl | 13 ++-----------
sha1_file.c | 11 +++++++++++
2 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index bae631e..a0a81f1 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -91,17 +91,8 @@ my $status_head = sprintf($status_fmt, 'staged', 'unstaged', 'path');
}
}
-{
- my $sha1;
- sub get_empty_tree {
- if (!$sha1) {
- local $ENV{GIT_INDEX_FILE} = "$GIT_DIR/empty_index";
- $sha1 = run_cmd_pipe(qw(git write-tree));
- chomp $sha1;
- unlink($ENV{GIT_INDEX_FILE});
- }
- return $sha1;
- }
+sub get_empty_tree {
+ return '4b825dc642cb6eb9a060e54bf8d69288fbee4904';
}
# Returns list of hashes, contents of each of which are:
diff --git a/sha1_file.c b/sha1_file.c
index 4179949..1a6c7c8 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1845,6 +1845,15 @@ static struct cached_object {
} *cached_objects;
static int cached_object_nr, cached_object_alloc;
+static struct cached_object empty_tree = {
+ /* empty tree sha1: 4b825dc642cb6eb9a060e54bf8d69288fbee4904 */
+ "\x4b\x82\x5d\xc6\x42\xcb\x6e\xb9\xa0\x60"
+ "\xe5\x4b\xf8\xd6\x92\x88\xfb\xee\x49\x04",
+ OBJ_TREE,
+ "",
+ 0
+};
+
static struct cached_object *find_cached_object(const unsigned char *sha1)
{
int i;
@@ -1854,6 +1863,8 @@ static struct cached_object *find_cached_object(const unsigned char *sha1)
if (!hashcmp(co->sha1, sha1))
return co;
}
+ if (!hashcmp(sha1, empty_tree.sha1))
+ return &empty_tree;
return NULL;
}
--
1.5.4.1.1297.g3482b-dirty
next prev parent reply other threads:[~2008-02-13 11:25 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-12 0:59 [Bug] git add -i fails in multiple ways prior to first commit Rhodes, Kate
2008-02-13 10:16 ` Jeff King
2008-02-13 10:23 ` Jakub Narebski
2008-02-13 10:37 ` Jeff King
2008-02-13 10:50 ` [PATCH] add--interactive: handle initial commit better Jeff King
2008-02-13 11:25 ` Jeff King [this message]
2008-02-13 12:19 ` Johannes Schindelin
2008-02-13 13:11 ` Jakub Narebski
2008-02-13 13:15 ` Jeff King
2008-02-13 13:22 ` Johannes Schindelin
2008-02-13 13:45 ` Johannes Schindelin
2008-02-13 11:30 ` [Bug] git add -i fails in multiple ways prior to first commit Junio C Hamano
2008-02-13 11:34 ` 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=20080213112504.GA26627@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=masukomi@gmail.com \
/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).