Skip to content

Commit 6523078

Browse files
Nicolas Pitregitster
authored andcommitted
make shallow repository deepening more network efficient
First of all, I can't find any reason why thin pack generation is explicitly disabled when dealing with a shallow repository. The possible delta base objects are collected from the edge commits which are always obtained through history walking with the same shallow refs as the client, Therefore the client is always going to have those base objects available. So let's remove that restriction. Then we can make shallow repository deepening much more efficient by using the remote's unshallowed commits as edge commits to get preferred base objects for thin pack generation. On git.git, this makes the data transfer for the deepening of a shallow repository from depth 1 to depth 2 around 134 KB instead of 3.68 MB. Signed-off-by: Nicolas Pitre <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8638682 commit 6523078

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

upload-pack.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ static int use_thin_pack, use_ofs_delta, use_include_tag;
3131
static int no_progress;
3232
static struct object_array have_obj;
3333
static struct object_array want_obj;
34+
static struct object_array extra_edge_obj;
3435
static unsigned int timeout;
3536
/* 0 for no sideband,
3637
* otherwise maximum packet size (up to 65520 bytes).
@@ -136,6 +137,10 @@ static int do_rev_list(int fd, void *create_full_pack)
136137
if (prepare_revision_walk(&revs))
137138
die("revision walk setup failed");
138139
mark_edges_uninteresting(revs.commits, &revs, show_edge);
140+
if (use_thin_pack)
141+
for (i = 0; i < extra_edge_obj.nr; i++)
142+
fprintf(pack_pipe, "-%s\n", sha1_to_hex(
143+
extra_edge_obj.objects[i].item->sha1));
139144
traverse_commit_list(&revs, show_commit, show_object, NULL);
140145
fflush(pack_pipe);
141146
fclose(pack_pipe);
@@ -466,7 +471,6 @@ static void receive_needs(void)
466471
if (!prefixcmp(line, "shallow ")) {
467472
unsigned char sha1[20];
468473
struct object *object;
469-
use_thin_pack = 0;
470474
if (get_sha1(line + 8, sha1))
471475
die("invalid shallow line: %s", line);
472476
object = parse_object(sha1);
@@ -478,7 +482,6 @@ static void receive_needs(void)
478482
}
479483
if (!prefixcmp(line, "deepen ")) {
480484
char *end;
481-
use_thin_pack = 0;
482485
depth = strtol(line + 7, &end, 0);
483486
if (end == line + 7 || depth <= 0)
484487
die("Invalid deepen: %s", line);
@@ -556,6 +559,7 @@ static void receive_needs(void)
556559
NULL, &want_obj);
557560
parents = parents->next;
558561
}
562+
add_object_array(object, NULL, &extra_edge_obj);
559563
}
560564
/* make sure commit traversal conforms to client */
561565
register_shallow(object->sha1);

0 commit comments

Comments
 (0)