git.vger.kernel.org archive mirror
 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>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v2 15/16] config: add core.noshallow to prevent turning a repo into a shallow one
Date: Sat, 20 Jul 2013 16:58:09 +0700	[thread overview]
Message-ID: <1374314290-5976-16-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1374314290-5976-1-git-send-email-pclouds@gmail.com>


Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Documentation/config.txt | 5 +++++
 builtin/receive-pack.c   | 9 ++++++++-
 cache.h                  | 1 +
 config.c                 | 5 +++++
 environment.c            | 1 +
 fetch-pack.c             | 9 ++++++++-
 t/t5536-fetch-shallow.sh | 9 +++++++++
 t/t5537-push-shallow.sh  | 6 ++++++
 8 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 81856dd..e811180 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -655,6 +655,11 @@ core.abbrev::
 	for abbreviated object names to stay unique for sufficiently long
 	time.
 
+core.noshallow::
+	If true, reject any pushes or fetches that may turn the
+	repository into a shallow one. This setting is ignored if the
+	repository is already shallow.
+
 add.ignore-errors::
 add.ignoreErrors::
 	Tells 'git add' to continue adding files when some files cannot be
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 54bf6b2..95ea481 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -936,7 +936,14 @@ static const char *unpack(int err_fd)
 					&shallow,
 					WRITE_SHALLOW_NO_CUT |
 					WRITE_SHALLOW_REWRITE);
-		commit_lock_file(&shallow_lock);
+		if (*alternate_shallow_file == '\0') {
+			unlink_or_warn(git_path("shallow"));
+			rollback_lock_file(&shallow_lock);
+		} else {
+			if (!is_repository_shallow() && cannot_be_shallow)
+				die("not allowed to turn this repository into a shallow one");
+			commit_lock_file(&shallow_lock);
+		}
 	}
 	return NULL;
 }
diff --git a/cache.h b/cache.h
index 7f17228..3a52b08 100644
--- a/cache.h
+++ b/cache.h
@@ -592,6 +592,7 @@ extern int fsync_object_files;
 extern int core_preload_index;
 extern int core_apply_sparse_checkout;
 extern int precomposed_unicode;
+extern int cannot_be_shallow;
 
 /*
  * The character that begins a commented line in user-editable file
diff --git a/config.c b/config.c
index d04e815..31f5a57 100644
--- a/config.c
+++ b/config.c
@@ -784,6 +784,11 @@ static int git_default_core_config(const char *var, const char *value)
 		return 0;
 	}
 
+	if (!strcmp(var, "core.noshallow")) {
+		cannot_be_shallow = git_config_bool(var, value);
+		return 0;
+	}
+
 	/* Add other config variables here and to Documentation/config.txt. */
 	return 0;
 }
diff --git a/environment.c b/environment.c
index 0cb67b2..14c8005 100644
--- a/environment.c
+++ b/environment.c
@@ -61,6 +61,7 @@ int merge_log_config = -1;
 int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
 struct startup_info *startup_info;
 unsigned long pack_size_limit_cfg;
