From: Jeff King <peff@peff.net>
To: "\"Peter Valdemar Mørch (Lists)\"" <4ux6as402@sneakemail.com>
Cc: git@vger.kernel.org
Subject: Re: How to fix (and find) many git-* --check errors?
Date: Fri, 8 Aug 2008 09:23:26 -0400 [thread overview]
Message-ID: <20080808132326.GC19705@sigill.intra.peff.net> (raw)
In-Reply-To: <489C40BC.8000008@sneakemail.com>
On Fri, Aug 08, 2008 at 02:49:00PM +0200, "Peter Valdemar Mørch (Lists)" wrote:
> (The diff between "the empty commit" and HEAD - well between the first
> commit and HEAD anyway. Is there a ref for "totally empty" or the
> revision before the first commit? Or a more elegant way to get this
> list?)
It is not advertised, but we always recognize the empty sha1 of the
empty tree:
git diff --check 4b825dc642cb6eb9a060e54bf8d69288fbee4904
In fact, just the other day I was using this for the Nth time and got
tired of looking it up in the code, so I wrote the patch below. I don't
know if it is too crazy to be included in mainline git (it was discussed
a long time ago, but I think the general response was "what would it be
good for?").
---
cache.h | 4 ++++
refs.c | 4 ++++
sha1_file.c | 3 +--
3 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/cache.h b/cache.h
index 30f1d62..4aa02ae 100644
--- a/cache.h
+++ b/cache.h
@@ -567,6 +567,10 @@ static inline unsigned int hexval(unsigned char c)
#define MINIMUM_ABBREV 4
#define DEFAULT_ABBREV 7
+#define EMPTY_TREE_SHA1 \
+ "\x4b\x82\x5d\xc6\x42\xcb\x6e\xb9\xa0\x60" \
+ "\xe5\x4b\xf8\xd6\x92\x88\xfb\xee\x49\x04"
+
extern int get_sha1(const char *str, unsigned char *sha1);
extern int get_sha1_with_mode(const char *str, unsigned char *sha1, unsigned *mode);
extern int get_sha1_hex(const char *hex, unsigned char *sha1);
diff --git a/refs.c b/refs.c
index 39a3b23..0acbcbc 100644
--- a/refs.c
+++ b/refs.c
@@ -427,6 +427,10 @@ const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *
}
list = list->next;
}
+ if (!strcmp(ref, "EMPTY")) {
+ hashcpy(sha1, (unsigned char *)EMPTY_TREE_SHA1);
+ return ref;
+ }
if (reading || errno != ENOENT)
return NULL;
hashclr(sha1);
diff --git a/sha1_file.c b/sha1_file.c
index 2aff59b..38aad13 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1985,8 +1985,7 @@ 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",
+ EMPTY_TREE_SHA1,
OBJ_TREE,
"",
0
--
1.6.0.rc1.260.g4782
next prev parent reply other threads:[~2008-08-08 13:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-08 12:49 How to fix (and find) many git-* --check errors? "Peter Valdemar Mørch (Lists)"
2008-08-08 13:23 ` Jeff King [this message]
2008-08-08 13:28 ` Björn Steinbrink
2008-08-08 14:57 ` "Peter Valdemar Mørch (Lists)"
2008-08-08 19:27 ` Junio C Hamano
2008-08-09 7:28 ` "Peter Valdemar Mørch (Lists)"
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=20080808132326.GC19705@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=4ux6as402@sneakemail.com \
--cc=git@vger.kernel.org \
/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).