[PATCH] git-ls-files: generalized pathspecs

This generalizes the git "glob" string to be a lot more like the
git-diff-* pathspecs (but there are still differences: the diff family
doesn't do any globbing, and because the diff family always generates the
full native pathname, it doesn't have the issue with "..").

It does three things:

 - it allows multiple matching strings, ie you can do things like

	git-ls-files arch/i386/ include/asm-i386/ | xargs grep pattern

 - the "matching" criteria is a combination of "exact path component
   match" (the same as the git-diff-* family), and "fnmatch()". However,
   you should be careful with the confusion between the git-ls-files
   internal globbing and the standard shell globbing, ie

	git-ls-files fs/*.c

   does globbing in the shell, and does something totally different from

	git-ls-files 'fs/*.c'

   which does the globbing inside git-ls-files.

   The latter has _one_ pathspec with a wildcard, and will match any .c
   file anywhere under the fs/ directory, while the former has been
   expanded by the shell into having _lots_ of pathspec entries, all of
   which are just in the top-level fs/ subdirectory. They will happily
   be matched exactly, but we will thus miss all the subdirectories under
   fs/.

   As a result, the first one will (on the current kernel) match 55 files,
   while the second one will match 664 files!

 - it uses the generic path prefixing, so that ".." and friends at the
   beginning of the path spec work automatically

   NOTE! When generating relative pathname output (the default), a
   pathspec that causes the base to be outside the current working
   directory will be rejected with an error message like:

	fatal: git-ls-files: cannot generate relative filenames containing '..'

   because we do not actually generate ".." in the output. However, the
   ".." format works fine for the --full-name case:

	cd arch/i386/kernel
	git-ls-files --full-name ../mm/

   results in

	arch/i386/mm/Makefile
	arch/i386/mm/boot_ioremap.c
	arch/i386/mm/discontig.c
	arch/i386/mm/extable.c
	arch/i386/mm/fault.c
	arch/i386/mm/highmem.c
	arch/i386/mm/hugetlbpage.c
	arch/i386/mm/init.c
	arch/i386/mm/ioremap.c
	arch/i386/mm/mmap.c
	arch/i386/mm/pageattr.c
	arch/i386/mm/pgtable.c

   Perhaps more commonly, the generic path prefixing means that "." and
   "./" automatically get simplified and work properly.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
1 file changed
tree: ef0de68612b416ce300eaba25bb562c43c0ac892
  1. debian/
  2. Documentation/
  3. mozilla-sha1/
  4. ppc/
  5. t/
  6. templates/
  7. tools/
  8. apply.c
  9. blob.c
  10. blob.h
  11. build-rev-cache.c
  12. cache.h
  13. cat-file.c
  14. checkout-cache.c
  15. clone-pack.c
  16. commit-tree.c
  17. commit.c
  18. commit.h
  19. connect.c
  20. convert-cache.c
  21. COPYING
  22. count-delta.c
  23. count-delta.h
  24. csum-file.c
  25. csum-file.h
  26. daemon.c
  27. date.c
  28. delta.h
  29. diff-cache.c
  30. diff-delta.c
  31. diff-files.c
  32. diff-helper.c
  33. diff-stages.c
  34. diff-tree.c
  35. diff.c
  36. diff.h
  37. diffcore-break.c
  38. diffcore-order.c
  39. diffcore-pathspec.c
  40. diffcore-pickaxe.c
  41. diffcore-rename.c
  42. diffcore.h
  43. entry.c
  44. epoch.c
  45. epoch.h
  46. export.c
  47. fetch-pack.c
  48. fsck-cache.c
  49. get-tar-commit-id.c
  50. git
  51. git-add-script
  52. git-apply-patch-script
  53. git-bisect-script
  54. git-branch-script
  55. git-checkout-script
  56. git-cherry
  57. git-clone-dumb-http
  58. git-clone-script
  59. git-commit-script
  60. git-core.spec.in
  61. git-count-objects-script
  62. git-cvsimport-script
  63. git-diff-script
  64. git-external-diff-script
  65. git-fetch-script
  66. git-format-patch-script
  67. git-log-script
  68. git-ls-remote-script
  69. git-merge-one-file-script
  70. git-parse-remote
  71. git-prune-script
  72. git-pull-script
  73. git-push-script
  74. git-rebase-script
  75. git-relink-script
  76. git-rename-script
  77. git-repack-script
  78. git-request-pull-script
  79. git-reset-script
  80. git-resolve-script
  81. git-revert-script
  82. git-send-email-script
  83. git-sh-setup-script
  84. git-shortlog
  85. git-show-branches-script
  86. git-status-script
  87. git-tag-script
  88. git-verify-tag-script
  89. git-whatchanged
  90. gitenv.c
  91. gitk
  92. hash-object.c
  93. http-pull.c
  94. ident.c
  95. index.c
  96. init-db.c
  97. INSTALL
  98. local-pull.c
  99. ls-files.c
  100. ls-tree.c
  101. Makefile
  102. merge-base.c
  103. merge-cache.c
  104. mktag.c
  105. object.c
  106. object.h
  107. pack-check.c
  108. pack-objects.c
  109. pack.h
  110. patch-delta.c
  111. patch-id.c
  112. path.c
  113. peek-remote.c
  114. pkt-line.c
  115. pkt-line.h
  116. prune-packed.c
  117. pull.c
  118. pull.h
  119. quote.c
  120. quote.h
  121. read-cache.c
  122. read-tree.c
  123. README
  124. receive-pack.c
  125. refs.c
  126. refs.h
  127. rev-cache.c
  128. rev-cache.h
  129. rev-list.c
  130. rev-parse.c
  131. rev-tree.c
  132. rsh.c
  133. rsh.h
  134. run-command.c
  135. run-command.h
  136. send-pack.c
  137. server-info.c
  138. setup.c
  139. sha1_file.c
  140. sha1_name.c
  141. show-index.c
  142. show-rev-cache.c
  143. ssh-pull.c
  144. ssh-push.c
  145. strbuf.c
  146. strbuf.h
  147. stripspace.c
  148. tag.c
  149. tag.h
  150. tar-tree.c
  151. test-date.c
  152. test-delta.c
  153. tree.c
  154. tree.h
  155. unpack-file.c
  156. unpack-objects.c
  157. update-cache.c
  158. update-server-info.c
  159. upload-pack.c
  160. usage.c
  161. var.c
  162. verify-pack.c
  163. write-tree.c