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 -- 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