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

Re: [PATCH RFC] parse_object: pass on the original sha1, not the replaced one

From
Nguyen Thai Ngoc Duy <pclouds@gmail.com>
Date
Aug 3, 2010, 06:01 UTC
Message-ID
<AANLkTikaPhV+SkzCJ+G3V39mS4FORELP34ePrPWbHFeV@mail.gmail.com>
In-Reply-To
<201008030700.40533.chriscool@tuxfamily.org>

On Tue, Aug 3, 2010 at 3:00 PM, Christian Couder <chriscool@tuxfamily.org> wrote:

Show 9 quoted lines
>> With parse_object(A), I get an object pointer whose sha1 is B.
>>
>> With  lookup_commit(A), I get an object pointer whose sha1 is A.
>
> Maybe there is a bug somewhere and you should get an object pointer whose sha1
> is B or maybe the content of the object that was inserted in the lookup table
> should have been the content from A and not from B. I will try to have a
> deeper look at that, but it would help if you could give an example of a
> command that triggers this behavior.
The following patch add "sha1" command. These commands give different sha1:

git sha1 `git rev-parse HEAD` `git rev-parse HEAD^` A git sha1 `git rev-parse HEAD` `git rev-parse HEAD^` B

(hopefully gmail won't break the patch, otherwise I'll resend to you privately)
diff --git a/Makefile b/Makefile
index f33648d..8556c65 100644
--- a/Makefile
+++ b/Makefile
@@ -649,6 +649,7 @@ LIB_OBJS += ws.o
 LIB_OBJS += wt-status.o
 LIB_OBJS += xdiff-interface.o

+BUILTIN_OBJS += builtin/sha1.o
 BUILTIN_OBJS += builtin/add.o
 BUILTIN_OBJS += builtin/annotate.o
 BUILTIN_OBJS += builtin/apply.o
diff --git a/builtin/sha1.c b/builtin/sha1.c
new file mode 100644
index 0000000..4700bc0
--- /dev/null
+++ b/builtin/sha1.c
@@ -0,0 +1,21 @@
+#include "cache.h"
+#include "commit.h"
+
+int cmd_sha1(int argc, char **argv)
+{
+	unsigned char old[20];
+	unsigned char new[20];
+	struct object *obj;
+
+	get_sha1_hex(argv[1], old);
+	get_sha1_hex(argv[2], new);
+	printf("old  = %s\nnew  = %s\n", argv[1], argv[2]);
+	replace_pair(old, new);
+	if (argv[3][0] == 'A')
+		obj = parse_object(old);
+	else
+		obj = lookup_commit(old);
+
+	printf("sha1 = %s\n", sha1_to_hex(obj->sha1));
+	return 0;
+}
diff --git a/git.c b/git.c
index f37028b..9bc2391 100644
--- a/git.c
+++ b/git.c
@@ -288,6 +288,7 @@ static int run_builtin(struct cmd_struct *p, int
argc, const char **argv)
 	return 0;
 }

+int cmd_sha1(int, const char **, const char*);
 static void handle_internal_command(int argc, const char **argv)
 {
 	const char *cmd = argv[0];
@@ -378,6 +379,7 @@ static void handle_internal_command(int argc,
const char **argv)
 		{ "revert", cmd_revert, RUN_SETUP | NEED_WORK_TREE },
 		{ "rm", cmd_rm, RUN_SETUP },
 		{ "send-pack", cmd_send_pack, RUN_SETUP },
+		{ "sha1", cmd_sha1, RUN_SETUP },
 		{ "shortlog", cmd_shortlog, USE_PAGER },
 		{ "show-branch", cmd_show_branch, RUN_SETUP },
 		{ "show", cmd_show, RUN_SETUP | USE_PAGER },
diff --git a/replace_object.c b/replace_object.c
index eb59604..1ec5df7 100644
--- a/replace_object.c
+++ b/replace_object.c
@@ -50,6 +50,16 @@ static int register_replace_object(struct
replace_object *replace,
 	return 0;
 }

+int replace_pair(const unsigned char *old,
+		 const unsigned char *new)
+{
+	struct replace_object *ro = xmalloc(sizeof(*ro));
+	hashcpy(ro->sha1[0],old);
+	hashcpy(ro->sha1[1],new);
+	register_replace_object(ro, 1);
+	return 0;
+}
+
 static int register_replace_ref(const char *refname,
 				const unsigned char *sha1,
 				int flag, void *cb_data)
-- 
Duy
Previous: Christian CouderNext: Christian Couder
Message 5 of 14 in “parse_object: pass on the original sha1, not the replaced one”
  1. parse_object: pass on the original sha1, not the replaced oneNguyễn Thái Ngọc Duy, Jul 31, 2010
  2. Christian CouderAug 2, 2010
  3. Nguyen Thai Ngoc DuyAug 2, 2010
  4. Christian CouderAug 3, 2010
  5. Nguyen Thai Ngoc DuyAug 3, 2010
  6. Christian CouderAug 4, 2010
  7. Nguyen Thai Ngoc DuyAug 4, 2010
  8. Christian CouderAug 4, 2010
  9. Nguyen Thai Ngoc DuyAug 4, 2010
  10. Christian CouderAug 5, 2010
  11. Nguyen Thai Ngoc DuyAug 7, 2010
  12. Christian CouderAug 13, 2010
  13. Nguyen Thai Ngoc DuyAug 13, 2010
  14. Christian CouderAug 14, 2010

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.