summaryrefslogtreecommitdiff
path: root/path.c
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2019-10-28 12:57:18 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-10-29 03:38:36 (GMT)
commit76a53d640f72fc77e7e9358dfeb5df5ece56515f (patch)
tree7a3817c9fc72729404874281fe11e7e48649f4e0 /path.c
parent3ce47211a6ecae0ebe241779ef7112ee21f04a74 (diff)
downloadgit-76a53d640f72fc77e7e9358dfeb5df5ece56515f.zip
git-76a53d640f72fc77e7e9358dfeb5df5ece56515f.tar.gz
git-76a53d640f72fc77e7e9358dfeb5df5ece56515f.tar.bz2
git_path(): handle `.lock` files correctly
Ever since worktrees were introduced, the `git_path()` function _really_ needed to be called e.g. to get at the path to `logs/HEAD` (`HEAD` is specific to the worktree, and therefore so is its reflog). However, the wrong path is returned for `logs/HEAD.lock`. This does not matter as long as the Git executable is doing the asking, as the path for that `logs/HEAD.lock` file is constructed from `git_path("logs/HEAD")` by appending the `.lock` suffix. However, Git GUI just learned to use `--git-path` instead of appending relative paths to what `git rev-parse --git-dir` returns (and as a consequence not only using the correct hooks directory, but also using the correct paths in worktrees other than the main one). While it does not seem as if Git GUI in particular is asking for `logs/HEAD.lock`, let's be safe rather than sorry. Side note: Git GUI _does_ ask for `index.lock`, but that is already resolved correctly, due to `update_common_dir()` preferring to leave unknown paths in the (worktree-specific) git directory. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'path.c')
-rw-r--r--path.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/path.c b/path.c
index 25e97b8..d086595 100644
--- a/path.c
+++ b/path.c
@@ -11,6 +11,7 @@
#include "path.h"
#include "packfile.h"
#include "object-store.h"
+#include "lockfile.h"
static int get_st_mode_bits(const char *path, int *mode)
{
@@ -350,9 +351,14 @@ static void update_common_dir(struct strbuf *buf, int git_dir_len,
const char *common_dir)
{
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);
+
+ if (has_lock_suffix)
+ strbuf_addstr(buf, LOCK_SUFFIX);
}
void report_linked_checkout_garbage(void)