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

Re: [PATCH v3] Document pack v4 format

From
Nicolas Pitre <nico@fluxnic.net>
Date
Sep 7, 2013, 04:52 UTC
Message-ID
<alpine.LFD.2.03.1309070043420.20709@syhkavp.arg>
In-Reply-To
<1378433643-15638-1-git-send-email-pclouds@gmail.com>
On Fri, 6 Sep 2013, Nguyễn Thái Ngọc Duy wrote:
Show 8 quoted lines
> 
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  Should be up to date with Nico's latest implementation and also cover
>  additions to the format that everybody seems to agree on:
> 
>   - new types for canonical trees and commits
>   - sha-1 table covering missing objects in thin packs

Yes, I've tweaked the format again. I've implemented the code needed to carry canonical commit and tree objects in pack v4. And things are much simpler if the canonical commit and tree types are identical to pack v2. Therefore the new types are used for the pack v4 optimized commit and tree representations.

I've therefore added this patch to my tree (with the needed changes to the documentation patch):

commit 98d4b75aff266015b5dff0a324a2984c2a8f7fa2
Author: Nicolas Pitre <nico@fluxnic.net>
Date:   Fri Sep 6 23:45:49 2013 -0400
    pack v4: allow canonical commit and tree objects
    
    If for some reason we can't transcode a commit or tree object (lossy
    encoding such as the zero-padded file mode for example) then we can still
    store the canonical object like in pack v2.
    
    This is also useful for completing a thin pack without having to add
    missing entries to the dictionary tables.
    
    To simplify things, the canonical commit and tree types retain their type
    number 1 and 2 respectively, and the transcoded types are now 9 and 10
    i.e. with bit 3 added.
    
    Signed-off-by: Nicolas Pitre <nico@fluxnic.net>
diff --git a/cache.h b/cache.h
index a6d016b..b68ad5a 100644
--- a/cache.h
+++ b/cache.h
@@ -330,6 +330,8 @@ enum object_type {
 	/* 5 for future expansion */
 	OBJ_OFS_DELTA = 6,
 	OBJ_REF_DELTA = 7,
+	OBJ_PV4_COMMIT = (8 + 1),
+	OBJ_PV4_TREE = (8 + 2),
 	OBJ_ANY,
 	OBJ_MAX
 };
diff --git a/packv4-create.c b/packv4-create.c
index 11cfe6f..38fa594 100644
--- a/packv4-create.c
+++ b/packv4-create.c
@@ -981,10 +981,15 @@ static off_t packv4_write_object(struct sha1file *f, struct packed_git *p,
 		die("unexpected object type %d", type);
 	}
 	free(src);
-	if (!result)
-		die("can't convert %s object %s",
-		    typename(type), sha1_to_hex(obj->sha1));
+	if (!result) {
+		warning("can't convert %s object %s",
+			typename(type), sha1_to_hex(obj->sha1));
+		/* fall back to copy the object in its original form */
+		return copy_object_data(f, p, obj->offset);
+	}
 
+	/* Use bit 3 to indicate a special type encoding */
+	type += 8;
 	hdrlen = write_object_header(f, type, obj_size);
 	sha1write(f, result, buf_size);
 	free(result);
diff --git a/packv4-parse.c b/packv4-parse.c
index 86ec535..63bba03 100644
--- a/packv4-parse.c
+++ b/packv4-parse.c
@@ -266,7 +266,7 @@ static int decode_entries(struct packed_git *p, struct pack_window **w_curs,
 			if (++scp - src >= avail - 20)
 				return -1;
 		/* let's still make sure this is actually a tree */
-		if ((*scp++ & 0xf) != OBJ_TREE)
+		if ((*scp++ & 0xf) != OBJ_PV4_TREE)
 			return -1;
 	}
 
