threads / discuss / 15993

git command to read

Subject: git command to read

## tl;dr

4 messages between Oct 21, 2008 and Oct 21, 2008.

replies: 3people: 3as markdown or json

Paul Mackerras· Oct 21, 2008, 11:21 UTC · lore
Junio,

Is there a command in git at the moment that will read commit IDs on standard input and print the contents of each commit on standard output (without waiting for EOF on stdin)?

I tried git rev-list --stdin --no-walk --header, but it seems to collect all the IDs from stdin and eliminate duplicates before outputting anything, which is not what I want. What I want is a process that I can run from gitk where I can write IDs to its stdin whenever gitk needs to know the contents of some commits, and know that those contents will be turning up on the pipe from its stdout in a timely fashion, without having to start a new process each time. Is there a way to do that currently?

The reason I want this is to reduce gitk's memory usage. At present it reads all the commits into memory, which takes about 160MB on the current kernel tree just to store the contents of all the commits (since Tcl stores strings internally as 2 bytes/character). Instead I plan to make gitk keep a cache of commits and read in commits as needed from an external process. When doing a search, we may need to read in nearly all the commits, and we'll need to do it quickly.

Thanks, Paul.

Jeff King· Oct 21, 2008, 11:25 UTC · re: Paul Mackerras · lore

Re: git command to read

On Tue, Oct 21, 2008 at 10:21:09PM +1100, Paul Mackerras wrote:
> Is there a command in git at the moment that will read commit IDs on
> standard input and print the contents of each commit on standard
> output (without waiting for EOF on stdin)?
How about:
  git cat-file --batch
?

Unfortunately it just dumps the raw commit information instead of allowing the usual formatting, but perhaps that is sufficient (you asked for "contents").

-Peff
Paul Mackerras· Oct 21, 2008, 11:45 UTC · re: Jeff King · lore

Re: git command to read

Jeff King writes:
Show 15 quoted lines
> On Tue, Oct 21, 2008 at 10:21:09PM +1100, Paul Mackerras wrote:
> 
> > Is there a command in git at the moment that will read commit IDs on
> > standard input and print the contents of each commit on standard
> > output (without waiting for EOF on stdin)?
> 
> How about:
> 
>   git cat-file --batch
> 
> ?
> 
> Unfortunately it just dumps the raw commit information instead of
> allowing the usual formatting, but perhaps that is sufficient (you asked
> for "contents").
Ah, thank you, that looks like just what I want. :)
Paul.
Alexander Gavrilov· Oct 21, 2008, 12:06 UTC · re: Paul Mackerras · lore

Re: git command to read

On Tue, Oct 21, 2008 at 3:45 PM, Paul Mackerras <paulus@samba.org> wrote:
Show 19 quoted lines
> Jeff King writes:
>
>> On Tue, Oct 21, 2008 at 10:21:09PM +1100, Paul Mackerras wrote:
>>
>> > Is there a command in git at the moment that will read commit IDs on
>> > standard input and print the contents of each commit on standard
>> > output (without waiting for EOF on stdin)?
>>
>> How about:
>>
>>   git cat-file --batch
>>
>> ?
>>
>> Unfortunately it just dumps the raw commit information instead of
>> allowing the usual formatting, but perhaps that is sufficient (you asked
>> for "contents").
>
> Ah, thank you, that looks like just what I want. :)

Since cat-file does not perform any encoding conversion, you'll have to process the encoding headers manually though.

Alexander

← back to recent threads