Skip to content

Commit

Permalink
Teach git-fetch to exploit server side automatic tag following
Browse files Browse the repository at this point in the history
If the remote peer upload-pack process supports the include-tag
protocol extension then we can avoid running a second fetch cycle
on the client side by letting the server send us the annotated tags
along with the objects it is packing for us.  In the following graph
we can now fetch both "tag1" and "tag2" on the same connection that
we fetched "master" from the remote when we only have L available
on the local side:

         T - tag1          S - tag2
        /                 /
   L - o ------ o ------ B
    \                     \
     \                     \
      origin/master         master

The objects for "tag1" are implicitly downloaded without our direct
knowledge.  The existing "quickfetch" optimization within git-fetch
discovers that tag1 is complete after the first connection and does
not open a second connection.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Shawn O. Pearce authored and Junio C Hamano committed Mar 5, 2008
1 parent 348e390 commit 41fa7d2
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions builtin-fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,8 @@ static int do_fetch(struct transport *transport,
read_ref(rm->peer_ref->name, rm->peer_ref->old_sha1);
}

if (tags == TAGS_DEFAULT && autotags)
transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, "1");
if (fetch_refs(transport, ref_map)) {
free_refs(ref_map);
return 1;
Expand All @@ -568,6 +570,7 @@ static int do_fetch(struct transport *transport,
ref_map = NULL;
find_non_local_tags(transport, &ref_map, &tail);
if (ref_map) {
transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, NULL);
transport_set_option(transport, TRANS_OPT_DEPTH, "0");
fetch_refs(transport, ref_map);
}
Expand Down
26 changes: 26 additions & 0 deletions t/t5503-tagfollow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,30 @@ test_expect_success 'fetch B, S (commit and tag : 1 connection)' '
git diff expect actual
'

cat - <<EOF >expect
#S
want $B
want $S
#E
EOF
test_expect_success 'new clone fetch master and tags' '
git branch -D cat
rm -f $U
(
mkdir clone2 &&
cd clone2 &&
git init &&
git remote add origin .. &&
GIT_DEBUG_SEND_PACK=3 git fetch 3>../$U &&
test $B = $(git rev-parse --verify origin/master) &&
test $S = $(git rev-parse --verify tag2) &&
test $B = $(git rev-parse --verify tag2^0) &&
test $T = $(git rev-parse --verify tag1) &&
test $A = $(git rev-parse --verify tag1^0)
) &&
test -s $U &&
cut -d" " -f1,2 $U >actual &&
git diff expect actual
'

test_done
5 changes: 5 additions & 0 deletions transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ static int close_bundle(struct transport *transport)
struct git_transport_data {
unsigned thin : 1;
unsigned keep : 1;
unsigned followtags : 1;
int depth;
struct child_process *conn;
int fd[2];
Expand All @@ -580,6 +581,9 @@ static int set_git_option(struct transport *connection,
} else if (!strcmp(name, TRANS_OPT_THIN)) {
data->thin = !!value;
return 0;
} else if (!strcmp(name, TRANS_OPT_FOLLOWTAGS)) {
data->followtags = !!value;
return 0;
} else if (!strcmp(name, TRANS_OPT_KEEP)) {
data->keep = !!value;
return 0;
Expand Down Expand Up @@ -628,6 +632,7 @@ static int fetch_refs_via_pack(struct transport *transport,
args.keep_pack = data->keep;
args.lock_pack = 1;
args.use_thin_pack = data->thin;
args.include_tag = data->followtags;
args.verbose = transport->verbose > 0;
args.depth = data->depth;

Expand Down
3 changes: 3 additions & 0 deletions transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ struct transport *transport_get(struct remote *, const char *);
/* Limit the depth of the fetch if not null */
#define TRANS_OPT_DEPTH "depth"

/* Aggressively fetch annotated tags if possible */
#define TRANS_OPT_FOLLOWTAGS "followtags"

/**
* Returns 0 if the option was used, non-zero otherwise. Prints a
* message to stderr if the option is not used.
Expand Down

0 comments on commit 41fa7d2

Please sign in to comment.