{"thread":{"id":"26469","subject":"[PATCH v5 0/4] Updated patch series for default upstream merge","startedAt":"2011-02-10T23:52:40Z","lastAt":"2011-02-12T13:02:01Z","messageCount":8,"participants":["Jared Hance","Junio C Hamano","Drew Northup"],"isPatch":true,"patchVersion":5,"patchTotal":4},"messages":[{"id":"160864","messageId":"1297381964-7137-1-git-send-email-jaredhance@gmail.com","threadId":"26469","inReplyTo":null,"subject":"[PATCH v5 0/4] Updated patch series for default upstream merge","fromName":"Jared Hance","fromEmail":"jaredhance@gmail.com","sentAt":"2011-02-10T23:52:40Z","receivedAt":"2011-02-10T23:52:40Z","isPatch":true,"sender":{"key":"jaredhance@gmail.com","avatar":"https://avatars.githubusercontent.com/u/170192?v=4"},"body":"This patch series allows merge, when given proper configuration, to default\nto the upstream of the current branch.\n\nThe last one I sent was malformed due to two versions of the patch series\nbeing in the tree at once; this is fixed and has some minor changes from\nv4.\n\nJared Hance (4):\n  merge: update the usage information to be more modern\n  merge: introduce setup_merge_commit helper function\n  merge: introduce per-branch-configuration helper function\n  merge: add support for merging from upstream by default\n\n Documentation/config.txt |    6 +++\n builtin/merge.c          |   90 ++++++++++++++++++++++++++++++++--------------\n 2 files changed, 69 insertions(+), 27 deletions(-)\n\n-- \n1.7.4\n"},{"id":"160865","messageId":"1297381964-7137-2-git-send-email-jaredhance@gmail.com","threadId":"26469","inReplyTo":"1297381964-7137-1-git-send-email-jaredhance@gmail.com","subject":"[PATCH v5 1/4] merge: update the usage information to be more modern","fromName":"Jared Hance","fromEmail":"jaredhance@gmail.com","sentAt":"2011-02-10T23:52:41Z","receivedAt":"2011-02-10T23:52:41Z","isPatch":true,"sender":{"key":"jaredhance@gmail.com","avatar":"https://avatars.githubusercontent.com/u/170192?v=4"},"body":"Apparantly, merge's usage information was outdated and used old terminology.\nFix it.\n\nSigned-off-by: Jared Hance <jaredhance@gmail.com>\n---\n builtin/merge.c |    4 ++--\n 1 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 42fff38..439d2c7 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -37,8 +37,8 @@ struct strategy {\n };\n \n static const char * const builtin_merge_usage[] = {\n-\t\"git merge [options] <remote>...\",\n-\t\"git merge [options] <msg> HEAD <remote>\",\n+\t\"git merge [options] <branch>...\",\n+\t\"git merge [options] <msg> HEAD <branch>\",\n \tNULL\n };\n \n-- \n1.7.4\n"},{"id":"160868","messageId":"1297381964-7137-3-git-send-email-jaredhance@gmail.com","threadId":"26469","inReplyTo":"1297381964-7137-1-git-send-email-jaredhance@gmail.com","subject":"[PATCH v5 2/4] merge: introduce setup_merge_commit helper function","fromName":"Jared Hance","fromEmail":"jaredhance@gmail.com","sentAt":"2011-02-10T23:52:42Z","receivedAt":"2011-02-10T23:52:42Z","isPatch":true,"sender":{"key":"jaredhance@gmail.com","avatar":"https://avatars.githubusercontent.com/u/170192?v=4"},"body":"Add a function to set up a merge commit given a branch\nor commit, which is currently used when parsing argv in a loop.\n\nSigned-off-by: Jared Hance <jaredhance@gmail.com>\n---\n builtin/merge.c |   44 +++++++++++++++++++++++++++-----------------\n 1 files changed, 27 insertions(+), 17 deletions(-)\n\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 439d2c7..cd23880 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -498,11 +498,15 @@ cleanup:\n \tstrbuf_release(&bname);\n }\n \n-static int git_merge_config(const char *k, const char *v, void *cb)\n+static int per_branch_config(const char *k, const char *v, void *cb)\n {\n-\tif (branch && !prefixcmp(k, \"branch.\") &&\n-\t\t!prefixcmp(k + 7, branch) &&\n-\t\t!strcmp(k + 7 + strlen(branch), \".mergeoptions\")) {\n+\tconst char *variable;\n+\tif (!branch || prefixcmp(k, \"branch.\") ||\n+\t   prefixcmp(k + 7, branch))\n+\t\treturn 1; /* not what I handle */\n+\n+\tvariable = k + 7 + strlen(branch);\n+\tif (!strcmp(variable, \".mergeoptions\")) {\n \t\tconst char **argv;\n \t\tint argc;\n \t\tchar *buf;\n@@ -911,6 +915,24 @@ static int evaluate_result(void)\n \treturn cnt;\n }\n \n+static void setup_merge_commit(struct strbuf *buf,\n+\tstruct commit_list ***remotes, const char *s)\n+{\n+\tstruct object *o;\n+\tstruct commit *commit;\n+\n+\to = peel_to_type(s, 0, NULL, OBJ_COMMIT);\n+\tif (!o)\n+\t\tdie(\"%s - not something we can merge\", s);\n+\tcommit = lookup_commit(o->sha1);\n+\tcommit->util = (void *)s;\n+\t*remotes = &commit_list_insert(commit, *remotes)->next;\n+\n+\tstrbuf_addf(buf, \"GITHEAD_%s\", sha1_to_hex(o->sha1));\n+\tsetenv(buf->buf, s, 1);\n+\tstrbuf_reset(buf);\n+}\n+\n int cmd_merge(int argc, const char **argv, const char *prefix)\n {\n \tunsigned char result_tree[20];\n@@ -1059,19 +1081,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \tstrbuf_reset(&buf);\n \n \tfor (i = 0; i < argc; i++) {\n-\t\tstruct object *o;\n-\t\tstruct commit *commit;\n-\n-\t\to = peel_to_type(argv[i], 0, NULL, OBJ_COMMIT);\n-\t\tif (!o)\n-\t\t\tdie(\"%s - not something we can merge\", argv[i]);\n-\t\tcommit = lookup_commit(o->sha1);\n-\t\tcommit->util = (void *)argv[i];\n-\t\tremotes = &commit_list_insert(commit, remotes)->next;\n-\n-\t\tstrbuf_addf(&buf, \"GITHEAD_%s\", sha1_to_hex(o->sha1));\n-\t\tsetenv(buf.buf, argv[i], 1);\n-\t\tstrbuf_reset(&buf);\n+\t\tsetup_merge_commit(&buf, &remotes, argv[i]);\n \t}\n \n \tif (!use_strategies) {\n-- \n1.7.4\n"},{"id":"160866","messageId":"1297381964-7137-4-git-send-email-jaredhance@gmail.com","threadId":"26469","inReplyTo":"1297381964-7137-1-git-send-email-jaredhance@gmail.com","subject":"[PATCH v5 3/4] merge: introduce per-branch-configuration helper function","fromName":"Jared Hance","fromEmail":"jaredhance@gmail.com","sentAt":"2011-02-10T23:52:43Z","receivedAt":"2011-02-10T23:52:43Z","isPatch":true,"sender":{"key":"jaredhance@gmail.com","avatar":"https://avatars.githubusercontent.com/u/170192?v=4"},"body":"Create a function that will hold configuration code for configuration\nvalues that are specified per branch, as suggested by Junio.\n\nSigned-off-by: Jared Hance <jaredhance@gmail.com>\n---\n builtin/merge.c |   12 ++++++++++++\n 1 files changed, 12 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex cd23880..71b392d 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -522,8 +522,20 @@ static int per_branch_config(const char *k, const char *v, void *cb)\n \t\tparse_options(argc, argv, NULL, builtin_merge_options,\n \t\t\t      builtin_merge_usage, 0);\n \t\tfree(buf);\n+\n+\t\treturn 0;\n \t}\n \n+\treturn 1; /* not what I handle */\n+}\n+\n+static int git_merge_config(const char *k, const char *v, void *cb)\n+{\n+\tint status = per_branch_config(k, v, cb);\n+\n+\tif (status <= 0)\n+\t\treturn status;\n+\n \tif (!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-- \n1.7.4\n"},{"id":"160867","messageId":"1297381964-7137-5-git-send-email-jaredhance@gmail.com","threadId":"26469","inReplyTo":"1297381964-7137-1-git-send-email-jaredhance@gmail.com","subject":"[PATCH v5 4/4] merge: add support for merging from upstream by default","fromName":"Jared Hance","fromEmail":"jaredhance@gmail.com","sentAt":"2011-02-10T23:52:44Z","receivedAt":"2011-02-10T23:52:44Z","isPatch":true,"sender":{"key":"jaredhance@gmail.com","avatar":"https://avatars.githubusercontent.com/u/170192?v=4"},"body":"Add the option merge.defaultupstream to add support for merging from\nthe upstream branch by default. The upstream branch is found using\nbranch.[name].merge.\n\nSigned-off-by: Jared Hance <jaredhance@gmail.com>\n---\n Documentation/config.txt |    6 ++++++\n builtin/merge.c          |   32 +++++++++++++++++++++++---------\n 2 files changed, 29 insertions(+), 9 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex c5e1835..4415691 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -1389,6 +1389,12 @@ man.<tool>.path::\n \n include::merge-config.txt[]\n \n+merge.defaultUpstream::\n+\tIf merge is called without any ref arguments, merge from the branch\n+\tspecified in branch.<current branch>.merge, which is considered to be\n+\tthe upstream branch for the current branch, possibly set by --track or\n+\t--set-upstream.\n+\n mergetool.<tool>.path::\n \tOverride the path for the given tool.  This is useful in case\n \tyour tool is not in the PATH.\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 71b392d..a3ca6a0 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] <branch>...\",\n+\t\"git merge [options] [<branch>...]\",\n \t\"git merge [options] <msg> HEAD <branch>\",\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@@ -524,7 +526,8 @@ static int per_branch_config(const char *k, const char *v, void *cb)\n \t\tfree(buf);\n \n \t\treturn 0;\n-\t}\n+\t} else if (!strcmp(variable, \".merge\"))\n+\t\treturn git_config_string(&upstream_branch, k, v);\n \n \treturn 1; /* not what I handle */\n }\n@@ -536,7 +539,9 @@ static int git_merge_config(const char *k, const char *v, void *cb)\n \tif (status <= 0)\n \t\treturn status;\n \n-\tif (!strcmp(k, \"merge.diffstat\") || !strcmp(k, \"merge.stat\"))\n+\tif (!strcmp(k, \"merge.defaultupstream\"))\n+\t\tdefault_upstream = git_config_bool(k, v);\n+\telse 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@@ -1017,9 +1022,13 @@ 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+\t\tif (!default_upstream || !upstream_branch)\n+\t\t\tusage_with_options(builtin_merge_usage,\n+\t\t\t\t\tbuiltin_merge_options);\n+\n+\t\tsetup_merge_commit(&buf, &remotes, upstream_branch);\n+\t}\n \n \t/*\n \t * This could be traditional \"merge <msg> HEAD <commit>...\"  and\n@@ -1082,9 +1091,14 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \t\t}\n \t}\n \n-\tif (head_invalid || !argc)\n-\t\tusage_with_options(builtin_merge_usage,\n-\t\t\tbuiltin_merge_options);\n+\tif (head_invalid)\n+\t\tusage_msg_opt(\"cannot use old-style invocation from an unborn\"\n+\t\t\t\t\"branch\", \n+\t\t\t\tbuiltin_merge_usage, builtin_merge_options);\n+\n+\tif (!argc && !(default_upstream && upstream_branch))\n+\t\tusage_msg_opt(\"no commit to merge specified\",\n+\t\t\t\tbuiltin_merge_usage, builtin_merge_options);\n \n \tstrbuf_addstr(&buf, \"merge\");\n \tfor (i = 0; i < argc; i++)\n-- \n1.7.4\n"},{"id":"160869","messageId":"7vsjvv1i5u.fsf@alter.siamese.dyndns.org","threadId":"26469","inReplyTo":"1297381964-7137-5-git-send-email-jaredhance@gmail.com","subject":"Re: [PATCH v5 4/4] merge: add support for merging from upstream by default","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-02-11T01:20:13Z","receivedAt":"2011-02-11T01:20:13Z","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> Add the option merge.defaultupstream to add support for merging from\n> the upstream branch by default. The upstream branch is found using\n> branch.[name].merge.\n>\n> Signed-off-by: Jared Hance <jaredhance@gmail.com>\n> ---\n\nThanks; the first three in the series looks right.\n\n> diff --git a/Documentation/config.txt b/Documentation/config.txt\n> index c5e1835..4415691 100644\n> --- a/Documentation/config.txt\n> +++ b/Documentation/config.txt\n> @@ -1389,6 +1389,12 @@ man.<tool>.path::\n>  \n>  include::merge-config.txt[]\n>  \n> +merge.defaultUpstream::\n\nI somehow had an impression that majority of others convinced you to\nrename this to default-to-upstream, but I may be mistaken.\n\nI think somebody who does not know the history of the development and\ndiscussion of this feature would think that this specifies the default\nupstream remote (i.e. not a boolean variable, but a string) given this\nname.\n\n> @@ -536,7 +539,9 @@ static int git_merge_config(const char *k, const char *v, void *cb)\n>  \tif (status <= 0)\n>  \t\treturn status;\n>  \n> -\tif (!strcmp(k, \"merge.diffstat\") || !strcmp(k, \"merge.stat\"))\n> +\tif (!strcmp(k, \"merge.defaultupstream\"))\n> +\t\tdefault_upstream = git_config_bool(k, v);\n> +\telse if (!strcmp(k, \"merge.diffstat\") || !strcmp(k, \"merge.stat\"))\n>  \t\tshow_diffstat = git_config_bool(k, v);\n\nIt is somewhat rude to reviewers' eyes to turn an existing \"if\" into \"else\nif\" and place new stuff at the beginning; unless there is a good reason\nthat the new stuff has to be at the beginning, that is.\n\nThis is not a new issue, but a callback function to git_config() should\nreturn once it recognized and handled the variable, instead of cascading\nthe controll out.  The \"diffstat/stat\" code shows a bad example and you\ninherited the badness from there.\n"},{"id":"160870","messageId":"7voc6j1hey.fsf@alter.siamese.dyndns.org","threadId":"26469","inReplyTo":"1297381964-7137-3-git-send-email-jaredhance@gmail.com","subject":"Re: [PATCH v5 2/4] merge: introduce setup_merge_commit helper function","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-02-11T01:36:21Z","receivedAt":"2011-02-11T01:36:21Z","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>  \tfor (i = 0; i < argc; i++) {\n> -\t\tstruct object *o;\n> ...\n> -\t\tstrbuf_reset(&buf);\n> +\t\tsetup_merge_commit(&buf, &remotes, argv[i]);\n>  \t}\n\nMicronit; the body becomes a single statement and you should lose the {}.\n\nThanks.  No need to resend.\n"},{"id":"160948","messageId":"1297515721.18669.1.camel@drew-northup.unet.maine.edu","threadId":"26469","inReplyTo":"1297381964-7137-2-git-send-email-jaredhance@gmail.com","subject":"Re: [PATCH v5 1/4] merge: update the usage information to be more modern","fromName":"Drew Northup","fromEmail":"drew.northup@maine.edu","sentAt":"2011-02-12T13:02:01Z","receivedAt":"2011-02-12T13:02:01Z","isPatch":true,"sender":{"key":"drew.northup@maine.edu","avatar":"https://avatars.githubusercontent.com/u/18331571?v=4"},"body":"\nOn Thu, 2011-02-10 at 18:52 -0500, Jared Hance wrote:\n> Apparantly, merge's usage information was outdated and used old terminology.\n> Fix it.\n> \n> Signed-off-by: Jared Hance <jaredhance@gmail.com>\n> ---\n\nJared,\nI suspect you meant \"Apparently\" there...\n\n-- \n-Drew Northup\n________________________________________________\n\"As opposed to vegetable or mineral error?\"\n-John Pescatore, SANS NewsBites Vol. 12 Num. 59\n"}]}