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

[PATCH v2 4/4] warn on unusable smudgeToFile/cleanFromFile config

From
Joey Hess <joeyh@joeyh.name>
Date
Jun 17, 2016, 20:31 UTC
Message-ID
<1466195481-23209-5-git-send-email-joeyh@joeyh.name>
In-Reply-To
<1466195481-23209-1-git-send-email-joeyh@joeyh.name>

Let the user know when they have a smudgeToFile/cleanFromFile config that cannot be used because the corresponding smudge/clean config is missing.

The warning is only displayed a maximum of once per git invocation, and only when doing an operation that would use the filter.

Signed-off-by: Joey Hess <joeyh@joeyh.name>
---
 convert.c | 34 ++++++++++++++++++++++++++--------
 1 file changed, 26 insertions(+), 8 deletions(-)
diff --git a/convert.c b/convert.c
index bf63ba0..84f6bc5 100644
--- a/convert.c
+++ b/convert.c
@@ -847,32 +847,50 @@ int would_convert_to_git_filter_fd(const char *path)
 	return apply_filter(path, NULL, NULL, 0, -1, NULL, ca.drv->clean);
 }
 
+static int can_filter_file(const char *filefilter, const char *filefiltername,
+			   const char *stdiofilter, const char *stdiofiltername,
+			   const struct conv_attrs *ca,
+			   int *warncount)
+{
+	if (! filefilter)
+		return 0;
+
+	if (stdiofilter)
+		return 1;
+
+	if (*warncount == 0)
+		warning("Not running your configured filter.%s.%s command, because filter.%s.%s is not configured",
+			ca->drv->name, filefiltername,
+			ca->drv->name, stdiofiltername);
+		*warncount=*warncount+1;
+	
+	return 0;
+}
+
 int can_clean_from_file(const char *path)
 {
 	struct conv_attrs ca;
+	static int warncount = 0;
 
 	convert_attrs(&ca, path);
 	if (!ca.drv)
 		return 0;
 
-	/* Only use the cleanFromFile filter when the clean filter is also
-	 * configured.
-	 */
-	return (ca.drv->clean_from_file && ca.drv->clean);
+	return can_filter_file(ca.drv->clean_from_file, "cleanFromFile",
+			       ca.drv->clean, "clean", &ca, &warncount);
 }
 
 int can_smudge_to_file(const char *path)
 {
 	struct conv_attrs ca;
+	static int warncount = 0;
 
 	convert_attrs(&ca, path);
 	if (!ca.drv)
 		return 0;
 
-	/* Only use the smudgeToFile filter when the smudge filter is also
-	 * configured.
-	 */
-	return (ca.drv->smudge_to_file && ca.drv->smudge);
+	return can_filter_file(ca.drv->smudge_to_file, "smudgeToFile",
+			       ca.drv->smudge, "smudge", &ca, &warncount);
 }
 
 const char *get_convert_attr_ascii(const char *path)
-- 
2.8.1
Previous: Joey HessNext: Joey Hess
Message 2 of 8 in “extend smudge/clean filters with direct file access”
  1. 0/4 extend smudge/clean filters with direct file accessJoey Hess, Jun 17, 2016
  2. 4/4 warn on unusable smudgeToFile/cleanFromFile configJoey Hess, Jun 17, 2016
  3. 3/4 use smudgeToFile in git checkout etcJoey Hess, Jun 17, 2016
  4. 1/4 add smudgeToFile and cleanFromFile filter configsJoey Hess, Jun 17, 2016
  5. 2/4 use cleanFromFile in git addJoey Hess, Jun 17, 2016
  6. Joey HessJun 17, 2016
  7. Junio C HamanoJun 17, 2016
  8. 0/4 clarify %f documentationJoey Hess, Jun 17, 2016

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.