Skip to contentSkip to conversation

Store peeled refs in packed-refs (take 2).

PATCH In review Junio C Hamano 2 participants 3 messages Aug 11, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Store peeled refs in packed-refs (take 2).

This fixes the previous implementation which failed to optimize repositories with tons of lightweight tags. The updated packed-refs format begins with "# packed-refs with:" line that lists the kind of extended data the file records. Currently, there is only one such extension defined, "peeled". This stores the "peeled tag" on a line that immediately follows a line for a tag object itself in the format "^<sha-1>".

The header line itself and any extended data are ignored by older implementation, so packed-refs file generated with this version can still be used by older git. packed-refs made by older git can of course be used with this version.

---
 builtin-pack-refs.c |    8 +++-
 builtin-show-ref.c  |    6 ++-
 refs.c              |  111 +++++++++++++++++++++++++++++---------------------
 refs.h              |    7 +--
 4 files changed, 77 insertions(+), 55 deletions(-)
builtin-pack-refs.c +6 -2
index ee5a556..8dc5b9e 100644
@@ -46,8 +46,8 @@ static int handle_one_ref(const char *pa
 		if (o->type == OBJ_TAG) {
 			o = deref_tag(o, path, 0);
 			if (o)
-				fprintf(cb->refs_file, "%s  %s^{}\n",
-					sha1_to_hex(o->sha1), path);
+				fprintf(cb->refs_file, "^%s\n",
+					sha1_to_hex(o->sha1));
 		}
 	}
 
@@ -111,6 +111,10 @@ int cmd_pack_refs(int argc, const char *
 	if (!cbdata.refs_file)
 		die("unable to create ref-pack file structure (%s)",
 		    strerror(errno));
+
+	/* perhaps other traits later as well */
+	fprintf(cbdata.refs_file, "# pack-refs with: peeled \n");
+
 	for_each_ref(handle_one_ref, &cbdata);
 	fflush(cbdata.refs_file);
 	fsync(fd);
builtin-show-ref.c +4 -2
index 9ae3d08..0739798 100644
@@ -67,8 +67,10 @@ match:
 		return 0;
 
 	if ((flag & REF_ISPACKED) && !peel_ref(refname, peeled)) {
-		hex = find_unique_abbrev(peeled, abbrev);
-		printf("%s %s^{}\n", hex, refname);
+		if (!is_null_sha1(peeled)) {
+			hex = find_unique_abbrev(peeled, abbrev);
+			printf("%s %s^{}\n", hex, refname);
+		}
 	}
 	else {
 		obj = parse_object(sha1);
refs.c +64 -47

204 lines not on this page · raw message

refs.h +3 -4
index 40048a6..cd1e1d6 100644
@@ -10,14 +10,13 @@ struct ref_lock {
 	int force_write;
 };
 
+#define REF_ISSYMREF 01
+#define REF_ISPACKED 02
+
 /*
  * Calls the specified function for each ref file until it returns nonzero,
  * and returns the value
  */
-#define REF_ISSYMREF 01
-#define REF_ISPACKED 02
-#define REF_ISPEELED 04 /* internal use */
-
 typedef int each_ref_fn(const char *refname, const unsigned char *sha1, int flags, void *cb_data);
 extern int head_ref(each_ref_fn, void *);
 extern int for_each_ref(each_ref_fn, void *);
Signature · 1 line
1.4.4.g26805
#1 lore raw
Quoted 4 lines · Junio C Hamano

there is only one such extension defined, "peeled". This stores the "peeled tag" on a line that immediately follows a line for a tag object itself in the format "^<sha-1>".

Thanks, I will try to do some performance tests this week end.

#2 lore raw
Quoted 8 lines · Marco Costalba
Quoted 4 lines · Junio C Hamano

there is only one such extension defined, "peeled". This stores the "peeled tag" on a line that immediately follows a line for a tag object itself in the format "^<sha-1>".

Thanks, I will try to do some performance tests this week end.

Cold cache tests with "git show-ref -d" on packed refs (after "git-pack-refs --prune")

Before patch:

- git tree 2374ms
- linux tree 2225ms

After patch:

- git tree 1108ms