2006-08-02 23:52:00 +02:00
|
|
|
#include "builtin.h"
|
2006-07-03 17:18:43 +02:00
|
|
|
#include "cache.h"
|
|
|
|
#include "commit.h"
|
|
|
|
#include "diff.h"
|
|
|
|
#include "revision.h"
|
|
|
|
#include "tag.h"
|
2010-03-24 08:16:03 +01:00
|
|
|
#include "string-list.h"
|
2006-07-03 17:18:43 +02:00
|
|
|
|
2008-10-02 14:59:18 +02:00
|
|
|
static const char * const fmt_merge_msg_usage[] = {
|
2010-09-08 19:59:54 +02:00
|
|
|
"git fmt-merge-msg [-m <message>] [--log[=<n>]|--no-log] [--file <file>]",
|
2008-10-02 14:59:18 +02:00
|
|
|
NULL
|
|
|
|
};
|
2006-07-03 17:18:43 +02:00
|
|
|
|
2010-09-08 19:59:54 +02:00
|
|
|
static int shortlog_len;
|
2006-07-03 17:18:43 +02:00
|
|
|
|
2008-05-14 19:46:53 +02:00
|
|
|
static int fmt_merge_msg_config(const char *key, const char *value, void *cb)
|
2006-07-03 17:18:43 +02:00
|
|
|
{
|
2010-09-08 19:59:55 +02:00
|
|
|
if (!strcmp(key, "merge.log") || !strcmp(key, "merge.summary")) {
|
|
|
|
int is_bool;
|
|
|
|
shortlog_len = git_config_bool_or_int(key, value, &is_bool);
|
|
|
|
if (!is_bool && shortlog_len < 0)
|
|
|
|
return error("%s: negative length %s", key, value);
|
|
|
|
if (is_bool && shortlog_len)
|
|
|
|
shortlog_len = DEFAULT_MERGE_LOG_LEN;
|
2008-04-06 03:23:45 +02:00
|
|
|
}
|
2006-07-03 17:18:43 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-24 08:16:03 +01:00
|
|
|
struct src_data {
|
|
|
|
struct string_list branch, tag, r_branch, generic;
|
|
|
|
int head_status;
|
2006-07-03 17:18:43 +02: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 08:51:05 +01:00
|
|
|
static void init_src_data(struct src_data *data)
|
2006-07-03 17:18:43 +02:00
|
|
|
{
|
2010-03-24 08:16:03 +01: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 17:18:43 +02:00
|
|
|
}
|
|
|
|
|
2010-07-04 21:46:19 +02:00
|
|
|
static struct string_list srcs = STRING_LIST_INIT_DUP;
|
|
|
|
static struct string_list origins = STRING_LIST_INIT_DUP;
|
2006-07-03 17:18:43 +02:00
|
|
|
|
|
|
|
static int handle_line(char *line)
|
|
|
|
{
|
|
|
|
int i, len = strlen(line);
|
|
|
|
unsigned char *sha1;
|
|
|
|
char *src, *origin;
|
|
|
|
struct src_data *src_data;
|
2010-03-24 08:16:03 +01:00
|
|
|
struct string_list_item *item;
|
2006-07-13 07:21:05 +02:00
|
|
|
int pulling_head = 0;
|
2006-07-03 17:18:43 +02: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 10:53:29 +01:00
|
|
|
if (!prefixcmp(line + 41, "not-for-merge"))
|
2006-07-03 17:18:43 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (line[41] != '\t')
|
|
|
|
return 2;
|
|
|
|
|
|
|
|
line[40] = 0;
|
|
|
|
sha1 = xmalloc(20);
|
|
|
|
i = get_sha1(line, sha1);
|
|
|
|
line[40] = '\t';
|
|
|
|
if (i)
|
|
|
|
return 3;
|
|
|
|
|
|
|
|
if (line[len - 1] == '\n')
|
|
|
|
line[len - 1] = 0;
|
|
|
|
line += 42;
|
|
|
|
|
|
|
|
src = strstr(line, " of ");
|
|
|
|
if (src) {
|
|
|
|
*src = 0;
|
|
|
|
src += 4;
|
2006-07-13 07:21:05 +02:00
|
|
|
pulling_head = 0;
|
|
|
|
} else {
|
|
|
|
src = line;
|
|
|
|
pulling_head = 1;
|
|
|
|
}
|
2006-07-03 17:18:43 +02:00
|
|
|
|
2010-03-24 08:16:03 +01:00
|
|
|
item = unsorted_string_list_lookup(&srcs, src);
|
|
|
|
if (!item) {
|
2010-06-26 01:41:38 +02:00
|
|
|
item = string_list_append(&srcs, src);
|
2010-03-24 08:16:03 +01:00
|
|
|
item->util = xcalloc(1, sizeof(struct src_data));
|
|
|
|
init_src_data(item->util);
|
2006-07-03 17:18:43 +02:00
|
|
|
}
|
2010-03-24 08:16:03 +01:00
|
|
|
src_data = item->util;
|
2006-07-03 17:18:43 +02:00
|
|
|
|
2006-07-13 07:21:05 +02:00
|
|
|
if (pulling_head) {
|
2010-03-24 08:16:03 +01:00
|
|
|
origin = src;
|
2006-07-13 07:21:05 +02: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 10:53:29 +01:00
|
|
|
} else if (!prefixcmp(line, "branch ")) {
|
2010-03-24 08:16:03 +01:00
|
|
|
origin = line + 7;
|
2010-06-26 01:41:38 +02:00
|
|
|
string_list_append(&src_data->branch, origin);
|
2006-07-03 17:18:43 +02: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 10:53:29 +01:00
|
|
|
} else if (!prefixcmp(line, "tag ")) {
|
2006-07-03 17:18:43 +02:00
|
|
|
origin = line;
|
2010-06-26 01:41:38 +02:00
|
|
|
string_list_append(&src_data->tag, origin + 4);
|
2006-07-03 17:18:43 +02:00
|
|
|
src_data->head_status |= 2;
|
2010-11-02 16:31:25 +01:00
|
|
|
} else if (!prefixcmp(line, "remote-tracking branch ")) {
|
|
|
|
origin = line + strlen("remote-tracking branch ");
|
2010-06-26 01:41:38 +02:00
|
|
|
string_list_append(&src_data->r_branch, origin);
|
2006-07-03 17:18:43 +02:00
|
|
|
src_data->head_status |= 2;
|
|
|
|
} else {
|
2010-03-24 08:16:03 +01:00
|
|
|
origin = src;
|
2010-06-26 01:41:38 +02:00
|
|
|
string_list_append(&src_data->generic, line);
|
2006-07-03 17:18:43 +02:00
|
|
|
src_data->head_status |= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(".", src) || !strcmp(src, origin)) {
|
|
|
|
int len = strlen(origin);
|
2010-03-24 08:16:03 +01:00
|
|
|
if (origin[0] == '\'' && origin[len - 1] == '\'')
|
2007-09-16 00:32:36 +02:00
|
|
|
origin = xmemdupz(origin + 1, len - 2);
|
2006-07-03 17:18:43 +02:00
|
|
|
} else {
|
2006-09-01 00:32:39 +02:00
|
|
|
char *new_origin = xmalloc(strlen(origin) + strlen(src) + 5);
|
2006-07-03 17:18:43 +02:00
|
|
|
sprintf(new_origin, "%s of %s", origin, src);
|
|
|
|
origin = new_origin;
|
|
|
|
}
|
2010-06-26 01:41:38 +02:00
|
|
|
string_list_append(&origins, origin)->util = sha1;
|
2006-07-03 17:18:43 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_joined(const char *singular, const char *plural,
|
2010-03-24 08:16:03 +01:00
|
|
|
struct string_list *list, struct strbuf *out)
|
2006-07-03 17:18:43 +02:00
|
|
|
{
|
|
|
|
if (list->nr == 0)
|
|
|
|
return;
|
|
|
|
if (list->nr == 1) {
|
2010-03-24 08:16:03 +01:00
|
|
|
strbuf_addf(out, "%s%s", singular, list->items[0].string);
|
2006-07-03 17:18:43 +02:00
|
|
|
} else {
|
|
|
|
int i;
|
2008-06-27 18:21:59 +02:00
|
|
|
strbuf_addstr(out, plural);
|
2006-07-03 17:18:43 +02:00
|
|
|
for (i = 0; i < list->nr - 1; i++)
|
2010-03-24 08:16:03 +01: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 17:18:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void shortlog(const char *name, unsigned char *sha1,
|
2008-06-27 18:21:59 +02:00
|
|
|
struct commit *head, struct rev_info *rev, int limit,
|
|
|
|
struct strbuf *out)
|
2006-07-03 17:18:43 +02:00
|
|
|
{
|
|
|
|
int i, count = 0;
|
|
|
|
struct commit *commit;
|
|
|
|
struct object *branch;
|
2010-07-04 21:46:19 +02:00
|
|
|
struct string_list subjects = STRING_LIST_INIT_DUP;
|
2007-11-13 08:16:08 +01:00
|
|
|
int flags = UNINTERESTING | TREESAME | SEEN | SHOWN | ADDED;
|
2010-03-24 08:16:01 +01:00
|
|
|
struct strbuf sb = STRBUF_INIT;
|
2006-07-03 17:18:43 +02:00
|
|
|
|
|
|
|
branch = deref_tag(parse_object(sha1), sha1_to_hex(sha1), 40);
|
2006-07-12 05:45:31 +02:00
|
|
|
if (!branch || branch->type != OBJ_COMMIT)
|
2006-07-03 17:18:43 +02: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 08:31:56 +01:00
|
|
|
if (prepare_revision_walk(rev))
|
|
|
|
die("revision walk setup failed");
|
2006-07-03 17:18:43 +02:00
|
|
|
while ((commit = get_revision(rev)) != NULL) {
|
2010-03-24 08:16:01 +01:00
|
|
|
struct pretty_print_context ctx = {0};
|
2006-07-03 17:18:43 +02:00
|
|
|
|
|
|
|
/* ignore merges */
|
|
|
|
if (commit->parents && commit->parents->next)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
count++;
|
|
|
|
if (subjects.nr > limit)
|
|
|
|
continue;
|
|
|
|
|
2010-03-24 08:16:01 +01:00
|
|
|
format_commit_message(commit, "%s", &sb, &ctx);
|
|
|
|
strbuf_ltrim(&sb);
|
2008-04-15 20:01:36 +02:00
|
|
|
|
2010-03-24 08:16:01 +01:00
|
|
|
if (!sb.len)
|
2010-06-26 01:41:38 +02:00
|
|
|
string_list_append(&subjects,
|
|
|
|
sha1_to_hex(commit->object.sha1));
|
2010-03-24 08:16:01 +01:00
|
|
|
else
|
2010-06-26 01:41:38 +02:00
|
|
|
string_list_append(&subjects, strbuf_detach(&sb, NULL));
|
2006-07-03 17:18:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (count > limit)
|
2008-06-27 18:21:59 +02:00
|
|
|
strbuf_addf(out, "\n* %s: (%d commits)\n", name, count);
|
2006-07-03 17:18:43 +02:00
|
|
|
else
|
2008-06-27 18:21:59 +02:00
|
|
|
strbuf_addf(out, "\n* %s:\n", name);
|
2006-07-03 17:18:43 +02:00
|
|
|
|
|
|
|
for (i = 0; i < subjects.nr; i++)
|
|
|
|
if (i >= limit)
|
2008-06-27 18:21:59 +02:00
|
|
|
strbuf_addf(out, " ...\n");
|
2006-07-03 17:18:43 +02:00
|
|
|
else
|
2010-03-24 08:16:03 +01:00
|
|
|
strbuf_addf(out, " %s\n", subjects.items[i].string);
|
2006-07-03 17:18:43 +02: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 08:16:03 +01:00
|
|
|
string_list_clear(&subjects, 0);
|
2006-07-03 17:18:43 +02:00
|
|
|
}
|
|
|
|
|
2010-05-10 19:17:50 +02:00
|
|
|
static void do_fmt_merge_msg_title(struct strbuf *out,
|
|
|
|
const char *current_branch) {
|
|
|
|
int i = 0;
|
2009-03-07 21:02:26 +01:00
|
|
|
char *sep = "";
|
2010-03-24 08:15:58 +01:00
|
|
|
|
2008-06-27 18:21:59 +02:00
|
|
|
strbuf_addstr(out, "Merge ");
|
2006-07-03 17:18:43 +02:00
|
|
|
for (i = 0; i < srcs.nr; i++) {
|
2010-03-24 08:16:03 +01:00
|
|
|
struct src_data *src_data = srcs.items[i].util;
|
2006-07-03 17:18:43 +02:00
|
|
|
const char *subsep = "";
|
|
|
|
|
2008-06-27 18:21:59 +02:00
|
|
|
strbuf_addstr(out, sep);
|
2006-07-03 17:18:43 +02:00
|
|
|
sep = "; ";
|
|
|
|
|
|
|
|
if (src_data->head_status == 1) {
|
2010-03-24 08:16:03 +01:00
|
|
|
strbuf_addstr(out, srcs.items[i].string);
|
2006-07-03 17:18:43 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (src_data->head_status == 3) {
|
|
|
|
subsep = ", ";
|
2008-06-27 18:21:59 +02:00
|
|
|
strbuf_addstr(out, "HEAD");
|
2006-07-03 17:18:43 +02:00
|
|
|
}
|
|
|
|
if (src_data->branch.nr) {
|
2008-06-27 18:21:59 +02:00
|
|
|
strbuf_addstr(out, subsep);
|
2006-07-03 17:18:43 +02:00
|
|
|
subsep = ", ";
|
2008-06-27 18:21:59 +02:00
|
|
|
print_joined("branch ", "branches ", &src_data->branch,
|
|
|
|
out);
|
2006-07-03 17:18:43 +02:00
|
|
|
}
|
|
|
|
if (src_data->r_branch.nr) {
|
2008-06-27 18:21:59 +02:00
|
|
|
strbuf_addstr(out, subsep);
|
2006-07-03 17:18:43 +02:00
|
|
|
subsep = ", ";
|
2010-11-02 16:31:25 +01:00
|
|
|
print_joined("remote-tracking branch ", "remote-tracking branches ",
|
2008-06-27 18:21:59 +02:00
|
|
|
&src_data->r_branch, out);
|
2006-07-03 17:18:43 +02:00
|
|
|
}
|
|
|
|
if (src_data->tag.nr) {
|
2008-06-27 18:21:59 +02:00
|
|
|
strbuf_addstr(out, subsep);
|
2006-07-03 17:18:43 +02:00
|
|
|
subsep = ", ";
|
2008-06-27 18:21:59 +02:00
|
|
|
print_joined("tag ", "tags ", &src_data->tag, out);
|
2006-07-03 17:18:43 +02:00
|
|
|
}
|
|
|
|
if (src_data->generic.nr) {
|
2008-06-27 18:21:59 +02:00
|
|
|
strbuf_addstr(out, subsep);
|
|
|
|
print_joined("commit ", "commits ", &src_data->generic,
|
|
|
|
out);
|
2006-07-03 17:18:43 +02:00
|
|
|
}
|
2010-03-24 08:16:03 +01:00
|
|
|
if (strcmp(".", srcs.items[i].string))
|
|
|
|
strbuf_addf(out, " of %s", srcs.items[i].string);
|
2006-07-03 17:18:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp("master", current_branch))
|
2008-06-27 18:21:59 +02:00
|
|
|
strbuf_addch(out, '\n');
|
2006-07-03 17:18:43 +02:00
|
|
|
else
|
2008-06-27 18:21:59 +02:00
|
|
|
strbuf_addf(out, " into %s\n", current_branch);
|
2010-05-10 19:17:50 +02:00
|
|
|
}
|
|
|
|
|
2010-09-08 19:59:53 +02:00
|
|
|
static int do_fmt_merge_msg(int merge_title, struct strbuf *in,
|
|
|
|
struct strbuf *out, int shortlog_len) {
|
|
|
|
int i = 0, pos = 0;
|
2010-05-10 19:17:50 +02:00
|
|
|
unsigned char head_sha1[20];
|
|
|
|
const char *current_branch;
|
|
|
|
|
|
|
|
/* get current branch */
|
|
|
|
current_branch = resolve_ref("HEAD", head_sha1, 1, NULL);
|
|
|
|
if (!current_branch)
|
|
|
|
die("No current branch");
|
|
|
|
if (!prefixcmp(current_branch, "refs/heads/"))
|
|
|
|
current_branch += 11;
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
if (handle_line(p))
|
|
|
|
die ("Error in line %d: %.*s", i, len, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!srcs.nr)
|
|
|
|
return 0;
|
|
|
|
|
2010-05-10 19:17:51 +02:00
|
|
|
if (merge_title)
|
|
|
|
do_fmt_merge_msg_title(out, current_branch);
|
2006-07-03 17:18:43 +02:00
|
|
|
|
2010-09-08 19:59:53 +02:00
|
|
|
if (shortlog_len) {
|
2006-07-03 17:18:43 +02:00
|
|
|
struct commit *head;
|
|
|
|
struct rev_info rev;
|
|
|
|
|
2011-09-17 13:57:45 +02:00
|
|
|
head = lookup_commit_or_die(head_sha1, "HEAD");
|
2008-06-27 18:21:59 +02:00
|
|
|
init_revisions(&rev, NULL);
|
2006-07-03 17:18:43 +02:00
|
|
|
rev.commit_format = CMIT_FMT_ONELINE;
|
|
|
|
rev.ignore_merges = 1;
|
|
|
|
rev.limited = 1;
|
|
|
|
|
2010-05-10 19:17:52 +02:00
|
|
|
if (suffixcmp(out->buf, "\n"))
|
|
|
|
strbuf_addch(out, '\n');
|
|
|
|
|
2006-07-03 17:18:43 +02:00
|
|
|
for (i = 0; i < origins.nr; i++)
|
2010-03-24 08:16:03 +01:00
|
|
|
shortlog(origins.items[i].string, origins.items[i].util,
|
2010-09-08 19:59:53 +02:00
|
|
|
head, &rev, shortlog_len, out);
|
2006-07-03 17:18:43 +02:00
|
|
|
}
|
2008-06-27 18:21:59 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-08 19:59:53 +02:00
|
|
|
int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
|
|
|
|
int merge_title, int shortlog_len) {
|
|
|
|
return do_fmt_merge_msg(merge_title, in, out, shortlog_len);
|
2010-05-10 19:17:49 +02:00
|
|
|
}
|
|
|
|
|
2008-06-27 18:21:59 +02:00
|
|
|
int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
2008-10-02 14:59:18 +02:00
|
|
|
const char *inpath = NULL;
|
2010-08-18 01:00:34 +02:00
|
|
|
const char *message = NULL;
|
2008-10-02 14:59:18 +02:00
|
|
|
struct option options[] = {
|
2010-09-08 19:59:54 +02: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 08:16:04 +01:00
|
|
|
"alias for --log (deprecated)",
|
2010-09-08 19:59:54 +02:00
|
|
|
PARSE_OPT_OPTARG | PARSE_OPT_HIDDEN, NULL,
|
|
|
|
DEFAULT_MERGE_LOG_LEN },
|
2010-08-18 01:00:34 +02:00
|
|
|
OPT_STRING('m', "message", &message, "text",
|
|
|
|
"use <text> as start of message"),
|
2009-05-23 20:53:13 +02:00
|
|
|
OPT_FILENAME('F', "file", &inpath, "file to read from"),
|
2008-10-02 14:59:18 +02:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
|
2008-06-27 18:21:59 +02:00
|
|
|
FILE *in = stdin;
|
2008-10-09 21:12:12 +02:00
|
|
|
struct strbuf input = STRBUF_INIT, output = STRBUF_INIT;
|
2008-06-27 18:21:59 +02:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
git_config(fmt_merge_msg_config, NULL);
|
2009-05-23 20:53:12 +02:00
|
|
|
argc = parse_options(argc, argv, prefix, options, fmt_merge_msg_usage,
|
|
|
|
0);
|
2008-10-02 14:59:18 +02:00
|
|
|
if (argc > 0)
|
|
|
|
usage_with_options(fmt_merge_msg_usage, options);
|
2010-09-08 19:59:54 +02:00
|
|
|
if (message && !shortlog_len) {
|
2010-08-18 01:00:34 +02:00
|
|
|
char nl = '\n';
|
|
|
|
write_in_full(STDOUT_FILENO, message, strlen(message));
|
|
|
|
write_in_full(STDOUT_FILENO, &nl, 1);
|
|
|
|
return 0;
|
|
|
|
}
|
2010-09-08 19:59:54 +02:00
|
|
|
if (shortlog_len < 0)
|
|
|
|
die("Negative --log=%d", shortlog_len);
|
2008-10-02 14:59:18 +02:00
|
|
|
|
|
|
|
if (inpath && strcmp(inpath, "-")) {
|
|
|
|
in = fopen(inpath, "r");
|
|
|
|
if (!in)
|
2009-06-27 17:58:47 +02:00
|
|
|
die_errno("cannot open '%s'", inpath);
|
2008-06-27 18:21:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (strbuf_read(&input, fileno(in), 0) < 0)
|
2009-06-27 17:58:46 +02:00
|
|
|
die_errno("could not read input file");
|
2010-09-08 19:59:53 +02:00
|
|
|
|
|
|
|
if (message)
|
2010-08-18 01:00:34 +02:00
|
|
|
strbuf_addstr(&output, message);
|
2010-09-08 19:59:53 +02:00
|
|
|
ret = fmt_merge_msg(&input, &output,
|
|
|
|
message ? 0 : 1,
|
2010-09-08 19:59:54 +02:00
|
|
|
shortlog_len);
|
2010-09-08 19:59:53 +02:00
|
|
|
|
2008-06-27 18:21:59 +02:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2008-10-02 14:59:18 +02:00
|
|
|
write_in_full(STDOUT_FILENO, output.buf, output.len);
|
2006-07-03 17:18:43 +02:00
|
|
|
return 0;
|
|
|
|
}
|