Re: [PATCH v3 00/32] nd/multiple-work-trees

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

 



Nguyễn Thái Ngọc Duy  <pclouds@xxxxxxxxx> writes:

> On Fri, Sep 26, 2014 at 4:20 AM, Junio C Hamano <gitster@xxxxxxxxx> wrote:
>> It has been a while since the last review exchanges were seen.  Will
>> it be time for v3 soon?
>
> Sorry I've been slow on picking up feedback from v2. v3 is rebased on
> latest master. Other changes are mostly *.txt, and one broken &&
> chain.

As there have been quite a lot of changes in overlapping areas
(e.g. with Ronnie and Jonathan's refs.c clean-up series, and also
with Tanay's config API changes in builtin/gc.c), I agree that it no
longer makes sense to stick to the old fork point.

This applies cleanly to the 'master', the result merges cleanly to
where the old series were merged to 'pu', and the difference between
the old/new "pu^{/^Merge branch 'nd/multiple-work-trees' into pu}"
commits matches what I remember from the review discussion you were
having on the old series with others (attached below for others to
eyeball as a rough substitute for an interdiff).

Thanks.

diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt
index 23f0c80..0c13825 100644
--- a/Documentation/git-checkout.txt
+++ b/Documentation/git-checkout.txt
@@ -229,8 +229,8 @@ section of linkgit:git-add[1] to learn how to operate the `--patch` mode.
 	Check out a branch in a separate working directory at
 	`<path>`. A new working directory is linked to the current
 	repository, sharing everything except working directory
-	specific files such as HEAD, index... See "MULTIPLE CHECKOUT
-	MODE" section for more information.
+	specific files such as HEAD, index... See "MULTIPLE WORKING
+	TREES" section for more information.
 
 <branch>::
 	Branch to checkout; if it refers to a branch (i.e., a name that,
@@ -395,58 +395,66 @@ $ git reflog -2 HEAD # or
 $ git log -g -2 HEAD
 ------------
 
-MULTIPLE CHECKOUT MODE
+MULTIPLE WORKING TREES
 ----------------------
-Normally a working directory is attached to repository. When "git
-checkout --to" is used, a new working directory is attached to the
-current repository. This new working directory is called "linked
-checkout" as compared to the "main checkout" prepared by "git init" or
-"git clone". A repository has one main checkout and zero or more
-linked checkouts.
-
-Each linked checkout has a private directory in $GIT_DIR/worktrees in
-the main checkout, usually named after the base name of the new
-working directory, optionally with a number added to make it
-unique. For example, the command `git checkout --to ../test-next next`
-running with $GIT_DIR=/path/main may create the directory
-`$GIT_DIR/worktrees/test-next` (or `$GIT_DIR/worktrees/test-next1` if
-`test-next` is already taken).
-
-Within a linked checkout, $GIT_DIR is set to point to this private
-directory (e.g. `/path/main/worktrees/test-next` in the example) and
-$GIT_COMMON_DIR is set to point back to the main checkout's $GIT_DIR
-(e.g. `/path/main`). Setting is done via a .git file located at the
-top directory of the linked checkout.
-
-Path resolution via `git rev-parse --git-path` would use either
-$GIT_DIR or $GIT_COMMON_DIR depending on the path. For example, the
-linked checkout's `$GIT_DIR/HEAD` resolve to
-`/path/main/worktrees/test-next/HEAD` (not `/path/main/HEAD` which is
-the main checkout's HEAD) while `$GIT_DIR/refs/heads/master` would use
-$GIT_COMMON_DIR and resolve to `/path/main/refs/heads/master`, which
-is shared across checkouts.
+
+A git repository can support multiple working trees, allowing you to check
+out more than one branch at a time.  With `git checkout --to` a new working
+tree is associated with the repository.  This new working tree is called a
+"linked working tree" as opposed to the "main working tree" prepared by "git
+init" or "git clone".  A repository has one main working tree (if it's not a
+bare repository) and zero or more linked working trees.
+
+Each linked working tree has a private sub-directory in the repository's
+$GIT_DIR/worktrees directory.  The private sub-directory's name is usually
+the base name of the linked working tree's path, possibly appended with a
+number to make it unique.  For example, when `$GIT_DIR=/path/main/.git` the
+command `git checkout --to /path/other/test-next next` creates the linked
+working tree in `/path/other/test-next` and also creates a
+`$GIT_DIR/worktrees/test-next` directory (or `$GIT_DIR/worktrees/test-next1`
+if `test-next` is already taken).
+
+Within a linked working tree, $GIT_DIR is set to point to this private
+directory (e.g. `/path/main/.git/worktrees/test-next` in the example) and
+$GIT_COMMON_DIR is set to point back to the main working tree's $GIT_DIR
+(e.g. `/path/main/.git`). These settings are made in a `.git` file located at
+the top directory of the linked working tree.
+
+Path resolution via `git rev-parse --git-path` uses either
+$GIT_DIR or $GIT_COMMON_DIR depending on the path. For example, in the
+linked working tree `git rev-parse --git-path HEAD` returns
+`/path/main/.git/worktrees/test-next/HEAD` (not
+`/path/other/test-next/.git/HEAD` or `/path/main/.git/HEAD`) while `git
+rev-parse --git-path refs/heads/master` uses
+$GIT_COMMON_DIR and returns `/path/main/.git/refs/heads/master`,
+since refs are shared across all working trees.
 
 See linkgit:gitrepository-layout[5] for more information. The rule of
 thumb is do not make any assumption about whether a path belongs to
 $GIT_DIR or $GIT_COMMON_DIR when you need to directly access something
 inside $GIT_DIR. Use `git rev-parse --git-path` to get the final path.
 
-When you are done, simply deleting the linked working directory would
-suffice. $GIT_DIR/worktrees can be cleaned up using `git prune
---worktrees`, which is part of automated garbage collection.
-
-After you move a linked working directory to another file system, or
-on a file system that does not support hard link, execute any git
-command (e.g. `git status`) in the new working directory so that it
-could update its location in $GIT_DIR/worktrees and not be
-accidentally pruned.
-
-To stop `git prune --worktrees` from deleting a specific working
-directory (e.g. because it's on a portable device), you could add the
-file 'locked' to $GIT_DIR/worktrees. For example, if `.git` file of
-the new working directory points to `/path/main/worktrees/test-next`,
-the full path of the 'locked' file would be
-`/path/main/worktrees/test-next/locked`. See
+When you are done with a linked working tree you can simply delete it.
+The working tree's entry in the repository's $GIT_DIR/worktrees
+directory will eventually be removed automatically (see
+`gc.pruneworktreesexpire` in linkgit::git-config[1]), or you can run
+`git prune --worktrees` in the main or any linked working tree to
+clean up any stale entries in $GIT_DIR/worktrees.
+
+If you move a linked working directory to another file system, or
+within a file system that does not support hard links, you need to run
+at least one git command inside the linked working directory
+(e.g. `git status`) in order to update its entry in $GIT_DIR/worktrees
+so that it does not get automatically removed.
+
+To prevent a $GIT_DIR/worktrees entry from from being pruned (which
+can be useful in some situations, such as when the
+entry's working tree is stored on a portable device), add a file named
+'locked' to the entry's directory. The file contains the reason in
+plain text. For example, if a linked working tree's `.git` file points
+to `/path/main/.git/worktrees/test-next` then a file named
+`/path/main/.git/worktrees/test-next/locked` will prevent the
+`test-next` entry from being pruned.  See
 linkgit:gitrepository-layout[5] for details.
 
 EXAMPLES
diff --git a/Documentation/git-prune.txt b/Documentation/git-prune.txt
index a0ea381..1cf3bed 100644
--- a/Documentation/git-prune.txt
+++ b/Documentation/git-prune.txt
@@ -49,7 +49,7 @@ OPTIONS
 	Only expire loose objects older than <time>.
 
 --worktrees::
-	Prune dead worktree information in $GIT_DIR/worktrees.
+	Prune dead working tree information in $GIT_DIR/worktrees.
 
 <head>...::
 	In addition to objects
diff --git a/builtin/gc.c b/builtin/gc.c
index 125f0dd..35542f3 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -57,12 +57,14 @@ static void remove_pidfile_on_signal(int signo)
 	raise(signo);
 }
 
-static void git_config_get_date_string(const char *var, const char **out)
+static void git_config_date_string(const char *key, const char **output)
 {
-	if (!git_config_get_string_const(var, out) && strcmp(*out, "now")) {
+	if (git_config_get_string_const(key, output))
+		return;
+	if (strcmp(*output, "now")) {
 		unsigned long now = approxidate("now");
-		if (approxidate(*out) >= now)
-			git_die_config(var, _("Invalid %s: '%s'"), var, *out);
+		if (approxidate(*output) >= now)
+			git_die_config(key, _("Invalid %s: '%s'"), key, *output);
 	}
 }
 
@@ -82,8 +84,8 @@ static void gc_config(void)
 	git_config_get_int("gc.auto", &gc_auto_threshold);
 	git_config_get_int("gc.autopacklimit", &gc_auto_pack_limit);
 	git_config_get_bool("gc.autodetach", &detach_auto);
-	git_config_get_date_string("gc.pruneexpire", &prune_expire);
-	git_config_get_date_string("gc.pruneworktreesexpire", &prune_worktrees_expire);
+	git_config_date_string("gc.pruneexpire", &prune_expire);
+	git_config_date_string("gc.pruneworktreesexpire", &prune_worktrees_expire);
 	git_config(git_default_config, NULL);
 }
 
diff --git a/refs.c b/refs.c
index c4850f5..33ac01c 100644
--- a/refs.c
+++ b/refs.c
@@ -2935,12 +2935,14 @@ static int log_ref_write(const char *refname, const unsigned char *old_sha1,
 		error("Unable to append to %s", log_file);
 		errno = save_errno;
 		result = -1;
+		goto done;
 	}
 	if (close(logfd)) {
 		int save_errno = errno;
 		error("Unable to append to %s", log_file);
 		errno = save_errno;
 		result = -1;
+		goto done;
 	}
 done:
 	strbuf_release(&sb_log_file);
diff --git a/t/t2025-checkout-to.sh b/t/t2025-checkout-to.sh
index 27384a1..eddd325 100755
--- a/t/t2025-checkout-to.sh
+++ b/t/t2025-checkout-to.sh
@@ -49,7 +49,7 @@ test_expect_success 'checkout --to a new worktree from a subdir' '
 test_expect_success 'checkout --to from a linked checkout' '
 	(
 		cd here &&
-		git checkout --detach --to nested-here master
+		git checkout --detach --to nested-here master &&
 		cd nested-here &&
 		git fsck
 	)
diff --git a/wrapper.c b/wrapper.c
index 6f40341..e821d05 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -531,6 +531,14 @@ struct passwd *xgetpwuid_self(void)
 	return pw;
 }
 
+char *xgetcwd(void)
+{
+	struct strbuf sb = STRBUF_INIT;
+	if (strbuf_getcwd(&sb))
+		die_errno(_("unable to get current working directory"));
+	return strbuf_detach(&sb, NULL);
+}
+
 int write_file(const char *path, int fatal, const char *fmt, ...)
 {
 	struct strbuf sb = STRBUF_INIT;
@@ -561,11 +569,3 @@ int write_file(const char *path, int fatal, const char *fmt, ...)
 	}
 	return 0;
 }
-
-char *xgetcwd(void)
-{
-	struct strbuf sb = STRBUF_INIT;
-	if (strbuf_getcwd(&sb))
-		die_errno(_("unable to get current working directory"));
-	return strbuf_detach(&sb, NULL);
-}
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[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]