2006-08-03 05:52:00 +08:00
|
|
|
#include "builtin.h"
|
2006-07-03 23:18:43 +08:00
|
|
|
#include "cache.h"
|
2017-06-15 02:07:36 +08:00
|
|
|
#include "config.h"
|
2015-06-22 22:03:05 +08:00
|
|
|
#include "refs.h"
|
2006-07-03 23:18:43 +08:00
|
|
|
#include "commit.h"
|
|
|
|
#include "diff.h"
|
|
|
|
#include "revision.h"
|
|
|
|
#include "tag.h"
|
2010-03-24 15:16:03 +08:00
|
|
|
#include "string-list.h"
|
2011-10-07 14:12:09 +08:00
|
|
|
#include "branch.h"
|
|
|
|
#include "fmt-merge-msg.h"
|
2011-11-05 12:06:30 +08:00
|
|
|
#include "gpg-interface.h"
|
2006-07-03 23:18:43 +08:00
|
|
|
|
2008-10-02 20:59:18 +08:00
|
|
|
static const char * const fmt_merge_msg_usage[] = {
|
2015-01-13 15:44:47 +08:00
|
|
|
N_("git fmt-merge-msg [-m <message>] [--log[=<n>] | --no-log] [--file <file>]"),
|
2008-10-02 20:59:18 +08:00
|
|
|
NULL
|
|
|
|
};
|
2006-07-03 23:18:43 +08:00
|
|
|
|
2011-10-07 14:12:09 +08:00
|
|
|
static int use_branch_desc;
|
2006-07-03 23:18:43 +08:00
|
|
|
|
2011-10-07 14:12:09 +08:00
|
|
|
int fmt_merge_msg_config(const char *key, const char *value, void *cb)
|
2006-07-03 23:18:43 +08:00
|
|
|
{
|
2010-09-09 01:59:55 +08:00
|
|
|
if (!strcmp(key, "merge.log") || !strcmp(key, "merge.summary")) {
|
|
|
|
int is_bool;
|
2011-10-07 14:12:09 +08:00
|
|
|
merge_log_config = git_config_bool_or_int(key, value, &is_bool);
|
|
|
|
if (!is_bool && merge_log_config < 0)
|
2010-09-09 01:59:55 +08:00
|
|
|
return error("%s: negative length %s", key, value);
|
2011-10-07 14:12:09 +08: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);
|
2012-03-14 01:00:00 +08:00
|
|
|
} else {
|
|
|
|
return git_default_config(key, value, cb);
|
2008-04-06 09:23:45 +08:00
|
|
|
}
|
2006-07-03 23:18:43 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-11-05 08:00:03 +08:00
|
|
|
/* merge data per repository where the merged tips came from */
|
2010-03-24 15:16:03 +08:00
|
|
|
struct src_data {
|
|
|
|
struct string_list branch, tag, r_branch, generic;
|
|
|
|
int head_status;
|
2006-07-03 23:18:43 +08:00
|
|
|
};
|
|
|
|
|
2011-10-07 14:12:09 +08:00
|
|
|
struct origin_data {
|
2017-02-22 07:47:24 +08:00
|
|
|
struct object_id oid;
|
2011-10-16 01:46:59 +08:00
|
|
|
unsigned is_local_branch:1;
|
2011-10-07 14:12:09 +08: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 15:51:05 +08:00
|
|
|
static void init_src_data(struct src_data *data)
|
2006-07-03 23:18:43 +08:00
|
|
|
{
|
2010-03-24 15:16:03 +08: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 23:18:43 +08:00
|
|
|
}
|
|
|
|
|
2010-07-05 03:46:19 +08:00
|
|
|
static struct string_list srcs = STRING_LIST_INIT_DUP;
|
|
|
|
static struct string_list origins = STRING_LIST_INIT_DUP;
|
2006-07-03 23:18:43 +08:00
|
|
|
|
2012-04-19 10:49:08 +08:00
|
|
|
struct merge_parents {
|
|
|
|
int alloc, nr;
|
|
|
|
struct merge_parent {
|
2017-02-22 07:47:24 +08:00
|
|
|
struct object_id given;
|
|
|
|
struct object_id commit;
|
2012-04-19 10:49:08 +08:00
|
|
|
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,
|
2017-02-22 07:47:24 +08:00
|
|
|
struct object_id *given,
|
|
|
|
struct object_id *commit)
|
2012-04-19 10:49:08 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < table->nr; i++) {
|
2017-02-22 07:47:24 +08:00
|
|
|
if (given && oidcmp(&table->item[i].given, given))
|
2012-04-19 10:49:08 +08:00
|
|
|
continue;
|
2017-02-22 07:47:24 +08:00
|
|
|
if (commit && oidcmp(&table->item[i].commit, commit))
|
2012-04-19 10:49:08 +08:00
|
|
|
continue;
|
|
|
|
return &table->item[i];
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void add_merge_parent(struct merge_parents *table,
|
2017-02-22 07:47:24 +08:00
|
|
|
struct object_id *given,
|
|
|
|
struct object_id *commit)
|
2012-04-19 10:49:08 +08:00
|
|
|
{
|
|
|
|
if (table->nr && find_merge_parent(table, given, commit))
|
|
|
|
return;
|
|
|
|
ALLOC_GROW(table->item, table->nr + 1, table->alloc);
|
2017-02-22 07:47:24 +08:00
|
|
|
oidcpy(&table->item[table->nr].given, given);
|
|
|
|
oidcpy(&table->item[table->nr].commit, commit);
|
2012-04-19 10:49:08 +08:00
|
|
|
table->item[table->nr].used = 0;
|
|
|
|
table->nr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int handle_line(char *line, struct merge_parents *merge_parents)
|
2006-07-03 23:18:43 +08:00
|
|
|
{
|
|
|
|
int i, len = strlen(line);
|
2011-10-07 14:12:09 +08:00
|
|
|
struct origin_data *origin_data;
|
2014-06-19 03:48:29 +08:00
|
|
|
char *src;
|
|
|
|
const char *origin;
|
2006-07-03 23:18:43 +08:00
|
|
|
struct src_data *src_data;
|
2010-03-24 15:16:03 +08:00
|
|
|
struct string_list_item *item;
|
2006-07-13 13:21:05 +08:00
|
|
|
int pulling_head = 0;
|
2017-02-22 07:47:24 +08:00
|
|
|
struct object_id oid;
|
2006-07-03 23:18:43 +08:00
|
|
|
|
2017-02-22 07:47:24 +08:00
|
|
|
if (len < GIT_SHA1_HEXSZ + 3 || line[GIT_SHA1_HEXSZ] != '\t')
|
2006-07-03 23:18:43 +08:00
|
|
|
return 1;
|
|
|
|
|
2017-02-22 07:47:24 +08:00
|
|
|
if (starts_with(line + GIT_SHA1_HEXSZ + 1, "not-for-merge"))
|
2006-07-03 23:18:43 +08:00
|
|
|
return 0;
|
|
|
|
|
2017-02-22 07:47:24 +08:00
|
|
|
if (line[GIT_SHA1_HEXSZ + 1] != '\t')
|
2006-07-03 23:18:43 +08:00
|
|
|
return 2;
|
|
|
|
|
2017-02-22 07:47:24 +08:00
|
|
|
i = get_oid_hex(line, &oid);
|
2012-04-19 10:49:08 +08:00
|
|
|
if (i)
|
2006-07-03 23:18:43 +08:00
|
|
|
return 3;
|
2012-04-19 10:49:08 +08:00
|
|
|
|
2017-02-22 07:47:24 +08:00
|
|
|
if (!find_merge_parent(merge_parents, &oid, NULL))
|
2012-04-19 10:49:08 +08:00
|
|
|
return 0; /* subsumed by other parents */
|
|
|
|
|
|
|
|
origin_data = xcalloc(1, sizeof(struct origin_data));
|
2017-02-22 07:47:24 +08:00
|
|
|
oidcpy(&origin_data->oid, &oid);
|
2006-07-03 23:18:43 +08:00
|
|
|
|
|
|
|
if (line[len - 1] == '\n')
|
|
|
|
line[len - 1] = 0;
|
2017-02-22 07:47:24 +08:00
|
|
|
line += GIT_SHA1_HEXSZ + 2;
|
2006-07-03 23:18:43 +08:00
|
|
|
|
2011-11-05 08:00:03 +08: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 23:18:43 +08:00
|
|
|
src = strstr(line, " of ");
|
|
|
|
if (src) {
|
|
|
|
*src = 0;
|
|
|
|
src += 4;
|
2006-07-13 13:21:05 +08:00
|
|
|
pulling_head = 0;
|
|
|
|
} else {
|
|
|
|
src = line;
|
|
|
|
pulling_head = 1;
|
|
|
|
}
|
2006-07-03 23:18:43 +08:00
|
|
|
|
2010-03-24 15:16:03 +08:00
|
|
|
item = unsorted_string_list_lookup(&srcs, src);
|
|
|
|
if (!item) {
|
2010-06-26 07:41:38 +08:00
|
|
|
item = string_list_append(&srcs, src);
|
2010-03-24 15:16:03 +08:00
|
|
|
item->util = xcalloc(1, sizeof(struct src_data));
|
|
|
|
init_src_data(item->util);
|
2006-07-03 23:18:43 +08:00
|
|
|
}
|
2010-03-24 15:16:03 +08:00
|
|
|
src_data = item->util;
|
2006-07-03 23:18:43 +08:00
|
|
|
|
2006-07-13 13:21:05 +08:00
|
|
|
if (pulling_head) {
|
2010-03-24 15:16:03 +08:00
|
|
|
origin = src;
|
2006-07-13 13:21:05 +08:00
|
|
|
src_data->head_status |= 1;
|
2013-12-01 04:55:40 +08:00
|
|
|
} else if (starts_with(line, "branch ")) {
|
2011-10-07 14:12:09 +08:00
|
|
|
origin_data->is_local_branch = 1;
|
2010-03-24 15:16:03 +08:00
|
|
|
origin = line + 7;
|
2010-06-26 07:41:38 +08:00
|
|
|
string_list_append(&src_data->branch, origin);
|
2006-07-03 23:18:43 +08:00
|
|
|
src_data->head_status |= 2;
|
2013-12-01 04:55:40 +08:00
|
|
|
} else if (starts_with(line, "tag ")) {
|
2006-07-03 23:18:43 +08:00
|
|
|
origin = line;
|
2010-06-26 07:41:38 +08:00
|
|
|
string_list_append(&src_data->tag, origin + 4);
|
2006-07-03 23:18:43 +08:00
|
|
|
src_data->head_status |= 2;
|
2014-06-19 03:48:29 +08:00
|
|
|
} else if (skip_prefix(line, "remote-tracking branch ", &origin)) {
|
2010-06-26 07:41:38 +08:00
|
|
|
string_list_append(&src_data->r_branch, origin);
|
2006-07-03 23:18:43 +08:00
|
|
|
src_data->head_status |= 2;
|
|
|
|
} else {
|
2010-03-24 15:16:03 +08:00
|
|
|
origin = src;
|
2010-06-26 07:41:38 +08:00
|
|
|
string_list_append(&src_data->generic, line);
|
2006-07-03 23:18:43 +08:00
|
|
|
src_data->head_status |= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(".", src) || !strcmp(src, origin)) {
|
|
|
|
int len = strlen(origin);
|
2010-03-24 15:16:03 +08:00
|
|
|
if (origin[0] == '\'' && origin[len - 1] == '\'')
|
2007-09-16 06:32:36 +08:00
|
|
|
origin = xmemdupz(origin + 1, len - 2);
|
2014-06-20 05:24:33 +08:00
|
|
|
} else
|
|
|
|
origin = xstrfmt("%s of %s", origin, src);
|
2011-10-07 14:12:09 +08:00
|
|
|
if (strcmp(".", src))
|
|
|
|
origin_data->is_local_branch = 0;
|
|
|
|
string_list_append(&origins, origin)->util = origin_data;
|
2006-07-03 23:18:43 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_joined(const char *singular, const char *plural,
|
2010-03-24 15:16:03 +08:00
|
|
|
struct string_list *list, struct strbuf *out)
|
2006-07-03 23:18:43 +08:00
|
|
|
{
|
|
|
|
if (list->nr == 0)
|
|
|
|
return;
|
|
|
|
if (list->nr == 1) {
|
2010-03-24 15:16:03 +08:00
|
|
|
strbuf_addf(out, "%s%s", singular, list->items[0].string);
|
2006-07-03 23:18:43 +08:00
|
|
|
} else {
|
|
|
|
int i;
|
2008-06-28 00:21:59 +08:00
|
|
|
strbuf_addstr(out, plural);
|
2006-07-03 23:18:43 +08:00
|
|
|
for (i = 0; i < list->nr - 1; i++)
|
2010-03-24 15:16:03 +08: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 23:18:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-07 14:12:09 +08: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;
|
|
|
|
}
|
2014-12-13 03:16:38 +08:00
|
|
|
strbuf_complete_line(out);
|
2011-10-07 14:12:09 +08:00
|
|
|
}
|
|
|
|
strbuf_release(&desc);
|
|
|
|
}
|
|
|
|
|
2012-03-14 01:00:00 +08:00
|
|
|
#define util_as_integral(elem) ((intptr_t)((elem)->util))
|
|
|
|
|
2015-04-16 05:18:37 +08:00
|
|
|
static void record_person_from_buf(int which, struct string_list *people,
|
|
|
|
const char *buffer)
|
2012-03-14 01:00:00 +08:00
|
|
|
{
|
2012-05-22 07:09:51 +08:00
|
|
|
char *name_buf, *name, *name_end;
|
2012-03-14 01:00:00 +08:00
|
|
|
struct string_list_item *elem;
|
2012-12-29 07:29:31 +08:00
|
|
|
const char *field;
|
2012-03-14 01:00:00 +08:00
|
|
|
|
2012-12-29 07:29:31 +08:00
|
|
|
field = (which == 'a') ? "\nauthor " : "\ncommitter ";
|
2014-06-11 05:41:51 +08:00
|
|
|
name = strstr(buffer, field);
|
2012-03-14 01:00:00 +08:00
|
|
|
if (!name)
|
|
|
|
return;
|
|
|
|
name += strlen(field);
|
|
|
|
name_end = strchrnul(name, '<');
|
|
|
|
if (*name_end)
|
|
|
|
name_end--;
|
|
|
|
while (isspace(*name_end) && name <= name_end)
|
|
|
|
name_end--;
|
2012-05-22 07:09:51 +08:00
|
|
|
if (name_end < name)
|
2012-03-14 01:00:00 +08:00
|
|
|
return;
|
2012-05-22 07:09:51 +08:00
|
|
|
name_buf = xmemdupz(name, name_end - name + 1);
|
2012-03-14 01:00:00 +08:00
|
|
|
|
|
|
|
elem = string_list_lookup(people, name_buf);
|
|
|
|
if (!elem) {
|
|
|
|
elem = string_list_insert(people, name_buf);
|
|
|
|
elem->util = (void *)0;
|
|
|
|
}
|
|
|
|
elem->util = (void*)(util_as_integral(elem) + 1);
|
2012-05-22 07:09:51 +08:00
|
|
|
free(name_buf);
|
2012-03-14 01:00:00 +08:00
|
|
|
}
|
|
|
|
|
2015-04-16 05:18:37 +08:00
|
|
|
|
|
|
|
static void record_person(int which, struct string_list *people,
|
|
|
|
struct commit *commit)
|
|
|
|
{
|
2015-05-12 05:23:45 +08:00
|
|
|
const char *buffer = get_commit_buffer(commit, NULL);
|
2015-04-16 05:18:37 +08:00
|
|
|
record_person_from_buf(which, people, buffer);
|
|
|
|
unuse_commit_buffer(commit, buffer);
|
|
|
|
}
|
|
|
|
|
2012-03-14 01:00:00 +08:00
|
|
|
static int cmp_string_list_util_as_integral(const void *a_, const void *b_)
|
|
|
|
{
|
|
|
|
const struct string_list_item *a = a_, *b = b_;
|
|
|
|
return util_as_integral(b) - util_as_integral(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void add_people_count(struct strbuf *out, struct string_list *people)
|
|
|
|
{
|
|
|
|
if (people->nr == 1)
|
2016-08-06 04:37:11 +08:00
|
|
|
strbuf_addstr(out, people->items[0].string);
|
2012-03-14 01:00:00 +08:00
|
|
|
else if (people->nr == 2)
|
|
|
|
strbuf_addf(out, "%s (%d) and %s (%d)",
|
|
|
|
people->items[0].string,
|
|
|
|
(int)util_as_integral(&people->items[0]),
|
|
|
|
people->items[1].string,
|
|
|
|
(int)util_as_integral(&people->items[1]));
|
|
|
|
else if (people->nr)
|
|
|
|
strbuf_addf(out, "%s (%d) and others",
|
|
|
|
people->items[0].string,
|
|
|
|
(int)util_as_integral(&people->items[0]));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void credit_people(struct strbuf *out,
|
|
|
|
struct string_list *them,
|
|
|
|
int kind)
|
|
|
|
{
|
|
|
|
const char *label;
|
|
|
|
const char *me;
|
|
|
|
|
|
|
|
if (kind == 'a') {
|
2013-04-07 23:25:43 +08:00
|
|
|
label = "By";
|
2012-03-14 01:00:00 +08:00
|
|
|
me = git_author_info(IDENT_NO_DATE);
|
|
|
|
} else {
|
2013-04-07 23:25:43 +08:00
|
|
|
label = "Via";
|
2012-03-14 01:00:00 +08:00
|
|
|
me = git_committer_info(IDENT_NO_DATE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!them->nr ||
|
|
|
|
(them->nr == 1 &&
|
|
|
|
me &&
|
refactor skip_prefix to return a boolean
The skip_prefix() function returns a pointer to the content
past the prefix, or NULL if the prefix was not found. While
this is nice and simple, in practice it makes it hard to use
for two reasons:
1. When you want to conditionally skip or keep the string
as-is, you have to introduce a temporary variable.
For example:
tmp = skip_prefix(buf, "foo");
if (tmp)
buf = tmp;
2. It is verbose to check the outcome in a conditional, as
you need extra parentheses to silence compiler
warnings. For example:
if ((cp = skip_prefix(buf, "foo"))
/* do something with cp */
Both of these make it harder to use for long if-chains, and
we tend to use starts_with() instead. However, the first line
of "do something" is often to then skip forward in buf past
the prefix, either using a magic constant or with an extra
strlen(3) (which is generally computed at compile time, but
means we are repeating ourselves).
This patch refactors skip_prefix() to return a simple boolean,
and to provide the pointer value as an out-parameter. If the
prefix is not found, the out-parameter is untouched. This
lets you write:
if (skip_prefix(arg, "foo ", &arg))
do_foo(arg);
else if (skip_prefix(arg, "bar ", &arg))
do_bar(arg);
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-06-19 03:44:19 +08:00
|
|
|
skip_prefix(me, them->items->string, &me) &&
|
2014-06-19 03:42:14 +08:00
|
|
|
starts_with(me, " <")))
|
2012-03-14 01:00:00 +08:00
|
|
|
return;
|
2013-04-07 23:25:43 +08:00
|
|
|
strbuf_addf(out, "\n%c %s ", comment_line_char, label);
|
2012-03-14 01:00:00 +08:00
|
|
|
add_people_count(out, them);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void add_people_info(struct strbuf *out,
|
|
|
|
struct string_list *authors,
|
|
|
|
struct string_list *committers)
|
|
|
|
{
|
2016-09-29 23:29:29 +08:00
|
|
|
QSORT(authors->items, authors->nr,
|
|
|
|
cmp_string_list_util_as_integral);
|
|
|
|
QSORT(committers->items, committers->nr,
|
|
|
|
cmp_string_list_util_as_integral);
|
2012-03-14 01:00:00 +08:00
|
|
|
|
|
|
|
credit_people(out, authors, 'a');
|
|
|
|
credit_people(out, committers, 'c');
|
|
|
|
}
|
|
|
|
|
2011-10-07 14:12:09 +08:00
|
|
|
static void shortlog(const char *name,
|
|
|
|
struct origin_data *origin_data,
|
|
|
|
struct commit *head,
|
2012-12-29 07:29:31 +08:00
|
|
|
struct rev_info *rev,
|
|
|
|
struct fmt_merge_msg_opts *opts,
|
2011-10-07 14:12:09 +08:00
|
|
|
struct strbuf *out)
|
2006-07-03 23:18:43 +08:00
|
|
|
{
|
|
|
|
int i, count = 0;
|
|
|
|
struct commit *commit;
|
|
|
|
struct object *branch;
|
2010-07-05 03:46:19 +08:00
|
|
|
struct string_list subjects = STRING_LIST_INIT_DUP;
|
2012-03-14 01:00:00 +08:00
|
|
|
struct string_list authors = STRING_LIST_INIT_DUP;
|
|
|
|
struct string_list committers = STRING_LIST_INIT_DUP;
|
2007-11-13 15:16:08 +08:00
|
|
|
int flags = UNINTERESTING | TREESAME | SEEN | SHOWN | ADDED;
|
2010-03-24 15:16:01 +08:00
|
|
|
struct strbuf sb = STRBUF_INIT;
|
2017-02-22 07:47:24 +08:00
|
|
|
const struct object_id *oid = &origin_data->oid;
|
2012-12-29 07:29:31 +08:00
|
|
|
int limit = opts->shortlog_len;
|
2006-07-03 23:18:43 +08:00
|
|
|
|
object: convert parse_object* to take struct object_id
Make parse_object, parse_object_or_die, and parse_object_buffer take a
pointer to struct object_id. Remove the temporary variables inserted
earlier, since they are no longer necessary. Transform all of the
callers using the following semantic patch:
@@
expression E1;
@@
- parse_object(E1.hash)
+ parse_object(&E1)
@@
expression E1;
@@
- parse_object(E1->hash)
+ parse_object(E1)
@@
expression E1, E2;
@@
- parse_object_or_die(E1.hash, E2)
+ parse_object_or_die(&E1, E2)
@@
expression E1, E2;
@@
- parse_object_or_die(E1->hash, E2)
+ parse_object_or_die(E1, E2)
@@
expression E1, E2, E3, E4, E5;
@@
- parse_object_buffer(E1.hash, E2, E3, E4, E5)
+ parse_object_buffer(&E1, E2, E3, E4, E5)
@@
expression E1, E2, E3, E4, E5;
@@
- parse_object_buffer(E1->hash, E2, E3, E4, E5)
+ parse_object_buffer(E1, E2, E3, E4, E5)
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-05-07 06:10:38 +08:00
|
|
|
branch = deref_tag(parse_object(oid), oid_to_hex(oid), GIT_SHA1_HEXSZ);
|
2006-07-12 11:45:31 +08:00
|
|
|
if (!branch || branch->type != OBJ_COMMIT)
|
2006-07-03 23:18:43 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
setup_revisions(0, NULL, rev, NULL);
|
|
|
|
add_pending_object(rev, branch, name);
|
|
|
|
add_pending_object(rev, &head->object, "^HEAD");
|
|
|
|
head->object.flags |= UNINTERESTING;
|
2008-02-18 15:31:56 +08:00
|
|
|
if (prepare_revision_walk(rev))
|
|
|
|
die("revision walk setup failed");
|
2006-07-03 23:18:43 +08:00
|
|
|
while ((commit = get_revision(rev)) != NULL) {
|
2010-03-24 15:16:01 +08:00
|
|
|
struct pretty_print_context ctx = {0};
|
2006-07-03 23:18:43 +08:00
|
|
|
|
2012-03-14 01:00:00 +08:00
|
|
|
if (commit->parents && commit->parents->next) {
|
|
|
|
/* do not list a merge but count committer */
|
2012-12-29 07:29:31 +08:00
|
|
|
if (opts->credit_people)
|
|
|
|
record_person('c', &committers, commit);
|
2006-07-03 23:18:43 +08:00
|
|
|
continue;
|
2012-03-14 01:00:00 +08:00
|
|
|
}
|
2012-12-29 07:29:31 +08:00
|
|
|
if (!count && opts->credit_people)
|
2012-03-14 01:00:00 +08:00
|
|
|
/* the 'tip' committer */
|
|
|
|
record_person('c', &committers, commit);
|
2012-12-29 07:29:31 +08:00
|
|
|
if (opts->credit_people)
|
|
|
|
record_person('a', &authors, commit);
|
2006-07-03 23:18:43 +08:00
|
|
|
count++;
|
|
|
|
if (subjects.nr > limit)
|
|
|
|
continue;
|
|
|
|
|
2010-03-24 15:16:01 +08:00
|
|
|
format_commit_message(commit, "%s", &sb, &ctx);
|
|
|
|
strbuf_ltrim(&sb);
|
2008-04-16 02:01:36 +08:00
|
|
|
|
2010-03-24 15:16:01 +08:00
|
|
|
if (!sb.len)
|
2010-06-26 07:41:38 +08:00
|
|
|
string_list_append(&subjects,
|
2015-11-10 10:22:28 +08:00
|
|
|
oid_to_hex(&commit->object.oid));
|
2010-03-24 15:16:01 +08:00
|
|
|
else
|
2010-06-26 07:41:38 +08:00
|
|
|
string_list_append(&subjects, strbuf_detach(&sb, NULL));
|
2006-07-03 23:18:43 +08:00
|
|
|
}
|
|
|
|
|
2012-12-29 07:29:31 +08:00
|
|
|
if (opts->credit_people)
|
|
|
|
add_people_info(out, &authors, &committers);
|
2006-07-03 23:18:43 +08:00
|
|
|
if (count > limit)
|
2008-06-28 00:21:59 +08:00
|
|
|
strbuf_addf(out, "\n* %s: (%d commits)\n", name, count);
|
2006-07-03 23:18:43 +08:00
|
|
|
else
|
2008-06-28 00:21:59 +08:00
|
|
|
strbuf_addf(out, "\n* %s:\n", name);
|
2006-07-03 23:18:43 +08:00
|
|
|
|
2011-10-07 14:12:09 +08:00
|
|
|
if (origin_data->is_local_branch && use_branch_desc)
|
|
|
|
add_branch_desc(out, name);
|
|
|
|
|
2006-07-03 23:18:43 +08:00
|
|
|
for (i = 0; i < subjects.nr; i++)
|
|
|
|
if (i >= limit)
|
2016-09-16 02:31:00 +08:00
|
|
|
strbuf_addstr(out, " ...\n");
|
2006-07-03 23:18:43 +08:00
|
|
|
else
|
2010-03-24 15:16:03 +08:00
|
|
|
strbuf_addf(out, " %s\n", subjects.items[i].string);
|
2006-07-03 23:18:43 +08: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;
|
|
|
|
|
2012-03-14 01:00:00 +08:00
|
|
|
string_list_clear(&authors, 0);
|
|
|
|
string_list_clear(&committers, 0);
|
2010-03-24 15:16:03 +08:00
|
|
|
string_list_clear(&subjects, 0);
|
2006-07-03 23:18:43 +08:00
|
|
|
}
|
|
|
|
|
2011-11-05 08:35:42 +08:00
|
|
|
static void fmt_merge_msg_title(struct strbuf *out,
|
2017-07-25 21:06:06 +08:00
|
|
|
const char *current_branch)
|
|
|
|
{
|
2010-05-11 01:17:50 +08:00
|
|
|
int i = 0;
|
2009-03-08 04:02:26 +08:00
|
|
|
char *sep = "";
|
2010-03-24 15:15:58 +08:00
|
|
|
|
2008-06-28 00:21:59 +08:00
|
|
|
strbuf_addstr(out, "Merge ");
|
2006-07-03 23:18:43 +08:00
|
|
|
for (i = 0; i < srcs.nr; i++) {
|
2010-03-24 15:16:03 +08:00
|
|
|
struct src_data *src_data = srcs.items[i].util;
|
2006-07-03 23:18:43 +08:00
|
|
|
const char *subsep = "";
|
|
|
|
|
2008-06-28 00:21:59 +08:00
|
|
|
strbuf_addstr(out, sep);
|
2006-07-03 23:18:43 +08:00
|
|
|
sep = "; ";
|
|
|
|
|
|
|
|
if (src_data->head_status == 1) {
|
2010-03-24 15:16:03 +08:00
|
|
|
strbuf_addstr(out, srcs.items[i].string);
|
2006-07-03 23:18:43 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (src_data->head_status == 3) {
|
|
|
|
subsep = ", ";
|
2008-06-28 00:21:59 +08:00
|
|
|
strbuf_addstr(out, "HEAD");
|
2006-07-03 23:18:43 +08:00
|
|
|
}
|
|
|
|
if (src_data->branch.nr) {
|
2008-06-28 00:21:59 +08:00
|
|
|
strbuf_addstr(out, subsep);
|
2006-07-03 23:18:43 +08:00
|
|
|
subsep = ", ";
|
2008-06-28 00:21:59 +08:00
|
|
|
print_joined("branch ", "branches ", &src_data->branch,
|
|
|
|
out);
|
2006-07-03 23:18:43 +08:00
|
|
|
}
|
|
|
|
if (src_data->r_branch.nr) {
|
2008-06-28 00:21:59 +08:00
|
|
|
strbuf_addstr(out, subsep);
|
2006-07-03 23:18:43 +08:00
|
|
|
subsep = ", ";
|
2010-11-02 23:31:25 +08:00
|
|
|
print_joined("remote-tracking branch ", "remote-tracking branches ",
|
2008-06-28 00:21:59 +08:00
|
|
|
&src_data->r_branch, out);
|
2006-07-03 23:18:43 +08:00
|
|
|
}
|
|
|
|
if (src_data->tag.nr) {
|
2008-06-28 00:21:59 +08:00
|
|
|
strbuf_addstr(out, subsep);
|
2006-07-03 23:18:43 +08:00
|
|
|
subsep = ", ";
|
2008-06-28 00:21:59 +08:00
|
|
|
print_joined("tag ", "tags ", &src_data->tag, out);
|
2006-07-03 23:18:43 +08:00
|
|
|
}
|
|
|
|
if (src_data->generic.nr) {
|
2008-06-28 00:21:59 +08:00
|
|
|
strbuf_addstr(out, subsep);
|
|
|
|
print_joined("commit ", "commits ", &src_data->generic,
|
|
|
|
out);
|
2006-07-03 23:18:43 +08:00
|
|
|
}
|
2010-03-24 15:16:03 +08:00
|
|
|
if (strcmp(".", srcs.items[i].string))
|
|
|
|
strbuf_addf(out, " of %s", srcs.items[i].string);
|
2006-07-03 23:18:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp("master", current_branch))
|
2008-06-28 00:21:59 +08:00
|
|
|
strbuf_addch(out, '\n');
|
2006-07-03 23:18:43 +08:00
|
|
|
else
|
2008-06-28 00:21:59 +08:00
|
|
|
strbuf_addf(out, " into %s\n", current_branch);
|
2010-05-11 01:17:50 +08:00
|
|
|
}
|
|
|
|
|
2011-11-05 12:06:30 +08: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);
|
2012-05-26 00:02:03 +08:00
|
|
|
if (sig->len) {
|
|
|
|
strbuf_addch(tagbuf, '\n');
|
2013-01-17 03:18:48 +08:00
|
|
|
strbuf_add_commented_lines(tagbuf, sig->buf, sig->len);
|
2012-05-26 00:02:03 +08:00
|
|
|
}
|
2011-11-05 12:06:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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 */
|
2013-02-15 00:04:44 +08:00
|
|
|
else if (verify_signed_buffer(buf, len, buf + len, size - len, &sig, NULL)) {
|
2011-11-05 12:06:30 +08:00
|
|
|
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;
|
2013-04-07 23:25:44 +08:00
|
|
|
strbuf_addch(&tagline, '\n');
|
|
|
|
strbuf_add_commented_lines(&tagline,
|
|
|
|
origins.items[first_tag].string,
|
|
|
|
strlen(origins.items[first_tag].string));
|
2011-11-05 12:06:30 +08:00
|
|
|
strbuf_insert(&tagbuf, 0, tagline.buf,
|
|
|
|
tagline.len);
|
|
|
|
strbuf_release(&tagline);
|
|
|
|
}
|
2013-04-07 23:25:44 +08:00
|
|
|
strbuf_addch(&tagbuf, '\n');
|
|
|
|
strbuf_add_commented_lines(&tagbuf,
|
|
|
|
origins.items[i].string,
|
|
|
|
strlen(origins.items[i].string));
|
2011-11-05 12:06:30 +08:00
|
|
|
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 10:49:08 +08:00
|
|
|
static void find_merge_parents(struct merge_parents *result,
|
2017-02-22 07:47:24 +08:00
|
|
|
struct strbuf *in, struct object_id *head)
|
2012-04-19 10:49:08 +08:00
|
|
|
{
|
2015-10-25 00:21:31 +08:00
|
|
|
struct commit_list *parents;
|
2012-04-19 10:49:08 +08:00
|
|
|
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');
|
2017-02-22 07:47:24 +08:00
|
|
|
struct object_id oid;
|
2012-04-19 10:49:08 +08:00
|
|
|
struct commit *parent;
|
|
|
|
struct object *obj;
|
|
|
|
|
|
|
|
len = newline ? newline - p : strlen(p);
|
|
|
|
pos += len + !!newline;
|
|
|
|
|
2017-02-22 07:47:24 +08:00
|
|
|
if (len < GIT_SHA1_HEXSZ + 3 ||
|
|
|
|
get_oid_hex(p, &oid) ||
|
|
|
|
p[GIT_SHA1_HEXSZ] != '\t' ||
|
|
|
|
p[GIT_SHA1_HEXSZ + 1] != '\t')
|
2012-04-19 10:49:08 +08:00
|
|
|
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.
|
|
|
|
*/
|
object: convert parse_object* to take struct object_id
Make parse_object, parse_object_or_die, and parse_object_buffer take a
pointer to struct object_id. Remove the temporary variables inserted
earlier, since they are no longer necessary. Transform all of the
callers using the following semantic patch:
@@
expression E1;
@@
- parse_object(E1.hash)
+ parse_object(&E1)
@@
expression E1;
@@
- parse_object(E1->hash)
+ parse_object(E1)
@@
expression E1, E2;
@@
- parse_object_or_die(E1.hash, E2)
+ parse_object_or_die(&E1, E2)
@@
expression E1, E2;
@@
- parse_object_or_die(E1->hash, E2)
+ parse_object_or_die(E1, E2)
@@
expression E1, E2, E3, E4, E5;
@@
- parse_object_buffer(E1.hash, E2, E3, E4, E5)
+ parse_object_buffer(&E1, E2, E3, E4, E5)
@@
expression E1, E2, E3, E4, E5;
@@
- parse_object_buffer(E1->hash, E2, E3, E4, E5)
+ parse_object_buffer(E1, E2, E3, E4, E5)
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-05-07 06:10:38 +08:00
|
|
|
obj = parse_object(&oid);
|
2012-04-19 10:49:08 +08:00
|
|
|
parent = (struct commit *)peel_to_type(NULL, 0, obj, OBJ_COMMIT);
|
|
|
|
if (!parent)
|
|
|
|
continue;
|
|
|
|
commit_list_insert(parent, &parents);
|
2017-02-22 07:47:24 +08:00
|
|
|
add_merge_parent(result, &obj->oid, &parent->object.oid);
|
2012-04-19 10:49:08 +08:00
|
|
|
}
|
Convert lookup_commit* to struct object_id
Convert lookup_commit, lookup_commit_or_die,
lookup_commit_reference, and lookup_commit_reference_gently to take
struct object_id arguments.
Introduce a temporary in parse_object buffer in order to convert this
function. This is required since in order to convert parse_object and
parse_object_buffer, lookup_commit_reference_gently and
lookup_commit_or_die would need to be converted. Not introducing a
temporary would therefore require that lookup_commit_or_die take a
struct object_id *, but lookup_commit would take unsigned char *,
leaving a confusing and hard-to-use interface.
parse_object_buffer will lose this temporary in a later patch.
This commit was created with manual changes to commit.c, commit.h, and
object.c, plus the following semantic patch:
@@
expression E1, E2;
@@
- lookup_commit_reference_gently(E1.hash, E2)
+ lookup_commit_reference_gently(&E1, E2)
@@
expression E1, E2;
@@
- lookup_commit_reference_gently(E1->hash, E2)
+ lookup_commit_reference_gently(E1, E2)
@@
expression E1;
@@
- lookup_commit_reference(E1.hash)
+ lookup_commit_reference(&E1)
@@
expression E1;
@@
- lookup_commit_reference(E1->hash)
+ lookup_commit_reference(E1)
@@
expression E1;
@@
- lookup_commit(E1.hash)
+ lookup_commit(&E1)
@@
expression E1;
@@
- lookup_commit(E1->hash)
+ lookup_commit(E1)
@@
expression E1, E2;
@@
- lookup_commit_or_die(E1.hash, E2)
+ lookup_commit_or_die(&E1, E2)
@@
expression E1, E2;
@@
- lookup_commit_or_die(E1->hash, E2)
+ lookup_commit_or_die(E1, E2)
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-05-07 06:10:10 +08:00
|
|
|
head_commit = lookup_commit(head);
|
2012-04-19 10:49:08 +08:00
|
|
|
if (head_commit)
|
|
|
|
commit_list_insert(head_commit, &parents);
|
|
|
|
parents = reduce_heads(parents);
|
|
|
|
|
|
|
|
while (parents) {
|
2015-10-25 00:21:31 +08:00
|
|
|
struct commit *cmit = pop_commit(&parents);
|
2012-04-19 10:49:08 +08:00
|
|
|
for (i = 0; i < result->nr; i++)
|
2017-02-22 07:47:24 +08:00
|
|
|
if (!oidcmp(&result->item[i].commit, &cmit->object.oid))
|
2012-04-19 10:49:08 +08:00
|
|
|
result->item[i].used = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 08:35:42 +08:00
|
|
|
int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
|
|
|
|
struct fmt_merge_msg_opts *opts)
|
|
|
|
{
|
2010-09-09 01:59:53 +08:00
|
|
|
int i = 0, pos = 0;
|
2017-02-22 07:47:24 +08:00
|
|
|
struct object_id head_oid;
|
2010-05-11 01:17:50 +08:00
|
|
|
const char *current_branch;
|
2011-12-13 22:17:48 +08:00
|
|
|
void *current_branch_to_free;
|
2012-04-19 10:49:08 +08:00
|
|
|
struct merge_parents merge_parents;
|
|
|
|
|
|
|
|
memset(&merge_parents, 0, sizeof(merge_parents));
|
2010-05-11 01:17:50 +08:00
|
|
|
|
|
|
|
/* get current branch */
|
2011-12-13 22:17:48 +08:00
|
|
|
current_branch = current_branch_to_free =
|
2017-02-22 07:47:24 +08:00
|
|
|
resolve_refdup("HEAD", RESOLVE_REF_READING, head_oid.hash, NULL);
|
2010-05-11 01:17:50 +08:00
|
|
|
if (!current_branch)
|
|
|
|
die("No current branch");
|
2013-12-01 04:55:40 +08:00
|
|
|
if (starts_with(current_branch, "refs/heads/"))
|
2010-05-11 01:17:50 +08:00
|
|
|
current_branch += 11;
|
|
|
|
|
2017-02-22 07:47:24 +08:00
|
|
|
find_merge_parents(&merge_parents, in, &head_oid);
|
2012-04-19 10:49:08 +08:00
|
|
|
|
2010-05-11 01:17:50 +08: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 10:49:08 +08:00
|
|
|
if (handle_line(p, &merge_parents))
|
2010-05-11 01:17:50 +08:00
|
|
|
die ("Error in line %d: %.*s", i, len, p);
|
|
|
|
}
|
|
|
|
|
2011-11-05 08:35:42 +08:00
|
|
|
if (opts->add_title && srcs.nr)
|
|
|
|
fmt_merge_msg_title(out, current_branch);
|
2010-05-11 01:17:50 +08:00
|
|
|
|
2011-11-05 12:06:30 +08:00
|
|
|
if (origins.nr)
|
|
|
|
fmt_merge_msg_sigs(out);
|
2006-07-03 23:18:43 +08:00
|
|
|
|
2011-11-05 08:35:42 +08:00
|
|
|
if (opts->shortlog_len) {
|
2006-07-03 23:18:43 +08:00
|
|
|
struct commit *head;
|
|
|
|
struct rev_info rev;
|
|
|
|
|
Convert lookup_commit* to struct object_id
Convert lookup_commit, lookup_commit_or_die,
lookup_commit_reference, and lookup_commit_reference_gently to take
struct object_id arguments.
Introduce a temporary in parse_object buffer in order to convert this
function. This is required since in order to convert parse_object and
parse_object_buffer, lookup_commit_reference_gently and
lookup_commit_or_die would need to be converted. Not introducing a
temporary would therefore require that lookup_commit_or_die take a
struct object_id *, but lookup_commit would take unsigned char *,
leaving a confusing and hard-to-use interface.
parse_object_buffer will lose this temporary in a later patch.
This commit was created with manual changes to commit.c, commit.h, and
object.c, plus the following semantic patch:
@@
expression E1, E2;
@@
- lookup_commit_reference_gently(E1.hash, E2)
+ lookup_commit_reference_gently(&E1, E2)
@@
expression E1, E2;
@@
- lookup_commit_reference_gently(E1->hash, E2)
+ lookup_commit_reference_gently(E1, E2)
@@
expression E1;
@@
- lookup_commit_reference(E1.hash)
+ lookup_commit_reference(&E1)
@@
expression E1;
@@
- lookup_commit_reference(E1->hash)
+ lookup_commit_reference(E1)
@@
expression E1;
@@
- lookup_commit(E1.hash)
+ lookup_commit(&E1)
@@
expression E1;
@@
- lookup_commit(E1->hash)
+ lookup_commit(E1)
@@
expression E1, E2;
@@
- lookup_commit_or_die(E1.hash, E2)
+ lookup_commit_or_die(&E1, E2)
@@
expression E1, E2;
@@
- lookup_commit_or_die(E1->hash, E2)
+ lookup_commit_or_die(E1, E2)
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-05-07 06:10:10 +08:00
|
|
|
head = lookup_commit_or_die(&head_oid, "HEAD");
|
2008-06-28 00:21:59 +08:00
|
|
|
init_revisions(&rev, NULL);
|
2006-07-03 23:18:43 +08:00
|
|
|
rev.commit_format = CMIT_FMT_ONELINE;
|
|
|
|
rev.ignore_merges = 1;
|
|
|
|
rev.limited = 1;
|
|
|
|
|
2012-05-26 00:02:03 +08:00
|
|
|
strbuf_complete_line(out);
|
2010-05-11 01:17:52 +08:00
|
|
|
|
2006-07-03 23:18:43 +08:00
|
|
|
for (i = 0; i < origins.nr; i++)
|
2011-10-07 14:12:09 +08:00
|
|
|
shortlog(origins.items[i].string,
|
|
|
|
origins.items[i].util,
|
2012-12-29 07:29:31 +08:00
|
|
|
head, &rev, opts, out);
|
2006-07-03 23:18:43 +08:00
|
|
|
}
|
2008-06-28 00:21:59 +08:00
|
|
|
|
2011-11-05 12:06:30 +08:00
|
|
|
strbuf_complete_line(out);
|
2011-12-13 22:17:48 +08:00
|
|
|
free(current_branch_to_free);
|
2012-04-19 10:49:08 +08:00
|
|
|
free(merge_parents.item);
|
2008-06-28 00:21:59 +08:00
|
|
|
return 0;
|
2010-05-11 01:17:49 +08:00
|
|
|
}
|
|
|
|
|
2008-06-28 00:21:59 +08:00
|
|
|
int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
2008-10-02 20:59:18 +08:00
|
|
|
const char *inpath = NULL;
|
2010-08-18 07:00:34 +08:00
|
|
|
const char *message = NULL;
|
2011-10-07 14:12:09 +08:00
|
|
|
int shortlog_len = -1;
|
2008-10-02 20:59:18 +08:00
|
|
|
struct option options[] = {
|
2012-08-20 20:32:10 +08:00
|
|
|
{ OPTION_INTEGER, 0, "log", &shortlog_len, N_("n"),
|
|
|
|
N_("populate log with at most <n> entries from shortlog"),
|
2010-09-09 01:59:54 +08:00
|
|
|
PARSE_OPT_OPTARG, NULL, DEFAULT_MERGE_LOG_LEN },
|
2012-08-20 20:32:10 +08:00
|
|
|
{ OPTION_INTEGER, 0, "summary", &shortlog_len, N_("n"),
|
|
|
|
N_("alias for --log (deprecated)"),
|
2010-09-09 01:59:54 +08:00
|
|
|
PARSE_OPT_OPTARG | PARSE_OPT_HIDDEN, NULL,
|
|
|
|
DEFAULT_MERGE_LOG_LEN },
|
2012-08-20 20:32:10 +08:00
|
|
|
OPT_STRING('m', "message", &message, N_("text"),
|
|
|
|
N_("use <text> as start of message")),
|
|
|
|
OPT_FILENAME('F', "file", &inpath, N_("file to read from")),
|
2008-10-02 20:59:18 +08:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
|
2008-06-28 00:21:59 +08:00
|
|
|
FILE *in = stdin;
|
2008-10-10 03:12:12 +08:00
|
|
|
struct strbuf input = STRBUF_INIT, output = STRBUF_INIT;
|
2008-06-28 00:21:59 +08:00
|
|
|
int ret;
|
2011-11-05 08:35:42 +08:00
|
|
|
struct fmt_merge_msg_opts opts;
|
2008-06-28 00:21:59 +08:00
|
|
|
|
|
|
|
git_config(fmt_merge_msg_config, NULL);
|
2009-05-24 02:53:12 +08:00
|
|
|
argc = parse_options(argc, argv, prefix, options, fmt_merge_msg_usage,
|
|
|
|
0);
|
2008-10-02 20:59:18 +08:00
|
|
|
if (argc > 0)
|
|
|
|
usage_with_options(fmt_merge_msg_usage, options);
|
2011-10-07 14:12:09 +08:00
|
|
|
if (shortlog_len < 0)
|
|
|
|
shortlog_len = (merge_log_config > 0) ? merge_log_config : 0;
|
2008-10-02 20:59:18 +08:00
|
|
|
|
|
|
|
if (inpath && strcmp(inpath, "-")) {
|
|
|
|
in = fopen(inpath, "r");
|
|
|
|
if (!in)
|
2009-06-27 23:58:47 +08:00
|
|
|
die_errno("cannot open '%s'", inpath);
|
2008-06-28 00:21:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (strbuf_read(&input, fileno(in), 0) < 0)
|
2009-06-27 23:58:46 +08:00
|
|
|
die_errno("could not read input file");
|
2010-09-09 01:59:53 +08:00
|
|
|
|
|
|
|
if (message)
|
2010-08-18 07:00:34 +08:00
|
|
|
strbuf_addstr(&output, message);
|
2010-09-09 01:59:53 +08:00
|
|
|
|
2011-11-05 08:35:42 +08:00
|
|
|
memset(&opts, 0, sizeof(opts));
|
|
|
|
opts.add_title = !message;
|
2012-12-29 07:29:31 +08:00
|
|
|
opts.credit_people = 1;
|
2011-11-05 08:35:42 +08:00
|
|
|
opts.shortlog_len = shortlog_len;
|
|
|
|
|
|
|
|
ret = fmt_merge_msg(&input, &output, &opts);
|
2008-06-28 00:21:59 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2008-10-02 20:59:18 +08:00
|
|
|
write_in_full(STDOUT_FILENO, output.buf, output.len);
|
2006-07-03 23:18:43 +08:00
|
|
|
return 0;
|
|
|
|
}
|