/* * Example implementation for the Git filter protocol version 2 * See Documentation/gitattributes.txt, section "Filter Protocol" * * Usage: test-tool rot13-filter [--always-delay] --log=<path> <capabilities> * * Log path defines a debug log file that the script writes to. The * subsequent arguments define a list of supported protocol capabilities * ("clean", "smudge", etc). * * When --always-delay is given all pathnames with the "can-delay" flag * that don't appear on the list bellow are delayed with a count of 1 * (see more below). * * This implementation supports special test cases: * (1) If data with the pathname "clean-write-fail.r" is processed with * a "clean" operation then the write operation will die. * (2) If data with the pathname "smudge-write-fail.r" is processed with * a "smudge" operation then the write operation will die. * (3) If data with the pathname "error.r" is processed with any * operation then the filter signals that it cannot or does not want * to process the file. * (4) If data with the pathname "abort.r" is processed with any * operation then the filter signals that it cannot or does not want * to process the file and any file after that is processed with the * same command. * (5) If data with a pathname that is a key in the delay hash is * requested (e.g. "test-delay10.a") then the filter responds with * a "delay" status and sets the "requested" field in the delay hash. * The filter will signal the availability of this object after * "count" (field in delay hash) "list_available_blobs" commands. * (6) If data with the pathname "missing-delay.a" is processed that the * filter will drop the path from the "list_available_blobs" response. * (7) If data with the pathname "invalid-delay.a" is processed that the * filter will add the path "unfiltered" which was not delayed before * to the "list_available_blobs" response. */ #include "test-tool.h" #include "pkt-line.h" #include "string-list.h" #include "strmap.h" #include "parse-options.h" static FILE *logfile; static int always_delay, has_clean_cap, has_smudge_cap; static struct strmap delay = …; static inline const char *str_or_null(const char *str) { … } static char *rot13(char *str) { … } static char *get_value(char *buf, const char *key) { … } /* * Read a text packet, expecting that it is in the form "key=value" for * the given key. An EOF does not trigger any error and is reported * back to the caller with NULL. Die if the "key" part of "key=value" does * not match the given key, or the value part is empty. */ static char *packet_key_val_read(const char *key) { … } static inline void assert_remote_capability(struct strset *caps, const char *cap) { … } static void read_capabilities(struct strset *remote_caps) { … } static void check_and_write_capabilities(struct strset *remote_caps, const char **caps, int nr_caps) { … } struct delay_entry { … }; static void free_delay_entries(void) { … } static void add_delay_entry(const char *pathname, int count, int requested) { … } static void reply_list_available_blobs_cmd(void) { … } static void command_loop(void) { … } static void packet_initialize(void) { … } static const char *rot13_usage[] = …; int cmd__rot13_filter(int argc, const char **argv) { … }