Re: [PATCH RFC] parse_object: pass on the original sha1, not the replaced one
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)
Show changes to 4 files +34 −0
Makefile, builtin/sha1.c, git.c, replace_object.c
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