summaryrefslogtreecommitdiff
path: root/log-tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'log-tree.c')
-rw-r--r--log-tree.c182
1 files changed, 116 insertions, 66 deletions
diff --git a/log-tree.c b/log-tree.c
index d0ac0a6..16031b4 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -1,8 +1,12 @@
-#include "cache.h"
+#include "git-compat-util.h"
#include "commit-reach.h"
#include "config.h"
#include "diff.h"
-#include "object-store.h"
+#include "diffcore.h"
+#include "environment.h"
+#include "hex.h"
+#include "object-name.h"
+#include "object-store-ll.h"
#include "repository.h"
#include "tmp-objdir.h"
#include "commit.h"
@@ -12,6 +16,8 @@
#include "merge-ort.h"
#include "reflog-walk.h"
#include "refs.h"
+#include "replace-object.h"
+#include "revision.h"
#include "string-list.h"
#include "color.h"
#include "gpg-interface.h"
@@ -20,6 +26,9 @@
#include "help.h"
#include "range-diff.h"
#include "strmap.h"
+#include "tree.h"
+#include "wildmatch.h"
+#include "write-or-die.h"
static struct decoration name_decoration = { "object names" };
static int decoration_loaded;
@@ -135,19 +144,22 @@ static int ref_filter_match(const char *refname,
}
static int add_ref_decoration(const char *refname, const struct object_id *oid,
- int flags, void *cb_data)
+ int flags UNUSED,
+ void *cb_data)
{
+ int i;
struct object *obj;
enum object_type objtype;
enum decoration_type deco_type = DECORATION_NONE;
struct decoration_filter *filter = (struct decoration_filter *)cb_data;
+ const char *git_replace_ref_base = ref_namespace[NAMESPACE_REPLACE].ref;
if (filter && !ref_filter_match(refname, filter))
return 0;
if (starts_with(refname, git_replace_ref_base)) {
struct object_id original_oid;
- if (!read_replace_refs)
+ if (!replace_refs_enabled(the_repository))
return 0;
if (get_oid_hex(refname + strlen(git_replace_ref_base),
&original_oid)) {
@@ -165,16 +177,21 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid,
return 0;
obj = lookup_object_by_type(the_repository, oid, objtype);
- if (starts_with(refname, "refs/heads/"))
- deco_type = DECORATION_REF_LOCAL;
- else if (starts_with(refname, "refs/remotes/"))
- deco_type = DECORATION_REF_REMOTE;
- else if (starts_with(refname, "refs/tags/"))
- deco_type = DECORATION_REF_TAG;
- else if (!strcmp(refname, "refs/stash"))
- deco_type = DECORATION_REF_STASH;
- else if (!strcmp(refname, "HEAD"))
- deco_type = DECORATION_REF_HEAD;
+ for (i = 0; i < ARRAY_SIZE(ref_namespace); i++) {
+ struct ref_namespace_info *info = &ref_namespace[i];
+
+ if (!info->decoration)
+ continue;
+ if (info->exact) {
+ if (!strcmp(refname, info->ref)) {
+ deco_type = info->decoration;
+ break;
+ }
+ } else if (starts_with(refname, info->ref)) {
+ deco_type = info->decoration;
+ break;
+ }
+ }
add_name_decoration(deco_type, refname, obj);
while (obj->type == OBJ_TAG) {
@@ -188,7 +205,8 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid,
return 0;
}
-static int add_graft_decoration(const struct commit_graft *graft, void *cb_data)
+static int add_graft_decoration(const struct commit_graft *graft,
+ void *cb_data UNUSED)
{
struct commit *commit = lookup_commit(the_repository, &graft->oid);
if (!commit)
@@ -225,7 +243,8 @@ static void show_parents(struct commit *commit, int abbrev, FILE *file)
struct commit_list *p;
for (p = commit->parents; p ; p = p->next) {
struct commit *parent = p->item;
- fprintf(file, " %s", find_unique_abbrev(&parent->object.oid, abbrev));
+ fprintf(file, " %s",
+ repo_find_unique_abbrev(the_repository, &parent->object.oid, abbrev));
}
}
@@ -233,7 +252,8 @@ static void show_children(struct rev_info *opt, struct commit *commit, int abbre
{
struct commit_list *p = lookup_decoration(&opt->children, &commit->object);
for ( ; p; p = p->next) {
- fprintf(opt->diffopt.file, " %s", find_unique_abbrev(&p->item->object.oid, abbrev));
+ fprintf(opt->diffopt.file, " %s",
+ repo_find_unique_abbrev(the_repository, &p->item->object.oid, abbrev));
}
}
@@ -284,26 +304,43 @@ static void show_name(struct strbuf *sb, const struct name_decoration *decoratio
/*
* The caller makes sure there is no funny color before calling.
- * format_decorations_extended makes sure the same after return.
+ * format_decorations ensures the same after return.
*/
-void format_decorations_extended(struct strbuf *sb,
+void format_decorations(struct strbuf *sb,
const struct commit *commit,
int use_color,
- const char *prefix,
- const char *separator,
- const char *suffix)
+ const struct decoration_options *opts)
{
const struct name_decoration *decoration;
const struct name_decoration *current_and_HEAD;
- const char *color_commit =
- diff_get_color(use_color, DIFF_COMMIT);
- const char *color_reset =
- decorate_get_color(use_color, DECORATION_NONE);
+ const char *color_commit, *color_reset;
+
+ const char *prefix = " (";
+ const char *suffix = ")";
+ const char *separator = ", ";
+ const char *pointer = " -> ";
+ const char *tag = "tag: ";
decoration = get_name_decoration(&commit->object);
if (!decoration)
return;
+ if (opts) {
+ if (opts->prefix)
+ prefix = opts->prefix;
+ if (opts->suffix)
+ suffix = opts->suffix;
+ if (opts->separator)
+ separator = opts->separator;
+ if (opts->pointer)
+ pointer = opts->pointer;
+ if (opts->tag)
+ tag = opts->tag;
+ }
+
+ color_commit = diff_get_color(use_color, DIFF_COMMIT);
+ color_reset = decorate_get_color(use_color, DECORATION_NONE);
+
current_and_HEAD = current_pointed_by_HEAD(decoration);
while (decoration) {
/*
@@ -312,31 +349,44 @@ void format_decorations_extended(struct strbuf *sb,
* appeared, skipping the entry for current.
*/
if (decoration != current_and_HEAD) {
- strbuf_addstr(sb, color_commit);
- strbuf_addstr(sb, prefix);
- strbuf_addstr(sb, color_reset);
- strbuf_addstr(sb, decorate_get_color(use_color, decoration->type));
- if (decoration->type == DECORATION_REF_TAG)
- strbuf_addstr(sb, "tag: ");
+ const char *color =
+ decorate_get_color(use_color, decoration->type);
+
+ if (*prefix) {
+ strbuf_addstr(sb, color_commit);
+ strbuf_addstr(sb, prefix);
+ strbuf_addstr(sb, color_reset);
+ }
+
+ if (*tag && decoration->type == DECORATION_REF_TAG) {
+ strbuf_addstr(sb, color);
+ strbuf_addstr(sb, tag);
+ strbuf_addstr(sb, color_reset);
+ }
+ strbuf_addstr(sb, color);
show_name(sb, decoration);
+ strbuf_addstr(sb, color_reset);
if (current_and_HEAD &&
decoration->type == DECORATION_REF_HEAD) {
- strbuf_addstr(sb, " -> ");
+ strbuf_addstr(sb, color_commit);
+ strbuf_addstr(sb, pointer);
strbuf_addstr(sb, color_reset);
strbuf_addstr(sb, decorate_get_color(use_color, current_and_HEAD->type));
show_name(sb, current_and_HEAD);
+ strbuf_addstr(sb, color_reset);
}
- strbuf_addstr(sb, color_reset);
prefix = separator;
}
decoration = decoration->next;
}
- strbuf_addstr(sb, color_commit);
- strbuf_addstr(sb, suffix);
- strbuf_addstr(sb, color_reset);
+ if (*suffix) {
+ strbuf_addstr(sb, color_commit);
+ strbuf_addstr(sb, suffix);
+ strbuf_addstr(sb, color_reset);
+ }
}
void show_decorations(struct rev_info *opt, struct commit *commit)
@@ -351,7 +401,7 @@ void show_decorations(struct rev_info *opt, struct commit *commit)
}
if (!opt->show_decorations)
return;
- format_decorations(&sb, commit, opt->diffopt.use_color);
+ format_decorations(&sb, commit, opt->diffopt.use_color, NULL);
fputs(sb.buf, opt->diffopt.file);
strbuf_release(&sb);
}
@@ -397,7 +447,8 @@ void fmt_output_commit(struct strbuf *filename,
struct pretty_print_context ctx = {0};
struct strbuf subject = STRBUF_INIT;
- format_commit_message(commit, "%f", &subject, &ctx);
+ repo_format_commit_message(the_repository, commit, "%f", &subject,
+ &ctx);
fmt_output_subject(filename, subject.buf, info);
strbuf_release(&subject);
}
@@ -419,20 +470,23 @@ void fmt_output_email_subject(struct strbuf *sb, struct rev_info *opt)
}
void log_write_email_headers(struct rev_info *opt, struct commit *commit,
- const char **extra_headers_p,
+ char **extra_headers_p,
int *need_8bit_cte_p,
int maybe_multipart)
{
- const char *extra_headers = opt->extra_headers;
+ struct strbuf headers = STRBUF_INIT;
const char *name = oid_to_hex(opt->zero_commit ?
null_oid() : &commit->object.oid);
*need_8bit_cte_p = 0; /* unknown */
+ if (opt->extra_headers && *opt->extra_headers)
+ strbuf_addstr(&headers, opt->extra_headers);
+
fprintf(opt->diffopt.file, "From %s Mon Sep 17 00:00:00 2001\n", name);
graph_show_oneline(opt->graph);
if (opt->message_id) {
- fprintf(opt->diffopt.file, "Message-Id: <%s>\n", opt->message_id);
+ fprintf(opt->diffopt.file, "Message-ID: <%s>\n", opt->message_id);
graph_show_oneline(opt->graph);
}
if (opt->ref_message_ids && opt->ref_message_ids->nr > 0) {
@@ -445,16 +499,13 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
graph_show_oneline(opt->graph);
}
if (opt->mime_boundary && maybe_multipart) {
- static struct strbuf subject_buffer = STRBUF_INIT;
static struct strbuf buffer = STRBUF_INIT;
struct strbuf filename = STRBUF_INIT;
*need_8bit_cte_p = -1; /* NEVER */
- strbuf_reset(&subject_buffer);
strbuf_reset(&buffer);
- strbuf_addf(&subject_buffer,
- "%s"
+ strbuf_addf(&headers,
"MIME-Version: 1.0\n"
"Content-Type: multipart/mixed;"
" boundary=\"%s%s\"\n"
@@ -465,10 +516,8 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
"Content-Type: text/plain; "
"charset=UTF-8; format=fixed\n"
"Content-Transfer-Encoding: 8bit\n\n",
- extra_headers ? extra_headers : "",
mime_boundary_leader, opt->mime_boundary,
mime_boundary_leader, opt->mime_boundary);
- extra_headers = subject_buffer.buf;
if (opt->numbered_files)
strbuf_addf(&filename, "%d", opt->nr);
@@ -488,7 +537,7 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
opt->diffopt.stat_sep = buffer.buf;
strbuf_release(&filename);
}
- *extra_headers_p = extra_headers;
+ *extra_headers_p = headers.len ? strbuf_detach(&headers, NULL) : NULL;
}
static void show_sig_lines(struct rev_info *opt, int status, const char *bol)
@@ -627,7 +676,6 @@ void show_log(struct rev_info *opt)
struct log_info *log = opt->loginfo;
struct commit *commit = log->commit, *parent = log->parent;
int abbrev_commit = opt->abbrev_commit ? opt->abbrev : the_hash_algo->hexsz;
- const char *extra_headers = opt->extra_headers;
struct pretty_print_context ctx = {0};
opt->loginfo = NULL;
@@ -636,7 +684,8 @@ void show_log(struct rev_info *opt)
if (!opt->graph)
put_revision_mark(opt, commit);
- fputs(find_unique_abbrev(&commit->object.oid, abbrev_commit), opt->diffopt.file);
+ fputs(repo_find_unique_abbrev(the_repository, &commit->object.oid, abbrev_commit),
+ opt->diffopt.file);
if (opt->print_parents)
show_parents(commit, abbrev_commit, opt->diffopt.file);
if (opt->children.name)
@@ -687,10 +736,9 @@ void show_log(struct rev_info *opt)
*/
if (cmit_fmt_is_mail(opt->commit_format)) {
- log_write_email_headers(opt, commit, &extra_headers,
+ log_write_email_headers(opt, commit, &ctx.after_subject,
&ctx.need_8bit_cte, 1);
ctx.rev = opt;
- ctx.print_email_subject = 1;
} else if (opt->commit_format != CMIT_FMT_USERFORMAT) {
fputs(diff_get_color_opt(&opt->diffopt, DIFF_COMMIT), opt->diffopt.file);
if (opt->commit_format != CMIT_FMT_ONELINE)
@@ -698,8 +746,8 @@ void show_log(struct rev_info *opt)
if (!opt->graph)
put_revision_mark(opt, commit);
- fputs(find_unique_abbrev(&commit->object.oid,
- abbrev_commit),
+ fputs(repo_find_unique_abbrev(the_repository, &commit->object.oid,
+ abbrev_commit),
opt->diffopt.file);
if (opt->print_parents)
show_parents(commit, abbrev_commit, opt->diffopt.file);
@@ -707,7 +755,7 @@ void show_log(struct rev_info *opt)
show_children(opt, commit, abbrev_commit);
if (parent)
fprintf(opt->diffopt.file, " (from %s)",
- find_unique_abbrev(&parent->object.oid, abbrev_commit));
+ repo_find_unique_abbrev(the_repository, &parent->object.oid, abbrev_commit));
fputs(diff_get_color_opt(&opt->diffopt, DIFF_RESET), opt->diffopt.file);
show_decorations(opt, commit);
if (opt->commit_format == CMIT_FMT_ONELINE) {
@@ -725,7 +773,7 @@ void show_log(struct rev_info *opt)
*/
show_reflog_message(opt->reflog_info,
opt->commit_format == CMIT_FMT_ONELINE,
- &opt->date_mode,
+ opt->date_mode,
opt->date_mode_explicit);
if (opt->commit_format == CMIT_FMT_ONELINE)
return;
@@ -756,7 +804,6 @@ void show_log(struct rev_info *opt)
ctx.date_mode = opt->date_mode;
ctx.date_mode_explicit = opt->date_mode_explicit;
ctx.abbrev = opt->diffopt.abbrev;
- ctx.after_subject = extra_headers;
ctx.preserve_subject = opt->preserve_subject;
ctx.encode_email_headers = opt->encode_email_headers;
ctx.reflog_info = opt->reflog_info;
@@ -805,6 +852,7 @@ void show_log(struct rev_info *opt)
strbuf_release(&msgbuf);
free(ctx.notes_message);
+ free(ctx.after_subject);
if (cmit_fmt_is_mail(ctx.fmt) && opt->idiff_oid1) {
struct diff_queue_struct dq;
@@ -838,7 +886,7 @@ void show_log(struct rev_info *opt)
* Pass minimum required diff-options to range-diff; others
* can be added later if deemed desirable.
*/
- diff_setup(&opts);
+ repo_diff_setup(the_repository, &opts);
opts.file = opt->diffopt.file;
opts.use_color = opt->diffopt.use_color;
diff_setup_done(&opts);
@@ -956,11 +1004,10 @@ static void cleanup_additional_headers(struct diff_options *o)
static int do_remerge_diff(struct rev_info *opt,
struct commit_list *parents,
- struct object_id *oid,
- struct commit *commit)
+ struct object_id *oid)
{
struct merge_options o;
- struct commit_list *bases;
+ struct commit_list *bases = NULL;
struct merge_result res = {0};
struct pretty_print_context ctx = {0};
struct commit *parent1 = parents->item;
@@ -975,15 +1022,18 @@ static int do_remerge_diff(struct rev_info *opt,
o.msg_header_prefix = "remerge";
ctx.abbrev = DEFAULT_ABBREV;
- format_commit_message(parent1, "%h (%s)", &parent1_desc, &ctx);
- format_commit_message(parent2, "%h (%s)", &parent2_desc, &ctx);
+ repo_format_commit_message(the_repository, parent1, "%h (%s)",
+ &parent1_desc, &ctx);
+ repo_format_commit_message(the_repository, parent2, "%h (%s)",
+ &parent2_desc, &ctx);
o.branch1 = parent1_desc.buf;
o.branch2 = parent2_desc.buf;
/* Parse the relevant commits and get the merge bases */
parse_commit_or_die(parent1);
parse_commit_or_die(parent2);
- bases = get_merge_bases(parent1, parent2);
+ if (repo_get_merge_bases(the_repository, parent1, parent2, &bases) < 0)
+ exit(128);
/* Re-merge the parents */
merge_incore_recursive(&o, bases, parent1, parent2, &res);
@@ -1052,7 +1102,7 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
"for octopus merges.\n");
return 1;
}
- return do_remerge_diff(opt, parents, oid, commit);
+ return do_remerge_diff(opt, parents, oid);
}
if (opt->combine_merges)
return do_diff_combined(opt, commit);