* 'git show' with multiple revisions
@ 2015-04-28 10:10 Ed Avis
2015-04-29 2:04 ` Jeff King
0 siblings, 1 reply; 7+ messages in thread
From: Ed Avis @ 2015-04-28 10:10 UTC (permalink / raw)
To: git
I would like to see the content of a file in multiple revisions.
I can get them with 'git show' as follows:
% git show REV1:FILE
% git show REV2:FILE
and so on. But that launches a new process for each revision. Now, there is
the option to pass multiple arguments to 'git show':
% git show REV1:FILE REV2:FILE
This gets both revisions in a single process and so is faster. But it
concatenates the content so there isn't a way to separate them out again.
Could 'git show' sprout an option to get multiple things programmatically
so that they can be separated out again? One way would be to quote or escape
the contents somehow so that the result can be parsed:
% git show --porcelain REV1:FILE REV2:FILE
The question is what format should be used to output many strings to stdout.
An alternative would be to specify an output file:
% git show --output foo REV1:FILE # writes foo
% git show --output foo REV1:FILE --output bar REV2:FILE # writes foo, bar
Note that here I am only getting the file content, not log messages or any of
the other things which 'git show' can produce. So perhaps what I really want
is some kind of 'git cat'. Or is there another more appropriate tool?
Thanks,
--
Ed Avis <eda@waniasset.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: 'git show' with multiple revisions
2015-04-28 10:10 'git show' with multiple revisions Ed Avis
@ 2015-04-29 2:04 ` Jeff King
2015-04-29 15:47 ` Ed Avis
0 siblings, 1 reply; 7+ messages in thread
From: Jeff King @ 2015-04-29 2:04 UTC (permalink / raw)
To: Ed Avis; +Cc: git
On Tue, Apr 28, 2015 at 10:10:52AM +0000, Ed Avis wrote:
> Could 'git show' sprout an option to get multiple things programmatically
> so that they can be separated out again? One way would be to quote or escape
> the contents somehow so that the result can be parsed:
>
> % git show --porcelain REV1:FILE REV2:FILE
>
> [...]
>
> Note that here I am only getting the file content, not log messages or any of
> the other things which 'git show' can produce. So perhaps what I really want
> is some kind of 'git cat'. Or is there another more appropriate tool?
I think you want `git cat-file`:
{
echo REV1:FILE
echo REV2:FILE
} |
git cat-file --batch
This prints a header line for each output object which contains the size
of the object (so a parser reads a header line, then N bytes, then a
header line, N bytes, and so on).
-Peff
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: 'git show' with multiple revisions
2015-04-29 2:04 ` Jeff King
@ 2015-04-29 15:47 ` Ed Avis
2015-04-29 15:53 ` Jeff King
2015-04-29 15:53 ` Junio C Hamano
0 siblings, 2 replies; 7+ messages in thread
From: Ed Avis @ 2015-04-29 15:47 UTC (permalink / raw)
To: git
Jeff King <peff <at> peff.net> writes:
>I think you want `git cat-file`:
>
> {
> echo REV1:FILE
> echo REV2:FILE
> } |
> git cat-file --batch
>
>This prints a header line for each output object which contains the size
>of the object (so a parser reads a header line, then N bytes, then a
>header line, N bytes, and so on).
This looks like what I want but the object ids printed appear to be the id
of the file in a given revision - not the id of the revision itself.
So the ids in the output are not the same as the ones in the input.
That's fine, as long as I can assume that the output entries are in the same
order as the input?
--
Ed Avis <eda@waniasset.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: 'git show' with multiple revisions
2015-04-29 15:47 ` Ed Avis
@ 2015-04-29 15:53 ` Jeff King
2015-04-29 15:53 ` Junio C Hamano
1 sibling, 0 replies; 7+ messages in thread
From: Jeff King @ 2015-04-29 15:53 UTC (permalink / raw)
To: Ed Avis; +Cc: git
On Wed, Apr 29, 2015 at 03:47:33PM +0000, Ed Avis wrote:
> Jeff King <peff <at> peff.net> writes:
>
> >I think you want `git cat-file`:
> >
> > {
> > echo REV1:FILE
> > echo REV2:FILE
> > } |
> > git cat-file --batch
> >
> >This prints a header line for each output object which contains the size
> >of the object (so a parser reads a header line, then N bytes, then a
> >header line, N bytes, and so on).
>
> This looks like what I want but the object ids printed appear to be the id
> of the file in a given revision - not the id of the revision itself.
> So the ids in the output are not the same as the ones in the input.
Correct. You are feeding a name which resolves to the blob sha1, so
that's what cat-file will output for the object id.
> That's fine, as long as I can assume that the output entries are in the same
> order as the input?
Yes, it will process and output them in order.
-Peff
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: 'git show' with multiple revisions
2015-04-29 15:47 ` Ed Avis
2015-04-29 15:53 ` Jeff King
@ 2015-04-29 15:53 ` Junio C Hamano
2015-04-29 16:01 ` Ed Avis
1 sibling, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2015-04-29 15:53 UTC (permalink / raw)
To: Ed Avis; +Cc: git
Ed Avis <eda@waniasset.com> writes:
> Jeff King <peff <at> peff.net> writes:
>
>>I think you want `git cat-file`:
>>
>> {
>> echo REV1:FILE
>> echo REV2:FILE
>> } |
>> git cat-file --batch
>>
>>This prints a header line for each output object which contains the size
>>of the object (so a parser reads a header line, then N bytes, then a
>>header line, N bytes, and so on).
>
> This looks like what I want but the object ids printed appear to be the id
> of the file in a given revision - not the id of the revision itself.
> So the ids in the output are not the same as the ones in the input.
Actually you are asking for REV1:FILE and REV2:FILE, and you are
getting these object IDs in the output (you are not asking for REV1
or REV2 henace you will not see these commit object IDs).
"cat-file --batch" will give you the objects in the order you ask.
I _think_ you can even do that interactively (i.e. you spawn the
process, you feed one object name to its input, you consume its
output by reading the header and then given number of bytes, and
then you feed the next object name to its input, and so on) without
deadlocking yourself.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: 'git show' with multiple revisions
2015-04-29 15:53 ` Junio C Hamano
@ 2015-04-29 16:01 ` Ed Avis
2015-04-29 16:08 ` Junio C Hamano
0 siblings, 1 reply; 7+ messages in thread
From: Ed Avis @ 2015-04-29 16:01 UTC (permalink / raw)
To: git
Junio C Hamano <gitster <at> pobox.com> writes:
>"cat-file --batch" will give you the objects in the order you ask.
Thanks, that makes it easy to deal with. In fact, I might prefer to use
git cat-file --batch-check and then use some other library to fetch the blob
contents.
--
Ed Avis <eda@waniasset.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: 'git show' with multiple revisions
2015-04-29 16:01 ` Ed Avis
@ 2015-04-29 16:08 ` Junio C Hamano
0 siblings, 0 replies; 7+ messages in thread
From: Junio C Hamano @ 2015-04-29 16:08 UTC (permalink / raw)
To: Ed Avis; +Cc: git
Ed Avis <eda@waniasset.com> writes:
> Junio C Hamano <gitster <at> pobox.com> writes:
>
>>"cat-file --batch" will give you the objects in the order you ask.
>
> Thanks, that makes it easy to deal with. In fact, I might prefer to use
> git cat-file --batch-check and then use some other library to fetch the blob
> contents.
If all you need is a translation from extended SHA-1 object name
like HEAD~243:Documentation/README to the raw 40-hex object name,
"rev-parse" may turn out to be more suitable tool than that.
It of course depends on your use case.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2015-04-29 16:08 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-28 10:10 'git show' with multiple revisions Ed Avis
2015-04-29 2:04 ` Jeff King
2015-04-29 15:47 ` Ed Avis
2015-04-29 15:53 ` Jeff King
2015-04-29 15:53 ` Junio C Hamano
2015-04-29 16:01 ` Ed Avis
2015-04-29 16:08 ` Junio C Hamano
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 NNTP newsgroup(s).