From: "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Johannes Schindelin <johannes.schindelin@gmx.de>,
Junio C Hamano <gitster@pobox.com>
Subject: [PATCH v4 0/2] Handle git_path() with lock files correctly in worktrees
Date: Mon, 28 Oct 2019 12:57:16 +0000 [thread overview]
Message-ID: <pull.401.v4.git.1572267438.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.401.v3.git.1571694882.gitgitgadget@gmail.com>
I stumbled over this during my recent work in Git GUI
[https://github.com/gitgitgadget/git/pull/361] that was originally really
only intended to use the correct hooks directory.
It turns out that my fears that index.lock was mishandled were unfounded,
hence this patch series has a lot lower priority for me than "OMG we must
push this into v2.24.0!".
Technically, the first patch is not needed (because I decided against adding
a test to t1400 in the end, in favor of t1500), but it shouldn't hurt,
either.
I verified locally that this patch pair does not conflict with
sg/dir-trie-fixes.
Changes since v3:
* Instead of duplicating the path when it has a .lock suffix, we now use
strbuf manipulation to strip the suffix temporarily.
* The test case in t1500 was scrapped in favor of a much simpler pair of
test cases in t0060.
Changes since v2:
* Adjusted the commit message to really not talk about index.lock.
* Instead of modifying the code inside trie_find() to special-case .lock, I
now copy the string without the suffix .lock (if any) before handing it
off to trie_find().
Changes since v1:
* Clarified the commit message to state that index.lock is fine, it is
logs/HEAD.lock that isn't.
Johannes Schindelin (2):
t1400: wrap setup code in test case
git_path(): handle `.lock` files correctly
path.c | 6 ++++++
t/t0060-path-utils.sh | 2 ++
t/t1400-update-ref.sh | 18 ++++++++++--------
3 files changed, 18 insertions(+), 8 deletions(-)
base-commit: 108b97dc372828f0e72e56bbb40cae8e1e83ece6
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-401%2Fdscho%2Flock-files-in-worktrees-v4
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-401/dscho/lock-files-in-worktrees-v4
Pull-Request: https://github.com/gitgitgadget/git/pull/401
Range-diff vs v3:
1: cf97c5182e = 1: cf97c5182e t1400: wrap setup code in test case
2: 8b1f4f089a ! 2: d98810875e git_path(): handle `.lock` files correctly
@@ -28,46 +28,40 @@
--- a/path.c
+++ b/path.c
@@
- static void update_common_dir(struct strbuf *buf, int git_dir_len,
+ #include "path.h"
+ #include "packfile.h"
+ #include "object-store.h"
++#include "lockfile.h"
+
+ static int get_st_mode_bits(const char *path, int *mode)
+ {
+@@
const char *common_dir)
{
-- char *base = buf->buf + git_dir_len;
-+ char *base = buf->buf + git_dir_len, *base2 = NULL;
-+
-+ if (ends_with(base, ".lock"))
-+ base = base2 = xstrndup(base, strlen(base) - 5);
+ char *base = buf->buf + git_dir_len;
++ int has_lock_suffix = strbuf_strip_suffix(buf, LOCK_SUFFIX);
+
init_common_trie();
if (trie_find(&common_trie, base, check_common, NULL) > 0)
replace_dir(buf, git_dir_len, common_dir);
+
-+ free(base2);
++ if (has_lock_suffix)
++ strbuf_addstr(buf, LOCK_SUFFIX);
}
void report_linked_checkout_garbage(void)
- diff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh
- --- a/t/t1500-rev-parse.sh
- +++ b/t/t1500-rev-parse.sh
+ diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh
+ --- a/t/t0060-path-utils.sh
+ +++ b/t/t0060-path-utils.sh
@@
- test_cmp expect actual
- '
-
-+test_expect_success 'git-path in worktree' '
-+ test_tick &&
-+ git commit --allow-empty -m empty &&
-+ git worktree add --detach wt &&
-+ test_write_lines >expect \
-+ "$(pwd)/.git/worktrees/wt/logs/HEAD" \
-+ "$(pwd)/.git/worktrees/wt/logs/HEAD.lock" \
-+ "$(pwd)/.git/worktrees/wt/index" \
-+ "$(pwd)/.git/worktrees/wt/index.lock" &&
-+ git -C wt rev-parse >actual \
-+ --git-path logs/HEAD --git-path logs/HEAD.lock \
-+ --git-path index --git-path index.lock &&
-+ test_cmp expect actual
-+'
-+
- test_expect_success 'rev-parse --is-shallow-repository in shallow repo' '
- test_commit test_commit &&
- echo true >expect &&
+ test_git_path GIT_OBJECT_DIRECTORY=foo objects2 .git/objects2
+ test_expect_success 'setup common repository' 'git --git-dir=bar init'
+ test_git_path GIT_COMMON_DIR=bar index .git/index
++test_git_path GIT_COMMON_DIR=bar index.lock .git/index.lock
+ test_git_path GIT_COMMON_DIR=bar HEAD .git/HEAD
+ test_git_path GIT_COMMON_DIR=bar logs/HEAD .git/logs/HEAD
++test_git_path GIT_COMMON_DIR=bar logs/HEAD.lock .git/logs/HEAD.lock
+ test_git_path GIT_COMMON_DIR=bar logs/refs/bisect/foo .git/logs/refs/bisect/foo
+ test_git_path GIT_COMMON_DIR=bar logs/refs/bisec/foo bar/logs/refs/bisec/foo
+ test_git_path GIT_COMMON_DIR=bar logs/refs/bisec bar/logs/refs/bisec
--
gitgitgadget
next prev parent reply other threads:[~2019-10-28 12:57 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-16 7:07 [PATCH 0/2] Handle git_path() with lock files correctly in worktrees Johannes Schindelin via GitGitGadget
2019-10-16 7:07 ` [PATCH 1/2] t1400: wrap setup code in test case Johannes Schindelin via GitGitGadget
2019-10-16 7:07 ` [PATCH 2/2] git_path(): handle `.lock` files correctly Johannes Schindelin via GitGitGadget
2019-10-16 11:04 ` SZEDER Gábor
2019-10-17 7:15 ` Junio C Hamano
2019-10-17 22:05 ` Johannes Schindelin
2019-10-18 11:06 ` SZEDER Gábor
2019-10-18 11:35 ` SZEDER Gábor
2019-10-21 16:00 ` [PATCH 0/5] path.c: a couple of common dir/trie fixes SZEDER Gábor
2019-10-21 16:00 ` [PATCH 1/5] Documentation: mention more worktree-specific exceptions SZEDER Gábor
2019-10-21 16:00 ` [PATCH 2/5] path.c: clarify trie_find()'s in-code comment SZEDER Gábor
2019-10-21 16:00 ` [PATCH 3/5] path.c: mark 'logs/HEAD' in 'common_list' as file SZEDER Gábor
2019-10-21 16:00 ` [PATCH 4/5] path.c: clarify two field names in 'struct common_dir' SZEDER Gábor
2019-10-21 16:00 ` [PATCH 5/5] path.c: don't call the match function without value in trie_find() SZEDER Gábor
2019-10-21 17:39 ` David Turner
2019-10-21 20:57 ` SZEDER Gábor
2019-10-23 4:01 ` Junio C Hamano
2019-10-23 16:20 ` SZEDER Gábor
2019-10-24 3:29 ` Junio C Hamano
2019-10-28 10:57 ` Johannes Schindelin
2019-10-28 12:00 ` SZEDER Gábor
2019-10-28 21:30 ` Johannes Schindelin
2019-10-18 11:42 ` [PATCH 0/2] path.c: minor common_list fixes SZEDER Gábor
2019-10-18 11:42 ` [PATCH 1/2] path.c: fix field name in 'struct common_dir' SZEDER Gábor
2019-10-18 11:42 ` [PATCH 2/2] path.c: mark 'logs/HEAD' in 'common_list' as file SZEDER Gábor
2019-10-21 19:35 ` [PATCH 0/2] path.c: minor common_list fixes Johannes Schindelin
2019-10-17 22:07 ` [PATCH v2 0/2] Handle git_path() with lock files correctly in worktrees Johannes Schindelin via GitGitGadget
2019-10-17 22:07 ` [PATCH v2 1/2] t1400: wrap setup code in test case Johannes Schindelin via GitGitGadget
2019-10-17 22:07 ` [PATCH v2 2/2] git_path(): handle `.lock` files correctly Johannes Schindelin via GitGitGadget
2019-10-18 1:23 ` Junio C Hamano
2019-10-18 12:35 ` SZEDER Gábor
2019-10-21 20:26 ` Johannes Schindelin
2019-10-23 2:12 ` Junio C Hamano
2019-10-21 21:54 ` [PATCH v3 0/2] Handle git_path() with lock files correctly in worktrees Johannes Schindelin via GitGitGadget
2019-10-21 21:54 ` [PATCH v3 1/2] t1400: wrap setup code in test case Johannes Schindelin via GitGitGadget
2019-10-21 21:54 ` [PATCH v3 2/2] git_path(): handle `.lock` files correctly Johannes Schindelin via GitGitGadget
2019-10-22 16:01 ` SZEDER Gábor
2019-10-23 3:38 ` Junio C Hamano
2019-10-28 12:01 ` Johannes Schindelin
2019-10-28 12:32 ` SZEDER Gábor
2019-10-28 17:30 ` Junio C Hamano
2019-10-28 12:57 ` Johannes Schindelin via GitGitGadget [this message]
2019-10-28 12:57 ` [PATCH v4 1/2] t1400: wrap setup code in test case Johannes Schindelin via GitGitGadget
2019-10-28 12:57 ` [PATCH v4 2/2] git_path(): handle `.lock` files correctly Johannes Schindelin via GitGitGadget
2019-10-29 3:39 ` [PATCH v4 0/2] Handle git_path() with lock files correctly in worktrees Junio C Hamano
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=pull.401.v4.git.1572267438.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=johannes.schindelin@gmx.de \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).