All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Jens Lehmann" <Jens.Lehmann@web.de>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 7/7] refs: do not update ref(log) referring to external objects
Date: Thu, 24 Jan 2013 15:42:20 +0700	[thread overview]
Message-ID: <1359016940-18849-7-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1359016940-18849-1-git-send-email-pclouds@gmail.com>


Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 refs.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/refs.c b/refs.c
index 541fec2..86003af 100644
--- a/refs.c
+++ b/refs.c
@@ -2014,6 +2014,18 @@ static int log_ref_write(const char *refname, const unsigned char *old_sha1,
 	char *logrec;
 	const char *committer;
 
+	if (object_database_contaminated) {
+		struct object_info oi;
+		if (sha1_object_info_extended(old_sha1, &oi) == -1 ||
+		    (oi.alt && oi.alt->external))
+			return error("cannot update reflog pointing to an external SHA-1 %s",
+				     sha1_to_hex(old_sha1));
+		if (sha1_object_info_extended(new_sha1, &oi) == -1 ||
+		    (oi.alt && oi.alt->external))
+			return error("cannot update reflog pointing to an external SHA-1 %s",
+				     sha1_to_hex(new_sha1));
+	}
+
 	if (log_all_ref_updates < 0)
 		log_all_ref_updates = !is_bare_repository();
 
@@ -2054,6 +2066,18 @@ int write_ref_sha1(struct ref_lock *lock,
 
 	if (!lock)
 		return -1;
+
+	if (object_database_contaminated) {
+		struct object_info oi;
+		if (sha1_object_info_extended(sha1, &oi) == -1 ||
+		    (oi.alt && oi.alt->external)) {
+			error("cannot update ref pointing to an external SHA-1 %s",
+			      sha1_to_hex(sha1));
+			unlock_ref(lock);
+			return -1;
+		}
+	}
+
 	if (!lock->force_write && !hashcmp(lock->old_sha1, sha1)) {
 		unlock_ref(lock);
 		return 0;
-- 
1.8.0.rc3.18.g0d9b108

  parent reply	other threads:[~2013-01-24  8:43 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-24  8:42 [PATCH 1/7] sha1_file: keep track of where an SHA-1 object comes from Nguyễn Thái Ngọc Duy
2013-01-24  8:42 ` [PATCH 2/7] sha1_file: separate alt object db from own repos and submodules's Nguyễn Thái Ngọc Duy
2013-01-24  8:42 ` [PATCH 3/7] sha1_file: refuse to write commits referring to external objects Nguyễn Thái Ngọc Duy
2013-01-24  8:42 ` [PATCH 4/7] sha1_file: refuse to write trees " Nguyễn Thái Ngọc Duy
2013-01-24  8:42 ` [PATCH 5/7] sha1_file: refuse to write tags " Nguyễn Thái Ngọc Duy
2013-01-24  8:42 ` [PATCH 6/7] read-cache: refuse to create index " Nguyễn Thái Ngọc Duy
2013-01-24 19:15   ` Junio C Hamano
2013-01-25  2:00     ` Duy Nguyen
2013-01-25 19:00       ` Junio C Hamano
2013-01-28  5:48         ` Duy Nguyen
2013-01-28  5:54           ` Junio C Hamano
2013-01-28  5:57             ` Duy Nguyen
2013-01-28  6:06               ` Junio C Hamano
2013-01-28  6:18           ` Duy Nguyen
2013-01-28  6:36             ` Junio C Hamano
2013-01-28  6:57               ` Duy Nguyen
2013-01-24  8:42 ` Nguyễn Thái Ngọc Duy [this message]
2013-01-24 17:45 ` [PATCH 1/7] sha1_file: keep track of where an SHA-1 object comes from Junio C Hamano
2013-01-25  1:38   ` Duy Nguyen
2013-01-25  3:58     ` Junio C Hamano
2013-01-25  4:02       ` Duy Nguyen

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=1359016940-18849-7-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=Jens.Lehmann@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.