# git command to read

4 messages from 2008-10-21 to 2008-10-21. Participants: Paul Mackerras, Jeff King, Alexander Gavrilov.
Thread: https://gitlist.dev/t/15993

## Paul Mackerras, 2008-10-21 11:21

Subject: git command to read
Message-ID: <18685.47909.354146.487700@cargo.ozlabs.ibm.com>
URL: https://gitlist.dev/e/18685.47909.354146.487700%40cargo.ozlabs.ibm.com

```
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, 2008-10-21 11:25

Subject: Re: git command to read
Message-ID: <20081021112521.GC17363@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20081021112521.GC17363%40coredump.intra.peff.net
In-Reply-To: <18685.47909.354146.487700@cargo.ozlabs.ibm.com>

```
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, 2008-10-21 11:45

Subject: Re: git command to read
Message-ID: <18685.49368.557513.727997@cargo.ozlabs.ibm.com>
URL: https://gitlist.dev/e/18685.49368.557513.727997%40cargo.ozlabs.ibm.com
In-Reply-To: <20081021112521.GC17363@coredump.intra.peff.net>

```
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. :)

Paul.

```

## Alexander Gavrilov, 2008-10-21 12:06

Subject: Re: git command to read
Message-ID: <bb6f213e0810210506u51cb83d4p718b793b3e9f7fca@mail.gmail.com>
URL: https://gitlist.dev/e/bb6f213e0810210506u51cb83d4p718b793b3e9f7fca%40mail.gmail.com
In-Reply-To: <18685.49368.557513.727997@cargo.ozlabs.ibm.com>

```
On Tue, Oct 21, 2008 at 3:45 PM, Paul Mackerras <paulus@samba.org> wrote:
> 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

```
