git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: How to determine when to stop receiving pack content

From
Farhan Khan <farhan@farhan.codes>
Date
Aug 11, 2019, 23:31 UTC
Message-ID
<53515e0fb56928114a63bfe87e24c743@farhan.codes>
In-Reply-To
<20190811150450.5pvgvwcqrrvzggbo@localhost.localdomain>
August 11, 2019 11:04 AM, "Pratyush Yadav" <me@yadavpratyush.com> wrote:
Show 39 quoted lines
> On 10/08/19 11:47PM, Farhan Khan wrote:
> 
>> Hi,
>> 
>> I am trying to write an implementation of git clone over ssh and am a little confused how to
>> determine a server response has ended. Specifically, after a client sends its requested 'want', the
>> server sends the pack content over. However, how does the client know to stop reading data? If I
>> run a simple read() of the file descriptor:
>> 
>> A. If I use reading blocking, the client will wait until new data is available, potentially
>> forever.
>> B. If I use non-blocking, the client might terminate reading for new data, when in reality new data
>> is in transit.
>> 
>> I do not see a mechanism to specify the size or to indicate the end of the pack content. Am I
>> missing something?
> 
> Well, I am not very familiar with git-clone internals, but I did some
> digging around, and I think I know what answer to your problem is.
> 
> Looking at Documentation/technical/protocol-v2.txt:34, the flush packet
> indicates the end of a message. Looking in the output section of the
> fetch command (protocol-v2.txt:342), it sends you some optional
> sections, and then the packfile and then sends a flush packet.
> 
> So your read should stop reading data when it sees the flush packet.
> 
> Another way would be to look at the packfile contents. Looking at
> Documentation/technical/pack-format.txt, the packfile contains the
> number of objects in the packfile, and each object entry has the object
> size. So you can stop reading after you have received the last object in
> the packfile (plus the 20-byte trailer).
> 
> I don't know which is the better way, but the former seems like a better
> choice to me.
> 
> --
> Regards,
> Pratyush Yadav
Hi Pratyush,
Thanks for your reply!
Unless I am mistaken, a pack file does not end in a flush_pkt. I ran some tests and did not see the stream end in "0000". Is there is a mistake somewhere on my end?

--- Farhan Khan PGP Fingerprint: 1312 89CE 663E 1EB2 179C 1C83 C41D 2281 F8DA C0DE

Previous: Pratyush YadavNext: Pratyush Yadav
Message 3 of 5 in “How to determine when to stop receiving pack content”
  1. Farhan KhanAug 10, 2019
  2. Pratyush YadavAug 11, 2019
  3. Farhan KhanAug 11, 2019
  4. Pratyush YadavAug 12, 2019
  5. Junio C HamanoAug 11, 2019

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.