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"
|
|
|
|
|
|
|
|
static const char *fmt_merge_msg_usage =
|
2008-04-06 01:23:45 +00:00
|
|
|
"git-fmt-merge-msg [--log] [--no-log] [--file <file>]";
|
2006-07-03 15:18:43 +00:00
|
|
|
|
2006-08-15 17:23:48 +00:00
|
|
|
static int merge_summary;
|
2006-07-03 15:18:43 +00:00
|
|
|
|
|
|
|
static int fmt_merge_msg_config(const char *key, const char *value)
|
|
|
|
{
|
2008-04-06 01:23:45 +00:00
|
|
|
static int found_merge_log = 0;
|
|
|
|
if (!strcmp("merge.log", key)) {
|
|
|
|
found_merge_log = 1;
|
|
|
|
merge_summary = git_config_bool(key, value);
|
|
|
|
}
|
|
|
|
if (!found_merge_log && !strcmp("merge.summary", key))
|
2006-07-03 15:18:43 +00:00
|
|
|
merge_summary = git_config_bool(key, value);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct list {
|
|
|
|
char **list;
|
|
|
|
void **payload;
|
|
|
|
unsigned nr, alloc;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void append_to_list(struct list *list, char *value, void *payload)
|
|
|
|
{
|
|
|
|
if (list->nr == list->alloc) {
|
|
|
|
list->alloc += 32;
|
2006-08-26 14:16:18 +00:00
|
|
|
list->list = xrealloc(list->list, sizeof(char *) * list->alloc);
|
|
|
|
list->payload = xrealloc(list->payload,
|
2006-07-03 15:18:43 +00:00
|
|
|
sizeof(char *) * list->alloc);
|
|
|
|
}
|
|
|
|
list->payload[list->nr] = payload;
|
|
|
|
list->list[list->nr++] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int find_in_list(struct list *list, char *value)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < list->nr; i++)
|
|
|
|
if (!strcmp(list->list[i], value))
|
|
|
|
return i;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_list(struct list *list)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (list->alloc == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < list->nr; i++) {
|
|
|
|
free(list->list[i]);
|
2006-08-28 04:19:39 +00:00
|
|
|
free(list->payload[i]);
|
2006-07-03 15:18:43 +00:00
|
|
|
}
|
|
|
|
free(list->list);
|
|
|
|
free(list->payload);
|
|
|
|
list->nr = list->alloc = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct src_data {
|
|
|
|
struct list branch, tag, r_branch, generic;
|
|
|
|
int head_status;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct list srcs = { NULL, NULL, 0, 0};
|
|
|
|
static struct list origins = { NULL, NULL, 0, 0};
|
|
|
|
|
|
|
|
static int handle_line(char *line)
|
|
|
|
{
|
|
|
|
int i, len = strlen(line);
|
|
|
|
unsigned char *sha1;
|
|
|
|
char *src, *origin;
|
|
|
|
struct src_data *src_data;
|
2006-07-13 05:21:05 +00:00
|
|
|
int pulling_head = 0;
|
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;
|
|
|
|
|
|
|
|
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 05:21:05 +00:00
|
|
|
pulling_head = 0;
|
|
|
|
} else {
|
|
|
|
src = line;
|
|
|
|
pulling_head = 1;
|
|
|
|
}
|
2006-07-03 15:18:43 +00:00
|
|
|
|
|
|
|
i = find_in_list(&srcs, src);
|
|
|
|
if (i < 0) {
|
|
|
|
i = srcs.nr;
|
2006-09-02 04:16:31 +00:00
|
|
|
append_to_list(&srcs, xstrdup(src),
|
2006-07-03 15:18:43 +00:00
|
|
|
xcalloc(1, sizeof(struct src_data)));
|
|
|
|
}
|
|
|
|
src_data = srcs.payload[i];
|
|
|
|
|
2006-07-13 05:21:05 +00:00
|
|
|
if (pulling_head) {
|
2006-09-02 04:16:31 +00:00
|
|
|
origin = xstrdup(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 ")) {
|
2006-09-02 04:16:31 +00:00
|
|
|
origin = xstrdup(line + 7);
|
2006-07-03 15:18:43 +00:00
|
|
|
append_to_list(&src_data->branch, origin, NULL);
|
|
|
|
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;
|
2006-09-02 04:16:31 +00:00
|
|
|
append_to_list(&src_data->tag, xstrdup(origin + 4), NULL);
|
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, "remote branch ")) {
|
2006-09-02 04:16:31 +00:00
|
|
|
origin = xstrdup(line + 14);
|
2006-07-03 15:18:43 +00:00
|
|
|
append_to_list(&src_data->r_branch, origin, NULL);
|
|
|
|
src_data->head_status |= 2;
|
|
|
|
} else {
|
2006-09-02 04:16:31 +00:00
|
|
|
origin = xstrdup(src);
|
|
|
|
append_to_list(&src_data->generic, xstrdup(line), NULL);
|
2006-07-03 15:18:43 +00:00
|
|
|
src_data->head_status |= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(".", src) || !strcmp(src, origin)) {
|
|
|
|
int len = strlen(origin);
|
|
|
|
if (origin[0] == '\'' && origin[len - 1] == '\'') {
|
2007-09-15 22:32:36 +00:00
|
|
|
origin = xmemdupz(origin + 1, len - 2);
|
|
|
|
} else {
|
2006-09-02 04:16:31 +00:00
|
|
|
origin = xstrdup(origin);
|
2007-09-15 22:32:36 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
append_to_list(&origins, origin, sha1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_joined(const char *singular, const char *plural,
|
|
|
|
struct list *list)
|
|
|
|
{
|
|
|
|
if (list->nr == 0)
|
|
|
|
return;
|
|
|
|
if (list->nr == 1) {
|
|
|
|
printf("%s%s", singular, list->list[0]);
|
|
|
|
} else {
|
|
|
|
int i;
|
|
|
|
printf("%s", plural);
|
|
|
|
for (i = 0; i < list->nr - 1; i++)
|
|
|
|
printf("%s%s", i > 0 ? ", " : "", list->list[i]);
|
|
|
|
printf(" and %s", list->list[list->nr - 1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void shortlog(const char *name, unsigned char *sha1,
|
|
|
|
struct commit *head, struct rev_info *rev, int limit)
|
|
|
|
{
|
|
|
|
int i, count = 0;
|
|
|
|
struct commit *commit;
|
|
|
|
struct object *branch;
|
|
|
|
struct list subjects = { NULL, NULL, 0, 0 };
|
2007-11-13 07:16:08 +00:00
|
|
|
int flags = UNINTERESTING | TREESAME | SEEN | SHOWN | ADDED;
|
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) {
|
|
|
|
char *oneline, *bol, *eol;
|
|
|
|
|
|
|
|
/* ignore merges */
|
|
|
|
if (commit->parents && commit->parents->next)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
count++;
|
|
|
|
if (subjects.nr > limit)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
bol = strstr(commit->buffer, "\n\n");
|
2008-04-15 18:01:36 +00:00
|
|
|
if (bol) {
|
|
|
|
unsigned char c;
|
|
|
|
do {
|
|
|
|
c = *++bol;
|
|
|
|
} while (isspace(c));
|
|
|
|
if (!c)
|
|
|
|
bol = NULL;
|
|
|
|
}
|
|
|
|
|
2006-07-03 15:18:43 +00:00
|
|
|
if (!bol) {
|
2006-09-02 04:16:31 +00:00
|
|
|
append_to_list(&subjects, xstrdup(sha1_to_hex(
|
2006-07-03 15:18:43 +00:00
|
|
|
commit->object.sha1)),
|
|
|
|
NULL);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
eol = strchr(bol, '\n');
|
|
|
|
if (eol) {
|
2007-09-15 22:32:36 +00:00
|
|
|
oneline = xmemdupz(bol, eol - bol);
|
|
|
|
} else {
|
2006-09-02 04:16:31 +00:00
|
|
|
oneline = xstrdup(bol);
|
2007-09-15 22:32:36 +00:00
|
|
|
}
|
2006-07-03 15:18:43 +00:00
|
|
|
append_to_list(&subjects, oneline, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count > limit)
|
|
|
|
printf("\n* %s: (%d commits)\n", name, count);
|
|
|
|
else
|
|
|
|
printf("\n* %s:\n", name);
|
|
|
|
|
|
|
|
for (i = 0; i < subjects.nr; i++)
|
|
|
|
if (i >= limit)
|
|
|
|
printf(" ...\n");
|
|
|
|
else
|
|
|
|
printf(" %s\n", subjects.list[i]);
|
|
|
|
|
|
|
|
clear_commit_marks((struct commit *)branch, flags);
|
|
|
|
clear_commit_marks(head, flags);
|
|
|
|
free_commit_list(rev->commits);
|
|
|
|
rev->commits = NULL;
|
|
|
|
rev->pending.nr = 0;
|
|
|
|
|
|
|
|
free_list(&subjects);
|
|
|
|
}
|
|
|
|
|
2006-08-02 21:52:00 +00:00
|
|
|
int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
|
2006-07-03 15:18:43 +00:00
|
|
|
{
|
|
|
|
int limit = 20, i = 0;
|
|
|
|
char line[1024];
|
|
|
|
FILE *in = stdin;
|
|
|
|
const char *sep = "";
|
|
|
|
unsigned char head_sha1[20];
|
2006-09-12 03:17:35 +00:00
|
|
|
const char *current_branch;
|
2006-07-03 15:18:43 +00:00
|
|
|
|
|
|
|
git_config(fmt_merge_msg_config);
|
|
|
|
|
|
|
|
while (argc > 1) {
|
2008-04-06 01:23:45 +00:00
|
|
|
if (!strcmp(argv[1], "--log") || !strcmp(argv[1], "--summary"))
|
2006-07-03 15:18:43 +00:00
|
|
|
merge_summary = 1;
|
2008-04-06 01:23:45 +00:00
|
|
|
else if (!strcmp(argv[1], "--no-log")
|
|
|
|
|| !strcmp(argv[1], "--no-summary"))
|
2006-07-03 15:18:43 +00:00
|
|
|
merge_summary = 0;
|
|
|
|
else if (!strcmp(argv[1], "-F") || !strcmp(argv[1], "--file")) {
|
2007-02-28 05:44:42 +00:00
|
|
|
if (argc < 3)
|
2006-07-03 15:18:43 +00:00
|
|
|
die ("Which file?");
|
|
|
|
if (!strcmp(argv[2], "-"))
|
|
|
|
in = stdin;
|
|
|
|
else {
|
|
|
|
fclose(in);
|
|
|
|
in = fopen(argv[2], "r");
|
2007-02-28 05:44:42 +00:00
|
|
|
if (!in)
|
|
|
|
die("cannot open %s", argv[2]);
|
2006-07-03 15:18:43 +00:00
|
|
|
}
|
|
|
|
argc--; argv++;
|
|
|
|
} else
|
|
|
|
break;
|
|
|
|
argc--; argv++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc > 1)
|
|
|
|
usage(fmt_merge_msg_usage);
|
|
|
|
|
|
|
|
/* get current branch */
|
2006-09-21 05:02:01 +00:00
|
|
|
current_branch = resolve_ref("HEAD", head_sha1, 1, NULL);
|
2006-11-17 06:57:20 +00:00
|
|
|
if (!current_branch)
|
|
|
|
die("No current branch");
|
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(current_branch, "refs/heads/"))
|
2006-07-03 15:18:43 +00:00
|
|
|
current_branch += 11;
|
|
|
|
|
|
|
|
while (fgets(line, sizeof(line), in)) {
|
|
|
|
i++;
|
|
|
|
if (line[0] == 0)
|
|
|
|
continue;
|
|
|
|
if (handle_line(line))
|
|
|
|
die ("Error in line %d: %s", i, line);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Merge ");
|
|
|
|
for (i = 0; i < srcs.nr; i++) {
|
|
|
|
struct src_data *src_data = srcs.payload[i];
|
|
|
|
const char *subsep = "";
|
|
|
|
|
|
|
|
printf(sep);
|
|
|
|
sep = "; ";
|
|
|
|
|
|
|
|
if (src_data->head_status == 1) {
|
|
|
|
printf(srcs.list[i]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (src_data->head_status == 3) {
|
|
|
|
subsep = ", ";
|
|
|
|
printf("HEAD");
|
|
|
|
}
|
|
|
|
if (src_data->branch.nr) {
|
|
|
|
printf(subsep);
|
|
|
|
subsep = ", ";
|
|
|
|
print_joined("branch ", "branches ", &src_data->branch);
|
|
|
|
}
|
|
|
|
if (src_data->r_branch.nr) {
|
|
|
|
printf(subsep);
|
|
|
|
subsep = ", ";
|
|
|
|
print_joined("remote branch ", "remote branches ",
|
|
|
|
&src_data->r_branch);
|
|
|
|
}
|
|
|
|
if (src_data->tag.nr) {
|
|
|
|
printf(subsep);
|
|
|
|
subsep = ", ";
|
|
|
|
print_joined("tag ", "tags ", &src_data->tag);
|
|
|
|
}
|
|
|
|
if (src_data->generic.nr) {
|
|
|
|
printf(subsep);
|
|
|
|
print_joined("commit ", "commits ", &src_data->generic);
|
|
|
|
}
|
|
|
|
if (strcmp(".", srcs.list[i]))
|
|
|
|
printf(" of %s", srcs.list[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp("master", current_branch))
|
|
|
|
putchar('\n');
|
|
|
|
else
|
|
|
|
printf(" into %s\n", current_branch);
|
|
|
|
|
|
|
|
if (merge_summary) {
|
|
|
|
struct commit *head;
|
|
|
|
struct rev_info rev;
|
|
|
|
|
|
|
|
head = lookup_commit(head_sha1);
|
2006-07-29 04:21:48 +00:00
|
|
|
init_revisions(&rev, prefix);
|
2006-07-03 15:18:43 +00:00
|
|
|
rev.commit_format = CMIT_FMT_ONELINE;
|
|
|
|
rev.ignore_merges = 1;
|
|
|
|
rev.limited = 1;
|
|
|
|
|
|
|
|
for (i = 0; i < origins.nr; i++)
|
|
|
|
shortlog(origins.list[i], origins.payload[i],
|
|
|
|
head, &rev, limit);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No cleanup yet; is standalone anyway */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|