2006-08-02 21:52:00 +00:00
|
|
|
#include "builtin.h"
|
2006-07-03 15:18:43 +00:00
|
|
|
#include "cache.h"
|
|
|
|
#include "commit.h"
|
|
|
|
#include "diff.h"
|
|
|
|
#include "revision.h"
|
|
|
|
#include "tag.h"
|
2010-03-24 07:16:03 +00:00
|
|
|
#include "string-list.h"
|
2011-10-07 06:12:09 +00:00
|
|
|
#include "branch.h"
|
|
|
|
#include "fmt-merge-msg.h"
|
2011-11-05 04:06:30 +00:00
|
|
|
#include "gpg-interface.h"
|
2006-07-03 15:18:43 +00:00
|
|
|
|
2008-10-02 12:59:18 +00:00
|
|
|
static const char * const fmt_merge_msg_usage[] = {
|
2010-09-08 17:59:54 +00:00
|
|
|
"git fmt-merge-msg [-m <message>] [--log[=<n>]|--no-log] [--file <file>]",
|
2008-10-02 12:59:18 +00:00
|
|
|
NULL
|
|
|
|
};
|
2006-07-03 15:18:43 +00:00
|
|
|
|
2011-10-07 06:12:09 +00:00
|
|
|
static int use_branch_desc;
|
2006-07-03 15:18:43 +00:00
|
|
|
|
2011-10-07 06:12:09 +00:00
|
|
|
int fmt_merge_msg_config(const char *key, const char *value, void *cb)
|
2006-07-03 15:18:43 +00:00
|
|
|
{
|
2010-09-08 17:59:55 +00:00
|
|
|
if (!strcmp(key, "merge.log") || !strcmp(key, "merge.summary")) {
|
|
|
|
int is_bool;
|
2011-10-07 06:12:09 +00:00
|
|
|
merge_log_config = git_config_bool_or_int(key, value, &is_bool);
|
|
|
|
if (!is_bool && merge_log_config < 0)
|
2010-09-08 17:59:55 +00:00
|
|
|
return error("%s: negative length %s", key, value);
|
2011-10-07 06:12:09 +00:00
|
|
|
if (is_bool && merge_log_config)
|
|
|
|
merge_log_config = DEFAULT_MERGE_LOG_LEN;
|
|
|
|
} else if (!strcmp(key, "merge.branchdesc")) {
|
|
|
|
use_branch_desc = git_config_bool(key, value);
|
2008-04-06 01:23:45 +00:00
|
|
|
}
|
2006-07-03 15:18:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-11-05 00:00:03 +00:00
|
|
|
/* merge data per repository where the merged tips came from */
|
2010-03-24 07:16:03 +00:00
|
|
|
struct src_data {
|
|
|
|
struct string_list branch, tag, r_branch, generic;
|
|
|
|
int head_status;
|
2006-07-03 15:18:43 +00:00
|
|
|
};
|
|
|
|
|
2011-10-07 06:12:09 +00:00
|
|
|
struct origin_data {
|
|
|
|
unsigned char sha1[20];
|
2011-10-15 17:46:59 +00:00
|
|
|
unsigned is_local_branch:1;
|
2011-10-07 06:12:09 +00:00
|
|
|
};
|
|
|
|
|
Fix sparse warnings
Fix warnings from 'make check'.
- These files don't include 'builtin.h' causing sparse to complain that
cmd_* isn't declared:
builtin/clone.c:364, builtin/fetch-pack.c:797,
builtin/fmt-merge-msg.c:34, builtin/hash-object.c:78,
builtin/merge-index.c:69, builtin/merge-recursive.c:22
builtin/merge-tree.c:341, builtin/mktag.c:156, builtin/notes.c:426
builtin/notes.c:822, builtin/pack-redundant.c:596,
builtin/pack-refs.c:10, builtin/patch-id.c:60, builtin/patch-id.c:149,
builtin/remote.c:1512, builtin/remote-ext.c:240,
builtin/remote-fd.c:53, builtin/reset.c:236, builtin/send-pack.c:384,
builtin/unpack-file.c:25, builtin/var.c:75
- These files have symbols which should be marked static since they're
only file scope:
submodule.c:12, diff.c:631, replace_object.c:92, submodule.c:13,
submodule.c:14, trace.c:78, transport.c:195, transport-helper.c:79,
unpack-trees.c:19, url.c:3, url.c:18, url.c:104, url.c:117, url.c:123,
url.c:129, url.c:136, thread-utils.c:21, thread-utils.c:48
- These files redeclare symbols to be different types:
builtin/index-pack.c:210, parse-options.c:564, parse-options.c:571,
usage.c:49, usage.c:58, usage.c:63, usage.c:72
- These files use a literal integer 0 when they really should use a NULL
pointer:
daemon.c:663, fast-import.c:2942, imap-send.c:1072, notes-merge.c:362
While we're in the area, clean up some unused #includes in builtin files
(mostly exec_cmd.h).
Signed-off-by: Stephen Boyd <bebarino@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-03-22 07:51:05 +00:00
|
|
|
static void init_src_data(struct src_data *data)
|
2006-07-03 15:18:43 +00:00
|
|
|
{
|
2010-03-24 07:16:03 +00:00
|
|
|
data->branch.strdup_strings = 1;
|
|
|
|
data->tag.strdup_strings = 1;
|
|
|
|
data->r_branch.strdup_strings = 1;
|
|
|
|
data->generic.strdup_strings = 1;
|
2006-07-03 15:18:43 +00:00
|
|
|
}
|
|
|
|
|
2010-07-04 19:46:19 +00:00
|
|
|
static struct string_list srcs = STRING_LIST_INIT_DUP;
|
|
|
|
static struct string_list origins = STRING_LIST_INIT_DUP;
|
2006-07-03 15:18:43 +00:00
|
|
|
|
2012-04-19 02:49:08 +00:00
|
|
|
struct merge_parents {
|
|
|
|
int alloc, nr;
|
|
|
|
struct merge_parent {
|
|
|
|
unsigned char given[20];
|
|
|
|
unsigned char commit[20];
|
|
|
|
unsigned char used;
|
|
|
|
} *item;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* I know, I know, this is inefficient, but you won't be pulling and merging
|
|
|
|
* hundreds of heads at a time anyway.
|
|
|
|
*/
|
|
|
|
static struct merge_parent *find_merge_parent(struct merge_parents *table,
|
|
|
|
unsigned char *given,
|
|
|
|
unsigned char *commit)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < table->nr; i++) {
|
|
|
|
if (given && hashcmp(table->item[i].given, given))
|
|
|
|
continue;
|
|
|
|
if (commit && hashcmp(table->item[i].commit, commit))
|
|
|
|
continue;
|
|
|
|
return &table->item[i];
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void add_merge_parent(struct merge_parents *table,
|
|
|
|
unsigned char *given,
|
|
|
|
unsigned char *commit)
|
|
|
|
{
|
|
|
|
if (table->nr && find_merge_parent(table, given, commit))
|
|
|
|
return;
|
|
|
|
ALLOC_GROW(table->item, table->nr + 1, table->alloc);
|
|
|
|
hashcpy(table->item[table->nr].given, given);
|
|
|
|
hashcpy(table->item[table->nr].commit, commit);
|
|
|
|
table->item[table->nr].used = 0;
|
|
|
|
table->nr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int handle_line(char *line, struct merge_parents *merge_parents)
|
2006-07-03 15:18:43 +00:00
|
|
|
{
|
|
|
|
int i, len = strlen(line);
|
2011-10-07 06:12:09 +00:00
|
|
|
struct origin_data *origin_data;
|
2006-07-03 15:18:43 +00:00
|
|
|
char *src, *origin;
|
|
|
|
struct src_data *src_data;
|
2010-03-24 07:16:03 +00:00
|
|
|
struct string_list_item *item;
|
2006-07-13 05:21:05 +00:00
|
|
|
int pulling_head = 0;
|
2012-04-19 02:49:08 +00:00
|
|
|
unsigned char sha1[20];
|
2006-07-03 15:18:43 +00:00
|
|
|
|
|
|
|
if (len < 43 || line[40] != '\t')
|
|
|
|
return 1;
|
|
|
|
|
Mechanical conversion to use prefixcmp()
This mechanically converts strncmp() to use prefixcmp(), but only when
the parameters match specific patterns, so that they can be verified
easily. Leftover from this will be fixed in a separate step, including
idiotic conversions like
if (!strncmp("foo", arg, 3))
=>
if (!(-prefixcmp(arg, "foo")))
This was done by using this script in px.perl
#!/usr/bin/perl -i.bak -p
if (/strncmp\(([^,]+), "([^\\"]*)", (\d+)\)/ && (length($2) == $3)) {
s|strncmp\(([^,]+), "([^\\"]*)", (\d+)\)|prefixcmp($1, "$2")|;
}
if (/strncmp\("([^\\"]*)", ([^,]+), (\d+)\)/ && (length($1) == $3)) {
s|strncmp\("([^\\"]*)", ([^,]+), (\d+)\)|(-prefixcmp($2, "$1"))|;
}
and running:
$ git grep -l strncmp -- '*.c' | xargs perl px.perl
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-20 09:53:29 +00:00
|
|
|
if (!prefixcmp(line + 41, "not-for-merge"))
|
2006-07-03 15:18:43 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (line[41] != '\t')
|
|
|
|
return 2;
|
|
|
|
|
2012-04-19 02:49:08 +00:00
|
|
|
i = get_sha1_hex(line, sha1);
|
|
|
|
if (i)
|
2006-07-03 15:18:43 +00:00
|
|
|
return 3;
|
2012-04-19 02:49:08 +00:00
|
|
|
|
|
|
|
if (!find_merge_parent(merge_parents, sha1, NULL))
|
|
|
|
return 0; /* subsumed by other parents */
|
|
|
|
|
|
|
|
origin_data = xcalloc(1, sizeof(struct origin_data));
|
|
|
|
hashcpy(origin_data->sha1, sha1);
|
2006-07-03 15:18:43 +00:00
|
|
|
|
|
|
|
if (line[len - 1] == '\n')
|
|
|
|
line[len - 1] = 0;
|
|
|
|
line += 42;
|
|
|
|
|
2011-11-05 00:00:03 +00:00
|
|
|
/*
|
|
|
|
* At this point, line points at the beginning of comment e.g.
|
|
|
|
* "branch 'frotz' of git://that/repository.git".
|
|
|
|
* Find the repository name and point it with src.
|
|
|
|
*/
|
2006-07-03 15:18:43 +00:00
|
|
|
src = strstr(line, " of ");
|
|
|
|
if (src) {
|
|
|
|
*src = 0;
|
|
|
|
src += 4;
|
2006-07-13 05:21:05 +00:00
|
|
|
pulling_head = 0;
|
|
|
|
} else {
|
|
|
|
src = line;
|
|
|
|
pulling_head = 1;
|
|
|
|
}
|
2006-07-03 15:18:43 +00:00
|
|
|
|
2010-03-24 07:16:03 +00:00
|
|
|
item = unsorted_string_list_lookup(&srcs, src);
|
|
|
|
if (!item) {
|
2010-06-25 23:41:38 +00:00
|
|
|
item = string_list_append(&srcs, src);
|
2010-03-24 07:16:03 +00:00
|
|
|
item->util = xcalloc(1, sizeof(struct src_data));
|
|
|
|
init_src_data(item->util);
|
2006-07-03 15:18:43 +00:00
|
|
|
}
|
2010-03-24 07:16:03 +00:00
|
|
|
src_data = item->util;
|
2006-07-03 15:18:43 +00:00
|
|
|
|
2006-07-13 05:21:05 +00:00
|
|
|
if (pulling_head) {
|
2010-03-24 07:16:03 +00:00
|
|
|
origin = src;
|
2006-07-13 05:21:05 +00:00
|
|
|
src_data->head_status |= 1;
|
Mechanical conversion to use prefixcmp()
This mechanically converts strncmp() to use prefixcmp(), but only when
the parameters match specific patterns, so that they can be verified
easily. Leftover from this will be fixed in a separate step, including
idiotic conversions like
if (!strncmp("foo", arg, 3))
=>
if (!(-prefixcmp(arg, "foo")))
This was done by using this script in px.perl
#!/usr/bin/perl -i.bak -p
if (/strncmp\(([^,]+), "([^\\"]*)", (\d+)\)/ && (length($2) == $3)) {
s|strncmp\(([^,]+), "([^\\"]*)", (\d+)\)|prefixcmp($1, "$2")|;
}
if (/strncmp\("([^\\"]*)", ([^,]+), (\d+)\)/ && (length($1) == $3)) {
s|strncmp\("([^\\"]*)", ([^,]+), (\d+)\)|(-prefixcmp($2, "$1"))|;
}
and running:
$ git grep -l strncmp -- '*.c' | xargs perl px.perl
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-20 09:53:29 +00:00
|
|
|
} else if (!prefixcmp(line, "branch ")) {
|
2011-10-07 06:12:09 +00:00
|
|
|
origin_data->is_local_branch = 1;
|
2010-03-24 07:16:03 +00:00
|
|
|
origin = line + 7;
|
2010-06-25 23:41:38 +00:00
|
|
|
string_list_append(&src_data->branch, origin);
|
2006-07-03 15:18:43 +00:00
|
|
|
src_data->head_status |= 2;
|
Mechanical conversion to use prefixcmp()
This mechanically converts strncmp() to use prefixcmp(), but only when
the parameters match specific patterns, so that they can be verified
easily. Leftover from this will be fixed in a separate step, including
idiotic conversions like
if (!strncmp("foo", arg, 3))
=>
if (!(-prefixcmp(arg, "foo")))
This was done by using this script in px.perl
#!/usr/bin/perl -i.bak -p
if (/strncmp\(([^,]+), "([^\\"]*)", (\d+)\)/ && (length($2) == $3)) {
s|strncmp\(([^,]+), "([^\\"]*)", (\d+)\)|prefixcmp($1, "$2")|;
}
if (/strncmp\("([^\\"]*)", ([^,]+), (\d+)\)/ && (length($1) == $3)) {
s|strncmp\("([^\\"]*)", ([^,]+), (\d+)\)|(-prefixcmp($2, "$1"))|;
}
and running:
$ git grep -l strncmp -- '*.c' | xargs perl px.perl
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-20 09:53:29 +00:00
|
|
|
} else if (!prefixcmp(line, "tag ")) {
|
2006-07-03 15:18:43 +00:00
|
|
|
origin = line;
|
2010-06-25 23:41:38 +00:00
|
|
|
string_list_append(&src_data->tag, origin + 4);
|
2006-07-03 15:18:43 +00:00
|
|
|
src_data->head_status |= 2;
|
2010-11-02 15:31:25 +00:00
|
|
|
} else if (!prefixcmp(line, "remote-tracking branch ")) {
|
|
|
|
origin = line + strlen("remote-tracking branch ");
|
2010-06-25 23:41:38 +00:00
|
|
|
string_list_append(&src_data->r_branch, origin);
|
2006-07-03 15:18:43 +00:00
|
|
|
src_data->head_status |= 2;
|
|
|
|
} else {
|
2010-03-24 07:16:03 +00:00
|
|
|
origin = src;
|
2010-06-25 23:41:38 +00:00
|
|
|
string_list_append(&src_data->generic, line);
|
2006-07-03 15:18:43 +00:00
|
|
|
src_data->head_status |= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(".", src) || !strcmp(src, origin)) {
|
|
|
|
int len = strlen(origin);
|
2010-03-24 07:16:03 +00:00
|
|
|
if (origin[0] == '\'' && origin[len - 1] == '\'')
|
2007-09-15 22:32:36 +00:00
|
|
|
origin = xmemdupz(origin + 1, len - 2);
|
2006-07-03 15:18:43 +00:00
|
|
|
} else {
|
2006-08-31 22:32:39 +00:00
|
|
|
char *new_origin = xmalloc(strlen(origin) + strlen(src) + 5);
|
2006-07-03 15:18:43 +00:00
|
|
|
sprintf(new_origin, "%s of %s", origin, src);
|
|
|
|
origin = new_origin;
|
|
|
|
}
|
2011-10-07 06:12:09 +00:00
|
|
|
if (strcmp(".", src))
|
|
|
|
origin_data->is_local_branch = 0;
|
|
|
|
string_list_append(&origins, origin)->util = origin_data;
|
2006-07-03 15:18:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_joined(const char *singular, const char *plural,
|
2010-03-24 07:16:03 +00:00
|
|
|
struct string_list *list, struct strbuf *out)
|
2006-07-03 15:18:43 +00:00
|
|
|
{
|
|
|
|
if (list->nr == 0)
|
|
|
|
return;
|
|
|
|
if (list->nr == 1) {
|
2010-03-24 07:16:03 +00:00
|
|
|
strbuf_addf(out, "%s%s", singular, list->items[0].string);
|
2006-07-03 15:18:43 +00:00
|
|
|
} else {
|
|
|
|
int i;
|
2008-06-27 16:21:59 +00:00
|
|
|
strbuf_addstr(out, plural);
|
2006-07-03 15:18:43 +00:00
|
|
|
for (i = 0; i < list->nr - 1; i++)
|
2010-03-24 07:16:03 +00:00
|
|
|
strbuf_addf(out, "%s%s", i > 0 ? ", " : "",
|
|
|
|
list->items[i].string);
|
|
|
|
strbuf_addf(out, " and %s", list->items[list->nr - 1].string);
|
2006-07-03 15:18:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-07 06:12:09 +00:00
|
|
|
static void add_branch_desc(struct strbuf *out, const char *name)
|
|
|
|
{
|
|
|
|
struct strbuf desc = STRBUF_INIT;
|
|
|
|
|
|
|
|
if (!read_branch_desc(&desc, name)) {
|
|
|
|
const char *bp = desc.buf;
|
|
|
|
while (*bp) {
|
|
|
|
const char *ep = strchrnul(bp, '\n');
|
|
|
|
if (*ep)
|
|
|
|
ep++;
|
|
|
|
strbuf_addf(out, " : %.*s", (int)(ep - bp), bp);
|
|
|
|
bp = ep;
|
|
|
|
}
|
|
|
|
if (out->buf[out->len - 1] != '\n')
|
|
|
|
strbuf_addch(out, '\n');
|
|
|
|
}
|
|
|
|
strbuf_release(&desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void shortlog(const char *name,
|
|
|
|
struct origin_data *origin_data,
|
|
|
|
struct commit *head,
|
|
|
|
struct rev_info *rev, int limit,
|
|
|
|
struct strbuf *out)
|
2006-07-03 15:18:43 +00:00
|
|
|
{
|
|
|
|
int i, count = 0;
|
|
|
|
struct commit *commit;
|
|
|
|
struct object *branch;
|
2010-07-04 19:46:19 +00:00
|
|
|
struct string_list subjects = STRING_LIST_INIT_DUP;
|
2007-11-13 07:16:08 +00:00
|
|
|
int flags = UNINTERESTING | TREESAME | SEEN | SHOWN | ADDED;
|
2010-03-24 07:16:01 +00:00
|
|
|
struct strbuf sb = STRBUF_INIT;
|
2011-10-07 06:12:09 +00:00
|
|
|
const unsigned char *sha1 = origin_data->sha1;
|
2006-07-03 15:18:43 +00:00
|
|
|
|
|
|
|
branch = deref_tag(parse_object(sha1), sha1_to_hex(sha1), 40);
|
2006-07-12 03:45:31 +00:00
|
|
|
if (!branch || branch->type != OBJ_COMMIT)
|
2006-07-03 15:18:43 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
setup_revisions(0, NULL, rev, NULL);
|
|
|
|
rev->ignore_merges = 1;
|
|
|
|
add_pending_object(rev, branch, name);
|
|
|
|
add_pending_object(rev, &head->object, "^HEAD");
|
|
|
|
head->object.flags |= UNINTERESTING;
|
2008-02-18 07:31:56 +00:00
|
|
|
if (prepare_revision_walk(rev))
|
|
|
|
die("revision walk setup failed");
|
2006-07-03 15:18:43 +00:00
|
|
|
while ((commit = get_revision(rev)) != NULL) {
|
2010-03-24 07:16:01 +00:00
|
|
|
struct pretty_print_context ctx = {0};
|
2006-07-03 15:18:43 +00:00
|
|
|
|
|
|
|
/* ignore merges */
|
|
|
|
if (commit->parents && commit->parents->next)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
count++;
|
|
|
|
if (subjects.nr > limit)
|
|
|
|
continue;
|
|
|
|
|
2010-03-24 07:16:01 +00:00
|
|
|
format_commit_message(commit, "%s", &sb, &ctx);
|
|
|
|
strbuf_ltrim(&sb);
|
2008-04-15 18:01:36 +00:00
|
|
|
|
2010-03-24 07:16:01 +00:00
|
|
|
if (!sb.len)
|
2010-06-25 23:41:38 +00:00
|
|
|
string_list_append(&subjects,
|
|
|
|
sha1_to_hex(commit->object.sha1));
|
2010-03-24 07:16:01 +00:00
|
|
|
else
|
2010-06-25 23:41:38 +00:00
|
|
|
string_list_append(&subjects, strbuf_detach(&sb, NULL));
|
2006-07-03 15:18:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (count > limit)
|
2008-06-27 16:21:59 +00:00
|
|
|
strbuf_addf(out, "\n* %s: (%d commits)\n", name, count);
|
2006-07-03 15:18:43 +00:00
|
|
|
else
|
2008-06-27 16:21:59 +00:00
|
|
|
strbuf_addf(out, "\n* %s:\n", name);
|
2006-07-03 15:18:43 +00:00
|
|
|
|
2011-10-07 06:12:09 +00:00
|
|
|
if (origin_data->is_local_branch && use_branch_desc)
|
|
|
|
add_branch_desc(out, name);
|
|
|
|
|
2006-07-03 15:18:43 +00:00
|
|
|
for (i = 0; i < subjects.nr; i++)
|
|
|
|
if (i >= limit)
|
2008-06-27 16:21:59 +00:00
|
|
|
strbuf_addf(out, " ...\n");
|
2006-07-03 15:18:43 +00:00
|
|
|
else
|
2010-03-24 07:16:03 +00:00
|
|
|
strbuf_addf(out, " %s\n", subjects.items[i].string);
|
2006-07-03 15:18:43 +00:00
|
|
|
|
|
|
|
clear_commit_marks((struct commit *)branch, flags);
|
|
|
|
clear_commit_marks(head, flags);
|
|
|
|
free_commit_list(rev->commits);
|
|
|
|
rev->commits = NULL;
|
|
|
|
rev->pending.nr = 0;
|
|
|
|
|
2010-03-24 07:16:03 +00:00
|
|
|
string_list_clear(&subjects, 0);
|
2006-07-03 15:18:43 +00:00
|
|
|
}
|
|
|
|
|
2011-11-05 00:35:42 +00:00
|
|
|
static void fmt_merge_msg_title(struct strbuf *out,
|
2010-05-10 17:17:50 +00:00
|
|
|
const char *current_branch) {
|
|
|
|
int i = 0;
|
2009-03-07 20:02:26 +00:00
|
|
|
char *sep = "";
|
2010-03-24 07:15:58 +00:00
|
|
|
|
2008-06-27 16:21:59 +00:00
|
|
|
strbuf_addstr(out, "Merge ");
|
2006-07-03 15:18:43 +00:00
|
|
|
for (i = 0; i < srcs.nr; i++) {
|
2010-03-24 07:16:03 +00:00
|
|
|
struct src_data *src_data = srcs.items[i].util;
|
2006-07-03 15:18:43 +00:00
|
|
|
const char *subsep = "";
|
|
|
|
|
2008-06-27 16:21:59 +00:00
|
|
|
strbuf_addstr(out, sep);
|
2006-07-03 15:18:43 +00:00
|
|
|
sep = "; ";
|
|
|
|
|
|
|
|
if (src_data->head_status == 1) {
|
2010-03-24 07:16:03 +00:00
|
|
|
strbuf_addstr(out, srcs.items[i].string);
|
2006-07-03 15:18:43 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (src_data->head_status == 3) {
|
|
|
|
subsep = ", ";
|
2008-06-27 16:21:59 +00:00
|
|
|
strbuf_addstr(out, "HEAD");
|
2006-07-03 15:18:43 +00:00
|
|
|
}
|
|
|
|
if (src_data->branch.nr) {
|
2008-06-27 16:21:59 +00:00
|
|
|
strbuf_addstr(out, subsep);
|
2006-07-03 15:18:43 +00:00
|
|
|
subsep = ", ";
|
2008-06-27 16:21:59 +00:00
|
|
|
print_joined("branch ", "branches ", &src_data->branch,
|
|
|
|
out);
|
2006-07-03 15:18:43 +00:00
|
|
|
}
|
|
|
|
if (src_data->r_branch.nr) {
|
2008-06-27 16:21:59 +00:00
|
|
|
strbuf_addstr(out, subsep);
|
2006-07-03 15:18:43 +00:00
|
|
|
subsep = ", ";
|
2010-11-02 15:31:25 +00:00
|
|
|
print_joined("remote-tracking branch ", "remote-tracking branches ",
|
2008-06-27 16:21:59 +00:00
|
|
|
&src_data->r_branch, out);
|
2006-07-03 15:18:43 +00:00
|
|
|
}
|
|
|
|
if (src_data->tag.nr) {
|
2008-06-27 16:21:59 +00:00
|
|
|
strbuf_addstr(out, subsep);
|
2006-07-03 15:18:43 +00:00
|
|
|
subsep = ", ";
|
2008-06-27 16:21:59 +00:00
|
|
|
print_joined("tag ", "tags ", &src_data->tag, out);
|
2006-07-03 15:18:43 +00:00
|
|
|
}
|
|
|
|
if (src_data->generic.nr) {
|
2008-06-27 16:21:59 +00:00
|
|
|
strbuf_addstr(out, subsep);
|
|
|
|
print_joined("commit ", "commits ", &src_data->generic,
|
|
|
|
out);
|
2006-07-03 15:18:43 +00:00
|
|
|
}
|
2010-03-24 07:16:03 +00:00
|
|
|
if (strcmp(".", srcs.items[i].string))
|
|
|
|
strbuf_addf(out, " of %s", srcs.items[i].string);
|
2006-07-03 15:18:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp("master", current_branch))
|
2008-06-27 16:21:59 +00:00
|
|
|
strbuf_addch(out, '\n');
|
2006-07-03 15:18:43 +00:00
|
|
|
else
|
2008-06-27 16:21:59 +00:00
|
|
|
strbuf_addf(out, " into %s\n", current_branch);
|
2010-05-10 17:17:50 +00:00
|
|
|
}
|
|
|
|
|
2011-11-05 04:06:30 +00:00
|
|
|
static void fmt_tag_signature(struct strbuf *tagbuf,
|
|
|
|
struct strbuf *sig,
|
|
|
|
const char *buf,
|
|
|
|
unsigned long len)
|
|
|
|
{
|
|
|
|
const char *tag_body = strstr(buf, "\n\n");
|
|
|
|
if (tag_body) {
|
|
|
|
tag_body += 2;
|
|
|
|
strbuf_add(tagbuf, tag_body, buf + len - tag_body);
|
|
|
|
}
|
|
|
|
strbuf_complete_line(tagbuf);
|
|
|
|
strbuf_add_lines(tagbuf, "# ", sig->buf, sig->len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fmt_merge_msg_sigs(struct strbuf *out)
|
|
|
|
{
|
|
|
|
int i, tag_number = 0, first_tag = 0;
|
|
|
|
struct strbuf tagbuf = STRBUF_INIT;
|
|
|
|
|
|
|
|
for (i = 0; i < origins.nr; i++) {
|
|
|
|
unsigned char *sha1 = origins.items[i].util;
|
|
|
|
enum object_type type;
|
|
|
|
unsigned long size, len;
|
|
|
|
char *buf = read_sha1_file(sha1, &type, &size);
|
|
|
|
struct strbuf sig = STRBUF_INIT;
|
|
|
|
|
|
|
|
if (!buf || type != OBJ_TAG)
|
|
|
|
goto next;
|
|
|
|
len = parse_signature(buf, size);
|
|
|
|
|
|
|
|
if (size == len)
|
|
|
|
; /* merely annotated */
|
|
|
|
else if (verify_signed_buffer(buf, len, buf + len, size - len, &sig)) {
|
|
|
|
if (!sig.len)
|
|
|
|
strbuf_addstr(&sig, "gpg verification failed.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!tag_number++) {
|
|
|
|
fmt_tag_signature(&tagbuf, &sig, buf, len);
|
|
|
|
first_tag = i;
|
|
|
|
} else {
|
|
|
|
if (tag_number == 2) {
|
|
|
|
struct strbuf tagline = STRBUF_INIT;
|
|
|
|
strbuf_addf(&tagline, "\n# %s\n",
|
|
|
|
origins.items[first_tag].string);
|
|
|
|
strbuf_insert(&tagbuf, 0, tagline.buf,
|
|
|
|
tagline.len);
|
|
|
|
strbuf_release(&tagline);
|
|
|
|
}
|
|
|
|
strbuf_addf(&tagbuf, "\n# %s\n",
|
|
|
|
origins.items[i].string);
|
|
|
|
fmt_tag_signature(&tagbuf, &sig, buf, len);
|
|
|
|
}
|
|
|
|
strbuf_release(&sig);
|
|
|
|
next:
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
if (tagbuf.len) {
|
|
|
|
strbuf_addch(out, '\n');
|
|
|
|
strbuf_addbuf(out, &tagbuf);
|
|
|
|
}
|
|
|
|
strbuf_release(&tagbuf);
|
|
|
|
}
|
|
|
|
|
2012-04-19 02:49:08 +00:00
|
|
|
static void find_merge_parents(struct merge_parents *result,
|
|
|
|
struct strbuf *in, unsigned char *head)
|
|
|
|
{
|
|
|
|
struct commit_list *parents, *next;
|
|
|
|
struct commit *head_commit;
|
|
|
|
int pos = 0, i, j;
|
|
|
|
|
|
|
|
parents = NULL;
|
|
|
|
while (pos < in->len) {
|
|
|
|
int len;
|
|
|
|
char *p = in->buf + pos;
|
|
|
|
char *newline = strchr(p, '\n');
|
|
|
|
unsigned char sha1[20];
|
|
|
|
struct commit *parent;
|
|
|
|
struct object *obj;
|
|
|
|
|
|
|
|
len = newline ? newline - p : strlen(p);
|
|
|
|
pos += len + !!newline;
|
|
|
|
|
|
|
|
if (len < 43 ||
|
|
|
|
get_sha1_hex(p, sha1) ||
|
|
|
|
p[40] != '\t' ||
|
|
|
|
p[41] != '\t')
|
|
|
|
continue; /* skip not-for-merge */
|
|
|
|
/*
|
|
|
|
* Do not use get_merge_parent() here; we do not have
|
|
|
|
* "name" here and we do not want to contaminate its
|
|
|
|
* util field yet.
|
|
|
|
*/
|
|
|
|
obj = parse_object(sha1);
|
|
|
|
parent = (struct commit *)peel_to_type(NULL, 0, obj, OBJ_COMMIT);
|
|
|
|
if (!parent)
|
|
|
|
continue;
|
|
|
|
commit_list_insert(parent, &parents);
|
|
|
|
add_merge_parent(result, obj->sha1, parent->object.sha1);
|
|
|
|
}
|
|
|
|
head_commit = lookup_commit(head);
|
|
|
|
if (head_commit)
|
|
|
|
commit_list_insert(head_commit, &parents);
|
|
|
|
parents = reduce_heads(parents);
|
|
|
|
|
|
|
|
while (parents) {
|
|
|
|
for (i = 0; i < result->nr; i++)
|
|
|
|
if (!hashcmp(result->item[i].commit,
|
|
|
|
parents->item->object.sha1))
|
|
|
|
result->item[i].used = 1;
|
|
|
|
next = parents->next;
|
|
|
|
free(parents);
|
|
|
|
parents = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = j = 0; i < result->nr; i++) {
|
|
|
|
if (result->item[i].used) {
|
|
|
|
if (i != j)
|
|
|
|
result->item[j] = result->item[i];
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result->nr = j;
|
|
|
|
}
|
|
|
|
|
2011-11-05 00:35:42 +00:00
|
|
|
int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
|
|
|
|
struct fmt_merge_msg_opts *opts)
|
|
|
|
{
|
2010-09-08 17:59:53 +00:00
|
|
|
int i = 0, pos = 0;
|
2010-05-10 17:17:50 +00:00
|
|
|
unsigned char head_sha1[20];
|
|
|
|
const char *current_branch;
|
2011-12-13 14:17:48 +00:00
|
|
|
void *current_branch_to_free;
|
2012-04-19 02:49:08 +00:00
|
|
|
struct merge_parents merge_parents;
|
|
|
|
|
|
|
|
memset(&merge_parents, 0, sizeof(merge_parents));
|
2010-05-10 17:17:50 +00:00
|
|
|
|
|
|
|
/* get current branch */
|
2011-12-13 14:17:48 +00:00
|
|
|
current_branch = current_branch_to_free =
|
|
|
|
resolve_refdup("HEAD", head_sha1, 1, NULL);
|
2010-05-10 17:17:50 +00:00
|
|
|
if (!current_branch)
|
|
|
|
die("No current branch");
|
|
|
|
if (!prefixcmp(current_branch, "refs/heads/"))
|
|
|
|
current_branch += 11;
|
|
|
|
|
2012-04-19 02:49:08 +00:00
|
|
|
find_merge_parents(&merge_parents, in, head_sha1);
|
|
|
|
|
2010-05-10 17:17:50 +00:00
|
|
|
/* get a line */
|
|
|
|
while (pos < in->len) {
|
|
|
|
int len;
|
|
|
|
char *newline, *p = in->buf + pos;
|
|
|
|
|
|
|
|
newline = strchr(p, '\n');
|
|
|
|
len = newline ? newline - p : strlen(p);
|
|
|
|
pos += len + !!newline;
|
|
|
|
i++;
|
|
|
|
p[len] = 0;
|
2012-04-19 02:49:08 +00:00
|
|
|
if (handle_line(p, &merge_parents))
|
2010-05-10 17:17:50 +00:00
|
|
|
die ("Error in line %d: %.*s", i, len, p);
|
|
|
|
}
|
|
|
|
|
2011-11-05 00:35:42 +00:00
|
|
|
if (opts->add_title && srcs.nr)
|
|
|
|
fmt_merge_msg_title(out, current_branch);
|
2010-05-10 17:17:50 +00:00
|
|
|
|
2011-11-05 04:06:30 +00:00
|
|
|
if (origins.nr)
|
|
|
|
fmt_merge_msg_sigs(out);
|
2006-07-03 15:18:43 +00:00
|
|
|
|
2011-11-05 00:35:42 +00:00
|
|
|
if (opts->shortlog_len) {
|
2006-07-03 15:18:43 +00:00
|
|
|
struct commit *head;
|
|
|
|
struct rev_info rev;
|
|
|
|
|
2011-09-17 11:57:45 +00:00
|
|
|
head = lookup_commit_or_die(head_sha1, "HEAD");
|
2008-06-27 16:21:59 +00:00
|
|
|
init_revisions(&rev, NULL);
|
2006-07-03 15:18:43 +00:00
|
|
|
rev.commit_format = CMIT_FMT_ONELINE;
|
|
|
|
rev.ignore_merges = 1;
|
|
|
|
rev.limited = 1;
|
|
|
|
|
2010-05-10 17:17:52 +00:00
|
|
|
if (suffixcmp(out->buf, "\n"))
|
|
|
|
strbuf_addch(out, '\n');
|
|
|
|
|
2006-07-03 15:18:43 +00:00
|
|
|
for (i = 0; i < origins.nr; i++)
|
2011-10-07 06:12:09 +00:00
|
|
|
shortlog(origins.items[i].string,
|
|
|
|
origins.items[i].util,
|
2011-11-05 00:35:42 +00:00
|
|
|
head, &rev, opts->shortlog_len, out);
|
2006-07-03 15:18:43 +00:00
|
|
|
}
|
2008-06-27 16:21:59 +00:00
|
|
|
|
2011-11-05 04:06:30 +00:00
|
|
|
strbuf_complete_line(out);
|
2011-12-13 14:17:48 +00:00
|
|
|
free(current_branch_to_free);
|
2012-04-19 02:49:08 +00:00
|
|
|
free(merge_parents.item);
|
2008-06-27 16:21:59 +00:00
|
|
|
return 0;
|
2010-05-10 17:17:49 +00:00
|
|
|
}
|
|
|
|
|
2008-06-27 16:21:59 +00:00
|
|
|
int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
2008-10-02 12:59:18 +00:00
|
|
|
const char *inpath = NULL;
|
2010-08-17 23:00:34 +00:00
|
|
|
const char *message = NULL;
|
2011-10-07 06:12:09 +00:00
|
|
|
int shortlog_len = -1;
|
2008-10-02 12:59:18 +00:00
|
|
|
struct option options[] = {
|
2010-09-08 17:59:54 +00:00
|
|
|
{ OPTION_INTEGER, 0, "log", &shortlog_len, "n",
|
|
|
|
"populate log with at most <n> entries from shortlog",
|
|
|
|
PARSE_OPT_OPTARG, NULL, DEFAULT_MERGE_LOG_LEN },
|
|
|
|
{ OPTION_INTEGER, 0, "summary", &shortlog_len, "n",
|
2010-03-24 07:16:04 +00:00
|
|
|
"alias for --log (deprecated)",
|
2010-09-08 17:59:54 +00:00
|
|
|
PARSE_OPT_OPTARG | PARSE_OPT_HIDDEN, NULL,
|
|
|
|
DEFAULT_MERGE_LOG_LEN },
|
2010-08-17 23:00:34 +00:00
|
|
|
OPT_STRING('m', "message", &message, "text",
|
|
|
|
"use <text> as start of message"),
|
2009-05-23 18:53:13 +00:00
|
|
|
OPT_FILENAME('F', "file", &inpath, "file to read from"),
|
2008-10-02 12:59:18 +00:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
|
2008-06-27 16:21:59 +00:00
|
|
|
FILE *in = stdin;
|
2008-10-09 19:12:12 +00:00
|
|
|
struct strbuf input = STRBUF_INIT, output = STRBUF_INIT;
|
2008-06-27 16:21:59 +00:00
|
|
|
int ret;
|
2011-11-05 00:35:42 +00:00
|
|
|
struct fmt_merge_msg_opts opts;
|
2008-06-27 16:21:59 +00:00
|
|
|
|
|
|
|
git_config(fmt_merge_msg_config, NULL);
|
2009-05-23 18:53:12 +00:00
|
|
|
argc = parse_options(argc, argv, prefix, options, fmt_merge_msg_usage,
|
|
|
|
0);
|
2008-10-02 12:59:18 +00:00
|
|
|
if (argc > 0)
|
|
|
|
usage_with_options(fmt_merge_msg_usage, options);
|
2011-10-07 06:12:09 +00:00
|
|
|
if (shortlog_len < 0)
|
|
|
|
shortlog_len = (merge_log_config > 0) ? merge_log_config : 0;
|
2008-10-02 12:59:18 +00:00
|
|
|
|
|
|
|
if (inpath && strcmp(inpath, "-")) {
|
|
|
|
in = fopen(inpath, "r");
|
|
|
|
if (!in)
|
2009-06-27 15:58:47 +00:00
|
|
|
die_errno("cannot open '%s'", inpath);
|
2008-06-27 16:21:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (strbuf_read(&input, fileno(in), 0) < 0)
|
2009-06-27 15:58:46 +00:00
|
|
|
die_errno("could not read input file");
|
2010-09-08 17:59:53 +00:00
|
|
|
|
|
|
|
if (message)
|
2010-08-17 23:00:34 +00:00
|
|
|
strbuf_addstr(&output, message);
|
2010-09-08 17:59:53 +00:00
|
|
|
|
2011-11-05 00:35:42 +00:00
|
|
|
memset(&opts, 0, sizeof(opts));
|
|
|
|
opts.add_title = !message;
|
|
|
|
opts.shortlog_len = shortlog_len;
|
|
|
|
|
|
|
|
ret = fmt_merge_msg(&input, &output, &opts);
|
2008-06-27 16:21:59 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2008-10-02 12:59:18 +00:00
|
|
|
write_in_full(STDOUT_FILENO, output.buf, output.len);
|
2006-07-03 15:18:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|