On Thursday 07 August 2008 Philipp Marek wrote:
... 
> I'll try
> to get type-specific ignore patterns (or something similar) added for the
> next release.
You can also try the attached patch :-)


Regards,

Phil


-- 
Versioning your /etc, /home or even your whole installation?
             Try fsvs (fsvs.tigris.org)!
Index: tests/011_ignore
===================================================================
--- tests/011_ignore	(Revision 1847)
+++ tests/011_ignore	(Arbeitskopie)
@@ -269,3 +269,24 @@ fi
 
 $SUCCESS "Absolute ignore pattern warnings tests"
 
+
+# Test the "dir-only" specification
+true | $BINdflt ignore load
+$BINq ci -m1
+# now we're clean.
+mkdir -p deep/a/b/c/dir
+touch deep/fileA
+touch deep/a/fileB
+touch deep/a/b/fileC
+touch deep/a/b/c/fileD
+touch deep/a/b/c/dir/file-ok
+$BINq ignore 't./deep/**ok*' 'dt./deep/**' './deep/**'
+$BINq ci -m1
+if [[ `$BINdflt log -v -r HEAD | grep file | wc -l` -eq 1 ]]
+then
+  $SUCCESS "dir-only pattern looks ok."
+else
+  $ERROR "wrong commit for dir-only pattern"
+fi
+
+
Index: src/global.h
===================================================================
--- src/global.h	(Revision 1847)
+++ src/global.h	(Arbeitskopie)
@@ -137,6 +137,8 @@ struct ignore_t {
 		};
 	};
 
+	/** Should this match only directories? */
+	unsigned int dir_only:1;
 	/** Is this an ignore or take pattern?  \a 0 = take, \a 1 = ignore */
 	unsigned int is_ignore:1;
 	/** Ignore case for comparing? */
Index: src/ignore.c
===================================================================
--- src/ignore.c	(Revision 1847)
+++ src/ignore.c	(Arbeitskopie)
@@ -395,15 +395,35 @@
  *   <td>Ignore case for matching
  * <tr><th>t
  *   <td>A negative ignore pattern, ie. a take pattern.
+ * <tr><th>d
+ *   <td>Match directories only. This is useful if you have a directory
+ *   tree in which only certain files should be taken; see below.
  * </table>
  *
  * \code
  *     t./proc/stat
  *     ./proc/
  * \endcode
- * Such
- * declaration would store \e only \c /proc/stat , and nothing else of \c 
- * /proc .
+ * Such declaration would store \e only \c /proc/stat , and nothing else 
+ * of \c /proc .
+ * 
+ * \code
+ *     td./var/vmail/§**
+ *     t./var/vmail/§**§/.*.sieve
+ *     ./var/vmail/§**
+ * \endcode
+ * This would take all \c ".*.sieve" files (or directories) below 
+ * \c /var/vmail, in all depths, and all directories there; but no other
+ * files.
+ *
+ * If your files are at a certain depth, and you don't want all other 
+ * directories taken, too, you can specify that exactly:
+ * \code
+ *     td./var/vmail/§*§
+ *     td./var/vmail/§*§/§*
+ *     t./var/vmail/§*§/§*§/.*.sieve
+ *     ./var/vmail/§**
+ * \endcode
  * 
  * */
 
@@ -760,6 +780,9 @@ int ign___init_pattern_into(char *patter
 			case 't':
 				ignore->is_ignore=0;
 				break;
+			case 'd':
+				ignore->dir_only=1;
+				break;
 			case 'i':
 				ignore->is_icase=1;
 				break;
@@ -1026,7 +1049,9 @@ inline int ign___compare_dev(struct ssta
 }
 
 
-/* Searches this entry for a take/ignore
+/** -.
+ *
+ * Searches this entry for a take/ignore pattern.
  *
  * If a parent directory has an ignore entry which might be valid 
  * for this directory (like **§/§*~), it is mentioned in this
@@ -1037,6 +1062,8 @@ inline int ign___compare_dev(struct ssta
  * we cannot easily optimize.
  * is_ignored is set to +1 if ignored, 0 if unknown, and -1 if 
  * on a take-list (overriding later ignore list).
+ *
+ * \a sts must already have the correct estat::st.mode bits set.
  */
 int ign__is_ignore(struct estat *sts,
 		int *is_ignored)
@@ -1129,8 +1156,14 @@ int ign__is_ignore(struct estat *sts,
 			if (ign->type == PT_SHELL || ign->type == PT_PCRE ||
 					ign->type == PT_SHELL_ABS)
 			{
-				DEBUGP("matching %s against %s",
-						cp, ign->pattern);
+				DEBUGP("matching %s(%0o) against %s(dir_only=%d)",
+						cp, sts->st.mode, ign->pattern, ign->dir_only);
+				if (ign->dir_only && !S_ISDIR(sts->st.mode))
+				{
+					status=PCRE_ERROR_NOMATCH;
+				}
+				else
+				{
 				status=pcre_exec(ign->compiled, ign->extra, 
 						cp, len, 
 						0, 0,
@@ -1139,6 +1172,7 @@ int ign__is_ignore(struct estat *sts,
 						status, "cannot match pattern %s on data %s",
 						ign->pattern, cp);
 			}
+			}
 			else if (ign->type == PT_DEVICE)
 			{
 				/* device compare */
Index: CHANGES
===================================================================
--- CHANGES	(Revision 1847)
+++ CHANGES	(Arbeitskopie)
@@ -9,6 +9,7 @@ Changes since 1.1.16
 - Bugfix for "dir_sort" option; the root directory wasn't printed.
 - The option "dir_sort" now uses strcoll(), ie. sorts according to the 
 	current locale.
+- A new flag for ignore patterns, for matching directories only.
 - Changed the recursive behaviour to do the whole hierarchy before the 
 	parent directory - needed for revert.
 - Configure and install fixes, patch by Maurice. Thank you.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to