{"thread":{"id":"14689","subject":"[PATCH 2/3] builtin-branch: factor out merge_filter matching","startedAt":"2008-07-26T10:27:22Z","lastAt":"2008-07-26T10:27:25Z","messageCount":4,"participants":["Lars Hjemli"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"85040","messageId":"1217068045-3575-1-git-send-email-hjemli@gmail.com","threadId":"14689","inReplyTo":null,"subject":"[PATCH 0/3] builtin-branch --[no-]merged post-optimization fixes","fromName":"Lars Hjemli","fromEmail":"hjemli@gmail.com","sentAt":"2008-07-26T10:27:22Z","receivedAt":"2008-07-26T10:27:22Z","isPatch":true,"sender":{"key":"hjemli@gmail.com","avatar":null},"body":"The optimization of --[no-]merged added some code duplication and a\npossible \"bug\" for -v output which this series tries to rectify.\n\nLars Hjemli (3):\n  builtin-branch: remove duplicated code\n  builtin-branch: factor out merge_filter matching\n  builtin-branch: fix -v for --[no-]merged\n\n builtin-branch.c |   42 ++++++++++++++++++++++++++++++------------\n 1 files changed, 30 insertions(+), 12 deletions(-)\n"},{"id":"85042","messageId":"1217068045-3575-2-git-send-email-hjemli@gmail.com","threadId":"14689","inReplyTo":"1217068045-3575-1-git-send-email-hjemli@gmail.com","subject":"[PATCH 1/3] builtin-branch: remove duplicated code","fromName":"Lars Hjemli","fromEmail":"hjemli@gmail.com","sentAt":"2008-07-26T10:27:23Z","receivedAt":"2008-07-26T10:27:23Z","isPatch":true,"sender":{"key":"hjemli@gmail.com","avatar":null},"body":"The previous optimization to --[no-]merged ended up with some duplicated\ncode which this patch removes.\n\nSigned-off-by: Lars Hjemli <hjemli@gmail.com>\n---\n builtin-branch.c |    9 ++-------\n 1 files changed, 2 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin-branch.c b/builtin-branch.c\nindex 5db8ad8..675a9b1 100644\n--- a/builtin-branch.c\n+++ b/builtin-branch.c\n@@ -214,7 +214,6 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,\n \tstruct commit *commit;\n \tint kind;\n \tint len;\n-\tstatic struct commit_list branch;\n \n \t/* Detect kind */\n \tif (!prefixcmp(refname, \"refs/heads/\")) {\n@@ -238,13 +237,9 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,\n \tif ((kind & ref_list->kinds) == 0)\n \t\treturn 0;\n \n-\tif (merge_filter != NO_FILTER) {\n-\t\tbranch.item = lookup_commit_reference_gently(sha1, 1);\n-\t\tif (!branch.item)\n-\t\t\tdie(\"Unable to lookup tip of branch %s\", refname);\n+\tif (merge_filter != NO_FILTER)\n \t\tadd_pending_object(&ref_list->revs,\n-\t\t\t\t   (struct object *)branch.item, refname);\n-\t}\n+\t\t\t\t   (struct object *)commit, refname);\n \n \t/* Resize buffer */\n \tif (ref_list->index >= ref_list->alloc) {\n-- \n1.6.0.rc0.79.gb0320\n"},{"id":"85039","messageId":"1217068045-3575-3-git-send-email-hjemli@gmail.com","threadId":"14689","inReplyTo":"1217068045-3575-2-git-send-email-hjemli@gmail.com","subject":"[PATCH 2/3] builtin-branch: factor out merge_filter matching","fromName":"Lars Hjemli","fromEmail":"hjemli@gmail.com","sentAt":"2008-07-26T10:27:24Z","receivedAt":"2008-07-26T10:27:24Z","isPatch":true,"sender":{"key":"hjemli@gmail.com","avatar":null},"body":"The logic for checking commits against merge_filter will be reused\nwhen we recalculate the maxwidth of refnames.\n\nSigned-off-by: Lars Hjemli <hjemli@gmail.com>\n---\n builtin-branch.c |   18 +++++++++++++-----\n 1 files changed, 13 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin-branch.c b/builtin-branch.c\nindex 675a9b1..bff74cf 100644\n--- a/builtin-branch.c\n+++ b/builtin-branch.c\n@@ -294,6 +294,17 @@ static void fill_tracking_info(char *stat, const char *branch_name)\n \t\tsprintf(stat, \"[ahead %d, behind %d] \", ours, theirs);\n }\n \n+static int matches_merge_filter(struct commit *commit)\n+{\n+\tint is_merged;\n+\t\n+\tif (merge_filter == NO_FILTER)\n+\t\treturn 1;\n+\t\t\n+\tis_merged = !!(commit->object.flags & UNINTERESTING);\n+\treturn (is_merged == (merge_filter == SHOW_MERGED));\n+}\n+\n static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,\n \t\t\t   int abbrev, int current)\n {\n@@ -301,11 +312,8 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,\n \tint color;\n \tstruct commit *commit = item->commit;\n \n-\tif (merge_filter != NO_FILTER) {\n-\t\tint is_merged = !!(item->commit->object.flags & UNINTERESTING);\n-\t\tif (is_merged != (merge_filter == SHOW_MERGED))\n-\t\t\treturn;\n-\t}\n+\tif (!matches_merge_filter(commit))\n+\t\treturn;\n \n \tswitch (item->kind) {\n \tcase REF_LOCAL_BRANCH:\n-- \n1.6.0.rc0.79.gb0320\n"},{"id":"85041","messageId":"1217068045-3575-4-git-send-email-hjemli@gmail.com","threadId":"14689","inReplyTo":"1217068045-3575-3-git-send-email-hjemli@gmail.com","subject":"[PATCH 3/3] builtin-branch: fix -v for --[no-]merged","fromName":"Lars Hjemli","fromEmail":"hjemli@gmail.com","sentAt":"2008-07-26T10:27:25Z","receivedAt":"2008-07-26T10:27:25Z","isPatch":true,"sender":{"key":"hjemli@gmail.com","avatar":null},"body":"After the optimization to --[no-]merged logic, the calculation of the\nwidth of the longest refname to be shown might become inaccurate (since\nthe matching against merge_filter is performed after adding refs to\nref_list). This patch forces a recalculation of maxwidth when it might\nbe needed.\n\nSigned-off-by: Lars Hjemli <hjemli@gmail.com>\n---\n builtin-branch.c |   15 +++++++++++++++\n 1 files changed, 15 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-branch.c b/builtin-branch.c\nindex bff74cf..fed6f5e 100644\n--- a/builtin-branch.c\n+++ b/builtin-branch.c\n@@ -363,6 +363,19 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,\n \t}\n }\n \n+static int calc_maxwidth(struct ref_list *refs)\n+{\n+\tint i, l, w = 0;\n+\tfor (i = 0; i < refs->index; i++) {\n+\t\tif (!matches_merge_filter(refs->list[i].commit))\n+\t\t\tcontinue;\n+\t\tl = strlen(refs->list[i].name);\n+\t\tif (l > w)\n+\t\t\tw = l;\n+\t}\n+\treturn w;\n+}\n+\n static void print_ref_list(int kinds, int detached, int verbose, int abbrev, struct commit_list *with_commit)\n {\n \tint i;\n@@ -383,6 +396,8 @@ static void print_ref_list(int kinds, int detached, int verbose, int abbrev, str\n \t\t\t\t   (struct object *) filter, \"\");\n \t\tref_list.revs.limited = 1;\n \t\tprepare_revision_walk(&ref_list.revs);\n+\t\tif (verbose)\n+\t\t\tref_list.maxwidth = calc_maxwidth(&ref_list);\n \t}\n \n \tqsort(ref_list.list, ref_list.index, sizeof(struct ref_item), ref_cmp);\n-- \n1.6.0.rc0.79.gb0320\n"}]}