* [PATCH] Add support for merging from upstream by default.
@ 2011-02-05 0:45 Jared Hance
2011-02-05 10:03 ` Andreas Schwab
0 siblings, 1 reply; 6+ messages in thread
From: Jared Hance @ 2011-02-05 0:45 UTC (permalink / raw)
To: git; +Cc: Jared Hance
Adds the option merge.defaultupstream to add support for merging from the
upstream branch by default. The upstream branch is found using
branch.[name].upstream.
---
So it turns out that the old code _did_ work with options; I had thought it
hadn't because I relied on !argc == 0, but since argc is decreased after parsing
options anyway, it isn't a problem. This update fixes the usage as Junio
suggested, since it does support options.
builtin/merge.c | 41 +++++++++++++++++++++++++++++++++++------
1 files changed, 35 insertions(+), 6 deletions(-)
diff --git a/builtin/merge.c b/builtin/merge.c
index 42fff38..a69b69f 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -37,6 +37,7 @@ struct strategy {
};
static const char * const builtin_merge_usage[] = {
+ "git merge",
"git merge [options] <remote>...",
"git merge [options] <msg> HEAD <remote>",
NULL
@@ -58,6 +59,8 @@ static int option_renormalize;
static int verbosity;
static int allow_rerere_auto;
static int abort_current_merge;
+static int default_upstream;
+static const char *upstream_branch;
static struct strategy all_strategy[] = {
{ "recursive", DEFAULT_TWOHEAD | NO_TRIVIAL },
@@ -519,8 +522,15 @@ static int git_merge_config(const char *k, const char *v, void *cb)
builtin_merge_usage, 0);
free(buf);
}
-
- if (!strcmp(k, "merge.diffstat") || !strcmp(k, "merge.stat"))
+ else if(branch && !prefixcmp(k, "branch.") &&
+ !prefixcmp(k + 7, branch) &&
+ !strcmp(k + 7 + strlen(branch), ".upstream")) {
+ return git_config_string(&upstream_branch, k, v);
+ }
+
+ if (!strcmp(k, "merge.defaultupstream"))
+ default_upstream = git_config_bool(k, v);
+ else if (!strcmp(k, "merge.diffstat") || !strcmp(k, "merge.stat"))
show_diffstat = git_config_bool(k, v);
else if (!strcmp(k, "pull.twohead"))
return git_config_string(&pull_twohead, k, v);
@@ -983,9 +993,28 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
if (!allow_fast_forward && fast_forward_only)
die("You cannot combine --no-ff with --ff-only.");
- if (!argc)
- usage_with_options(builtin_merge_usage,
- builtin_merge_options);
+ if (!argc) {
+ if(default_upstream && upstream_branch) {
+ struct object *o;
+ struct commit *commit;
+
+ o = peel_to_type(upstream_branch, 0, NULL, OBJ_COMMIT);
+ if (!o)
+ die("%s - not something we can merge", argv[i]);
+ commit = lookup_commit(o->sha1);
+ commit->util = (void *)upstream_branch;
+ remotes = &commit_list_insert(commit, remotes)->next;
+
+ strbuf_addf(&buf, "GITHEAD_%s", sha1_to_hex(o->sha1));
+ setenv(buf.buf, upstream_branch, 1);
+ strbuf_reset(&buf);
+ }
+ else {
+ usage_with_options(builtin_merge_usage,
+ builtin_merge_options);
+
+ }
+ }
/*
* This could be traditional "merge <msg> HEAD <commit>..." and
@@ -1048,7 +1077,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
}
}
- if (head_invalid || !argc)
+ if (head_invalid || (!argc && !(default_upstream && upstream_branch)))
usage_with_options(builtin_merge_usage,
builtin_merge_options);
--
1.7.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] Add support for merging from upstream by default.
2011-02-05 0:45 [PATCH] Add support for merging from upstream by default Jared Hance
@ 2011-02-05 10:03 ` Andreas Schwab
2011-02-05 13:31 ` Jared Hance
0 siblings, 1 reply; 6+ messages in thread
From: Andreas Schwab @ 2011-02-05 10:03 UTC (permalink / raw)
To: Jared Hance; +Cc: git
Jared Hance <jaredhance@gmail.com> writes:
> diff --git a/builtin/merge.c b/builtin/merge.c
> index 42fff38..a69b69f 100644
> --- a/builtin/merge.c
> +++ b/builtin/merge.c
> @@ -37,6 +37,7 @@ struct strategy {
> };
>
> static const char * const builtin_merge_usage[] = {
> + "git merge",
Doesn't that form take options as well?
> "git merge [options] <remote>...",
IOW, how about changing that to
"git merge [options] [<remote>...]",
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] Add support for merging from upstream by default.
2011-02-05 10:03 ` Andreas Schwab
@ 2011-02-05 13:31 ` Jared Hance
2011-02-07 1:59 ` Junio C Hamano
2011-02-07 9:36 ` Bert Wesarg
0 siblings, 2 replies; 6+ messages in thread
From: Jared Hance @ 2011-02-05 13:31 UTC (permalink / raw)
To: git; +Cc: Jared Hance
Adds the option merge.defaultupstream to add support for merging from the
upstream branch by default. The upstream branch is found using
branch.[name].upstream.
---
I checked it this time, it really is the right usage.
builtin/merge.c | 42 +++++++++++++++++++++++++++++++++++-------
1 files changed, 35 insertions(+), 7 deletions(-)
diff --git a/builtin/merge.c b/builtin/merge.c
index 42fff38..596febe 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -37,7 +37,7 @@ struct strategy {
};
static const char * const builtin_merge_usage[] = {
- "git merge [options] <remote>...",
+ "git merge [options] [<remote>...]",
"git merge [options] <msg> HEAD <remote>",
NULL
};
@@ -58,6 +58,8 @@ static int option_renormalize;
static int verbosity;
static int allow_rerere_auto;
static int abort_current_merge;
+static int default_upstream;
+static const char *upstream_branch;
static struct strategy all_strategy[] = {
{ "recursive", DEFAULT_TWOHEAD | NO_TRIVIAL },
@@ -519,8 +521,15 @@ static int git_merge_config(const char *k, const char *v, void *cb)
builtin_merge_usage, 0);
free(buf);
}
-
- if (!strcmp(k, "merge.diffstat") || !strcmp(k, "merge.stat"))
+ else if(branch && !prefixcmp(k, "branch.") &&
+ !prefixcmp(k + 7, branch) &&
+ !strcmp(k + 7 + strlen(branch), ".upstream")) {
+ return git_config_string(&upstream_branch, k, v);
+ }
+
+ if (!strcmp(k, "merge.defaultupstream"))
+ default_upstream = git_config_bool(k, v);
+ else if (!strcmp(k, "merge.diffstat") || !strcmp(k, "merge.stat"))
show_diffstat = git_config_bool(k, v);
else if (!strcmp(k, "pull.twohead"))
return git_config_string(&pull_twohead, k, v);
@@ -983,9 +992,28 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
if (!allow_fast_forward && fast_forward_only)
die("You cannot combine --no-ff with --ff-only.");
- if (!argc)
- usage_with_options(builtin_merge_usage,
- builtin_merge_options);
+ if (!argc) {
+ if(default_upstream && upstream_branch) {
+ struct object *o;
+ struct commit *commit;
+
+ o = peel_to_type(upstream_branch, 0, NULL, OBJ_COMMIT);
+ if (!o)
+ die("%s - not something we can merge", argv[i]);
+ commit = lookup_commit(o->sha1);
+ commit->util = (void *)upstream_branch;
+ remotes = &commit_list_insert(commit, remotes)->next;
+
+ strbuf_addf(&buf, "GITHEAD_%s", sha1_to_hex(o->sha1));
+ setenv(buf.buf, upstream_branch, 1);
+ strbuf_reset(&buf);
+ }
+ else {
+ usage_with_options(builtin_merge_usage,
+ builtin_merge_options);
+
+ }
+ }
/*
* This could be traditional "merge <msg> HEAD <commit>..." and
@@ -1048,7 +1076,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
}
}
- if (head_invalid || !argc)
+ if (head_invalid || (!argc && !(default_upstream && upstream_branch)))
usage_with_options(builtin_merge_usage,
builtin_merge_options);
--
1.7.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] Add support for merging from upstream by default.
2011-02-05 13:31 ` Jared Hance
@ 2011-02-07 1:59 ` Junio C Hamano
2011-02-07 9:36 ` Bert Wesarg
1 sibling, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2011-02-07 1:59 UTC (permalink / raw)
To: Jared Hance; +Cc: git
Jared Hance <jaredhance@gmail.com> writes:
> Adds the option merge.defaultupstream to add support for merging from the
> upstream branch by default. The upstream branch is found using
> branch.[name].upstream.
> ---
Sign off?
The patch (rather your code before getting handed to your MUA) seems
severely whitespace damaged.
> diff --git a/builtin/merge.c b/builtin/merge.c
> index 42fff38..596febe 100644
> --- a/builtin/merge.c
> +++ b/builtin/merge.c
> @@ -37,7 +37,7 @@ struct strategy {
> };
>
> static const char * const builtin_merge_usage[] = {
> - "git merge [options] <remote>...",
> + "git merge [options] [<remote>...]",
> "git merge [options] <msg> HEAD <remote>",
> NULL
> };
> @@ -58,6 +58,8 @@ static int option_renormalize;
> static int verbosity;
> static int allow_rerere_auto;
> static int abort_current_merge;
> +static int default_upstream;
> +static const char *upstream_branch;
>
> static struct strategy all_strategy[] = {
> { "recursive", DEFAULT_TWOHEAD | NO_TRIVIAL },
> @@ -519,8 +521,15 @@ static int git_merge_config(const char *k, const char *v, void *cb)
> builtin_merge_usage, 0);
> free(buf);
> }
> -
> - if (!strcmp(k, "merge.diffstat") || !strcmp(k, "merge.stat"))
> + else if(branch && !prefixcmp(k, "branch.") &&
> + !prefixcmp(k + 7, branch) &&
> + !strcmp(k + 7 + strlen(branch), ".upstream")) {
> + return git_config_string(&upstream_branch, k, v);
> + }
Shouldn't this be inside a single large if block that is guarded by
if (branch && !prefixcmp(k, "branch.") && !prefixcmp(k + 7, branch))
with a small refactoring of the existing code in git_merge_config(), the
first if statement? It probably is a good idea to hand that off to a
small helper function as well, i.e. the first if statement in
git_merge_config() becomes something like:
status = per_branch_config(k, v, cb);
if (status <= 0)
return status;
and then a new helper function is defined right in front of it, perhaps
static int per_branch_config(const char *k, const char *v, void *cb)
{
const char *variable;
if (!branch || prefixcmp(k, "branch.")
|| prefixcmp(k + 7, branch))
return 1; /* ignore me */
variable = k + 7 + strlen(branch);
if (strcmp(variable, ".mergeoptions")) {
...
return 0; /* done */
}
if (strcmp(variable, ".upstream")) {
...
return 0; /* or -1 if you see an error */
}
return 1; /* not what I handle */
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Add support for merging from upstream by default.
2011-02-05 13:31 ` Jared Hance
2011-02-07 1:59 ` Junio C Hamano
@ 2011-02-07 9:36 ` Bert Wesarg
2011-02-07 9:43 ` Bert Wesarg
1 sibling, 1 reply; 6+ messages in thread
From: Bert Wesarg @ 2011-02-07 9:36 UTC (permalink / raw)
To: Jared Hance; +Cc: git
On Sat, Feb 5, 2011 at 14:31, Jared Hance <jaredhance@gmail.com> wrote:
> Adds the option merge.defaultupstream to add support for merging from the
> upstream branch by default. The upstream branch is found using
> branch.[name].upstream.
Why do we need a per branch config for this, isn't .origin/.merge
enough? Or, where is the connection between your new .upstream and the
@{upstream} ref?
Bert
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Add support for merging from upstream by default.
2011-02-07 9:36 ` Bert Wesarg
@ 2011-02-07 9:43 ` Bert Wesarg
0 siblings, 0 replies; 6+ messages in thread
From: Bert Wesarg @ 2011-02-07 9:43 UTC (permalink / raw)
To: Jared Hance; +Cc: git
On Mon, Feb 7, 2011 at 10:36, Bert Wesarg <bert.wesarg@googlemail.com> wrote:
> On Sat, Feb 5, 2011 at 14:31, Jared Hance <jaredhance@gmail.com> wrote:
>> Adds the option merge.defaultupstream to add support for merging from the
>> upstream branch by default. The upstream branch is found using
>> branch.[name].upstream.
>
> Why do we need a per branch config for this, isn't .origin/.merge
Why do we need a *new* per branch config for this, isn't .origin/.merge
> enough? Or, where is the connection between your new .upstream and the
> @{upstream} ref?
>
> Bert
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-02-07 9:44 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-05 0:45 [PATCH] Add support for merging from upstream by default Jared Hance
2011-02-05 10:03 ` Andreas Schwab
2011-02-05 13:31 ` Jared Hance
2011-02-07 1:59 ` Junio C Hamano
2011-02-07 9:36 ` Bert Wesarg
2011-02-07 9:43 ` Bert Wesarg
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.