Code

Merge branch 'bs/maint-1.6.0-tree-walk-prefix'
authorJunio C Hamano <gitster@pobox.com>
Wed, 8 Apr 2009 05:33:10 +0000 (22:33 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 8 Apr 2009 05:33:10 +0000 (22:33 -0700)
* bs/maint-1.6.0-tree-walk-prefix:
  match_tree_entry(): a pathspec only matches at directory boundaries
  tree_entry_interesting: a pathspec only matches at directory boundary

1  2 
t/t4010-diff-pathspec.sh
tree.c

diff --combined t/t4010-diff-pathspec.sh
index 9322298ecc6cb79f0123dea4e329317c5bfbfd11,4c4c8b1570c01721e8ac2c8d16837e68ecaa30f5..94df7ae53a0ef47c0ef10ca6b3215ffdf38fa399
@@@ -10,7 -10,7 +10,7 @@@ Prepare
          path1/file1
  '
  . ./test-lib.sh
 -. ../diff-lib.sh ;# test-lib chdir's into trash
 +. "$TEST_DIRECTORY"/diff-lib.sh ;# test-lib chdir's into trash
  
  test_expect_success \
      setup \
@@@ -62,4 -62,12 +62,12 @@@ test_expect_success 
      'git diff-index --cached $tree -- file0/ >current &&
       compare_diff_raw current expected'
  
+ test_expect_success 'diff-tree pathspec' '
+       tree2=$(git write-tree) &&
+       echo "$tree2" &&
+       git diff-tree -r --name-only $tree $tree2 -- pa path1/a >current &&
+       >expected &&
+       test_cmp expected current
+ '
  test_done
diff --combined tree.c
index 25d2e29fa8b1dfb964b97a10898c77d8fe86ef78,d82a047e5550702bf6e1fd5a8930897124e7a96f..0d703a0c473e65c60d9e130b4e1fd50b79e9462b
--- 1/tree.c
--- 2/tree.c
+++ b/tree.c
@@@ -60,8 -60,12 +60,12 @@@ static int match_tree_entry(const char 
                        /* If it doesn't match, move along... */
                        if (strncmp(base, match, matchlen))
                                continue;
-                       /* The base is a subdirectory of a path which was specified. */
-                       return 1;
+                       /* pathspecs match only at the directory boundaries */
+                       if (!matchlen ||
+                           base[matchlen] == '/' ||
+                           match[matchlen - 1] == '/')
+                               return 1;
+                       continue;
                }
  
                /* Does the base match? */
@@@ -110,7 -114,7 +114,7 @@@ int read_tree_recursive(struct tree *tr
                case 0:
                        continue;
                case READ_TREE_RECURSIVE:
 -                      break;;
 +                      break;
                default:
                        return -1;
                }
                        if (retval)
                                return -1;
                        continue;
 +              } else if (S_ISGITLINK(entry.mode)) {
 +                      int retval;
 +                      struct strbuf path;
 +                      unsigned int entrylen;
 +                      struct commit *commit;
 +
 +                      entrylen = tree_entry_len(entry.path, entry.sha1);
 +                      strbuf_init(&path, baselen + entrylen + 1);
 +                      strbuf_add(&path, base, baselen);
 +                      strbuf_add(&path, entry.path, entrylen);
 +                      strbuf_addch(&path, '/');
 +
 +                      commit = lookup_commit(entry.sha1);
 +                      if (!commit)
 +                              die("Commit %s in submodule path %s not found",
 +                                  sha1_to_hex(entry.sha1), path.buf);
 +
 +                      if (parse_commit(commit))
 +                              die("Invalid commit %s in submodule path %s",
 +                                  sha1_to_hex(entry.sha1), path.buf);
 +
 +                      retval = read_tree_recursive(commit->tree,
 +                                                   path.buf, path.len,
 +                                                   stage, match, fn, context);
 +                      strbuf_release(&path);
 +                      if (retval)
 +                              return -1;
 +                      continue;
                }
        }
        return 0;