From f98548764ea0baf7490b76782e323f90a941cc74 Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Thu, 9 Sep 2010 14:15:57 -0500 Subject: [PATCH 1/7] t/t7008: workaround broken handling of \000 by printf on IRIX On IRIX 6.5, the printf utility in /usr/bin does not appear to handle the \ddd notation according to POSIX. This printf appears to halt processing of the string argument and ignore any additional characters in the string. Work around this flaw by replacing the \000's with 'Q' and using the q_to_nul helper function provided by test-lib.sh This problem with printf is not apparent when using the Bash shell since Bash implements a POSIX compatible printf function internally. Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- t/t7008-grep-binary.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/t/t7008-grep-binary.sh b/t/t7008-grep-binary.sh index c0f9f3f705..e058d184d1 100755 --- a/t/t7008-grep-binary.sh +++ b/t/t7008-grep-binary.sh @@ -5,7 +5,7 @@ test_description='git grep in binary files' . ./test-lib.sh test_expect_success 'setup' " - printf 'binary\000file\n' >a && + echo 'binaryQfile' | q_to_nul >a && git add a && git commit -m. " @@ -70,32 +70,32 @@ test_expect_failure 'git grep .fi a' ' ' test_expect_success 'git grep -F yf a' " - printf 'y\000f' >f && + printf 'yQf' | q_to_nul >f && git grep -f f -F a " test_expect_success 'git grep -F yx a' " - printf 'y\000x' >f && + printf 'yQx' | q_to_nul >f && test_must_fail git grep -f f -F a " test_expect_success 'git grep -Fi Yf a' " - printf 'Y\000f' >f && + printf 'YQf' | q_to_nul >f && git grep -f f -Fi a " test_expect_failure 'git grep -Fi Yx a' " - printf 'Y\000x' >f && + printf 'YQx' | q_to_nul >f && test_must_fail git grep -f f -Fi a " test_expect_success 'git grep yf a' " - printf 'y\000f' >f && + printf 'yQf' | q_to_nul >f && git grep -f f a " test_expect_failure 'git grep yx a' " - printf 'y\000x' >f && + printf 'yQx' | q_to_nul >f && test_must_fail git grep -f f a " From a1d558d254f84e4b816497fe30b2b8ef0b47ba71 Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Thu, 9 Sep 2010 14:15:58 -0500 Subject: [PATCH 2/7] Makefile: use compat regex on IRIX 6.5 The IRIX 6.5 regex.h header file defines REG_STARTEND, but the feature does not appear to work. Since REG_STARTEND is required for proper functioning of git-grep, set NO_REGEX and use the alternative regex libraries in compat/ Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 8b7c243473..c27e8bcc37 100644 --- a/Makefile +++ b/Makefile @@ -982,6 +982,7 @@ ifeq ($(uname_S),IRIX) # NO_MMAP. If you suspect that your compiler is not affected by this # issue, comment out the NO_MMAP statement. NO_MMAP = YesPlease + NO_REGEX = YesPlease SNPRINTF_RETURNS_BOGUS = YesPlease SHELL_PATH = /usr/gnu/bin/bash NEEDS_LIBGEN = YesPlease @@ -1000,6 +1001,7 @@ ifeq ($(uname_S),IRIX64) # NO_MMAP. If you suspect that your compiler is not affected by this # issue, comment out the NO_MMAP statement. NO_MMAP = YesPlease + NO_REGEX = YesPlease SNPRINTF_RETURNS_BOGUS = YesPlease SHELL_PATH=/usr/gnu/bin/bash NEEDS_LIBGEN = YesPlease From f31dbdc7dad3511e1ee73cb04a032773d11231cd Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Thu, 9 Sep 2010 13:56:36 -0500 Subject: [PATCH 3/7] builtin/fetch.c: comment that branch->remote_name is usable when has_merge Save future readers the trouble of tracing code to determine that the two uses of branch->remote_name are safe when has_merge is set, by adding a comment explaining that it is so. Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- builtin/fetch.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/builtin/fetch.c b/builtin/fetch.c index fccc9cbea3..6fc5047703 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -148,6 +148,7 @@ static struct ref *get_ref_map(struct transport *transport, int has_merge = branch_has_merge_config(branch); if (remote && (remote->fetch_refspec_nr || + /* Note: has_merge implies non-NULL branch->remote_name */ (has_merge && !strcmp(branch->remote_name, remote->name)))) { for (i = 0; i < remote->fetch_refspec_nr; i++) { get_fetch_map(remote_refs, &remote->fetch[i], &tail, 0); @@ -162,6 +163,8 @@ static struct ref *get_ref_map(struct transport *transport, * if the remote we're fetching from is the same * as given in branch..remote, we add the * ref given in branch..merge, too. + * + * Note: has_merge implies non-NULL branch->remote_name */ if (has_merge && !strcmp(branch->remote_name, remote->name)) From 042cca38866569ca8a64c6ef1f95c58b157e4d36 Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Thu, 9 Sep 2010 13:56:37 -0500 Subject: [PATCH 4/7] t/t5510-fetch.sh: improve testing with explicit URL and merge spec Commit 6106ce46 introduced a test to demonstrate fetch's failure to retrieve any objects or update FETCH_HEAD when it was supplied a repository URL and the current branch had a configured merge spec. This commit expands the original test based on comments from Junio Hamano. In addition to actually verifying that the fetch updates FETCH_HEAD correctly, and does not update the current branch, two more tests are added to ensure that the merge configuration is ignored even when the supplied URL matches the URL of the remote configured for the branch. Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- t/t5510-fetch.sh | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh index 8fbd894e7f..efb42d1540 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -240,10 +240,36 @@ test_expect_success 'fetch with a non-applying branch..merge' ' git fetch blub ' -test_expect_success 'fetch from GIT URL with a non-applying branch..merge' ' +# URL supplied to fetch does not match the url of the configured branch's remote +test_expect_success 'fetch from GIT URL with a non-applying branch..merge [1]' ' + one_head=$(cd one && git rev-parse HEAD) && + this_head=$(git rev-parse HEAD) && git update-ref -d FETCH_HEAD && git fetch one && - git rev-parse --verify FETCH_HEAD + test $one_head = "$(git rev-parse --verify FETCH_HEAD)" && + test $this_head = "$(git rev-parse --verify HEAD)" +' + +# URL supplied to fetch matches the url of the configured branch's remote and +# the merge spec matches the branch the remote HEAD points to +test_expect_success 'fetch from GIT URL with a non-applying branch..merge [2]' ' + one_ref=$(cd one && git symbolic-ref HEAD) && + git config branch.master.remote blub && + git config branch.master.merge "$one_ref" && + git update-ref -d FETCH_HEAD && + git fetch one && + test $one_head = "$(git rev-parse --verify FETCH_HEAD)" && + test $this_head = "$(git rev-parse --verify HEAD)" +' + +# URL supplied to fetch matches the url of the configured branch's remote, but +# the merge spec does not match the branch the remote HEAD points to +test_expect_success 'fetch from GIT URL with a non-applying branch..merge [3]' ' + git config branch.master.merge "${one_ref}_not" && + git update-ref -d FETCH_HEAD && + git fetch one && + test $one_head = "$(git rev-parse --verify FETCH_HEAD)" && + test $this_head = "$(git rev-parse --verify HEAD)" ' # the strange name is: a\!'b From ef5644ea6ecec4ee6d6254612af2ed58499ac2fe Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Thu, 9 Sep 2010 14:02:45 -0500 Subject: [PATCH 5/7] diff.c: call regfree to free memory allocated by regcomp when necessary Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- diff.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/diff.c b/diff.c index 93004922de..19b5bf63ed 100644 --- a/diff.c +++ b/diff.c @@ -912,7 +912,10 @@ static void free_diff_words_data(struct emit_callback *ecbdata) free (ecbdata->diff_words->minus.orig); free (ecbdata->diff_words->plus.text.ptr); free (ecbdata->diff_words->plus.orig); - free(ecbdata->diff_words->word_regex); + if (ecbdata->diff_words->word_regex) { + regfree(ecbdata->diff_words->word_regex); + free(ecbdata->diff_words->word_regex); + } free(ecbdata->diff_words); ecbdata->diff_words = NULL; } From 1b6ecbad3511b1aaa65172ef8b520dd3b5141614 Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Thu, 9 Sep 2010 14:02:46 -0500 Subject: [PATCH 6/7] xdiff-interface.c: always trim trailing space from xfuncname matches Generally, trailing space is removed from the string matched by the xfuncname patterns. The exception is when the matched string exceeds the length of the fixed-size buffer that it will be copied in to. But, a string that exceeds the buffer can still contain trailing space in the portion of the string that will be copied into the buffer. So, simplify this code slightly, and just perform the trailing space removal always. Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- xdiff-interface.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/xdiff-interface.c b/xdiff-interface.c index cd2285de1c..e1e054e4d9 100644 --- a/xdiff-interface.c +++ b/xdiff-interface.c @@ -286,9 +286,8 @@ static long ff_regexp(const char *line, long len, result = pmatch[i].rm_eo - pmatch[i].rm_so; if (result > buffer_size) result = buffer_size; - else - while (result > 0 && (isspace(line[result - 1]))) - result--; + while (result > 0 && (isspace(line[result - 1]))) + result--; memcpy(buffer, line, result); fail: free(line_buffer); From bff42061214e17f342efc909c73f29bf66df51e9 Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Thu, 9 Sep 2010 14:02:47 -0500 Subject: [PATCH 7/7] t/t4018: test whether the word_regex patterns compile Previously (e3bf5e43), a test was added to test whether the builtin xfuncname regular expressions could be compiled without error by regcomp. Let's do the same for the word_regex patterns. This should help catch any cross-platform incompatibilities that exist between the pattern creator's system and the various platforms that the test suite is commonly run on. Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- t/t4018-diff-funcname.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh index 61de8a2718..620cd02798 100755 --- a/t/t4018-diff-funcname.sh +++ b/t/t4018-diff-funcname.sh @@ -40,6 +40,11 @@ do ! ( git diff --no-index Beer.java Beer-correct.java 2>&1 | grep "fatal" > /dev/null ) ' + test_expect_success "builtin $p wordRegex pattern compiles" ' + ! ( git diff --no-index --word-diff \ + Beer.java Beer-correct.java 2>&1 | + grep "fatal" > /dev/null ) + ' done test_expect_success 'default behaviour' '