git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
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: Thu, 5 Aug 2010 08:07:45 +1000	[thread overview]
Message-ID: <AANLkTimVnAO6kCAo8N6DM9GX3z+DjKJgKizdTnktyb8Q@mail.gmail.com> (raw)
In-Reply-To: <201008041457.31975.chriscool@tuxfamily.org>

[-- Attachment #1: Type: text/plain, Size: 2639 bytes --]

On Wed, Aug 4, 2010 at 10:57 PM, Christian Couder
<chriscool@tuxfamily.org> wrote:
> 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

[-- Attachment #2: sha1.c --]
[-- Type: application/octet-stream, Size: 516 bytes --]

#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);

	parse_commit((struct commit *)obj);
	printf("sha1 = %s\n", sha1_to_hex(obj->sha1));
	printf("%s\n", ((struct commit*)obj)->buffer);
	return 0;
}

  reply	other threads:[~2010-08-04 22:07 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
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 [this message]
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=AANLkTimVnAO6kCAo8N6DM9GX3z+DjKJgKizdTnktyb8Q@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).