{"thread":{"id":"7790","subject":"[PATCH] dir.c(common_prefix): Fix two bugs","startedAt":"2007-04-23T08:21:25Z","lastAt":"2007-04-23T09:22:21Z","messageCount":4,"participants":["Johannes Schindelin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"40178","messageId":"Pine.LNX.4.64.0704231020070.8822@racer.site","threadId":"7790","inReplyTo":null,"subject":"[PATCH] dir.c(common_prefix): Fix two bugs","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-04-23T08:21:25Z","receivedAt":"2007-04-23T08:21:25Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nThe function common_prefix() is used to find the common subdirectory of\na couple of pathnames. When checking if the next pathname matches up with\nthe prefix, it incorrectly checked the whole path, not just the prefix\n(including the slash). Thus, the expensive part of the loop was executed\nalways.\n\nThe other bug is more serious: if the first and the last pathname in the\nlist have a longer common prefix than the common prefix for _all_ pathnames\nin the list, the longer one would be chosen. This bug was probably hidden\nby the fact that bash's wildcard expansion sorts the results, and the code\njust so happens to work with sorted input.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n\n\tIf you're up for a very surprising error message, run the test \n\twithout compiling git-add first...\n\n dir.c          |    3 ++-\n t/t3700-add.sh |    6 ++++++\n 2 files changed, 8 insertions(+), 1 deletions(-)\n\ndiff --git a/dir.c b/dir.c\nindex 6564a92..d306352 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -34,8 +34,9 @@ int common_prefix(const char **pathspec)\n \tprefix = slash - path + 1;\n \twhile ((next = *++pathspec) != NULL) {\n \t\tint len = strlen(next);\n-\t\tif (len >= prefix && !memcmp(path, next, len))\n+\t\tif (len >= prefix && !memcmp(path, next, prefix))\n \t\t\tcontinue;\n+\t\tlen = prefix - 1;\n \t\tfor (;;) {\n \t\t\tif (!len)\n \t\t\t\treturn 0;\ndiff --git a/t/t3700-add.sh b/t/t3700-add.sh\nindex 08e0352..ad8cc7d 100755\n--- a/t/t3700-add.sh\n+++ b/t/t3700-add.sh\n@@ -104,4 +104,10 @@ test_expect_success 'add ignored ones with -f' '\n \tgit-ls-files --error-unmatch d.ig/d.if d.ig/d.ig\n '\n \n+mkdir 1 1/2 1/3\n+touch 1/2/a 1/3/b 1/2/c\n+test_expect_success 'check correct prefix detection' '\n+\tgit add 1/2/a 1/3/b 1/2/c\n+'\n+\n test_done\n-- \n1.5.1.1.2671.g2bc0-dirty\n"},{"id":"40181","messageId":"7vzm4zh3z7.fsf@assigned-by-dhcp.cox.net","threadId":"7790","inReplyTo":"Pine.LNX.4.64.0704231020070.8822@racer.site","subject":"Re: [PATCH] dir.c(common_prefix): Fix two bugs","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-04-23T08:47:24Z","receivedAt":"2007-04-23T08:47:24Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> \tIf you're up for a very surprising error message, run the test \n> \twithout compiling git-add first...\n\n$ PATH=/usr/bin:/bin sh t3700-add.sh -i -v\n* expecting success: touch foo && git-add foo\n./test-lib.sh: line 136: git-add: command not found\n* FAIL 1: Test of git-add\n        touch foo && git-add foo\n$ echo $?\n1\n"},{"id":"40183","messageId":"Pine.LNX.4.64.0704231108230.8822@racer.site","threadId":"7790","inReplyTo":"7vzm4zh3z7.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] dir.c(common_prefix): Fix two bugs","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-04-23T09:12:26Z","receivedAt":"2007-04-23T09:12:26Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 23 Apr 2007, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n> \n> > \tIf you're up for a very surprising error message, run the test \n> > \twithout compiling git-add first...\n> \n> $ PATH=/usr/bin:/bin sh t3700-add.sh -i -v\n> * expecting success: touch foo && git-add foo\n> ./test-lib.sh: line 136: git-add: command not found\n> * FAIL 1: Test of git-add\n>         touch foo && git-add foo\n> $ echo $?\n> 1\n\n;-)\n\nI did not say you should \"make clean\" first... For the record: this is \nwhat the surprising error looks like on my machine:\n\n\t* expecting success:\n        \tgit add 1/2/a 1/3/b 1/2/c\n\t\n\tThe following paths are ignored by one of your .gitignore files:\n\t1/3/b\n\tUse -f if you really want to add them.\n\t* FAIL 15: check correct prefix detection\n\nThe surprising factor is, of course, that there is no .gitignore file.\n\nCiao,\nDscho\n"},{"id":"40184","messageId":"7vslarh2cy.fsf@assigned-by-dhcp.cox.net","threadId":"7790","inReplyTo":"Pine.LNX.4.64.0704231108230.8822@racer.site","subject":"Re: [PATCH] dir.c(common_prefix): Fix two bugs","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-04-23T09:22:21Z","receivedAt":"2007-04-23T09:22:21Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"In any case, well spotted, thanks.\n"}]}