{"thread":{"id":"21560","subject":"[PATCH 6/8] builtin-fetch: add --prune option","startedAt":"2009-11-10T08:15:47Z","lastAt":"2009-11-10T09:49:21Z","messageCount":5,"participants":["Björn Gustavsson","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":8},"messages":[{"id":"127223","messageId":"4AF92133.6070005@gmail.com","threadId":"21560","inReplyTo":null,"subject":"[PATCH 6/8] builtin-fetch: add --prune option","fromName":"Björn Gustavsson","fromEmail":"bgustavsson@gmail.com","sentAt":"2009-11-10T08:15:47Z","receivedAt":"2009-11-10T08:15:47Z","isPatch":true,"sender":{"key":"bgustavsson@gmail.com","avatar":"https://avatars.githubusercontent.com/u/74840?v=4"},"body":"From: Jay Soffian <jaysoffian@gmail.com>\n\nTeach fetch to cull stale remote tracking branches after fetching via --prune.\n\nSigned-off-by: Jay Soffian <jaysoffian@gmail.com>\nSigned-off-by: Björn Gustavsson <bgustavsson@gmail.com>\n---\n Documentation/fetch-options.txt |    4 ++++\n builtin-fetch.c                 |   32 ++++++++++++++++++++++++++++++--\n 2 files changed, 34 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/fetch-options.txt b/Documentation/fetch-options.txt\nindex 8b0cf58..500637a 100644\n--- a/Documentation/fetch-options.txt\n+++ b/Documentation/fetch-options.txt\n@@ -28,6 +28,10 @@ ifndef::git-pull[]\n --multiple::\n \tAllow several <repository> and <group> arguments to be\n \tspecified. No <refspec>s may be specified.\n+\n+--prune::\n+\tAfter fetching, remove any remote tracking branches which\n+\tno longer exist\ton the remote.\n endif::git-pull[]\n \n ifdef::git-pull[]\ndiff --git a/builtin-fetch.c b/builtin-fetch.c\nindex 945dfd8..fd31072 100644\n--- a/builtin-fetch.c\n+++ b/builtin-fetch.c\n@@ -26,7 +26,7 @@ enum {\n \tTAGS_SET = 2\n };\n \n-static int all, append, force, keep, multiple, update_head_ok, verbosity;\n+static int all, append, force, keep, multiple, prune, update_head_ok, verbosity;\n static int tags = TAGS_DEFAULT;\n static const char *depth;\n static const char *upload_pack;\n@@ -49,6 +49,8 @@ static struct option builtin_fetch_options[] = {\n \t\t    \"fetch all tags and associated objects\", TAGS_SET),\n \tOPT_SET_INT('n', NULL, &tags,\n \t\t    \"do not fetch all tags (--no-tags)\", TAGS_UNSET),\n+\tOPT_BOOLEAN('p', \"prune\", &prune,\n+\t\t    \"prune tracking branches no longer on remote\"),\n \tOPT_BOOLEAN('k', \"keep\", &keep, \"keep downloaded pack\"),\n \tOPT_BOOLEAN('u', \"update-head-ok\", &update_head_ok,\n \t\t    \"allow updating of HEAD ref\"),\n@@ -492,6 +494,28 @@ static int fetch_refs(struct transport *transport, struct ref *ref_map)\n \treturn ret;\n }\n \n+static int prune_refs(struct transport *transport, struct ref *ref_map)\n+{\n+\tint result = 0;\n+\tstruct ref *ref, *stale_refs = get_stale_heads(transport->remote, ref_map);\n+\tconst char *dangling_msg = dry_run\n+\t\t? \"   (%s will become dangling)\\n\"\n+\t\t: \"   (%s has become dangling)\\n\";\n+\n+\tfor (ref = stale_refs; ref; ref = ref->next) {\n+\t\tif (!dry_run)\n+\t\t\tresult |= delete_ref(ref->name, NULL, 0);\n+\t\tif (verbosity >= 0) {\n+\t\t\tfprintf(stderr, \" x %-*s %-*s -> %s\\n\",\n+\t\t\t\tSUMMARY_WIDTH, \"[deleted]\",\n+\t\t\t\tREFCOL_WIDTH, \"(none)\", prettify_refname(ref->name));\n+\t\t\twarn_dangling_symref(stderr, dangling_msg, ref->name);\n+\t\t}\n+\t}\n+\tfree_refs(stale_refs);\n+\treturn result;\n+}\n+\n static int add_existing(const char *refname, const unsigned char *sha1,\n \t\t\tint flag, void *cbdata)\n {\n@@ -657,6 +681,8 @@ static int do_fetch(struct transport *transport,\n \t\tfree_refs(ref_map);\n \t\treturn 1;\n \t}\n+\tif (prune)\n+\t\tprune_refs(transport, ref_map);\n \tfree_refs(ref_map);\n \n \t/* if neither --no-tags nor --tags was specified, do automated tag\n@@ -740,9 +766,11 @@ static int add_remote_or_group(const char *name, struct string_list *list)\n static int fetch_multiple(struct string_list *list)\n {\n \tint i, result = 0;\n-\tconst char *argv[] = { \"fetch\", NULL, NULL, NULL, NULL };\n+\tconst char *argv[] = { \"fetch\", NULL, NULL, NULL, NULL, NULL };\n \tint argc = 1;\n \n+\tif (prune)\n+\t\targv[argc++] = \"--prune\";\n \tif (verbosity >= 2)\n \t\targv[argc++] = \"-v\";\n \tif (verbosity >= 1)\n-- \n1.6.5.1.69.g36942\n"},{"id":"127229","messageId":"7vfx8mg3mw.fsf@alter.siamese.dyndns.org","threadId":"21560","inReplyTo":"4AF92133.6070005@gmail.com","subject":"Re: [PATCH 6/8] builtin-fetch: add --prune option","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-11-10T08:55:51Z","receivedAt":"2009-11-10T08:55:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Björn Gustavsson <bgustavsson@gmail.com> writes:\n\n> From: Jay Soffian <jaysoffian@gmail.com>\n\nThanks for being careful; it would be even better if you preserve the\nauthor date by copying Date: from the original.\n\n> Teach fetch to cull stale remote tracking branches after fetching via --prune.\n>\n> Signed-off-by: Jay Soffian <jaysoffian@gmail.com>\n> Signed-off-by: Björn Gustavsson <bgustavsson@gmail.com>\n\nYuck...\n\nbuiltin-fetch.c: In function 'prune_refs':\nbuiltin-fetch.c:500: error: implicit declaration of function 'get_stale_heads'\nbuiltin-fetch.c:500: error: initialization makes pointer from integer without a cast\nbuiltin-fetch.c:501: error: 'dry_run' undeclared (first use in this function)\nbuiltin-fetch.c:501: error: (Each undeclared identifier is reported only once\nbuiltin-fetch.c:501: error: for each function it appears in.)\nmake: *** [builtin-fetch.o] Error 1\n"},{"id":"127230","messageId":"7vbpjag3as.fsf@alter.siamese.dyndns.org","threadId":"21560","inReplyTo":"7vfx8mg3mw.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH 6/8] builtin-fetch: add --prune option","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-11-10T09:03:07Z","receivedAt":"2009-11-10T09:03:07Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Björn Gustavsson <bgustavsson@gmail.com> writes:\n>\n>> From: Jay Soffian <jaysoffian@gmail.com>\n>\n> Thanks for being careful; it would be even better if you preserve the\n> author date by copying Date: from the original.\n>\n>> Teach fetch to cull stale remote tracking branches after fetching via --prune.\n>>\n>> Signed-off-by: Jay Soffian <jaysoffian@gmail.com>\n>> Signed-off-by: Björn Gustavsson <bgustavsson@gmail.com>\n>\n> Yuck...\n>\n> builtin-fetch.c: In function 'prune_refs':\n> builtin-fetch.c:500: error: implicit declaration of function 'get_stale_heads'\n> builtin-fetch.c:500: error: initialization makes pointer from integer without a cast\n> builtin-fetch.c:501: error: 'dry_run' undeclared (first use in this function)\n> builtin-fetch.c:501: error: (Each undeclared identifier is reported only once\n> builtin-fetch.c:501: error: for each function it appears in.)\n> make: *** [builtin-fetch.o] Error 1\n\nAh, I know.  You forgot the first one from Jay's series.\n"},{"id":"127233","messageId":"6672d0160911100143r3967d080t1a31906a99440d8d@mail.gmail.com","threadId":"21560","inReplyTo":"7vfx8mg3mw.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH 6/8] builtin-fetch: add --prune option","fromName":"Björn Gustavsson","fromEmail":"bgustavsson@gmail.com","sentAt":"2009-11-10T09:43:15Z","receivedAt":"2009-11-10T09:43:15Z","isPatch":true,"sender":{"key":"bgustavsson@gmail.com","avatar":"https://avatars.githubusercontent.com/u/74840?v=4"},"body":"2009/11/10 Junio C Hamano <gitster@pobox.com>:\n> Björn Gustavsson <bgustavsson@gmail.com> writes:\n>\n>> From: Jay Soffian <jaysoffian@gmail.com>\n>\n> Thanks for being careful; it would be even better if you preserve the\n> author date by copying Date: from the original.\n\nThanks for the tip! Will do that next time.\n\n-- \nBjörn Gustavsson, Erlang/OTP, Ericsson AB\n"},{"id":"127234","messageId":"6672d0160911100149k6d89ba14rb94f25fe49fee75c@mail.gmail.com","threadId":"21560","inReplyTo":"7vbpjag3as.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH 6/8] builtin-fetch: add --prune option","fromName":"Björn Gustavsson","fromEmail":"bgustavsson@gmail.com","sentAt":"2009-11-10T09:49:21Z","receivedAt":"2009-11-10T09:49:21Z","isPatch":true,"sender":{"key":"bgustavsson@gmail.com","avatar":"https://avatars.githubusercontent.com/u/74840?v=4"},"body":"2009/11/10 Junio C Hamano <gitster@pobox.com>:\n>> Yuck...\n>>\n>> builtin-fetch.c: In function 'prune_refs':\n>> builtin-fetch.c:500: error: implicit declaration of function 'get_stale_heads'\n>> builtin-fetch.c:500: error: initialization makes pointer from integer without a cast\n>> builtin-fetch.c:501: error: 'dry_run' undeclared (first use in this function)\n>> builtin-fetch.c:501: error: (Each undeclared identifier is reported only once\n>> builtin-fetch.c:501: error: for each function it appears in.)\n>> make: *** [builtin-fetch.o] Error 1\n>\n> Ah, I know.  You forgot the first one from Jay's series.\n>\n\nOff-by-one error when I ran format-patch. Sorry for that.\n\n-- \nBjörn Gustavsson, Erlang/OTP, Ericsson AB\n"}]}