From: Nguyen Thai Ngoc Duy <pclouds@gmail.com>
To: Christian Couder <chriscool@tuxfamily.org>
Cc: git <git@vger.kernel.org>
Subject: Re: [PATCH RFC] parse_object: pass on the original sha1, not the replaced one
Date: Tue, 3 Aug 2010 16:01:32 +1000 [thread overview]
Message-ID: <AANLkTikaPhV+SkzCJ+G3V39mS4FORELP34ePrPWbHFeV@mail.gmail.com> (raw)
In-Reply-To: <201008030700.40533.chriscool@tuxfamily.org>
On Tue, Aug 3, 2010 at 3:00 PM, Christian Couder
<chriscool@tuxfamily.org> wrote:
>> 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
next prev parent reply other threads:[~2010-08-03 6:01 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-31 12:36 [PATCH RFC] parse_object: pass on the original sha1, not the replaced one Nguyễn Thái Ngọc Duy
2010-08-02 7:42 ` Christian Couder
2010-08-02 9:31 ` Nguyen Thai Ngoc Duy
2010-08-03 5:00 ` Christian Couder
2010-08-03 6:01 ` Nguyen Thai Ngoc Duy [this message]
2010-08-04 11:58 ` Christian Couder
2010-08-04 12:42 ` Nguyen Thai Ngoc Duy
2010-08-04 12:57 ` Christian Couder
2010-08-04 22:07 ` Nguyen Thai Ngoc Duy
2010-08-05 11:41 ` Christian Couder
2010-08-07 4:03 ` Nguyen Thai Ngoc Duy
2010-08-13 3:59 ` Christian Couder
2010-08-13 9:02 ` Nguyen Thai Ngoc Duy
2010-08-14 2:03 ` Christian Couder
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AANLkTikaPhV+SkzCJ+G3V39mS4FORELP34ePrPWbHFeV@mail.gmail.com \
--to=pclouds@gmail.com \
--cc=chriscool@tuxfamily.org \
--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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).