From fa64a2fdbeedd98c5f24d1662bcc470a8449abcf Mon Sep 17 00:00:00 2001 From: Jonathan Tan Date: Wed, 26 Jul 2017 11:17:29 -0700 Subject: sub-process: refactor handshake to common function Refactor, into a common function, the version and capability negotiation done when invoking a long-running process as a clean or smudge filter. This will be useful for other Git code that needs to interact similarly with a long-running process. As you can see in the change to t0021, this commit changes the error message reported when the long-running process does not introduce itself with the expected "server"-terminated line. Originally, the error message reports that the filter "does not support filter protocol version 2", differentiating between the old single-file filter protocol and the new multi-file filter protocol - I have updated it to something more generic and useful. Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano --- sub-process.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'sub-process.h') diff --git a/sub-process.h b/sub-process.h index e546216145..caa91a9b92 100644 --- a/sub-process.h +++ b/sub-process.h @@ -29,6 +29,16 @@ struct subprocess_entry { struct child_process process; }; +struct subprocess_capability { + const char *name; + + /* + * subprocess_handshake will "|=" this value to supported_capabilities + * if the server reports that it supports this capability. + */ + unsigned int flag; +}; + /* subprocess functions */ /* Function to test two subprocess hashmap entries for equality. */ @@ -62,6 +72,22 @@ static inline struct child_process *subprocess_get_child_process( return &entry->process; } +/* + * Perform the version and capability negotiation as described in the "Long + * Running Filter Process" section of the gitattributes documentation using the + * given requested versions and capabilities. The "versions" and "capabilities" + * parameters are arrays terminated by a 0 or blank struct. + * + * This function is typically called when a subprocess is started (as part of + * the "startfn" passed to subprocess_start). + */ +int subprocess_handshake(struct subprocess_entry *entry, + const char *welcome_prefix, + int *versions, + int *chosen_version, + struct subprocess_capability *capabilities, + unsigned int *supported_capabilities); + /* * Helper function that will read packets looking for "status=" * key/value pairs and return the value from the last "status" packet -- cgit v1.2.1