From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: "Kyle J. McKay" <mackyle@gmail.com>,
Git mailing list <git@vger.kernel.org>
Subject: [PATCH 2/4] filter_ref: make a copy of extra "sought" entries
Date: Thu, 19 Mar 2015 16:37:09 -0400 [thread overview]
Message-ID: <20150319203708.GB7666@peff.net> (raw)
In-Reply-To: <20150319203126.GA31663@peff.net>
If the server supports allow_tip_sha1_in_want, we add any
unmatched raw-sha1 entries in our "sought" list of refs to
the list of refs we will ask the other side for. We do so by
inserting the original "struct ref" directly into our list,
rather than making a copy. This has several problems.
The most minor problem is that one cannot ever free the
resulting list; it contains structs that are copies of the
remote refs (made earlier by fetch_pack) along with sought
refs that are referenced elsewhere.
But more importantly that we set the ref->next pointer to
NULL, chopping off the remainder of any existing list that
the ref was a part of. We get the set of "sought" refs in
an array rather than a linked list, but that array is often
in turn generated from a list. The test modification in
t5516 demonstrates this. Rather than fetching just an exact
sha1, we fetch that sha1 plus another ref:
- we build a linked list of refs to fetch when do_fetch
calls get_ref_map; the exact sha1 is first, followed by
the named ref ("refs/heads/extra" in this case).
- we pass that linked list to transport_fetch_ref, which
squashes it into an array of pointers
- that array goes to fetch_pack, which calls filter_ref.
There we generate the want list from a mix of what the
remote side has advertised, and the "sought" entry for
the exact sha1. We set the sought entry's "next" pointer
to NULL.
- after we return from transport_fetch_refs, we then try
to update the refs by following the linked list. But our
list is now truncated, and we do not update
refs/heads/extra at all.
We can fix this by making a copy of the ref. There's nothing
that fetch_pack does to it that must be reflected in the
original "sought" list (and indeed, if that were the case we
would have a serious bug, because it is only exact-sha1
entries which are treated this way).
Signed-off-by: Jeff King <peff@peff.net>
---
I always feel a little dirty modifying an existing test rather than
writing a new one that more clearly demonstrates what we are testing.
But the setup involved in the exact-sha1 fetch is a little complicated,
so this seemed easiest (and anybody blaming the change can hopefully
rely on the explanation above to understand what is going on).
fetch-pack.c | 5 ++---
t/t5516-fetch-push.sh | 13 ++++++++++---
2 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/fetch-pack.c b/fetch-pack.c
index 058c258..84d5a66 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -555,9 +555,8 @@ static void filter_refs(struct fetch_pack_args *args,
continue;
ref->matched = 1;
- *newtail = ref;
- ref->next = NULL;
- newtail = &ref->next;
+ *newtail = copy_ref(ref);
+ newtail = &(*newtail)->next;
}
}
*refs = newlist;
diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh
index 630885d..5e04d64 100755
--- a/t/t5516-fetch-push.sh
+++ b/t/t5516-fetch-push.sh
@@ -1107,9 +1107,16 @@ test_expect_success 'fetch exact SHA1' '
git config uploadpack.allowtipsha1inwant true
) &&
- git fetch -v ../testrepo $the_commit:refs/heads/copy &&
- result=$(git rev-parse --verify refs/heads/copy) &&
- test "$the_commit" = "$result"
+ git fetch -v ../testrepo $the_commit:refs/heads/copy master:refs/heads/extra &&
+ cat >expect <<-EOF &&
+ $the_commit
+ $the_first_commit
+ EOF
+ {
+ git rev-parse --verify refs/heads/copy &&
+ git rev-parse --verify refs/heads/extra
+ } >actual &&
+ test_cmp expect actual
)
'
--
2.3.3.520.g3cfbb5d
next prev parent reply other threads:[~2015-03-19 20:37 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-15 6:37 Bug in fetch-pack.c, please confirm Kyle J. McKay
2015-03-15 7:27 ` Junio C Hamano
2015-03-15 7:30 ` Junio C Hamano
2015-03-15 22:21 ` Kyle J. McKay
2015-03-16 1:13 ` Jeff King
2015-03-19 17:41 ` Junio C Hamano
2015-03-19 18:55 ` Jeff King
2015-03-19 19:01 ` Junio C Hamano
2015-03-19 20:31 ` Jeff King
2015-03-19 20:34 ` [PATCH 1/4] filter_ref: avoid overwriting ref->old_sha1 with garbage Jeff King
2015-03-19 21:09 ` Junio C Hamano
2015-03-19 20:37 ` Jeff King [this message]
2015-03-19 20:38 ` [PATCH 3/4] fetch_refs_via_pack: free extra copy of refs Jeff King
2015-03-19 20:39 ` [PATCH 4/4] fetch-pack: remove dead assignment to ref->new_sha1 Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150319203708.GB7666@peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=mackyle@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).