+int cannot_be_shallow;
 
 /*
  * The character that begins a commented line in user-editable file
diff --git a/fetch-pack.c b/fetch-pack.c
index f337526..40e7aa2 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -960,7 +960,14 @@ struct ref *fetch_pack(struct fetch_pack_args *args,
 							WRITE_SHALLOW_NO_CUT |
 							WRITE_SHALLOW_REWRITE);
 			}
-			commit_lock_file(&shallow_lock);
+			if (*alternate_shallow_file == '\0') {
+				unlink_or_warn(git_path("shallow"));
+				rollback_lock_file(&shallow_lock);
+			} else {
+				if (!is_repository_shallow() && cannot_be_shallow)
+					die("not allowed to turn this repository into a shallow one");
+				commit_lock_file(&shallow_lock);
+			}
 		}
 	}
 
diff --git a/t/t5536-fetch-shallow.sh b/t/t5536-fetch-shallow.sh
index 6ea6347..b7f89b1 100755
--- a/t/t5536-fetch-shallow.sh
+++ b/t/t5536-fetch-shallow.sh
@@ -102,6 +102,15 @@ EOF
 
 '
 
+test_expect_success 'core.noshallow' '
+	git init clean &&
+	(
+	cd clean &&
+	git config core.noshallow true &&
+	test_must_fail git fetch ../shallow/.git
+	)
+'
+
 if test -n "$NO_CURL" -o -z "$GIT_TEST_HTTPD"; then
 	say 'skipping remaining tests, git built without http support'
 	test_done
diff --git a/t/t5537-push-shallow.sh b/t/t5537-push-shallow.sh
index 8bea496..0edd51f 100755
--- a/t/t5537-push-shallow.sh
+++ b/t/t5537-push-shallow.sh
@@ -108,6 +108,12 @@ EOF
 	)
 '
 
+test_expect_success 'core.noshallow' '
+	git init clean &&
+	git --git-dir=clean/.git config core.noshallow true &&
+	test_must_fail git --git-dir=shallow/.git push clean master:refs/remotes/shallow/master
+'
+
 if test -n "$NO_CURL" -o -z "$GIT_TEST_HTTPD"; then
 	say 'skipping remaining tests, git built without http support'
 	test_done
-- 
1.8.2.83.gc99314b

  parent reply	other threads:[~2013-07-20  9:59 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-17 12:47 [PATCH 0/7] First class shallow clone Nguyễn Thái Ngọc Duy
2013-07-17 12:47 ` [PATCH 1/7] transport.h: remove send_pack prototype, already defined in send-pack.h Nguyễn Thái Ngọc Duy
2013-07-17 12:47 ` [PATCH 2/7] {receive,upload}-pack: advertise shallow graft information Nguyễn Thái Ngọc Duy
2013-07-17 12:47 ` [PATCH 3/7] connect.c: teach get_remote_heads to parse "shallow" lines Nguyễn Thái Ngọc Duy
2013-07-20  3:27   ` Junio C Hamano
2013-07-17 12:47 ` [PATCH 4/7] Move setup_alternate_shallow and write_shallow_commits to shallow.c Nguyễn Thái Ngọc Duy
2013-07-17 12:47 ` [PATCH 5/7] fetch-pack: support fetching from a shallow repository Nguyễn Thái Ngọc Duy
2013-07-20  3:17   ` Junio C Hamano
2013-07-17 12:47 ` [PATCH 6/7] {send,receive}-pack: support pushing from a shallow clone Nguyễn Thái Ngọc Duy
2013-07-17 12:47 ` [PATCH 7/7] send-pack: support pushing to " Nguyễn Thái Ngọc Duy
2013-07-20  9:57 ` [PATCH v2 00/16] First class " Nguyễn Thái Ngọc Duy
2013-07-20  9:57   ` [PATCH v2 01/16] send-pack: forbid pushing from a shallow repository Nguyễn Thái Ngọc Duy
2013-07-20  9:57   ` [PATCH v2 02/16] {receive,upload}-pack: advertise shallow graft information Nguyễn Thái Ngọc Duy
2013-07-20  9:57   ` [PATCH v2 03/16] connect.c: teach get_remote_heads to parse "shallow" lines Nguyễn Thái Ngọc Duy
2013-07-20  9:57   ` [PATCH v2 04/16] Move setup_alternate_shallow and write_shallow_commits to shallow.c Nguyễn Thái Ngọc Duy
2013-07-20  9:57   ` [PATCH v2 05/16] fetch-pack: support fetching from a shallow repository Nguyễn Thái Ngọc Duy
2013-07-22 19:10     ` Philip Oakley
2013-07-23  2:06       ` Duy Nguyen
2013-07-23 14:39         ` Duy Nguyen
2013-07-20  9:58   ` [PATCH v2 06/16] {send,receive}-pack: support pushing from a shallow clone Nguyễn Thái Ngọc Duy
2013-07-20  9:58   ` [PATCH v2 07/16] send-pack: support pushing to " Nguyễn Thái Ngọc Duy
2013-07-20  9:58   ` [PATCH v2 08/16] upload-pack: let pack-objects do the object counting in shallow case Nguyễn Thái Ngọc Duy
2013-07-20  9:58   ` [PATCH v2 09/16] pack-protocol.txt: a bit about smart http Nguyễn Thái Ngọc Duy
2013-07-20  9:58   ` [PATCH v2 10/16] Add document for command arguments for supporting " Nguyễn Thái Ngọc Duy
2013-07-20  9:58   ` [PATCH v2 11/16] {fetch,upload}-pack: support fetching from a shallow clone via " Nguyễn Thái Ngọc Duy
2013-07-20  9:58   ` [PATCH v2 12/16] receive-pack: support pushing to a shallow clone via http Nguyễn Thái Ngọc Duy
2013-07-20  9:58   ` [PATCH v2 13/16] send-pack: support pushing from " Nguyễn Thái Ngọc Duy
2013-07-20  9:58   ` [PATCH v2 14/16] git-clone.txt: remove shallow clone limitations Nguyễn Thái Ngọc Duy
2013-07-20  9:58   ` Nguyễn Thái Ngọc Duy [this message]
2013-07-22 19:23     ` [PATCH v2 15/16] config: add core.noshallow to prevent turning a repo into a shallow one Philip Oakley
2013-07-23  1:28       ` Duy Nguyen
2013-07-23  4:06         ` Junio C Hamano
2013-07-23 19:44         ` Philip Oakley
2013-07-20  9:58   ` [PATCH v2 16/16] clone: use git protocol for cloning shallow repo locally Nguyễn Thái Ngọc Duy
2013-07-22 23:41   ` [PATCH v2 00/16] First class shallow clone Philip Oakley
2013-07-23  1:20     ` Duy Nguyen
2013-07-23  4:08       ` Junio C Hamano
2013-07-23  5:01         ` Duy Nguyen
2013-07-23 22:33       ` Philip Oakley
2013-07-24  1:57         ` Duy Nguyen
2013-07-24  7:38           ` Philip Oakley
2013-07-24  8:30           ` Piotr Krukowiecki
2013-07-24 10:35             ` Duy Nguyen
2013-07-24 16:50               ` Piotr Krukowiecki

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=1374314290-5976-16-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --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 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).