git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 7/8] setup_tree_pathspec(): interpret '^' as negative pathspec

From
Elijah Newren <newren@gmail.com>
Date
Sep 11, 2010, 17:29 UTC
Message-ID
<AANLkTin_m+zjHND5AwFhkrZM-VEkn70qgCTwpB2B+RA+@mail.gmail.com>
In-Reply-To
<1283961023-4491-8-git-send-email-pclouds@gmail.com>
2010/9/8 Nguyễn Thái Ngọc Duy <pclouds@gmail.com>:
Show 9 quoted lines
> This patch does preparation work for tree exclusion in
> tree_entry_interesting(). '^' has similar meaning to '!' in
> gitexcludes. '!' is not used because bash does not like arguments with
> a leading '!'.
>
> Eventually, "git diff -- foo ^foo/bar" should show differences in foo,
> except foo/bar. If "git diff -- ^foo" is given, then it implies
> everything except foo, which could surprise users that
> "bar" in "git diff -- bar ^foo" has no effect at all.
I really like the work here.  There are just two things that I think
are missing:
  * It doesn't handle files with leading carats in their name
  * It handles some nested include/exclude cases (e.g. dir
^dir/subdir) but not more complicated ones.

You could add these three testcases (on top of your 8/8 patch) to see what I mean:

test_expect_failure 'diff ^one one/two' '
	printf "file\none/two/file\n" >expected &&
	git diff --name-only HEAD^ HEAD -- ^one one/two >result &&
	test_cmp expected result
'
test_expect_failure 'diff ^funny-filename' '
	touch ^funny-filename &&
	git add ^funny-filename &&
	git commit -m "Add a filename with a leading carat" &&
	git ls-files >expected &&
	git diff --name-only HEAD^^ HEAD -- ^funny-filename >result &&
	test_cmp expected result &&
	echo ^funny-filename >expected &&
	git diff --name-only HEAD^^ HEAD -- ^^funny-filename >result &&
	test_cmp expected result &&
	git ls-files | grep -v funny-filename >expected &&
	git diff --name-only HEAD^^ HEAD -- ^^^funny-filename >result &&
	test_cmp expected result
'
test_expect_failure 'deeper nested exclude/include' '
	touch one/two/zoo &&
	for i in one/file one/zoo one/two/file; do echo 2 >>$i; done &&
	git add one &&
	git commit -m 4 &&
	printf "one/file\none/two/file\none/zoo\n" > expected &&
	git diff --name-only HEAD^ HEAD -- one ^one/two one/two/file >result &&
	test_cmp expected result &&
	printf "one/two/zoo\n" > expected &&
	git diff --name-only HEAD^ HEAD -- ^one one/two ^one/two/file >result &&
	test_cmp expected result
'
Note: In the second test, I used:
 * "^funny" to search for all files EXCEPT "funny"
 * "^^funny" to search for a file named "^funny"
 * "^^^funny" to search for all files EXCEPT "^funny"
I'm not sure if that's really the syntax we want to adopt, but it
should be easy to change if we decide on some other syntax.
Previous: Nguyễn Thái Ngọc DuyNext: Nguyen Thai Ngoc Duy
Message 13 of 21 in “en/object-list-with-pathspec v4”
  1. 0/8 en/object-list-with-pathspec v4Nguyễn Thái Ngọc Duy, Sep 8, 2010
  2. 1/8 diff-no-index: use diff_tree_setup_paths()Nguyễn Thái Ngọc Duy, Sep 8, 2010
  3. 2/8 Introduce struct tree_pathspec_listNguyễn Thái Ngọc Duy, Sep 8, 2010
  4. 3/8 tree_entry_interesting(): remove dependency on struct diff_optionsNguyễn Thái Ngọc Duy, Sep 8, 2010
  5. Junio C HamanoSep 14, 2010
  6. Nguyen Thai Ngoc DuySep 14, 2010
  7. Junio C HamanoSep 14, 2010
  8. 4/8 tree-walk: move tree_entry_interesting() from tree-diff.cNguyễn Thái Ngọc Duy, Sep 8, 2010
  9. 5/8 Add testcases showing how pathspecs are ignored with rev-list --objectsNguyễn Thái Ngọc Duy, Sep 8, 2010
  10. Junio C HamanoSep 14, 2010
  11. 6/8 Make rev-list --objects work together with pathspecsNguyễn Thái Ngọc Duy, Sep 8, 2010
  12. 7/8 setup_tree_pathspec(): interpret '^' as negative pathspecNguyễn Thái Ngọc Duy, Sep 8, 2010
  13. Elijah NewrenSep 11, 2010
  14. Nguyen Thai Ngoc DuySep 13, 2010
  15. Junio C HamanoSep 14, 2010
  16. Nguyen Thai Ngoc DuySep 14, 2010
  17. 8/8 tree_entry_interesting(): support negative pathspecNguyễn Thái Ngọc Duy, Sep 8, 2010
  18. Elijah NewrenSep 11, 2010
  19. Junio C HamanoSep 14, 2010
  20. Nguyen Thai Ngoc DuySep 14, 2010
  21. Elijah NewrenSep 11, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.