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

Re: [PATCH v7 6/6] convert: add "status=delayed" to filter process protocol

From
Lars Schneider <larsxschneider@gmail.com>
Date
Jun 27, 2017, 21:49 UTC
Message-ID
<7FF53F59-1240-4BED-999F-FE9C9AD7E6AC@gmail.com>
In-Reply-To
<77DBCB49-2A44-42BB-9060-23FA79C1CF57@gmail.com>
Show 34 quoted lines
> On 27 Jun 2017, at 22:34, Lars Schneider <larsxschneider@gmail.com> wrote:
> 
> 
>> On 27 Jun 2017, at 21:00, Junio C Hamano <gitster@pobox.com> wrote:
>> 
>> Lars Schneider <larsxschneider@gmail.com> writes:
>> 
>>> @@ -533,7 +534,8 @@ static int start_multi_file_filter_fn(struct subprocess_entry *subprocess)
>>> 	if (err)
>>> 		goto done;
>>> 
>>> -	err = packet_writel(process->in, "capability=clean", "capability=smudge", NULL);
>>> +	err = packet_writel(process->in,
>>> +		"capability=clean", "capability=smudge", "capability=delay", NULL);
>>> 
>>> 	for (;;) {
>>> 		cap_buf = packet_read_line(process->out, NULL);
>>> @@ -549,6 +551,8 @@ static int start_multi_file_filter_fn(struct subprocess_entry *subprocess)
>>> 			entry->supported_capabilities |= CAP_CLEAN;
>>> 		} else if (!strcmp(cap_name, "smudge")) {
>>> 			entry->supported_capabilities |= CAP_SMUDGE;
>>> +		} else if (!strcmp(cap_name, "delay")) {
>>> +			entry->supported_capabilities |= CAP_DELAY;
>>> 		} else {
>>> 			warning(
>>> 				"external filter '%s' requested unsupported filter capability '%s'",
>> 
>> I thought you said something about attempting to make this more
>> table-driven; did the attempt produce a better result?  Just being
>> curious.
> 
> I treated that as low-prio as I got the impression that you are generally OK with
> the current implementation. I promise to send a patch with this change. 
> Either as part of this series or as a follow up patch.
How about this?
 static int start_multi_file_filter_fn(struct subprocess_entry *subprocess)
 {
-       int err;
+       int err, i;
        struct cmd2process *entry = (struct cmd2process *)subprocess;
        struct string_list cap_list = STRING_LIST_INIT_NODUP;
        char *cap_buf;
@@ -516,6 +516,15 @@ static int start_multi_file_filter_fn(struct subprocess_entry *subprocess)
        struct child_process *process = &subprocess->process;
        const char *cmd = subprocess->cmd;

+       static const struct {
+               const char *name;
+               unsigned int cap;
+       } known_caps[] = {
+               { "clean",  CAP_CLEAN  },
+               { "smudge", CAP_SMUDGE },
+               { "delay",  CAP_DELAY  },
+       };
+
        sigchain_push(SIGPIPE, SIG_IGN);

        err = packet_writel(process->in, "git-filter-client", "version=2", NULL);
@@ -534,8 +543,15 @@ static int start_multi_file_filter_fn(struct subprocess_entry *subprocess)
        if (err)
                goto done;

-       err = packet_writel(process->in,
-               "capability=clean", "capability=smudge", "capability=delay", NULL);
+       for (i = 0; i < ARRAY_SIZE(known_caps); ++i) {
+               err = packet_write_fmt_gently(
+                       process->in, "capability=%s\n", known_caps[i].name);
+               if (err)
+                       goto done;
+       }
+       err = packet_flush_gently(process->in);
+       if (err)
+               goto done;

        for (;;) {
                cap_buf = packet_read_line(process->out, NULL);
@@ -547,18 +563,15 @@ static int start_multi_file_filter_fn(struct subprocess_entry *subprocess)
                        continue;

                cap_name = cap_list.items[1].string;
-               if (!strcmp(cap_name, "clean")) {
-                       entry->supported_capabilities |= CAP_CLEAN;
-               } else if (!strcmp(cap_name, "smudge")) {
-                       entry->supported_capabilities |= CAP_SMUDGE;
-               } else if (!strcmp(cap_name, "delay")) {
-                       entry->supported_capabilities |= CAP_DELAY;
-               } else {
-                       warning(
-                               "external filter '%s' requested unsupported filter capability '%s'",
-                               cmd, cap_name
-                       );
-               }
+               i = ARRAY_SIZE(known_caps) - 1;
+               while (i >= 0 && strcmp(cap_name, known_caps[i].name))
+                       i--;
+
+               if (i >= 0)
+                       entry->supported_capabilities |= known_caps[i].cap;
+               else
+                       warning("external filter '%s' requested unsupported filter capability '%s'",
+                       cmd, cap_name);

                string_list_clear(&cap_list, 0);
Previous: Lars SchneiderNext: Lars Schneider
Message 13 of 15 in “convert: add "status=delayed" to filter process protocol”
  1. 0/6 convert: add "status=delayed" to filter process protocolLars Schneider, Jun 27, 2017
  2. 1/6 t0021: keep filter log files on comparisonLars Schneider, Jun 27, 2017
  3. 2/6 t0021: make debug log file name configurableLars Schneider, Jun 27, 2017
  4. 3/6 t0021: write "OUT <size>" only on successLars Schneider, Jun 27, 2017
  5. Junio C HamanoJun 27, 2017
  6. Lars SchneiderJun 27, 2017
  7. Junio C HamanoJun 27, 2017
  8. 6/6 convert: add "status=delayed" to filter process protocolLars Schneider, Jun 27, 2017
  9. Junio C HamanoJun 27, 2017
  10. Lars SchneiderJun 27, 2017
  11. Junio C HamanoJun 27, 2017
  12. Lars SchneiderJun 27, 2017
  13. Lars SchneiderJun 27, 2017
  14. 5/6 convert: move multiple file filter error handling to separate functionLars Schneider, Jun 27, 2017
  15. 4/6 convert: put the flags field before the flag itself for consistent styleLars Schneider, Jun 27, 2017

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.