{"thread":{"id":"1293","subject":"[PATCH 2/2] apply.c: --exclude=fnmatch-pattern option.","startedAt":"2005-07-22T16:56:57Z","lastAt":"2005-07-22T16:56:57Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"6307","messageId":"7vll3ywzhi.fsf@assigned-by-dhcp.cox.net","threadId":"1293","inReplyTo":null,"subject":"[PATCH 2/2] apply.c: --exclude=fnmatch-pattern option.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-07-22T16:56:57Z","receivedAt":"2005-07-22T16:56:57Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Adds --exclude=pattern option to the \"git-apply\" command.  This\nwas useful while reimporting the BKCVS patchset dump of the\nLinux kernel, starting at 2.4.0 and ending at 2.6.12-rc2 Ingo\nannounced some time ago to exclude BitKeeper directory.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\n apply.c |   45 ++++++++++++++++++++++++++++++++++++++-------\n 1 files changed, 38 insertions(+), 7 deletions(-)\n\n3206526a0af9403fc6184dc17879206b9216924f\ndiff --git a/apply.c b/apply.c\n--- a/apply.c\n+++ b/apply.c\n@@ -13,7 +13,7 @@\n  * uses the working tree as a \"branch\" for a 3-way merge.\n  */\n #include <ctype.h>\n-\n+#include <fnmatch.h>\n #include \"cache.h\"\n \n // We default to the merge behaviour, since that's what most people would\n@@ -1345,9 +1345,9 @@ static void write_out_one_result(struct \n \tcreate_file(patch);\n }\n \n-static void write_out_results(struct patch *list)\n+static void write_out_results(struct patch *list, int skipped_patch)\n {\n-\tif (!list)\n+\tif (!list && !skipped_patch)\n \t\tdie(\"No changes\");\n \n \twhile (list) {\n@@ -1358,12 +1358,30 @@ static void write_out_results(struct pat\n \n static struct cache_file cache_file;\n \n+static struct excludes {\n+\tstruct excludes *next;\n+\tconst char *path;\n+} *excludes;\n+\n+static int use_patch(struct patch *p)\n+{\n+\tconst char *pathname = p->new_name ? : p->old_name;\n+\tstruct excludes *x = excludes;\n+\twhile (x) {\n+\t\tif (fnmatch(x->path, pathname, 0) == 0)\n+\t\t\treturn 0;\n+\t\tx = x->next;\n+\t}\n+\treturn 1;\n+}\n+\n static int apply_patch(int fd)\n {\n \tint newfd;\n \tunsigned long offset, size;\n \tchar *buffer = read_patch_file(fd, &size);\n \tstruct patch *list = NULL, **listp = &list;\n+\tint skipped_patch = 0;\n \n \tif (!buffer)\n \t\treturn -1;\n@@ -1377,9 +1395,15 @@ static int apply_patch(int fd)\n \t\tnr = parse_chunk(buffer + offset, size, patch);\n \t\tif (nr < 0)\n \t\t\tbreak;\n-\t\tpatch_stats(patch);\n-\t\t*listp = patch;\n-\t\tlistp = &patch->next;\n+\t\tif (use_patch(patch)) {\n+\t\t\tpatch_stats(patch);\n+\t\t\t*listp = patch;\n+\t\t\tlistp = &patch->next;\n+\t\t} else {\n+\t\t\t/* perhaps free it a bit better? */\n+\t\t\tfree(patch);\n+\t\t\tskipped_patch++;\n+\t\t}\n \t\toffset += nr;\n \t\tsize -= nr;\n \t}\n@@ -1397,7 +1421,7 @@ static int apply_patch(int fd)\n \t\texit(1);\n \n \tif (apply)\n-\t\twrite_out_results(list);\n+\t\twrite_out_results(list, skipped_patch);\n \n \tif (write_index) {\n \t\tif (write_cache(newfd, active_cache, active_nr) ||\n@@ -1432,6 +1456,13 @@ int main(int argc, char **argv)\n \t\t\tread_stdin = 0;\n \t\t\tcontinue;\n \t\t}\n+\t\tif (!strncmp(arg, \"--exclude=\", 10)) {\n+\t\t\tstruct excludes *x = xmalloc(sizeof(*x));\n+\t\t\tx->path = arg + 10;\n+\t\t\tx->next = excludes;\n+\t\t\texcludes = x;\n+\t\t\tcontinue;\n+\t\t}\n \t\t/* NEEDSWORK: this does not do anything at this moment. */\n \t\tif (!strcmp(arg, \"--no-merge\")) {\n \t\t\tmerge_patch = 0;\n"}]}