Skip to content

Commit

Permalink
Merge branch 'jn/update-contrib-example-merge'
Browse files Browse the repository at this point in the history
* jn/update-contrib-example-merge: (24 commits)
  merge script: learn --[no-]rerere-autoupdate
  merge script: notice @{-1} shorthand
  merge script: handle --no-ff --no-commit correctly
  merge script: --ff-only to disallow true merge
  merge script: handle many-way octopus
  merge script: handle -m --log correctly
  merge script: forbid merge -s index
  merge script: allow custom strategies
  merge script: merge -X<option>
  merge script: improve log message subject
  merge script: refuse to merge during merge
  merge script: tweak unmerged files message to match builtin
  merge script: --squash, --ff from unborn branch are errors
  fmt-merge-msg -m to override merge title
  merge-base --independent to print reduced parent list in a merge
  merge-base --octopus to mimic show-branch --merge-base
  Documentation: add a SEE ALSO section for merge-base
  t6200 (fmt-merge-msg): style nitpicks
  t6010 (merge-base): modernize style
  t7600 (merge): test merge from branch yet to be born
  ...
  • Loading branch information
Junio C Hamano committed Sep 3, 2010
2 parents 8aed4a5 + fdc4408 commit 2b916ff
Show file tree
Hide file tree
Showing 9 changed files with 701 additions and 562 deletions.
9 changes: 7 additions & 2 deletions Documentation/git-fmt-merge-msg.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ git-fmt-merge-msg - Produce a merge commit message
SYNOPSIS
--------
[verse]
'git fmt-merge-msg' [--log | --no-log] <$GIT_DIR/FETCH_HEAD
'git fmt-merge-msg' [--log | --no-log] -F <file>
'git fmt-merge-msg' [-m <message>] [--log | --no-log] <$GIT_DIR/FETCH_HEAD
'git fmt-merge-msg' [-m <message>] [--log | --no-log] -F <file>

DESCRIPTION
-----------
Expand Down Expand Up @@ -38,6 +38,11 @@ OPTIONS
Synonyms to --log and --no-log; these are deprecated and will be
removed in the future.

-m <message>::
--message <message>::
Use <message> instead of the branch names for the first line
of the log message. For use with `--log`.

-F <file>::
--file <file>::
Take the list of merged objects from <file> instead of
Expand Down
34 changes: 27 additions & 7 deletions Documentation/git-merge-base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ git-merge-base - Find as good common ancestors as possible for a merge

SYNOPSIS
--------
'git merge-base' [-a|--all] <commit> <commit>...
[verse]
'git merge-base' [-a|--all] [--octopus] <commit> <commit>...
'git merge-base' --independent <commit>...

DESCRIPTION
-----------
Expand All @@ -20,12 +22,12 @@ that does not have any better common ancestor is a 'best common
ancestor', i.e. a 'merge base'. Note that there can be more than one
merge base for a pair of commits.

Among the two commits to compute the merge base from, one is specified by
the first commit argument on the command line; the other commit is a
(possibly hypothetical) commit that is a merge across all the remaining
commits on the command line. As the most common special case, specifying only
two commits on the command line means computing the merge base between
the given two commits.
Unless `--octopus` is given, among the two commits to compute the merge
base from, one is specified by the first commit argument on the command
line; the other commit is a (possibly hypothetical) commit that is a merge
across all the remaining commits on the command line. As the most common
special case, specifying only two commits on the command line means
computing the merge base between the given two commits.

As a consequence, the 'merge base' is not necessarily contained in each of the
commit arguments if more than two commits are specified. This is different
Expand All @@ -37,6 +39,18 @@ OPTIONS
--all::
Output all merge bases for the commits, instead of just one.

--octopus::
Compute the best common ancestors of all supplied commits,
in preparation for an n-way merge. This mimics the behavior
of 'git show-branch --merge-base'.

--independent::
Instead of printing merge bases, print a minimal subset of
the supplied commits with the same ancestors. In other words,
among the commits given, list those which cannot be reached
from any other. This mimics the behavior of 'git show-branch
--independent'.

DISCUSSION
----------

Expand Down Expand Up @@ -96,6 +110,12 @@ Documentation
--------------
Documentation by David Greaves, Junio C Hamano and the git-list <git@vger.kernel.org>.

See also
--------
linkgit:git-rev-list[1],
linkgit:git-show-branch[1],
linkgit:git-merge[1]

GIT
---
Part of the linkgit:git[1] suite
18 changes: 16 additions & 2 deletions builtin/fmt-merge-msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "string-list.h"

