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 4, 2010, 22:07 UTC
Message-ID
<AANLkTimVnAO6kCAo8N6DM9GX3z+DjKJgKizdTnktyb8Q@mail.gmail.com>
In-Reply-To
<201008041457.31975.chriscool@tuxfamily.org>

On Wed, Aug 4, 2010 at 10:57 PM, Christian Couder <chriscool@tuxfamily.org> wrote:

Show 71 quoted lines
> On Wednesday 04 August 2010 14:42:50 Nguyen Thai Ngoc Duy wrote:
>> On Wed, Aug 4, 2010 at 9:58 PM, Christian Couder
>>
>> <chriscool@tuxfamily.org> wrote:
>> >> > 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
>> >
>> > Yes, but that does not mean that the content of the object returned by
>> > lookup_commit(A) is not the content of A.
>> >
>> > Or do you have an example where the content of the object returned by
>> > lookup_commit(A) is not the content of A?
>>
>> Both return the content of B. I modified my patch a bit to also show
>> the content, ((struct commit*)obj)->buffer.
>
> I also modified your patch but I don't get any content shown when using
> lookup_commit()
>
> I use:
>
> diff --git a/builtin/sha1.c b/builtin/sha1.c
> new file mode 100644
> index 0000000..8e081b2
> --- /dev/null
> +++ b/builtin/sha1.c
> @@ -0,0 +1,27 @@
> +#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 {
> +              struct commit *com = lookup_commit(old);
> +              if (com->buffer)
> +                      printf("commit buffer:\n%s", com->buffer);
> +              else
> +                      printf("no commit buffer\n");
> +              obj = (struct object *)com;
> +       }
> +
> +       printf("sha1 = %s\n", sha1_to_hex(obj->sha1));
> +       return 0;
> +}
>
> and I get:
>
> $ git sha1 `git rev-parse HEAD` `git rev-parse HEAD^` B
> old  = 5b4585a035e2ba61573273dacc6d17d7e8fcbc7d
> new  = c9b402bd93105f80f3c5d67ecfccc8ba36810613
> no commit buffer
> sha1 = 5b4585a035e2ba61573273dacc6d17d7e8fcbc7d
>
> Could you show what code you use?

You need parse_commit() (unless somebody already did that before lookup_commit()).

-- 
Duy
Previous: Christian CouderNext: Christian Couder
Message 9 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.