Browse Source
* dr/ceiling: Eliminate an unnecessary chdir("..") Add support for GIT_CEILING_DIRECTORIES Fold test-absolute-path into test-path-utils Implement normalize_absolute_path Conflicts: cache.h setup.cmaint
Junio C Hamano
17 years ago
12 changed files with 406 additions and 32 deletions
@ -0,0 +1,87 @@
@@ -0,0 +1,87 @@
|
||||
#!/bin/sh |
||||
# |
||||
# Copyright (c) 2008 David Reiss |
||||
# |
||||
|
||||
test_description='Test various path utilities' |
||||
|
||||
. ./test-lib.sh |
||||
|
||||
norm_abs() { |
||||
test_expect_success "normalize absolute" \ |
||||
"test \$(test-path-utils normalize_absolute_path '$1') = '$2'" |
||||
} |
||||
|
||||
ancestor() { |
||||
test_expect_success "longest ancestor" \ |
||||
"test \$(test-path-utils longest_ancestor_length '$1' '$2') = '$3'" |
||||
} |
||||
|
||||
norm_abs "" / |
||||
norm_abs / / |
||||
norm_abs // / |
||||
norm_abs /// / |
||||
norm_abs /. / |
||||
norm_abs /./ / |
||||
norm_abs /./.. / |
||||
norm_abs /../. / |
||||
norm_abs /./../.// / |
||||
norm_abs /dir/.. / |
||||
norm_abs /dir/sub/../.. / |
||||
norm_abs /dir /dir |
||||
norm_abs /dir// /dir |
||||
norm_abs /./dir /dir |
||||
norm_abs /dir/. /dir |
||||
norm_abs /dir///./ /dir |
||||
norm_abs /dir//sub/.. /dir |
||||
norm_abs /dir/sub/../ /dir |
||||
norm_abs //dir/sub/../. /dir |
||||
norm_abs /dir/s1/../s2/ /dir/s2 |
||||
norm_abs /d1/s1///s2/..//../s3/ /d1/s3 |
||||
norm_abs /d1/s1//../s2/../../d2 /d2 |
||||
norm_abs /d1/.../d2 /d1/.../d2 |
||||
norm_abs /d1/..././../d2 /d1/d2 |
||||
|
||||
ancestor / "" -1 |
||||
ancestor / / -1 |
||||
ancestor /foo "" -1 |
||||
ancestor /foo : -1 |
||||
ancestor /foo ::. -1 |
||||
ancestor /foo ::..:: -1 |
||||
ancestor /foo / 0 |
||||
ancestor /foo /fo -1 |
||||
ancestor /foo /foo -1 |
||||
ancestor /foo /foo/ -1 |
||||
ancestor /foo /bar -1 |
||||
ancestor /foo /bar/ -1 |
||||
ancestor /foo /foo/bar -1 |
||||
ancestor /foo /foo:/bar/ -1 |
||||
ancestor /foo /foo/:/bar/ -1 |
||||
ancestor /foo /foo::/bar/ -1 |
||||
ancestor /foo /:/foo:/bar/ 0 |
||||
ancestor /foo /foo:/:/bar/ 0 |
||||
ancestor /foo /:/bar/:/foo 0 |
||||
ancestor /foo/bar "" -1 |
||||
ancestor /foo/bar / 0 |
||||
ancestor /foo/bar /fo -1 |
||||
ancestor /foo/bar foo -1 |
||||
ancestor /foo/bar /foo 4 |
||||
ancestor /foo/bar /foo/ 4 |
||||
ancestor /foo/bar /foo/ba -1 |
||||
ancestor /foo/bar /:/fo 0 |
||||
ancestor /foo/bar /foo:/foo/ba 4 |
||||
ancestor /foo/bar /bar -1 |
||||
ancestor /foo/bar /bar/ -1 |
||||
ancestor /foo/bar /fo: -1 |
||||
ancestor /foo/bar :/fo -1 |
||||
ancestor /foo/bar /foo:/bar/ 4 |
||||
ancestor /foo/bar /:/foo:/bar/ 4 |
||||
ancestor /foo/bar /foo:/:/bar/ 4 |
||||
ancestor /foo/bar /:/bar/:/fo 0 |
||||
ancestor /foo/bar /:/bar/ 0 |
||||
ancestor /foo/bar :://foo/. 4 |
||||
ancestor /foo/bar :://foo/.:: 4 |
||||
ancestor /foo/bar //foo/./::/bar 4 |
||||
ancestor /foo/bar ::/bar -1 |
||||
|
||||
test_done |
@ -0,0 +1,163 @@
@@ -0,0 +1,163 @@
|
||||
#!/bin/sh |
||||
|
||||
test_description='test GIT_CEILING_DIRECTORIES' |
||||
. ./test-lib.sh |
||||
|
||||
test_prefix() { |
||||
test_expect_success "$1" \ |
||||
"test '$2' = \"\$(git rev-parse --show-prefix)\"" |
||||
} |
||||
|
||||
test_fail() { |
||||
test_expect_code 128 "$1: prefix" \ |
||||
"git rev-parse --show-prefix" |
||||
} |
||||
|
||||
TRASH_ROOT="$(pwd)" |
||||
ROOT_PARENT=$(dirname "$TRASH_ROOT") |
||||
|
||||
|
||||
unset GIT_CEILING_DIRECTORIES |
||||
test_prefix no_ceil "" |
||||
|
||||
export GIT_CEILING_DIRECTORIES |
||||
|
||||
GIT_CEILING_DIRECTORIES="" |
||||
test_prefix ceil_empty "" |
||||
|
||||
GIT_CEILING_DIRECTORIES="$ROOT_PARENT" |
||||
test_prefix ceil_at_parent "" |
||||
|
||||
GIT_CEILING_DIRECTORIES="$ROOT_PARENT/" |
||||
test_prefix ceil_at_parent_slash "" |
||||
|
||||
GIT_CEILING_DIRECTORIES="$TRASH_ROOT" |
||||
test_prefix ceil_at_trash "" |
||||
|
||||
GIT_CEILING_DIRECTORIES="$TRASH_ROOT/" |
||||
test_prefix ceil_at_trash_slash "" |
||||
|
||||
GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sub" |
||||
test_prefix ceil_at_sub "" |
||||
|
||||
GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sub/" |
||||
test_prefix ceil_at_sub_slash "" |
||||
|
||||
|
||||
mkdir -p sub/dir || exit 1 |
||||
cd sub/dir || exit 1 |
||||
|
||||
unset GIT_CEILING_DIRECTORIES |
||||
test_prefix subdir_no_ceil "sub/dir/" |
||||
|
||||
export GIT_CEILING_DIRECTORIES |
||||
|
||||
GIT_CEILING_DIRECTORIES="" |
||||
test_prefix subdir_ceil_empty "sub/dir/" |
||||
|
||||
GIT_CEILING_DIRECTORIES="$TRASH_ROOT" |
||||
test_fail subdir_ceil_at_trash |
||||
|
||||
GIT_CEILING_DIRECTORIES="$TRASH_ROOT/" |
||||
test_fail subdir_ceil_at_trash_slash |
||||
|
||||
GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sub" |
||||
test_fail subdir_ceil_at_sub |
||||
|
||||
GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sub/" |
||||
test_fail subdir_ceil_at_sub_slash |
||||
|
||||
GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sub/dir" |
||||
test_prefix subdir_ceil_at_subdir "sub/dir/" |
||||
|
||||
GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sub/dir/" |
||||
test_prefix subdir_ceil_at_subdir_slash "sub/dir/" |
||||
|
||||
|
||||
GIT_CEILING_DIRECTORIES="$TRASH_ROOT/su" |
||||
test_prefix subdir_ceil_at_su "sub/dir/" |
||||
|
||||
GIT_CEILING_DIRECTORIES="$TRASH_ROOT/su/" |
||||
test_prefix subdir_ceil_at_su_slash "sub/dir/" |
||||
|
||||
GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sub/di" |
||||
test_prefix subdir_ceil_at_sub_di "sub/dir/" |
||||
|
||||
GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sub/di" |
||||
test_prefix subdir_ceil_at_sub_di_slash "sub/dir/" |
||||
|
||||
GIT_CEILING_DIRECTORIES="$TRASH_ROOT/subdi" |
||||
test_prefix subdir_ceil_at_subdi "sub/dir/" |
||||
|
||||
GIT_CEILING_DIRECTORIES="$TRASH_ROOT/subdi" |
||||
test_prefix subdir_ceil_at_subdi_slash "sub/dir/" |
||||
|
||||
|
||||
GIT_CEILING_DIRECTORIES="foo:$TRASH_ROOT/sub" |
||||
test_fail second_of_two |
||||
|
||||
GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sub:bar" |
||||
test_fail first_of_two |
||||
|
||||
GIT_CEILING_DIRECTORIES="foo:$TRASH_ROOT/sub:bar" |
||||
test_fail second_of_three |
||||
|
||||
|
||||
GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sub" |
||||
GIT_DIR=../../.git |
||||
export GIT_DIR |
||||
test_prefix git_dir_specified "" |
||||
unset GIT_DIR |
||||
|
||||
|
||||
cd ../.. || exit 1 |
||||
mkdir -p s/d || exit 1 |
||||
cd s/d || exit 1 |
||||
|
||||
unset GIT_CEILING_DIRECTORIES |
||||
test_prefix sd_no_ceil "s/d/" |
||||
|
||||
export GIT_CEILING_DIRECTORIES |
||||
|
||||
GIT_CEILING_DIRECTORIES="" |
||||
test_prefix sd_ceil_empty "s/d/" |
||||
|
||||
GIT_CEILING_DIRECTORIES="$TRASH_ROOT" |
||||
test_fail sd_ceil_at_trash |
||||
|
||||
GIT_CEILING_DIRECTORIES="$TRASH_ROOT/" |
||||
test_fail sd_ceil_at_trash_slash |
||||
|
||||
GIT_CEILING_DIRECTORIES="$TRASH_ROOT/s" |
||||
test_fail sd_ceil_at_s |
||||
|
||||
GIT_CEILING_DIRECTORIES="$TRASH_ROOT/s/" |
||||
test_fail sd_ceil_at_s_slash |
||||
|
||||
GIT_CEILING_DIRECTORIES="$TRASH_ROOT/s/d" |
||||
test_prefix sd_ceil_at_sd "s/d/" |
||||
|
||||
GIT_CEILING_DIRECTORIES="$TRASH_ROOT/s/d/" |
||||
test_prefix sd_ceil_at_sd_slash "s/d/" |
||||
|
||||
|
||||
GIT_CEILING_DIRECTORIES="$TRASH_ROOT/su" |
||||
test_prefix sd_ceil_at_su "s/d/" |
||||
|
||||
GIT_CEILING_DIRECTORIES="$TRASH_ROOT/su/" |
||||
test_prefix sd_ceil_at_su_slash "s/d/" |
||||
|
||||
GIT_CEILING_DIRECTORIES="$TRASH_ROOT/s/di" |
||||
test_prefix sd_ceil_at_s_di "s/d/" |
||||
|
||||
GIT_CEILING_DIRECTORIES="$TRASH_ROOT/s/di" |
||||
test_prefix sd_ceil_at_s_di_slash "s/d/" |
||||
|
||||
GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sdi" |
||||
test_prefix sd_ceil_at_sdi "s/d/" |
||||
|
||||
GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sdi" |
||||
test_prefix sd_ceil_at_sdi_slash "s/d/" |
||||
|
||||
|
||||
test_done |
@ -1,11 +0,0 @@
@@ -1,11 +0,0 @@
|
||||
#include "cache.h" |
||||
|
||||
int main(int argc, char **argv) |
||||
{ |
||||
while (argc > 1) { |
||||
puts(make_absolute_path(argv[1])); |
||||
argc--; |
||||
argv++; |
||||
} |
||||
return 0; |
||||
} |
@ -0,0 +1,26 @@
@@ -0,0 +1,26 @@
|
||||
#include "cache.h" |
||||
|
||||
int main(int argc, char **argv) |
||||
{ |
||||
if (argc == 3 && !strcmp(argv[1], "normalize_absolute_path")) { |
||||
char *buf = xmalloc(strlen(argv[2])+1); |
||||
int rv = normalize_absolute_path(buf, argv[2]); |
||||
assert(strlen(buf) == rv); |
||||
puts(buf); |
||||
} |
||||
|
||||
if (argc >= 2 && !strcmp(argv[1], "make_absolute_path")) { |
||||
while (argc > 2) { |
||||
puts(make_absolute_path(argv[2])); |
||||
argc--; |
||||
argv++; |
||||
} |
||||
} |
||||
|
||||
if (argc == 4 && !strcmp(argv[1], "longest_ancestor_length")) { |
||||
int len = longest_ancestor_length(argv[2], argv[3]); |
||||
printf("%d\n", len); |
||||
} |
||||
|
||||
return 0; |
||||
} |
Loading…
Reference in new issue