static const char * const fmt_merge_msg_usage[] = {
"git fmt-merge-msg [--log|--no-log] [--file <file>]",
"git fmt-merge-msg [-m <message>] [--log|--no-log] [--file <file>]",
NULL
};

Expand Down Expand Up @@ -319,11 +319,14 @@ int fmt_merge_msg_shortlog(struct strbuf *in, struct strbuf *out) {
int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
{
const char *inpath = NULL;
const char *message = NULL;
struct option options[] = {
OPT_BOOLEAN(0, "log", &merge_summary, "populate log with the shortlog"),
{ OPTION_BOOLEAN, 0, "summary", &merge_summary, NULL,
"alias for --log (deprecated)",
PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
OPT_STRING('m', "message", &message, "text",
"use <text> as start of message"),
OPT_FILENAME('F', "file", &inpath, "file to read from"),
OPT_END()
};
Expand All @@ -337,6 +340,12 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
0);
if (argc > 0)
usage_with_options(fmt_merge_msg_usage, options);
if (message && !merge_summary) {
char nl = '\n';
write_in_full(STDOUT_FILENO, message, strlen(message));
write_in_full(STDOUT_FILENO, &nl, 1);
return 0;
}

if (inpath && strcmp(inpath, "-")) {
in = fopen(inpath, "r");
Expand All @@ -346,7 +355,12 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)

if (strbuf_read(&input, fileno(in), 0) < 0)
die_errno("could not read input file");
ret = fmt_merge_msg(merge_summary, &input, &output);
if (message) {
strbuf_addstr(&output, message);
ret = fmt_merge_msg_shortlog(&input, &output);
} else {
ret = fmt_merge_msg(merge_summary, &input, &output);
}
if (ret)
return ret;
write_in_full(STDOUT_FILENO, output.buf, output.len);
Expand Down
44 changes: 41 additions & 3 deletions builtin/merge-base.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ static int show_merge_base(struct commit **rev, int rev_nr, int show_all)
}

static const char * const merge_base_usage[] = {
"git merge-base [-a|--all] <commit> <commit>...",
"git merge-base [-a|--all] [--octopus] <commit> <commit>...",
"git merge-base --independent <commit>...",
NULL
};

Expand All @@ -41,21 +42,58 @@ static struct commit *get_commit_reference(const char *arg)
return r;
}

static int handle_octopus(int count, const char **args, int reduce, int show_all)
{
struct commit_list *revs = NULL;
struct commit_list *result;
int i;

if (reduce)
show_all = 1;

for (i = count - 1; i >= 0; i--)
commit_list_insert(get_commit_reference(args[i]), &revs);

result = reduce ? reduce_heads(revs) : get_octopus_merge_bases(revs);

if (!result)
return 1;

while (result) {
printf("%s\n", sha1_to_hex(result->item->object.sha1));
if (!show_all)
return 0;
result = result->next;
}

return 0;
}

int cmd_merge_base(int argc, const char **argv, const char *prefix)
{
struct commit **rev;
int rev_nr = 0;
int show_all = 0;
int octopus = 0;
int reduce = 0;

struct option options[] = {
OPT_BOOLEAN('a', "all", &show_all, "outputs all common ancestors"),
OPT_BOOLEAN('a', "all", &show_all, "output all common ancestors"),
OPT_BOOLEAN(0, "octopus", &octopus, "find ancestors for a single n-way merge"),
OPT_BOOLEAN(0, "independent", &reduce, "list revs not reachable from others"),
OPT_END()
};

git_config(git_default_config, NULL);
argc = parse_options(argc, argv, prefix, options, merge_base_usage, 0);
if (argc < 2)
if (!octopus && !reduce && argc < 2)
usage_with_options(merge_base_usage, options);
if (reduce && (show_all || octopus))
die("--independent cannot be used with other options");

if (octopus || reduce)
return handle_octopus(argc, argv, reduce, show_all);

rev = xmalloc(argc * sizeof(*rev));
while (argc-- > 0)
rev[rev_nr++] = get_commit_reference(*argv++);
Expand Down
2 changes: 1 addition & 1 deletion builtin/merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
strbuf_addstr(&truname, "refs/heads/");
strbuf_addstr(&truname, remote);
strbuf_setlen(&truname, truname.len - len);
if (resolve_ref(truname.buf, buf_sha, 0, NULL)) {
if (resolve_ref(truname.buf, buf_sha, 1, NULL)) {
strbuf_addf(msg,
"%s\t\tbranch '%s'%s of .\n",
sha1_to_hex(remote_head->sha1),
Expand Down
Loading

0 comments on commit 2b916ff

Please sign in to comment.