[PATCH 2/4] refs: mostly remove core.preferSymlinkRefs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This step and the next step are for Git 3.0.

Now we are preparing for a big Git 3.0 transition after warning
against use of this configuration variable to create a new symlink
that represents a symbolic ref for N months, it is time to actually
remove the support of the configuration variable.

In this patch, we mostly ignore core.preferSymlinkRefs and always
create a textual symref when we are asked to create a symref, but
when core.preferSymlinkRefs would have caused us to use a symbolic
link in an older version of Git, we will issue a warning.  We also
have in our build infrastructure to selectively set the CPP macro
NO_SYMLINK_HEAD, but an accompanying patch will remove them.

The final warning is meant to help users who set the configuration
variable and expected it to create a symlink, but instead got a
textual symref.  They may not even recognise the configuration after
they set it long time ago and forgot about it by now, so we keep the
"git config --help" entry for the variable to help them recall what
it was about.

After a few releases, we will get rid of this warning and the
codebase will look as if such a configuration variable never
existed, but we are not quite there yet.

Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx>
---
 Documentation/config/core.txt |  4 ++--
 refs/files-backend.c          | 29 +++---------------------
 t/t0600-reffiles-backend.sh   | 42 +++++++++++++++++++++++------------
 3 files changed, 33 insertions(+), 42 deletions(-)

diff --git a/Documentation/config/core.txt b/Documentation/config/core.txt
index f0245f5050..a6f67cab27 100644
--- a/Documentation/config/core.txt
+++ b/Documentation/config/core.txt
@@ -285,10 +285,10 @@ CIFS/Microsoft Windows.
 +
 False by default.
 
-core.preferSymlinkRefs (deprecated)::
+core.preferSymlinkRefs (removed)::
 	Instead of the default "symref" format for HEAD and other
 	symbolic reference files, use symbolic links.  The support
-	for this variable will be dropped in Git 3.0.
+	for this variable was dropped in Git 3.0.
 
 core.alternateRefsCommand::
 	When advertising tips of available history from an alternate, use the shell to
diff --git a/refs/files-backend.c b/refs/files-backend.c
index c40a248b9f..1296272252 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -2011,26 +2011,6 @@ static int commit_ref_update(struct files_ref_store *refs,
 	return 0;
 }
 
-#ifdef NO_SYMLINK_HEAD
-#define create_ref_symlink(a, b) (-1)
-#else
-static int create_ref_symlink(struct ref_lock *lock, const char *target)
-{
-	int ret = -1;
-
-	char *ref_path = get_locked_file_path(&lock->lk);
-	unlink(ref_path);
-	ret = symlink(target, ref_path);
-	free(ref_path);
-
-	if (ret)
-		fprintf(stderr, "no symlink - falling back to symbolic ref\n");
-	else
-		warning("core.preferSymlinkRefs will be removed in Git 3.0");
-	return ret;
-}
-#endif
-
 static int create_symref_lock(struct ref_lock *lock, const char *target,
 			      struct strbuf *err)
 {
@@ -3003,13 +2983,10 @@ static int files_transaction_finish(struct ref_store *ref_store,
 			}
 		}
 
-		/*
-		 * We try creating a symlink, if that succeeds we continue to the
-		 * next update. If not, we try and create a regular symref.
-		 */
+		/* Warn against core.preferSymlinkRefs set to true */
 		if (update->new_target && prefer_symlink_refs)
-			if (!create_ref_symlink(lock, update->new_target))
-				continue;
+			/* we used to, but no longer, create a symlink here */
+			warning("core.preferSymlinkRefs was removed in Git 3.0");
 
 		if (update->flags & REF_NEEDS_COMMIT) {
 			clear_loose_ref_cache(refs);
diff --git a/t/t0600-reffiles-backend.sh b/t/t0600-reffiles-backend.sh
index d369330562..4e517cdc13 100755
--- a/t/t0600-reffiles-backend.sh
+++ b/t/t0600-reffiles-backend.sh
@@ -468,26 +468,40 @@ test_expect_success POSIXPERM 'git reflog expire honors core.sharedRepository' '
 	esac
 '
 
-test_expect_success SYMLINKS 'symref transaction supports symlinks' '
+test_expect_success SYMLINKS 'symlinks used as symrefs are still supported' '
 	test_when_finished "git symbolic-ref -d TEST_SYMREF_HEAD || :" &&
 	git update-ref refs/heads/new HEAD &&
-	test_config core.prefersymlinkrefs true &&
-	cat >stdin <<-EOF &&
-	start
-	symref-create TEST_SYMREF_HEAD refs/heads/new
-	prepare
-	commit
-	EOF
-	git update-ref --no-deref --stdin <stdin 2>stderr &&
+	# manually do this, as core.prefersymlinkrefs no longer
+	# affects how a symref is created (as a textual symref).
+	ln -f -s refs/heads/new .git/TEST_SYMREF_HEAD &&
 	test_path_is_symlink .git/TEST_SYMREF_HEAD &&
-	test "$(test_readlink .git/TEST_SYMREF_HEAD)" = refs/heads/new &&
-	test_grep "core\.preferSymlinkRefs will be removed" stderr
+	echo refs/heads/new >expect &&
+	git symbolic-ref TEST_SYMREF_HEAD >actual &&
+	test_cmp actual expect
+'
+
+test_expect_success 'core.prefersymlinkrefs gets a warning' '
+	test_when_finished "git symbolic-ref -d TEST_SYMREF_HEAD || :" &&
+	git update-ref refs/heads/new HEAD &&
+
+	test_config core.prefersymlinkrefs true &&
+	git symbolic-ref TEST_SYMREF_HEAD refs/heads/new 2>stderr &&
+	test_grep "core\.preferSymlinkRefs was removed" stderr &&
+
+	git symbolic-ref -d TEST_SYMREF_HEAD &&
+	git config core.prefersymlinkrefs false &&
+	git symbolic-ref TEST_SYMREF_HEAD refs/heads/new 2>stderr &&
+	test_grep ! "core\.preferSymlinkRefs was removed" stderr &&
+
+	git symbolic-ref -d TEST_SYMREF_HEAD &&
+	git config --unset core.prefersymlinkrefs &&
+	git symbolic-ref TEST_SYMREF_HEAD refs/heads/new 2>stderr &&
+	test_grep ! "core\.preferSymlinkRefs was removed" stderr
 '
 
-test_expect_success 'symref transaction supports false symlink config' '
+test_expect_success 'symref transaction' '
 	test_when_finished "git symbolic-ref -d TEST_SYMREF_HEAD || :" &&
 	git update-ref refs/heads/new HEAD &&
-	test_config core.prefersymlinkrefs false &&
 	cat >stdin <<-EOF &&
 	start
 	symref-create TEST_SYMREF_HEAD refs/heads/new
@@ -499,7 +513,7 @@ test_expect_success 'symref transaction supports false symlink config' '
 	git symbolic-ref TEST_SYMREF_HEAD >actual &&
 	echo refs/heads/new >expect &&
 	test_cmp expect actual &&
-	test_grep ! "core\.preferSymlinkRefs will be removed" stderr
+	test_grep ! "core\.preferSymlinkRefs was removed" stderr
 '
 
 test_done
-- 
2.46.1-742-g4240f61078





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux