Skip to content

Support multiple checkouts

Nguyễn Thái Ngọc Duy git 5 versions In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v7 Latest31 patches 12 repliesIn review
  2. v632 patches 6 repliesSuperseded
  3. v528 patches 12 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v427 patches21 repliesSuperseded
v325 patches52 repliesSuperseded

Patches in v7 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/31path.c: make get_pathname() return strbuf instead of static bufferpath.c+51 -690 replies
2/31path.c: make get_pathname() call sites return const char *builtin/checkout.c builtin/clone.c builtin/fetch.c +12 more+36 -320 replies
3/31git_snpath(): retire and replace with strbuf_git_path()builtin/checkout.c cache.h path.c +2 more+61 -470 replies
4/31path.c: rename vsnpath() to do_git_path()path.c+4 -40 replies
5/31path.c: group git_path(), git_pathdup() and strbuf_git_path() togetherpath.c+10 -100 replies
6/31git_path(): be aware of file relocation in $GIT_DIRDocumentation/git-rev-parse.txt builtin/rev-parse.c cache.h +3 more+95 -70 replies
7/31*.sh: respect $GIT_INDEX_FILEgit-pull.sh git-stash.sh+2 -20 replies
8/31reflog: avoid constructing .lock path with git_pathbuiltin/reflog.c+1 -10 replies
9/31fast-import: use git_path() for accessing .git dir instead of get_git_dir()fast-import.c+1 -40 replies
10/31commit: use SEQ_DIR instead of hardcoding "sequencer"builtin/commit.c+1 -10 replies
11/31$GIT_COMMON_DIR: a new environment variableDocumentation/git.txt Documentation/gitrepository-layout.txt cache.h +3 more+114 -171 reply
12/31git-sh-setup.sh: use rev-parse --git-path to get $GIT_DIR/objectsgit-sh-setup.sh+1 -10 replies
13/31*.sh: avoid hardcoding $GIT_DIR/hooks/...git-am.sh git-rebase--interactive.sh git-rebase--merge.sh +3 more+22 -240 replies
14/31git-stash: avoid hardcoding $GIT_DIR/logs/....git-stash.sh+2 -20 replies
15/31setup.c: convert is_git_directory() to use strbufsetup.c+21 -160 replies
16/31setup.c: detect $GIT_COMMON_DIR in is_git_directory()Documentation/gitrepository-layout.txt setup.c+44 -60 replies
17/31setup.c: convert check_repository_format_gently to use strbufsetup.c+8 -40 replies
18/31setup.c: detect $GIT_COMMON_DIR check_repository_format_gently()setup.c+4 -20 replies
19/31setup.c: support multi-checkout repo setupDocumentation/config.txt Documentation/git-rev-parse.txt builtin/rev-parse.c +6 more+115 -140 replies
20/31wrapper.c: wrapper to open a file, fprintf then closecache.h wrapper.c+33 -00 replies
21/31use new wrapper write_file() for simple file writingbuiltin/branch.c builtin/init-db.c daemon.c +2 more+8 -310 replies
22/31checkout: support checking out into a new working directoryDocumentation/git-checkout.txt Documentation/git.txt Documentation/gitrepository-layout.txt +3 more+183 -43 replies
23/31checkout: clean up half-prepared directories in --to modebuiltin/checkout.c+47 -23 replies
24/31checkout: detach if the branch is already checked out elsewherebuiltin/checkout.c t/t2025-checkout-to.sh+104 -30 replies
25/31prune: strategies for linked checkoutsDocumentation/git-prune.txt Documentation/gitrepository-layout.txt builtin/checkout.c +3 more+232 -02 replies
26/31gc: style change -- no SP before closing bracketbuiltin/gc.c+1 -10 replies
27/31gc: factor out gc.pruneexpire parsing codebuiltin/gc.c+13 -80 replies
28/31gc: support prune --reposDocumentation/config.txt builtin/gc.c+18 -00 replies
29/31count-objects: report unused files in $GIT_DIR/repos/...builtin/count-objects.c cache.h path.c+31 -30 replies
30/31git_path(): keep "info/sparse-checkout" per work-treepath.c t/t0060-path-utils.sh+3 -10 replies
31/31checkout: don't require a work tree when checking out into a new onebuiltin/checkout.c git.c t/t2025-checkout-to.sh+19 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v7 yet.

Read the v7 thread

Cover letter [PATCH v7 00/31] Support multiple checkouts

v7 fixes all comments from Eric and Max. Jeff's two patches are dropped because they have landed in latest master now. Diff against v6:

Documentation/config.txt +1 -1
index 470f979..57999fa 100644
@@ -1215,7 +1215,7 @@ gc.prunereposexpire::
 	When 'git gc' is run, it will call
 	'prune --repos --expire 3.months.ago'.
 	Override the grace period with this config variable. The value
-	"now" may be used to disable the grace period and always prune
+	"now" may be used to disable the grace period and prune
 	$GIT_DIR/repos immediately.
 
 gc.reflogexpire::
builtin/checkout.c +11 -7
index dc8503a..c83f476 100644
@@ -1010,15 +1010,13 @@ static int check_linked_checkout(struct branch_info *new,
 				  const char *name, const char *path)
 {
 	struct strbuf sb = STRBUF_INIT;
-	char *start, *end;
-	if (strbuf_read_file(&sb, path, 0) < 0)
-		return 0;
-	if (!starts_with(sb.buf, "ref:")) {
+	const char *start, *end;
+	if (strbuf_read_file(&sb, path, 0) < 0 ||
+	    !skip_prefix(sb.buf, "ref:", &start)) {
 		strbuf_release(&sb);
 		return 0;
 	}
 
-	start = sb.buf + 4;
 	while (isspace(*start))
 		start++;
 	end = start;
@@ -1200,8 +1198,14 @@ static int parse_branchname_arg(int argc, const char **argv,
 	else
 		new->path = NULL; /* not an existing branch */
 
-	if (new->path)
-		check_linked_checkouts(new);
+	if (new->path) {
+		unsigned char sha1[20];
+		int flag;
+		char *head_ref = resolve_refdup("HEAD", sha1, 0, &flag);
+		if (!(flag & REF_ISSYMREF) || strcmp(head_ref, new->path))
+			check_linked_checkouts(new);
+		free(head_ref);
+	}
 
 	new->commit = lookup_commit_reference_gently(rev, 1);
 	if (!new->commit) {
builtin/gc.c +16 -17
index 1190183..0c65808 100644
@@ -57,6 +57,17 @@ static void remove_pidfile_on_signal(int signo)
 	raise(signo);
 }
 
+static int git_config_date_string(const char **output,
+				  const char *var, const char *value)
+{
+	if (value && strcmp(value, "now")) {
+		unsigned long now = approxidate("now");
+		if (approxidate(value) >= now)
+			return error(_("Invalid %s: '%s'"), var, value);
+	}
+	return git_config_string(output, var, value);
+}
+
 static int gc_config(const char *var, const char *value, void *cb)
 {
 	if (!strcmp(var, "gc.packrefs")) {
@@ -86,22 +97,10 @@ static int gc_config(const char *var, const char *value, void *cb)
 		detach_auto = git_config_bool(var, value);
 		return 0;
 	}
-	if (!strcmp(var, "gc.pruneexpire")) {
-		if (value && strcmp(value, "now")) {
-			unsigned long now = approxidate("now");
-			if (approxidate(value) >= now)
-				return error(_("Invalid %s: '%s'"), var, value);
-		}
-		return git_config_string(&prune_expire, var, value);
-	}
-	if (!strcmp(var, "gc.prunereposexpire")) {
-		if (value && strcmp(value, "now")) {
-			unsigned long now = approxidate("now");
-			if (approxidate(value) >= now)
-				return error(_("Invalid %s: '%s'"), var, value);
-		}
-		return git_config_string(&prune_repos_expire, var, value);
-	}
+	if (!strcmp(var, "gc.pruneexpire"))
+		return git_config_date_string(&prune_expire, var, value);
+	if (!strcmp(var, "gc.prunereposexpire"))
+		return git_config_date_string(&prune_repos_expire, var, value);
 	return git_default_config(var, value, cb);
 }
 
@@ -295,7 +294,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
 		OPT__QUIET(&quiet, N_("suppress progress reporting")),
 		{ OPTION_STRING, 0, "prune", &prune_expire, N_("date"),
 			N_("prune unreferenced objects"),
-			PARSE_OPT_OPTARG, NULL, (intptr_t)prune_expire},
+			PARSE_OPT_OPTARG, NULL, (intptr_t)prune_expire },
 		OPT_BOOL(0, "aggressive", &aggressive, N_("be more thorough (increased runtime)")),
 		OPT_BOOL(0, "auto", &auto_gc, N_("enable auto-gc mode")),
 		OPT_BOOL(0, "force", &force, N_("force running gc even if there may be another gc running")),
builtin/prune.c +47 -22

111 lines not on this page · raw message

t/t2025-checkout-to.sh +8 -0
index a219851..b0d97a0 100755
@@ -54,6 +54,14 @@ test_expect_success 'detach if the same branch is already checked out' '
 	)
 '
 
+test_expect_success 'not detach on re-checking out current branch' '
+	(
+		cd there &&
+		git checkout newmaster &&
+		git symbolic-ref HEAD
+	)
+'
+
 test_expect_success 'checkout --to from a bare repo' '
 	(
 		git clone --bare . bare &&
t/t2026-prune-linked-checkouts.sh new file +84 -0

84 lines not on this page · raw message

Signature · 1 line
1.9.1.346.ga2b5940