mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

189 lines
6.2 KiB

  1. The --exclude-dir option, extraced from grep CVS.
  2. (This is part of the tagged since 2006 but not yet packaged and released grep 2.5.2)
  3. diff -ru grep-2.5.1a.orig/NEWS grep-2.5.1a/NEWS
  4. --- grep-2.5.1a.orig/NEWS 2002-03-26 16:34:03.000000000 +0100
  5. +++ grep-2.5.1a/NEWS 2007-06-21 09:35:41.000000000 +0200
  6. @@ -1,3 +1,7 @@
  7. +Version 2.5.2
  8. + - The new option --exclude-dir allows to specify a directory pattern that
  9. + will be exclided from recursive grep.
  10. +
  11. Version 2.5.1
  12. - This is a bugfix release. No new features.
  13. diff -ru grep-2.5.1a.orig/doc/grep.1 grep-2.5.1a/doc/grep.1
  14. --- grep-2.5.1a.orig/doc/grep.1 2004-11-12 12:26:37.000000000 +0100
  15. +++ grep-2.5.1a/doc/grep.1 2007-06-21 09:39:52.000000000 +0200
  16. @@ -329,6 +329,17 @@
  17. Recurse in directories skip file matching
  18. .I PATTERN.
  19. .TP
  20. +.BR "\fR \fP \-\^\-exclude-from=" FILE
  21. +Skip files whose base name matches any of the file-name globs read from
  22. +.I FILE
  23. +(using wildcard matching as described under
  24. +.BR \-\^\-exclude ).
  25. +.TP
  26. +.BR "\fR \fP \-\^\-exclude-dir=" DIR
  27. +Exclude directories matching the pattern
  28. +.I DIR
  29. +from recursive searches.
  30. +.TP
  31. .BR \-s ", " \-\^\-no-messages
  32. Suppress error messages about nonexistent or unreadable files.
  33. Portability note: unlike \s-1GNU\s0
  34. diff -ru grep-2.5.1a.orig/doc/grep.texi grep-2.5.1a/doc/grep.texi
  35. --- grep-2.5.1a.orig/doc/grep.texi 2004-11-12 12:26:48.000000000 +0100
  36. +++ grep-2.5.1a/doc/grep.texi 2007-06-21 09:41:18.000000000 +0200
  37. @@ -425,6 +425,20 @@
  38. @cindex searching directory trees
  39. When processing directories recursively, skip files matching @var{file_pattern}.
  40. +@item --exclude-from=@var{file}
  41. +@opindex --exclude-from
  42. +@cindex exclude files
  43. +@cindex searching directory trees
  44. +Skip files whose base name matches any of the file-name globs
  45. +read from @var{file} (using wildcard matching as described
  46. +under @samp{--exclude}).
  47. +
  48. +@item --exclude-dir=@var{dir}
  49. +@opindex --exclude-dir
  50. +@cindex exclude directories
  51. +Exclude directories matching the pattern @var{dir} from recursive
  52. +directory searches.
  53. +
  54. @item -m @var{num}
  55. @itemx --max-count=@var{num}
  56. @opindex -m
  57. diff -ru grep-2.5.1a.orig/lib/savedir.c grep-2.5.1a/lib/savedir.c
  58. --- grep-2.5.1a.orig/lib/savedir.c 2001-03-04 06:33:12.000000000 +0100
  59. +++ grep-2.5.1a/lib/savedir.c 2007-06-21 09:35:41.000000000 +0200
  60. @@ -100,7 +100,7 @@
  61. Return NULL if DIR cannot be opened or if out of memory. */
  62. char *
  63. savedir (const char *dir, off_t name_size, struct exclude *included_patterns,
  64. - struct exclude *excluded_patterns)
  65. + struct exclude *excluded_patterns, struct exclude *excluded_directory_patterns )
  66. {
  67. DIR *dirp;
  68. struct dirent *dp;
  69. @@ -143,6 +143,14 @@
  70. && excluded_filename (excluded_patterns, dp->d_name, 0))
  71. continue;
  72. }
  73. +
  74. + if ( excluded_directory_patterns
  75. + && isdir1 (dir, dp->d_name) )
  76. + {
  77. + if (excluded_directory_patterns
  78. + && excluded_filename (excluded_directory_patterns, dp->d_name, 0))
  79. + continue;
  80. + }
  81. if (size_needed > name_size)
  82. {
  83. diff -ru grep-2.5.1a.orig/lib/savedir.h grep-2.5.1a/lib/savedir.h
  84. --- grep-2.5.1a.orig/lib/savedir.h 2001-03-04 06:33:12.000000000 +0100
  85. +++ grep-2.5.1a/lib/savedir.h 2007-06-21 09:35:41.000000000 +0200
  86. @@ -13,6 +13,7 @@
  87. extern char *
  88. savedir PARAMS ((const char *dir, off_t name_size,
  89. - struct exclude *, struct exclude *));
  90. + struct exclude *, struct exclude *,
  91. + struct exclude *));
  92. #endif
  93. diff -ru grep-2.5.1a.orig/src/grep.c grep-2.5.1a/src/grep.c
  94. --- grep-2.5.1a.orig/src/grep.c 2004-11-12 12:25:35.000000000 +0100
  95. +++ grep-2.5.1a/src/grep.c 2007-06-21 09:36:17.000000000 +0200
  96. @@ -78,6 +78,7 @@
  97. static struct exclude *excluded_patterns;
  98. static struct exclude *included_patterns;
  99. +static struct exclude *excluded_directory_patterns;
  100. /* Short options. */
  101. static char const short_options[] =
  102. "0123456789A:B:C:D:EFGHIPUVX:abcd:e:f:hiKLlm:noqRrsuvwxyZz";
  103. @@ -91,7 +92,8 @@
  104. EXCLUDE_OPTION,
  105. EXCLUDE_FROM_OPTION,
  106. LINE_BUFFERED_OPTION,
  107. - LABEL_OPTION
  108. + LABEL_OPTION,
  109. + EXCLUDE_DIRECTORY_OPTION
  110. };
  111. /* Long options equivalences. */
  112. @@ -111,6 +113,7 @@
  113. {"extended-regexp", no_argument, NULL, 'E'},
  114. {"exclude", required_argument, NULL, EXCLUDE_OPTION},
  115. {"exclude-from", required_argument, NULL, EXCLUDE_FROM_OPTION},
  116. + {"exclude-dir", required_argument, NULL, EXCLUDE_DIRECTORY_OPTION},
  117. {"file", required_argument, NULL, 'f'},
  118. {"files-with-matches", no_argument, NULL, 'l'},
  119. {"files-without-match", no_argument, NULL, 'L'},
  120. @@ -984,9 +987,14 @@
  121. static int
  122. grepdir (char const *dir, struct stats const *stats)
  123. {
  124. - int status = 1;
  125. struct stats const *ancestor;
  126. char *name_space;
  127. + int status = 1;
  128. + if ( excluded_directory_patterns &&
  129. + excluded_filename (excluded_directory_patterns, dir, 0) ) {
  130. + return 1;
  131. + }
  132. +
  133. /* Mingw32 does not support st_ino. No known working hosts use zero
  134. for st_ino, so assume that the Mingw32 bug applies if it's zero. */
  135. @@ -1002,7 +1010,7 @@
  136. }
  137. name_space = savedir (dir, stats->stat.st_size, included_patterns,
  138. - excluded_patterns);
  139. + excluded_patterns, excluded_directory_patterns);
  140. if (! name_space)
  141. {
  142. @@ -1102,6 +1110,7 @@
  143. --include=PATTERN files that match PATTERN will be examined\n\
  144. --exclude=PATTERN files that match PATTERN will be skipped.\n\
  145. --exclude-from=FILE files that match PATTERN in FILE will be skipped.\n\
  146. + --exclude-dir=PATTERN directories that match PATTERN will be skipped.\n\
  147. -L, --files-without-match only print FILE names containing no match\n\
  148. -l, --files-with-matches only print FILE names containing matches\n\
  149. -c, --count only print a count of matching lines per FILE\n\
  150. @@ -1596,7 +1605,6 @@
  151. excluded_patterns = new_exclude ();
  152. add_exclude (excluded_patterns, optarg);
  153. break;
  154. -
  155. case EXCLUDE_FROM_OPTION:
  156. if (!excluded_patterns)
  157. excluded_patterns = new_exclude ();
  158. @@ -1607,11 +1615,19 @@
  159. }
  160. break;
  161. + case EXCLUDE_DIRECTORY_OPTION:
  162. + if (!excluded_directory_patterns)
  163. + excluded_directory_patterns = new_exclude ();
  164. + add_exclude (excluded_directory_patterns, optarg);
  165. + break;
  166. +
  167. case INCLUDE_OPTION:
  168. if (!included_patterns)
  169. included_patterns = new_exclude ();
  170. add_exclude (included_patterns, optarg);
  171. break;
  172. +
  173. +
  174. case LINE_BUFFERED_OPTION:
  175. line_buffered = 1;