{"thread":{"id":"26413","subject":"[PATCH] Add support for merging from upstream by default.","startedAt":"2011-02-05T00:45:21Z","lastAt":"2011-02-07T09:43:55Z","messageCount":6,"participants":["Jared Hance","Andreas Schwab","Junio C Hamano","Bert Wesarg"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"160417","messageId":"1296866721-27818-1-git-send-email-jaredhance@gmail.com","threadId":"26413","inReplyTo":null,"subject":"[PATCH] Add support for merging from upstream by default.","fromName":"Jared Hance","fromEmail":"jaredhance@gmail.com","sentAt":"2011-02-05T00:45:21Z","receivedAt":"2011-02-05T00:45:21Z","isPatch":true,"sender":{"key":"jaredhance@gmail.com","avatar":"https://avatars.githubusercontent.com/u/170192?v=4"},"body":"Adds the option merge.defaultupstream to add support for merging from the\nupstream branch by default. The upstream branch is found using\nbranch.[name].upstream.\n---\n\nSo it turns out that the old code _did_ work with options; I had thought it\nhadn't because I relied on !argc == 0, but since argc is decreased after parsing\noptions anyway, it isn't a problem. This update fixes the usage as Junio\nsuggested, since it does support options.\n\n builtin/merge.c |   41 +++++++++++++++++++++++++++++++++++------\n 1 files changed, 35 insertions(+), 6 deletions(-)\n\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 42fff38..a69b69f 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -37,6 +37,7 @@ struct strategy {\n };\n \n static const char * const builtin_merge_usage[] = {\n+        \"git merge\",\n \t\"git merge [options] <remote>...\",\n \t\"git merge [options] <msg> HEAD <remote>\",\n \tNULL\n@@ -58,6 +59,8 @@ static int option_renormalize;\n static int verbosity;\n static int allow_rerere_auto;\n static int abort_current_merge;\n+static int default_upstream;\n+static const char *upstream_branch;\n \n static struct strategy all_strategy[] = {\n \t{ \"recursive\",  DEFAULT_TWOHEAD | NO_TRIVIAL },\n@@ -519,8 +522,15 @@ static int git_merge_config(const char *k, const char *v, void *cb)\n \t\t\t      builtin_merge_usage, 0);\n \t\tfree(buf);\n \t}\n-\n-\tif (!strcmp(k, \"merge.diffstat\") || !strcmp(k, \"merge.stat\"))\n+        else if(branch && !prefixcmp(k, \"branch.\") &&\n+                !prefixcmp(k + 7, branch) &&\n+                !strcmp(k + 7 + strlen(branch), \".upstream\")) {\n+                return git_config_string(&upstream_branch, k, v);\n+        }\n+\n+        if (!strcmp(k, \"merge.defaultupstream\"))\n+                default_upstream = git_config_bool(k, v);\n+        else if (!strcmp(k, \"merge.diffstat\") || !strcmp(k, \"merge.stat\"))\n \t\tshow_diffstat = git_config_bool(k, v);\n \telse if (!strcmp(k, \"pull.twohead\"))\n \t\treturn git_config_string(&pull_twohead, k, v);\n@@ -983,9 +993,28 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \tif (!allow_fast_forward && fast_forward_only)\n \t\tdie(\"You cannot combine --no-ff with --ff-only.\");\n \n-\tif (!argc)\n-\t\tusage_with_options(builtin_merge_usage,\n-\t\t\tbuiltin_merge_options);\n+\tif (!argc) {\n+                if(default_upstream && upstream_branch) {\n+\t\t        struct object *o;\n+                        struct commit *commit;\n+\n+                        o = peel_to_type(upstream_branch, 0, NULL, OBJ_COMMIT);\n+                        if (!o)\n+                            die(\"%s - not something we can merge\", argv[i]);\n+                        commit = lookup_commit(o->sha1);\n+                        commit->util = (void *)upstream_branch;\n+                        remotes = &commit_list_insert(commit, remotes)->next;\n+\n+                        strbuf_addf(&buf, \"GITHEAD_%s\", sha1_to_hex(o->sha1));\n+                        setenv(buf.buf, upstream_branch, 1);\n+                        strbuf_reset(&buf);\n+                }\n+                else {\n+\t\t        usage_with_options(builtin_merge_usage,\n+\t\t\t        builtin_merge_options);\n+\n+                }\n+        }\n \n \t/*\n \t * This could be traditional \"merge <msg> HEAD <commit>...\"  and\n@@ -1048,7 +1077,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \t\t}\n \t}\n \n-\tif (head_invalid || !argc)\n+\tif (head_invalid || (!argc && !(default_upstream && upstream_branch)))\n \t\tusage_with_options(builtin_merge_usage,\n \t\t\tbuiltin_merge_options);\n \n-- \n1.7.4\n"},{"id":"160432","messageId":"m2k4he23z6.fsf@whitebox.home","threadId":"26413","inReplyTo":"1296866721-27818-1-git-send-email-jaredhance@gmail.com","subject":"Re: [PATCH] Add support for merging from upstream by default.","fromName":"Andreas Schwab","fromEmail":"schwab@linux-m68k.org","sentAt":"2011-02-05T10:03:09Z","receivedAt":"2011-02-05T10:03:09Z","isPatch":true,"sender":{"key":"schwab@linux-m68k.org","avatar":"https://avatars.githubusercontent.com/u/2175493?v=4"},"body":"Jared Hance <jaredhance@gmail.com> writes:\n\n> diff --git a/builtin/merge.c b/builtin/merge.c\n> index 42fff38..a69b69f 100644\n> --- a/builtin/merge.c\n> +++ b/builtin/merge.c\n> @@ -37,6 +37,7 @@ struct strategy {\n>  };\n>  \n>  static const char * const builtin_merge_usage[] = {\n> +        \"git merge\",\n\nDoesn't that form take options as well?\n\n>  \t\"git merge [options] <remote>...\",\n\nIOW, how about changing that to\n\n  \t\"git merge [options] [<remote>...]\",\n\nAndreas.\n\n-- \nAndreas Schwab, schwab@linux-m68k.org\nGPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5\n\"And now for something completely different.\"\n"},{"id":"160439","messageId":"1296912681-4161-1-git-send-email-jaredhance@gmail.com","threadId":"26413","inReplyTo":"m2k4he23z6.fsf@whitebox.home","subject":"[PATCH] Add support for merging from upstream by default.","fromName":"Jared Hance","fromEmail":"jaredhance@gmail.com","sentAt":"2011-02-05T13:31:21Z","receivedAt":"2011-02-05T13:31:21Z","isPatch":true,"sender":{"key":"jaredhance@gmail.com","avatar":"https://avatars.githubusercontent.com/u/170192?v=4"},"body":"Adds the option merge.defaultupstream to add support for merging from the\nupstream branch by default. The upstream branch is found using\nbranch.[name].upstream.\n---\n\nI checked it this time, it really is the right usage.\n\n builtin/merge.c |   42 +++++++++++++++++++++++++++++++++++-------\n 1 files changed, 35 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 42fff38..596febe 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -37,7 +37,7 @@ struct strategy {\n };\n \n static const char * const builtin_merge_usage[] = {\n-\t\"git merge [options] <remote>...\",\n+\t\"git merge [options] [<remote>...]\",\n \t\"git merge [options] <msg> HEAD <remote>\",\n \tNULL\n };\n@@ -58,6 +58,8 @@ static int option_renormalize;\n static int verbosity;\n static int allow_rerere_auto;\n static int abort_current_merge;\n+static int default_upstream;\n+static const char *upstream_branch;\n \n static struct strategy all_strategy[] = {\n \t{ \"recursive\",  DEFAULT_TWOHEAD | NO_TRIVIAL },\n@@ -519,8 +521,15 @@ static int git_merge_config(const char *k, const char *v, void *cb)\n \t\t\t      builtin_merge_usage, 0);\n \t\tfree(buf);\n \t}\n-\n-\tif (!strcmp(k, \"merge.diffstat\") || !strcmp(k, \"merge.stat\"))\n+        else if(branch && !prefixcmp(k, \"branch.\") &&\n+                !prefixcmp(k + 7, branch) &&\n+                !strcmp(k + 7 + strlen(branch), \".upstream\")) {\n+                return git_config_string(&upstream_branch, k, v);\n+        }\n+\n+        if (!strcmp(k, \"merge.defaultupstream\"))\n+                default_upstream = git_config_bool(k, v);\n+        else if (!strcmp(k, \"merge.diffstat\") || !strcmp(k, \"merge.stat\"))\n \t\tshow_diffstat = git_config_bool(k, v);\n \telse if (!strcmp(k, \"pull.twohead\"))\n \t\treturn git_config_string(&pull_twohead, k, v);\n@@ -983,9 +992,28 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \tif (!allow_fast_forward && fast_forward_only)\n \t\tdie(\"You cannot combine --no-ff with --ff-only.\");\n \n-\tif (!argc)\n-\t\tusage_with_options(builtin_merge_usage,\n-\t\t\tbuiltin_merge_options);\n+\tif (!argc) {\n+                if(default_upstream && upstream_branch) {\n+\t\t        struct object *o;\n+                        struct commit *commit;\n+\n+                        o = peel_to_type(upstream_branch, 0, NULL, OBJ_COMMIT);\n+                        if (!o)\n+                            die(\"%s - not something we can merge\", argv[i]);\n+                        commit = lookup_commit(o->sha1);\n+                        commit->util = (void *)upstream_branch;\n+                        remotes = &commit_list_insert(commit, remotes)->next;\n+\n+                        strbuf_addf(&buf, \"GITHEAD_%s\", sha1_to_hex(o->sha1));\n+                        setenv(buf.buf, upstream_branch, 1);\n+                        strbuf_reset(&buf);\n+                }\n+                else {\n+\t\t        usage_with_options(builtin_merge_usage,\n+\t\t\t        builtin_merge_options);\n+\n+                }\n+        }\n \n \t/*\n \t * This could be traditional \"merge <msg> HEAD <commit>...\"  and\n@@ -1048,7 +1076,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \t\t}\n \t}\n \n-\tif (head_invalid || !argc)\n+\tif (head_invalid || (!argc && !(default_upstream && upstream_branch)))\n \t\tusage_with_options(builtin_merge_usage,\n \t\t\tbuiltin_merge_options);\n \n-- \n1.7.4\n"},{"id":"160567","messageId":"7vaai8wqny.fsf@alter.siamese.dyndns.org","threadId":"26413","inReplyTo":"1296912681-4161-1-git-send-email-jaredhance@gmail.com","subject":"Re: [PATCH] Add support for merging from upstream by default.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-02-07T01:59:29Z","receivedAt":"2011-02-07T01:59:29Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jared Hance <jaredhance@gmail.com> writes:\n\n> Adds the option merge.defaultupstream to add support for merging from the\n> upstream branch by default. The upstream branch is found using\n> branch.[name].upstream.\n> ---\n\nSign off?\n\nThe patch (rather your code before getting handed to your MUA) seems\nseverely whitespace damaged.\n\n> diff --git a/builtin/merge.c b/builtin/merge.c\n> index 42fff38..596febe 100644\n> --- a/builtin/merge.c\n> +++ b/builtin/merge.c\n> @@ -37,7 +37,7 @@ struct strategy {\n>  };\n>  \n>  static const char * const builtin_merge_usage[] = {\n> -\t\"git merge [options] <remote>...\",\n> +\t\"git merge [options] [<remote>...]\",\n>  \t\"git merge [options] <msg> HEAD <remote>\",\n>  \tNULL\n>  };\n> @@ -58,6 +58,8 @@ static int option_renormalize;\n>  static int verbosity;\n>  static int allow_rerere_auto;\n>  static int abort_current_merge;\n> +static int default_upstream;\n> +static const char *upstream_branch;\n>  \n>  static struct strategy all_strategy[] = {\n>  \t{ \"recursive\",  DEFAULT_TWOHEAD | NO_TRIVIAL },\n> @@ -519,8 +521,15 @@ static int git_merge_config(const char *k, const char *v, void *cb)\n>  \t\t\t      builtin_merge_usage, 0);\n>  \t\tfree(buf);\n>  \t}\n> -\n> -\tif (!strcmp(k, \"merge.diffstat\") || !strcmp(k, \"merge.stat\"))\n> +        else if(branch && !prefixcmp(k, \"branch.\") &&\n> +                !prefixcmp(k + 7, branch) &&\n> +                !strcmp(k + 7 + strlen(branch), \".upstream\")) {\n> +                return git_config_string(&upstream_branch, k, v);\n> +        }\n\nShouldn't this be inside a single large if block that is guarded by\n\n\tif (branch && !prefixcmp(k, \"branch.\") && !prefixcmp(k + 7, branch))\n\nwith a small refactoring of the existing code in git_merge_config(), the\nfirst if statement?  It probably is a good idea to hand that off to a\nsmall helper function as well, i.e. the first if statement in\ngit_merge_config() becomes something like:\n\n\tstatus = per_branch_config(k, v, cb);\n        if (status <= 0)\n\t\treturn status;\n\nand then a new helper function is defined right in front of it, perhaps\n\n\tstatic int per_branch_config(const char *k, const char *v, void *cb)\n\t{\n        \tconst char *variable;\n        \tif (!branch || prefixcmp(k, \"branch.\")\n                    || prefixcmp(k + 7, branch))\n\t\t\treturn 1; /* ignore me */\n\t\tvariable = k + 7 + strlen(branch);\n                if (strcmp(variable, \".mergeoptions\")) {\n                \t...\n                        return 0; /* done */\n\t\t}\n                if (strcmp(variable, \".upstream\")) {\n                \t...\n                        return 0; /* or -1 if you see an error */\n\t\t}\n                return 1; /* not what I handle */\n\t}\n"},{"id":"160592","messageId":"AANLkTikii-fx5nYeBDc70eh_wj05sEZ6fH6=bF9GqHBK@mail.gmail.com","threadId":"26413","inReplyTo":"1296912681-4161-1-git-send-email-jaredhance@gmail.com","subject":"Re: [PATCH] Add support for merging from upstream by default.","fromName":"Bert Wesarg","fromEmail":"bert.wesarg@googlemail.com","sentAt":"2011-02-07T09:36:05Z","receivedAt":"2011-02-07T09:36:05Z","isPatch":true,"sender":{"key":"bert.wesarg@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/111934?v=4"},"body":"On Sat, Feb 5, 2011 at 14:31, Jared Hance <jaredhance@gmail.com> wrote:\n> Adds the option merge.defaultupstream to add support for merging from the\n> upstream branch by default. The upstream branch is found using\n> branch.[name].upstream.\n\nWhy do we need a per branch config for this, isn't .origin/.merge\nenough? Or, where is the connection between your new .upstream and the\n@{upstream} ref?\n\nBert\n"},{"id":"160593","messageId":"AANLkTim7hRrGtT_9dsHWp-405H_RF1s=UUQ6BPFCOY+n@mail.gmail.com","threadId":"26413","inReplyTo":"AANLkTikii-fx5nYeBDc70eh_wj05sEZ6fH6=bF9GqHBK@mail.gmail.com","subject":"Re: [PATCH] Add support for merging from upstream by default.","fromName":"Bert Wesarg","fromEmail":"bert.wesarg@googlemail.com","sentAt":"2011-02-07T09:43:55Z","receivedAt":"2011-02-07T09:43:55Z","isPatch":true,"sender":{"key":"bert.wesarg@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/111934?v=4"},"body":"On Mon, Feb 7, 2011 at 10:36, Bert Wesarg <bert.wesarg@googlemail.com> wrote:\n> On Sat, Feb 5, 2011 at 14:31, Jared Hance <jaredhance@gmail.com> wrote:\n>> Adds the option merge.defaultupstream to add support for merging from the\n>> upstream branch by default. The upstream branch is found using\n>> branch.[name].upstream.\n>\n> Why do we need a per branch config for this, isn't .origin/.merge\n\nWhy do we need a *new* per branch config for this, isn't .origin/.merge\n\n> enough? Or, where is the connection between your new .upstream and the\n> @{upstream} ref?\n>\n> Bert\n>\n"}]}