git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] add--interactive: handle initial commit better

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Feb 13, 2008, 13:45 UTC
Message-ID
<alpine.LSU.1.00.0802131344121.30505@racer.site>
In-Reply-To
<alpine.LSU.1.00.0802131321140.30505@racer.site>
Hi,
On Wed, 13 Feb 2008, Johannes Schindelin wrote:
Show 15 quoted lines
> On Wed, 13 Feb 2008, Jakub Narebski wrote:
> 
> > Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> > 
> > > On Wed, 13 Feb 2008, Jeff King wrote:
> > > >  	}
> > > > +	if (!hashcmp(sha1, empty_tree.sha1))
> > > > +		return &empty_tree;
> > > >  	return NULL;
> > > >  }
> > > 
> > > Heh.  This is cute.  But it is also a bit hard to reference, no?  I 
> > > mean, you have to remember the SHA-1 of it...
> > > 
> > > Maybe {} ?
IOW something like this (on top of your two patches; feel free to merge):

-- snipsnap -- [PATCH] Make {} synonymous to the empty tree

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
 cache.h     |    5 +++++
 sha1_file.c |    4 +---
 sha1_name.c |    5 +++++
 3 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/cache.h b/cache.h
index f4c56fa..b71f772 100644
--- a/cache.h
+++ b/cache.h
@@ -266,6 +266,11 @@ static inline enum object_type object_type(unsigned int mode)
 #define INFOATTRIBUTES_FILE "info/attributes"
 #define ATTRIBUTE_MACRO_PREFIX "[attr]"
 
+/* empty tree sha1: 4b825dc642cb6eb9a060e54bf8d69288fbee4904 */
+#define EMPTY_TREE_SHA1 (unsigned char *)\
+	"\x4b\x82\x5d\xc6\x42\xcb\x6e\xb9\xa0\x60" \
+	"\xe5\x4b\xf8\xd6\x92\x88\xfb\xee\x49\x04"
+
 extern int is_bare_repository_cfg;
 extern int is_bare_repository(void);
 extern int is_inside_git_dir(void);
diff --git a/sha1_file.c b/sha1_file.c
index 1a6c7c8..cba629a 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1846,9 +1846,7 @@ static struct cached_object {
 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
diff --git a/sha1_name.c b/sha1_name.c
index 6cfd1f9..3a39a55 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -760,5 +760,10 @@ int get_sha1_with_mode(const char *name, unsigned char *sha1, unsigned *mode)
 			return get_tree_entry(tree_sha1, cp+1, sha1, mode);
 		}
 	}
+	if (ret && !strcmp(name, "{}")) {
+		*mode = 0755;
+		hashcpy(sha1, EMPTY_TREE_SHA1);
+		ret = 0;
+	}
 	return ret;
 }
Previous: Johannes SchindelinNext: Junio C Hamano
Message 11 of 13 in “[Bug] git add -i fails in multiple ways prior to first commit.”
  1. Rhodes, KateFeb 12, 2008
  2. Jeff KingFeb 13, 2008
  3. Jakub NarebskiFeb 13, 2008
  4. Jeff KingFeb 13, 2008
  5. add--interactive: handle initial commit betterJeff King, Feb 13, 2008
  6. Jeff KingFeb 13, 2008
  7. Johannes SchindelinFeb 13, 2008
  8. Jakub NarebskiFeb 13, 2008
  9. Jeff KingFeb 13, 2008
  10. Johannes SchindelinFeb 13, 2008
  11. Johannes SchindelinFeb 13, 2008
  12. Junio C HamanoFeb 13, 2008
  13. Jeff KingFeb 13, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.