git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Christian Couder <christian.couder@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>,
	Christian Couder <chriscool@tuxfamily.org>,
	Ramsay Jones <ramsay@ramsayjones.plus.com>,
	Jonathan Tan <jonathantanmy@google.com>
Subject: [PATCH v4 11/12] pack-objects: add checks for duplicate objects
Date: Wed, 18 Dec 2019 12:25:46 +0100	[thread overview]
Message-ID: <20191218112547.4974-12-chriscool@tuxfamily.org> (raw)
In-Reply-To: <20191218112547.4974-1-chriscool@tuxfamily.org>

From: Jeff King <peff@peff.net>

Additional checks are added in have_duplicate_entry() and
obj_is_packed() to avoid duplicate objects in the reuse
bitmap. It was probably buggy to not have such a check
before.

Git as a client would never both asks for a tag by sha1 and
specify "include-tag", but libgit2 will, so a libgit2 client
cloning from a Git server would trigger the bug.

If a client both asks for a tag by sha1 and specifies
"include-tag", we may end up including the tag in the reuse
bitmap (due to the first thing), and then later adding it to
the packlist (due to the second). This results in duplicate
objects in the pack, which git chokes on. We should notice
that we are already including it when doing the include-tag
portion, and avoid adding it to the packlist.

The simplest place to fix this is right in add_ref_tag(),
where we could avoid peeling the tag at all if we know that
we are already including it. However, this pushes the check
instead into have_duplicate_entry(). This fixes not only
this case, but also means that we cannot have any similar
problems lurking in other code.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 builtin/pack-objects.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index c80c1fac94..b1998202fb 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -1127,6 +1127,10 @@ static int have_duplicate_entry(const struct object_id *oid,
 {
 	struct object_entry *entry;
 
+	if (reuse_packfile_bitmap &&
+	    bitmap_walk_contains(bitmap_git, reuse_packfile_bitmap, oid))
+		return 1;
+
 	entry = packlist_find(&to_pack, oid);
 	if (!entry)
 		return 0;
@@ -2681,7 +2685,9 @@ static void ll_find_deltas(struct object_entry **list, unsigned list_size,
 
 static int obj_is_packed(const struct object_id *oid)
 {
-	return !!packlist_find(&to_pack, oid);
+	return packlist_find(&to_pack, oid) ||
+		(reuse_packfile_bitmap &&
+		 bitmap_walk_contains(bitmap_git, reuse_packfile_bitmap, oid));
 }
 
 static void add_tag_chain(const struct object_id *oid)
-- 
2.24.1.498.g561400140f


  parent reply	other threads:[~2019-12-18 11:26 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-18 11:25 [PATCH v4 00/12] Rewrite packfile reuse code Christian Couder
2019-12-18 11:25 ` [PATCH v4 01/12] builtin/pack-objects: report reused packfile objects Christian Couder
2019-12-18 11:25 ` [PATCH v4 02/12] packfile: expose get_delta_base() Christian Couder
2019-12-18 11:25 ` [PATCH v4 03/12] ewah/bitmap: introduce bitmap_word_alloc() Christian Couder
2019-12-18 11:25 ` [PATCH v4 04/12] pack-bitmap: introduce bitmap_walk_contains() Christian Couder
2019-12-18 11:25 ` [PATCH v4 05/12] pack-bitmap: uninteresting oid can be outside bitmapped packfile Christian Couder
2019-12-18 11:25 ` [PATCH v4 06/12] pack-bitmap: simplify bitmap_has_oid_in_uninteresting() Christian Couder
2019-12-18 11:25 ` [PATCH v4 07/12] csum-file: introduce hashfile_total() Christian Couder
2019-12-18 11:25 ` [PATCH v4 08/12] pack-objects: introduce pack.allowPackReuse Christian Couder
2019-12-18 11:25 ` [PATCH v4 09/12] builtin/pack-objects: introduce obj_is_packed() Christian Couder
2019-12-18 11:25 ` [PATCH v4 10/12] pack-objects: improve partial packfile reuse Christian Couder
2019-12-18 11:25 ` Christian Couder [this message]
2019-12-18 11:25 ` [PATCH v4 12/12] pack-bitmap: don't rely on bitmap_git->reuse_objects Christian Couder

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191218112547.4974-12-chriscool@tuxfamily.org \
    --to=christian.couder@gmail.com \
    --cc=chriscool@tuxfamily.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jonathantanmy@google.com \
    --cc=peff@peff.net \
    --cc=ramsay@ramsayjones.plus.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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).