diff options
author | Junio C Hamano <gitster@pobox.com> | 2010-01-22 16:12:41 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-01-22 16:12:41 -0800 |
commit | 459a18864fe5afaf1d7a7856906c921d6b756733 (patch) | |
tree | 893ad8a44980b1ab79ebb8a6ff47b020dfe9959e | |
parent | 630724ca79b1a7893a8d9c04367eae857ff1a7b0 (diff) | |
parent | 288123f01cb1b835edbf6e2e188159c2ff858aca (diff) | |
download | git-459a18864fe5afaf1d7a7856906c921d6b756733.tar.gz |
Merge branch 'maint'
* maint:
ignore duplicated slashes in make_relative_path()
-rw-r--r-- | path.c | 39 | ||||
-rwxr-xr-x | t/t1501-worktree.sh | 6 |
2 files changed, 36 insertions, 9 deletions
@@ -394,17 +394,38 @@ int set_shared_perm(const char *path, int mode) const char *make_relative_path(const char *abs, const char *base) { static char buf[PATH_MAX + 1]; - int baselen; - if (!base) - return abs; - baselen = strlen(base); - if (prefixcmp(abs, base)) + int i = 0, j = 0; + + if (!base || !base[0]) return abs; - if (abs[baselen] == '/') - baselen++; - else if (base[baselen - 1] != '/') + while (base[i]) { + if (is_dir_sep(base[i])) { + if (!is_dir_sep(abs[j])) + return abs; + while (is_dir_sep(base[i])) + i++; + while (is_dir_sep(abs[j])) + j++; + continue; + } else if (abs[j] != base[i]) { + return abs; + } + i++; + j++; + } + if ( + /* "/foo" is a prefix of "/foo" */ + abs[j] && + /* "/foo" is not a prefix of "/foobar" */ + !is_dir_sep(base[i-1]) && !is_dir_sep(abs[j]) + ) return abs; - strcpy(buf, abs + baselen); + while (is_dir_sep(abs[j])) + j++; + if (!abs[j]) + strcpy(buf, "."); + else + strcpy(buf, abs + j); return buf; } diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh index 74e6443664..9df301211c 100755 --- a/t/t1501-worktree.sh +++ b/t/t1501-worktree.sh @@ -189,4 +189,10 @@ test_expect_success 'absolute pathspec should fail gracefully' ' ) ' +test_expect_success 'make_relative_path handles double slashes in GIT_DIR' ' + : > dummy_file + echo git --git-dir="$(pwd)//repo.git" --work-tree="$(pwd)" add dummy_file && + git --git-dir="$(pwd)//repo.git" --work-tree="$(pwd)" add dummy_file +' + test_done |