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

[PATCH 1/2] pack-format.txt: define "varint" format

From
MÅMartin Ågren <martin.agren@gmail.com>
Date
Dec 21, 2020, 07:54 UTC
Message-ID
<42c6206b102cd97290fd9ad207bb39b20660064c.1608537234.git.martin.agren@gmail.com>
In-Reply-To
<cover.1608537234.git.martin.agren@gmail.com>

We define our varint format pretty much on the fly as we describe a pack file entry. In preparation for referring to it in more places in this document, define "varint" and refer to it.

Signed-off-by: Martin Ågren <martin.agren@gmail.com>
---
 Documentation/technical/pack-format.txt | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/Documentation/technical/pack-format.txt b/Documentation/technical/pack-format.txt
index f96b2e605f..42198de74c 100644
--- a/Documentation/technical/pack-format.txt
+++ b/Documentation/technical/pack-format.txt
@@ -55,6 +55,15 @@ Valid object types are:
 
 Type 5 is reserved for future expansion. Type 0 is invalid.
 
+=== Variable-length integer encoding
+
+This document uses "varint" encoding of non-negative integers: From
+each byte, the seven least significant bits are used to form the
+resulting integer. As long as the most significant bit is 1, this
+process continues; the byte with MSB 0 provides the last seven bits.
+The seven-bit chunks are concatenated. Later values are more
+significant.
+
 === Deltified representation
 
 Conceptually there are only four object types: commit, tree, tag and
@@ -196,10 +205,10 @@ Pack file entry: <+
 	1-byte size extension bit (MSB)
 	       type (next 3 bit)
 	       size0 (lower 4-bit)
-        n-byte sizeN (as long as MSB is set, each 7-bit)
-		size0..sizeN form 4+7+7+..+7 bit integer, size0
-		is the least significant part, and sizeN is the
-		most significant part.
+        n-byte size1 (varint encoding; present if MSB is set)
+        If the MSB is set, the size is size0 + 16*size1, otherwise
+        it is size0. (Equivalently, the entire packed object header
+        is a varint encoding of (size/16)*128 + type*16 + size%16.)
      packed object data:
         If it is not DELTA, then deflated bytes (the size above
 		is the size before compression).
-- 
2.30.0.rc1
Previous: Martin ÅgrenNext: Junio C Hamano
Message 3 of 8 in “Documentation errors for HTTP protocol v2 and packfile”
  1. Ross LightDec 19, 2020
  2. 0/2 pack-format.txt: document lengths at start of delta dataMartin Ågren, Dec 21, 2020
  3. 1/2 pack-format.txt: define "varint" formatMartin Ågren, Dec 21, 2020
  4. Junio C HamanoDec 21, 2020
  5. Martin ÅgrenDec 29, 2020
  6. 2/2 pack-format.txt: document lengths at start of delta dataMartin Ågren, Dec 21, 2020
  7. Ross LightDec 23, 2020
  8. pack-format.txt: document sizes at start of delta dataMartin Ågren, Dec 29, 2020

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.