diff --git a/sha1_file.c b/sha1_file.c
index 79e1293..c7bf677 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1806,6 +1806,11 @@ static enum object_type packed_to_object_type(struct packed_git *p,
 	}
 
 	switch (type) {
+	case OBJ_PV4_COMMIT:
+	case OBJ_PV4_TREE:
+		/* hide pack v4 special object types */
+		type -= 8;
+		break;
 	case OBJ_BAD:
 	case OBJ_COMMIT:
 	case OBJ_TREE:
@@ -2171,17 +2176,16 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset,
 		if (data)
 			die("BUG in unpack_entry: left loop at a valid delta");
 		break;
+	case OBJ_PV4_COMMIT:
+		data = pv4_get_commit(p, &w_curs, curpos, size);
+		type -= 8;
+		break;
+	case OBJ_PV4_TREE:
+		data = pv4_get_tree(p, &w_curs, curpos, size);
+		type -= 8;
+		break;
 	case OBJ_COMMIT:
 	case OBJ_TREE:
-		if (p->version >= 4 && !base_from_cache) {
-			if (type == OBJ_COMMIT) {
-				data = pv4_get_commit(p, &w_curs, curpos, size);
-			} else {
-				data = pv4_get_tree(p, &w_curs, curpos, size);
-			}
-			break;
-		}
-		/* fall through */
 	case OBJ_BLOB:
 	case OBJ_TAG:
 		if (!base_from_cache)
Previous: Nicolas PitreNext: Duy Nguyen
Message 76 of 83 in “Preliminary pack v4 support”
  1. 00/23 Preliminary pack v4 supportNicolas Pitre, Aug 27, 2013
  2. 01/23 pack v4: initial pack dictionary structure and codeNicolas Pitre, Aug 27, 2013
  3. Junio C HamanoAug 27, 2013
  4. Nicolas PitreAug 27, 2013
  5. 02/23 export packed_object_info()Nicolas Pitre, Aug 27, 2013
  6. 03/23 pack v4: scan tree objectsNicolas Pitre, Aug 27, 2013
  7. 04/23 pack v4: add tree entry mode support to dictionary entriesNicolas Pitre, Aug 27, 2013
  8. 05/23 pack v4: add commit object parsingNicolas Pitre, Aug 27, 2013
  9. Junio C HamanoAug 27, 2013
  10. Nicolas PitreAug 27, 2013
  11. Junio C HamanoAug 27, 2013
  12. 06/23 pack v4: split the object list and dictionary creationNicolas Pitre, Aug 27, 2013
  13. 07/23 pack v4: move to struct pack_idx_entry and get rid of our own struct idx_entryNicolas Pitre, Aug 27, 2013
  14. 08/23 pack v4: basic references encodingNicolas Pitre, Aug 27, 2013
  15. Junio C HamanoAug 27, 2013
  16. Nicolas PitreAug 27, 2013
  17. 09/23 pack v4: commit object encodingNicolas Pitre, Aug 27, 2013
  18. Junio C HamanoAug 27, 2013
  19. Nicolas PitreAug 27, 2013
  20. Nicolas PitreAug 27, 2013
  21. Junio C HamanoAug 27, 2013
  22. Nicolas PitreAug 27, 2013
  23. Duy NguyenSep 2, 2013
  24. Nicolas PitreSep 3, 2013
  25. Duy NguyenSep 3, 2013
  26. Nicolas PitreSep 5, 2013
  27. 10/23 pack v4: tree object encodingNicolas Pitre, Aug 27, 2013
  28. Junio C HamanoAug 27, 2013
  29. Nicolas PitreAug 27, 2013
  30. 11/23 pack v4: dictionary table outputNicolas Pitre, Aug 27, 2013
  31. 12/23 pack v4: creation codeNicolas Pitre, Aug 27, 2013
  32. Junio C HamanoAug 27, 2013
  33. Nicolas PitreAug 27, 2013
  34. 13/23 pack v4: object headersNicolas Pitre, Aug 27, 2013
  35. 14/23 pack v4: object data copyNicolas Pitre, Aug 27, 2013
  36. Junio C HamanoAug 27, 2013
  37. Nicolas PitreAug 27, 2013
  38. 15/23 pack v4: object writingNicolas Pitre, Aug 27, 2013
  39. 16/23 pack v4: tree object delta encodingNicolas Pitre, Aug 27, 2013
  40. 17/23 pack v4: load delta candidate for encoding tree objectsNicolas Pitre, Aug 27, 2013
  41. 18/23 pack v4: honor pack.compression config optionNicolas Pitre, Aug 27, 2013
  42. 19/23 pack v4: relax commit parsing a bitNicolas Pitre, Aug 27, 2013
  43. 20/23 pack index v3Nicolas Pitre, Aug 27, 2013
  44. 21/23 pack v4: normalize pack name to properly generate the pack index file nameNicolas Pitre, Aug 27, 2013
  45. 22/23 pack v4: add progress displayNicolas Pitre, Aug 27, 2013
  46. 23/23 initial pack index v3 support on the read sideNicolas Pitre, Aug 27, 2013
  47. Duy NguyenAug 31, 2013
  48. Nicolas PitreSep 3, 2013
  49. Duy NguyenSep 3, 2013
  50. Document pack v4 formatNguyễn Thái Ngọc Duy, Aug 27, 2013
  51. Junio C HamanoAug 27, 2013
  52. Nicolas PitreAug 27, 2013
  53. Document pack v4 formatNguyễn Thái Ngọc Duy, Aug 31, 2013
  54. Nicolas PitreSep 3, 2013
  55. Nicolas PitreSep 3, 2013
  56. Duy NguyenSep 3, 2013
  57. Duy NguyenSep 3, 2013
  58. Nicolas PitreSep 5, 2013
  59. Duy NguyenSep 5, 2013
  60. Nicolas PitreSep 5, 2013
  61. Duy NguyenSep 5, 2013
  62. Nicolas PitreSep 5, 2013
  63. Duy NguyenSep 5, 2013
  64. Nicolas PitreSep 5, 2013
  65. Junio C HamanoSep 5, 2013
  66. Nicolas PitreSep 5, 2013
  67. Duy NguyenSep 6, 2013
  68. Nicolas PitreSep 6, 2013
  69. Document pack v4 formatNguyễn Thái Ngọc Duy, Sep 6, 2013
  70. Nicolas PitreSep 6, 2013
  71. Duy NguyenSep 6, 2013
  72. Nicolas PitreSep 6, 2013
  73. Duy NguyenSep 6, 2013
  74. Nicolas PitreSep 6, 2013
  75. Nicolas PitreSep 7, 2013
  76. Nicolas PitreSep 7, 2013
  77. Duy NguyenSep 7, 2013
  78. Junio C HamanoAug 27, 2013
  79. Nicolas PitreAug 27, 2013
  80. Junio C HamanoAug 27, 2013
  81. Duy NguyenAug 28, 2013
  82. Nicolas PitreAug 28, 2013
  83. Duy NguyenAug 28, 2013

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.