author | Junio C Hamano <gitster@pobox.com> | |
Tue, 31 May 2011 19:19:11 +0000 (12:19 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Tue, 31 May 2011 19:19:11 +0000 (12:19 -0700) |
* jk/format-patch-am:
format-patch: preserve subject newlines with -k
clean up calling conventions for pretty.c functions
pretty: add pp_commit_easy function for simple callers
mailinfo: always clean up rfc822 header folding
t: test subject handling in format-patch / am pipeline
Conflicts:
builtin/branch.c
builtin/log.c
commit.h
format-patch: preserve subject newlines with -k
clean up calling conventions for pretty.c functions
pretty: add pp_commit_easy function for simple callers
mailinfo: always clean up rfc822 header folding
t: test subject handling in format-patch / am pipeline
Conflicts:
builtin/branch.c
builtin/log.c
commit.h
1 | 2 | |||
---|---|---|---|---|
builtin/branch.c | patch | | diff1 | | diff2 | | blob | history |
builtin/checkout.c | patch | | diff1 | | diff2 | | blob | history |
builtin/log.c | patch | | diff1 | | diff2 | | blob | history |
builtin/merge.c | patch | | diff1 | | diff2 | | blob | history |
builtin/rev-list.c | patch | | diff1 | | diff2 | | blob | history |
builtin/shortlog.c | patch | | diff1 | | diff2 | | blob | history |
builtin/show-branch.c | patch | | diff1 | | diff2 | | blob | history |
commit.h | patch | | diff1 | | diff2 | | blob | history |
log-tree.c | patch | | diff1 | | diff2 | | blob | history |
pretty.c | patch | | diff1 | | diff2 | | blob | history |
revision.h | patch | | diff1 | | diff2 | | blob | history |
diff --cc builtin/branch.c
index 9cca1b9afc20caf6333d0269386249f41fa8746f,d8f15221ed5b7f67875549685fe7aad92909a1d4..d6ab93bfbb369965e76e384e6984a29b667cdfbe
--- 1/builtin/branch.c
--- 2/builtin/branch.c
+++ b/builtin/branch.c
return (is_merged == (merge_filter == SHOW_MERGED));
}
- struct pretty_print_context ctx = {0};
- pretty_print_commit(CMIT_FMT_ONELINE, commit,
- &subject, &ctx);
+static void add_verbose_info(struct strbuf *out, struct ref_item *item,
+ int verbose, int abbrev)
+{
+ struct strbuf subject = STRBUF_INIT, stat = STRBUF_INIT;
+ const char *sub = " **** invalid ref ****";
+ struct commit *commit = item->commit;
+
+ if (commit && !parse_commit(commit)) {
++ pp_commit_easy(CMIT_FMT_ONELINE, commit, &subject);
+ sub = subject.buf;
+ }
+
+ if (item->kind == REF_LOCAL_BRANCH)
+ fill_tracking_info(&stat, item->name, verbose > 1);
+
+ strbuf_addf(out, " %s %s%s",
+ find_unique_abbrev(item->commit->object.sha1, abbrev),
+ stat.buf, sub);
+ strbuf_release(&stat);
+ strbuf_release(&subject);
+}
+
static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
int abbrev, int current, char *prefix)
{
diff --cc builtin/checkout.c
index 4761769512a8abcdd5652a93d39be18154e251dd,c1759dc3a44c7d4df4d9bed03f22ab7be8df2257..28cdc51b85e7d433dca085c0080f964d19a391b4
--- 1/builtin/checkout.c
--- 2/builtin/checkout.c
+++ b/builtin/checkout.c
run_diff_index(&rev, 0);
}
-static void describe_detached_head(char *msg, struct commit *commit)
+static void describe_detached_head(const char *msg, struct commit *commit)
{
struct strbuf sb = STRBUF_INIT;
- struct pretty_print_context ctx = {0};
parse_commit(commit);
- pretty_print_commit(CMIT_FMT_ONELINE, commit, &sb, &ctx);
+ pp_commit_easy(CMIT_FMT_ONELINE, commit, &sb);
fprintf(stderr, "%s %s... %s\n", msg,
find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV), sb.buf);
strbuf_release(&sb);
report_tracking(new);
}
- struct pretty_print_context ctx = { 0 };
-
+struct rev_list_args {
+ int argc;
+ int alloc;
+ const char **argv;
+};
+
+static void add_one_rev_list_arg(struct rev_list_args *args, const char *s)
+{
+ ALLOC_GROW(args->argv, args->argc + 1, args->alloc);
+ args->argv[args->argc++] = s;
+}
+
+static int add_one_ref_to_rev_list_arg(const char *refname,
+ const unsigned char *sha1,
+ int flags,
+ void *cb_data)
+{
+ add_one_rev_list_arg(cb_data, refname);
+ return 0;
+}
+
+static int clear_commit_marks_from_one_ref(const char *refname,
+ const unsigned char *sha1,
+ int flags,
+ void *cb_data)
+{
+ struct commit *commit = lookup_commit_reference_gently(sha1, 1);
+ if (commit)
+ clear_commit_marks(commit, -1);
+ return 0;
+}
+
+static void describe_one_orphan(struct strbuf *sb, struct commit *commit)
+{
- pretty_print_commit(CMIT_FMT_ONELINE, commit, sb, &ctx);
+ parse_commit(commit);
+ strbuf_addstr(sb, " ");
+ strbuf_addstr(sb,
+ find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV));
+ strbuf_addch(sb, ' ');
++ pp_commit_easy(CMIT_FMT_ONELINE, commit, sb);
+ strbuf_addch(sb, '\n');
+}
+
+#define ORPHAN_CUTOFF 4
+static void suggest_reattach(struct commit *commit, struct rev_info *revs)
+{
+ struct commit *c, *last = NULL;
+ struct strbuf sb = STRBUF_INIT;
+ int lost = 0;
+ while ((c = get_revision(revs)) != NULL) {
+ if (lost < ORPHAN_CUTOFF)
+ describe_one_orphan(&sb, c);
+ last = c;
+ lost++;
+ }
+ if (ORPHAN_CUTOFF < lost) {
+ int more = lost - ORPHAN_CUTOFF;
+ if (more == 1)
+ describe_one_orphan(&sb, last);
+ else
+ strbuf_addf(&sb, _(" ... and %d more.\n"), more);
+ }
+
+ fprintf(stderr,
+ Q_(
+ /* The singular version */
+ "Warning: you are leaving %d commit behind, "
+ "not connected to\n"
+ "any of your branches:\n\n"
+ "%s\n"
+ "If you want to keep it by creating a new branch, "
+ "this may be a good time\nto do so with:\n\n"
+ " git branch new_branch_name %s\n\n",
+ /* The plural version */
+ "Warning: you are leaving %d commits behind, "
+ "not connected to\n"
+ "any of your branches:\n\n"
+ "%s\n"
+ "If you want to keep them by creating a new branch, "
+ "this may be a good time\nto do so with:\n\n"
+ " git branch new_branch_name %s\n\n",
+ /* Give ngettext() the count */
+ lost),
+ lost,
+ sb.buf,
+ sha1_to_hex(commit->object.sha1));
+ strbuf_release(&sb);
+}
+
+/*
+ * We are about to leave commit that was at the tip of a detached
+ * HEAD. If it is not reachable from any ref, this is the last chance
+ * for the user to do so without resorting to reflog.
+ */
+static void orphaned_commit_warning(struct commit *commit)
+{
+ struct rev_list_args args = { 0, 0, NULL };
+ struct rev_info revs;
+
+ add_one_rev_list_arg(&args, "(internal)");
+ add_one_rev_list_arg(&args, sha1_to_hex(commit->object.sha1));
+ add_one_rev_list_arg(&args, "--not");
+ for_each_ref(add_one_ref_to_rev_list_arg, &args);
+ add_one_rev_list_arg(&args, "--");
+ add_one_rev_list_arg(&args, NULL);
+
+ init_revisions(&revs, NULL);
+ if (setup_revisions(args.argc - 1, args.argv, &revs, NULL) != 1)
+ die(_("internal error: only -- alone should have been left"));
+ if (prepare_revision_walk(&revs))
+ die(_("internal error in revision walk"));
+ if (!(commit->object.flags & UNINTERESTING))
+ suggest_reattach(commit, &revs);
+ else
+ describe_detached_head(_("Previous HEAD position was"), commit);
+
+ clear_commit_marks(commit, -1);
+ for_each_ref(clear_commit_marks_from_one_ref, NULL);
+}
+
static int switch_branches(struct checkout_opts *opts, struct branch_info *new)
{
int ret = 0;
diff --cc builtin/log.c
index 224b16792042c5633a2f1820082b3ca18d81e5fd,0e46e5ae95a6ebb33d98cfde7505b50ed1a51c4d..5c2af590047d92554d87acc5d7113a2f1f730a96
--- 1/builtin/log.c
--- 2/builtin/log.c
+++ b/builtin/log.c
static void make_cover_letter(struct rev_info *rev, int use_stdout,
int numbered, int numbered_files,
struct commit *origin,
- int nr, struct commit **list, struct commit *head)
+ int nr, struct commit **list, struct commit *head,
+ int quiet)
{
const char *committer;
- const char *subject_start = NULL;
const char *body = "*** SUBJECT HERE ***\n\n*** BLURB HERE ***\n";
const char *msg;
- const char *extra_headers = rev->extra_headers;
struct shortlog log;
struct strbuf sb = STRBUF_INIT;
int i;
struct diff_options opts;
int need_8bit_cte = 0;
struct commit *commit = NULL;
+ struct pretty_print_context pp = {0};
if (rev->commit_format != CMIT_FMT_EMAIL)
- die("Cover letter needs email format");
+ die(_("Cover letter needs email format"));
committer = git_committer_info(0);
numbered = 0;
if (numbered && keep_subject)
- die ("-n and -k are mutually exclusive.");
+ die (_("-n and -k are mutually exclusive."));
if (keep_subject && subject_prefix)
- die ("--subject-prefix and -k are mutually exclusive.");
+ die (_("--subject-prefix and -k are mutually exclusive."));
+ rev.preserve_subject = keep_subject;
argc = setup_revisions(argc, argv, &rev, &s_r_opt);
if (argc > 1)
NULL
};
- struct pretty_print_context ctx = {0};
- pretty_print_commit(CMIT_FMT_ONELINE, commit, &buf, &ctx);
+static void print_commit(char sign, struct commit *commit, int verbose,
+ int abbrev)
+{
+ if (!verbose) {
+ printf("%c %s\n", sign,
+ find_unique_abbrev(commit->object.sha1, abbrev));
+ } else {
+ struct strbuf buf = STRBUF_INIT;
++ pp_commit_easy(CMIT_FMT_ONELINE, commit, &buf);
+ printf("%c %s %s\n", sign,
+ find_unique_abbrev(commit->object.sha1, abbrev),
+ buf.buf);
+ strbuf_release(&buf);
+ }
+}
+
int cmd_cherry(int argc, const char **argv, const char *prefix)
{
struct rev_info revs;
diff --cc builtin/merge.c
index 5a2a1eb797c88990337f0b9cbb5dcabc73222a22,c902e81cf189c687652bb7752080438f51e15380..325891edb610945d01899b102993202af279bf3f
--- 1/builtin/merge.c
--- 2/builtin/merge.c
+++ b/builtin/merge.c
strbuf_addch(&out, '\n');
strbuf_addf(&out, "commit %s\n",
sha1_to_hex(commit->object.sha1));
- pretty_print_commit(rev.commit_format, commit, &out, &ctx);
+ pretty_print_commit(&ctx, commit, &out);
}
if (write(fd, out.buf, out.len) < 0)
- die_errno("Writing SQUASH_MSG");
+ die_errno(_("Writing SQUASH_MSG"));
if (close(fd))
- die_errno("Finishing SQUASH_MSG");
+ die_errno(_("Finishing SQUASH_MSG"));
strbuf_release(&out);
}
diff --cc builtin/rev-list.c
Simple merge
diff --cc builtin/shortlog.c
Simple merge
diff --cc builtin/show-branch.c
Simple merge
diff --cc commit.h
index 3114bd1781c3c5e735dfc1b1a7b4131270992f14,e985dcc6e5d3d0f19db8bd691d226d00b234ae98..a2d571b97410fa857b4c177325c4556dac50fe3f
+++ b/commit.h
CMIT_FMT_UNSPECIFIED
};
-struct pretty_print_context
-{
+struct pretty_print_context {
+ enum cmit_fmt fmt;
int abbrev;
const char *subject;
const char *after_subject;
diff --cc log-tree.c
Simple merge
diff --cc pretty.c
Simple merge
diff --cc revision.h
index 4499cebded6bc4348c0648a77d6e0dae4cf00acf,f8ddd83e79db99bfe93dee96696b6606916bd403..3d64adad18e2c889b7a7b7367f99c239f958dc70
--- 1/revision.h
--- 2/revision.h
+++ b/revision.h
show_notes_given:1,
pretty_given:1,
abbrev_commit:1,
+ abbrev_commit_given:1,
use_terminator:1,
missing_newline:1,
- date_mode_explicit:1;
+ date_mode_explicit:1,
+ preserve_subject:1;
unsigned int disable_stdin:1;
enum date_mode date_mode;