summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--builtin-diff.c2
-rw-r--r--builtin-log.c172
-rw-r--r--builtin-rev-list.c2
-rw-r--r--builtin-show-branch.c2
-rw-r--r--builtin.h1
-rw-r--r--cache.h1
-rw-r--r--commit.c44
-rw-r--r--commit.h3
-rw-r--r--date.c29
-rw-r--r--diff.c6
-rw-r--r--diff.h3
-rwxr-xr-xgit-format-patch.sh344
-rwxr-xr-xgit-rebase.sh2
-rw-r--r--git.c1
-rw-r--r--log-tree.c74
-rw-r--r--revision.h2
17 files changed, 319 insertions, 373 deletions
diff --git a/Makefile b/Makefile
index 3bfe1c3..7e6517f 100644
--- a/Makefile
+++ b/Makefile
@@ -116,7 +116,7 @@ SCRIPT_SH = \
git-bisect.sh git-branch.sh git-checkout.sh \
git-cherry.sh git-clean.sh git-clone.sh git-commit.sh \
git-fetch.sh \
- git-format-patch.sh git-ls-remote.sh \
+ git-ls-remote.sh \
git-merge-one-file.sh git-parse-remote.sh \
git-prune.sh git-pull.sh git-rebase.sh \
git-repack.sh git-request-pull.sh git-reset.sh \
@@ -170,7 +170,7 @@ BUILT_INS = git-log$X git-whatchanged$X git-show$X \
git-count-objects$X git-diff$X git-push$X \
git-grep$X git-add$X git-rm$X git-rev-list$X \
git-check-ref-format$X \
- git-init-db$X git-tar-tree$X git-upload-tar$X \
+ git-init-db$X git-tar-tree$X git-upload-tar$X git-format-patch$X \
git-ls-files$X git-ls-tree$X \
git-read-tree$X git-commit-tree$X \
git-apply$X git-show-branch$X git-diff-files$X \
diff --git a/builtin-diff.c b/builtin-diff.c
index de81b05..27451d5 100644
--- a/builtin-diff.c
+++ b/builtin-diff.c
@@ -233,7 +233,7 @@ static int builtin_diff_combined(struct rev_info *revs,
return 0;
}
-static void add_head(struct rev_info *revs)
+void add_head(struct rev_info *revs)
{
unsigned char sha1[20];
struct object *obj;
diff --git a/builtin-log.c b/builtin-log.c
index c4ceee0..c8feb0f 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -9,6 +9,10 @@
#include "diff.h"
#include "revision.h"
#include "log-tree.h"
+#include "builtin.h"
+
+/* this is in builtin-diff.c */
+void add_head(struct rev_info *revs);
static int cmd_log_wc(int argc, const char **argv, char **envp,
struct rev_info *rev)
@@ -74,3 +78,171 @@ int cmd_log(int argc, const char **argv, char **envp)
rev.diffopt.recursive = 1;
return cmd_log_wc(argc, argv, envp, &rev);
}
+
+static int istitlechar(char c)
+{
+ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
+ (c >= '0' && c <= '9') || c == '.' || c == '_';
+}
+
+static FILE *realstdout = NULL;
+static char *output_directory = NULL;
+
+static void reopen_stdout(struct commit *commit, int nr, int keep_subject)
+{
+ char filename[1024];
+ char *sol;
+ int len = 0;
+
+ if (output_directory) {
+ strncpy(filename, output_directory, 1010);
+ len = strlen(filename);
+ if (filename[len - 1] != '/')
+ filename[len++] = '/';
+ }
+
+ sprintf(filename + len, "%04d", nr);
+ len = strlen(filename);
+
+ sol = strstr(commit->buffer, "\n\n");
+ if (sol) {
+ int j, space = 1;
+
+ sol += 2;
+ /* strip [PATCH] or [PATCH blabla] */
+ if (!keep_subject && !strncmp(sol, "[PATCH", 6)) {
+ char *eos = strchr(sol + 6, ']');
+ if (eos) {
+ while (isspace(*eos))
+ eos++;
+ sol = eos;
+ }
+ }
+
+ for (j = 0; len < 1024 - 6 && sol[j] && sol[j] != '\n'; j++) {
+ if (istitlechar(sol[j])) {
+ if (space) {
+ filename[len++] = '-';
+ space = 0;
+ }
+ filename[len++] = sol[j];
+ if (sol[j] == '.')
+ while (sol[j + 1] == '.')
+ j++;
+ } else
+ space = 1;
+ }
+ while (filename[len - 1] == '.' || filename[len - 1] == '-')
+ len--;
+ }
+ strcpy(filename + len, ".txt");
+ fprintf(realstdout, "%s\n", filename);
+ freopen(filename, "w", stdout);
+}
+
+int cmd_format_patch(int argc, const char **argv, char **envp)
+{
+ struct commit *commit;
+ struct commit **list = NULL;
+ struct rev_info rev;
+ int nr = 0, total, i, j;
+ int use_stdout = 0;
+ int numbered = 0;
+ int keep_subject = 0;
+
+ init_revisions(&rev);
+ rev.commit_format = CMIT_FMT_EMAIL;
+ rev.verbose_header = 1;
+ rev.diff = 1;
+ rev.diffopt.with_raw = 0;
+ rev.diffopt.with_stat = 1;
+ rev.combine_merges = 0;
+ rev.ignore_merges = 1;
+ rev.diffopt.output_format = DIFF_FORMAT_PATCH;
+
+ /*
+ * Parse the arguments before setup_revisions(), or something
+ * like "git fmt-patch -o a123 HEAD^.." may fail; a123 is
+ * possibly a valid SHA1.
+ */
+ for (i = 1, j = 1; i < argc; i++) {
+ if (!strcmp(argv[i], "--stdout"))
+ use_stdout = 1;
+ else if (!strcmp(argv[i], "-n") ||
+ !strcmp(argv[i], "--numbered"))
+ numbered = 1;
+ else if (!strcmp(argv[i], "-k") ||
+ !strcmp(argv[i], "--keep-subject")) {
+ keep_subject = 1;
+ rev.total = -1;
+ } else if (!strcmp(argv[i], "-o")) {
+ if (argc < 3)
+ die ("Which directory?");
+ if (mkdir(argv[i + 1], 0777) < 0 && errno != EEXIST)
+ die("Could not create directory %s",
+ argv[i + 1]);
+ output_directory = strdup(argv[i + 1]);
+ i++;
+ }
+ else if (!strcmp(argv[i], "--attach"))
+ rev.mime_boundary = git_version_string;
+ else if (!strncmp(argv[i], "--attach=", 9))
+ rev.mime_boundary = argv[i] + 9;
+ else
+ argv[j++] = argv[i];
+ }
+ argc = j;
+
+ if (numbered && keep_subject < 0)
+ die ("-n and -k are mutually exclusive.");
+
+ argc = setup_revisions(argc, argv, &rev, "HEAD");
+ if (argc > 1)
+ die ("unrecognized argument: %s", argv[1]);
+
+ if (rev.pending_objects && rev.pending_objects->next == NULL) {
+ rev.pending_objects->item->flags |= UNINTERESTING;
+ add_head(&rev);
+ }
+
+ if (!use_stdout)
+ realstdout = fdopen(dup(1), "w");
+
+ prepare_revision_walk(&rev);
+ while ((commit = get_revision(&rev)) != NULL) {
+ /* ignore merges */
+ if (commit->parents && commit->parents->next)
+ continue;
+ nr++;
+ list = realloc(list, nr * sizeof(list[0]));
+ list[nr - 1] = commit;
+ }
+ total = nr;
+ if (numbered)
+ rev.total = total;
+ while (0 <= --nr) {
+ int shown;
+ commit = list[nr];
+ rev.nr = total - nr;
+ if (!use_stdout)
+ reopen_stdout(commit, rev.nr, keep_subject);
+ shown = log_tree_commit(&rev, commit);
+ free(commit->buffer);
+ commit->buffer = NULL;
+ if (shown) {
+ if (rev.mime_boundary)
+ printf("\n--%s%s--\n\n\n",
+ mime_boundary_leader,
+ rev.mime_boundary);
+ else
+ printf("-- \n%s\n\n", git_version_string);
+ }
+ if (!use_stdout)
+ fclose(stdout);
+ }
+ if (output_directory)
+ free(output_directory);
+ free(list);
+ return 0;
+}
+
diff --git a/builtin-rev-list.c b/builtin-rev-list.c
index 446802d..f11dbd6 100644
--- a/builtin-rev-list.c
+++ b/builtin-rev-list.c
@@ -85,7 +85,7 @@ static void show_commit(struct commit *commit)
static char pretty_header[16384];
pretty_print_commit(revs.commit_format, commit, ~0,
pretty_header, sizeof(pretty_header),
- revs.abbrev);
+ revs.abbrev, NULL, NULL);
printf("%s%c", pretty_header, hdr_termination);
}
fflush(stdout);
diff --git a/builtin-show-branch.c b/builtin-show-branch.c
index 3af24e7..2895140 100644
--- a/builtin-show-branch.c
+++ b/builtin-show-branch.c
@@ -260,7 +260,7 @@ static void show_one_commit(struct commit *commit, int no_name)
struct commit_name *name = commit->object.util;
if (commit->object.parsed)
pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0,
- pretty, sizeof(pretty), 0);
+ pretty, sizeof(pretty), 0, NULL, NULL);
else
strcpy(pretty, "(unavailable)");
if (!strncmp(pretty, "[PATCH] ", 8))
diff --git a/builtin.h b/builtin.h
index fa5e50e..714b975 100644
--- a/builtin.h
+++ b/builtin.h
@@ -20,6 +20,7 @@ extern int cmd_whatchanged(int argc, const char **argv, char **envp);
extern int cmd_show(int argc, const char **argv, char **envp);
extern int cmd_log(int argc, const char **argv, char **envp);
extern int cmd_diff(int argc, const char **argv, char **envp);
+extern int cmd_format_patch(int argc, const char **argv, char **envp);
extern int cmd_count_objects(int argc, const char **argv, char **envp);
extern int cmd_push(int argc, const char **argv, char **envp);
diff --git a/cache.h b/cache.h
index d8aa9e6..f625c8e 100644
--- a/cache.h
+++ b/cache.h
@@ -258,6 +258,7 @@ extern void *read_object_with_reference(const unsigned char *sha1,
unsigned char *sha1_ret);
const char *show_date(unsigned long time, int timezone);
+const char *show_rfc2822_date(unsigned long time, int timezone);
int parse_date(const char *date, char *buf, int bufsize);
void datestamp(char *buf, int bufsize);
unsigned long approxidate(const char *);
diff --git a/commit.c b/commit.c
index 4a26070..0b163d4 100644
--- a/commit.c
+++ b/commit.c
@@ -30,6 +30,7 @@ struct cmt_fmt_map {
{ "raw", 1, CMIT_FMT_RAW },
{ "medium", 1, CMIT_FMT_MEDIUM },
{ "short", 1, CMIT_FMT_SHORT },
+ { "email", 1, CMIT_FMT_EMAIL },
{ "full", 5, CMIT_FMT_FULL },
{ "fuller", 5, CMIT_FMT_FULLER },
{ "oneline", 1, CMIT_FMT_ONELINE },
@@ -438,6 +439,10 @@ static int add_user_info(const char *what, enum cmit_fmt fmt, char *buf, const c
time = strtoul(date, &date, 10);
tz = strtol(date, NULL, 10);
+ if (fmt == CMIT_FMT_EMAIL) {
+ what = "From";
+ filler = "";
+ }
ret = sprintf(buf, "%s: %.*s%.*s\n", what,
(fmt == CMIT_FMT_FULLER) ? 4 : 0,
filler, namelen, line);
@@ -445,6 +450,10 @@ static int add_user_info(const char *what, enum cmit_fmt fmt, char *buf, const c
case CMIT_FMT_MEDIUM:
ret += sprintf(buf + ret, "Date: %s\n", show_date(time, tz));
break;
+ case CMIT_FMT_EMAIL:
+ ret += sprintf(buf + ret, "Date: %s\n",
+ show_rfc2822_date(time, tz));
+ break;
case CMIT_FMT_FULLER:
ret += sprintf(buf + ret, "%sDate: %s\n", what, show_date(time, tz));
break;
@@ -455,10 +464,12 @@ static int add_user_info(const char *what, enum cmit_fmt fmt, char *buf, const c
return ret;
}
-static int is_empty_line(const char *line, int len)
+static int is_empty_line(const char *line, int *len_p)
{
+ int len = *len_p;
while (len && isspace(line[len-1]))
len--;
+ *len_p = len;
return !len;
}
@@ -467,7 +478,8 @@ static int add_merge_info(enum cmit_fmt fmt, char *buf, const struct commit *com
struct commit_list *parent = commit->parents;
int offset;
- if ((fmt == CMIT_FMT_ONELINE) || !parent || !parent->next)
+ if ((fmt == CMIT_FMT_ONELINE) || (fmt == CMIT_FMT_EMAIL) ||
+ !parent || !parent->next)
return 0;
offset = sprintf(buf, "Merge:");
@@ -486,14 +498,17 @@ static int add_merge_info(enum cmit_fmt fmt, char *buf, const struct commit *com
return offset;
}
-unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit, unsigned long len, char *buf, unsigned long space, int abbrev)
+unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit, unsigned long len, char *buf, unsigned long space, int abbrev, const char *subject, const char *after_subject)
{
int hdr = 1, body = 0;
unsigned long offset = 0;
- int indent = (fmt == CMIT_FMT_ONELINE) ? 0 : 4;
+ int indent = 4;
int parents_shown = 0;
const char *msg = commit->buffer;
+ if (fmt == CMIT_FMT_ONELINE || fmt == CMIT_FMT_EMAIL)
+ indent = 0;
+
for (;;) {
const char *line = msg;
int linelen = get_one_line(msg, len);
@@ -516,7 +531,7 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit
if (hdr) {
if (linelen == 1) {
hdr = 0;
- if (fmt != CMIT_FMT_ONELINE)
+ if ((fmt != CMIT_FMT_ONELINE) && !subject)
buf[offset++] = '\n';
continue;
}
@@ -554,20 +569,37 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit
continue;
}
- if (is_empty_line(line, linelen)) {
+ if (is_empty_line(line, &linelen)) {
if (!body)
continue;
+ if (subject)
+ continue;
if (fmt == CMIT_FMT_SHORT)
break;
} else {
body = 1;
}
+ if (subject) {
+ int slen = strlen(subject);
+ memcpy(buf + offset, subject, slen);
+ offset += slen;
+ }
memset(buf + offset, ' ', indent);
memcpy(buf + offset + indent, line, linelen);
offset += linelen + indent;
+ buf[offset++] = '\n';
if (fmt == CMIT_FMT_ONELINE)
break;
+ if (after_subject) {
+ int slen = strlen(after_subject);
+ if (slen > space - offset - 1)
+ slen = space - offset - 1;
+ memcpy(buf + offset, after_subject, slen);
+ offset += slen;
+ after_subject = NULL;
+ }
+ subject = NULL;
}
while (offset && isspace(buf[offset-1]))
offset--;
diff --git a/commit.h b/commit.h
index de142af..c9de167 100644
--- a/commit.h
+++ b/commit.h
@@ -45,12 +45,13 @@ enum cmit_fmt {
CMIT_FMT_FULL,
CMIT_FMT_FULLER,
CMIT_FMT_ONELINE,
+ CMIT_FMT_EMAIL,
CMIT_FMT_UNSPECIFIED,
};
extern enum cmit_fmt get_commit_format(const char *arg);
-extern unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *, unsigned long len, char *buf, unsigned long space, int abbrev);
+extern unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *, unsigned long len, char *buf, unsigned long space, int abbrev, const char *subject, const char *after_subject);
/** Removes the first commit from a list sorted by date, and adds all
* of its parents.
diff --git a/date.c b/date.c
index 034d722..365dc3b 100644
--- a/date.c
+++ b/date.c
@@ -42,18 +42,24 @@ static const char *weekday_names[] = {
* thing, which means that tz -0100 is passed in as the integer -100,
* even though it means "sixty minutes off"
*/
-const char *show_date(unsigned long time, int tz)
+static struct tm *time_to_tm(unsigned long time, int tz)
{
- struct tm *tm;
time_t t;
- static char timebuf[200];
int minutes;
minutes = tz < 0 ? -tz : tz;
minutes = (minutes / 100)*60 + (minutes % 100);
minutes = tz < 0 ? -minutes : minutes;
t = time + minutes * 60;
- tm = gmtime(&t);
+ return gmtime(&t);
+}
+
+const char *show_date(unsigned long time, int tz)
+{
+ struct tm *tm;
+ static char timebuf[200];
+
+ tm = time_to_tm(time, tz);
if (!tm)
return NULL;
sprintf(timebuf, "%.3s %.3s %d %02d:%02d:%02d %d %+05d",
@@ -65,6 +71,21 @@ const char *show_date(unsigned long time, int tz)
return timebuf;
}
+const char *show_rfc2822_date(unsigned long time, int tz)
+{
+ struct tm *tm;
+ static char timebuf[200];
+
+ tm = time_to_tm(time, tz);
+ if (!tm)
+ return NULL;
+ sprintf(timebuf, "%.3s, %d %.3s %d %02d:%02d:%02d %+05d",
+ weekday_names[tm->tm_wday], tm->tm_mday,
+ month_names[tm->tm_mon], tm->tm_year + 1900,
+ tm->tm_hour, tm->tm_min, tm->tm_sec, tz);
+ return timebuf;
+}
+
/*
* Check these. And note how it doesn't do the summer-time conversion.
*
diff --git a/diff.c b/diff.c
index 77c09a8..9e9cfc8 100644
--- a/diff.c
+++ b/diff.c
@@ -299,6 +299,7 @@ static void diffstat_consume(void *priv, char *line, unsigned long len)
static const char pluses[] = "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++";
static const char minuses[]= "----------------------------------------------------------------------";
+const char mime_boundary_leader[] = "------------";
static void show_stats(struct diffstat_t* data)
{
@@ -1991,7 +1992,10 @@ void diff_flush(struct diff_options *options)
if (options->summary)
for (i = 0; i < q->nr; i++)
diff_summary(q->queue[i]);
- putchar(options->line_termination);
+ if (options->stat_sep)
+ fputs(options->stat_sep, stdout);
+ else
+ putchar(options->line_termination);
}
for (i = 0; i < q->nr; i++) {
struct diff_filepair *p = q->queue[i];
diff --git a/diff.h b/diff.h
index c672277..4fc597c 100644
--- a/diff.h
+++ b/diff.h
@@ -44,6 +44,7 @@ struct diff_options {
int rename_limit;
int setup;
int abbrev;
+ const char *stat_sep;
int nr_paths;
const char **paths;
@@ -52,6 +53,8 @@ struct diff_options {
add_remove_fn_t add_remove;
};
+extern const char mime_boundary_leader[];
+
extern void diff_tree_setup_paths(const char **paths, struct diff_options *);
extern void diff_tree_release_paths(struct diff_options *);
extern int diff_tree(struct tree_desc *t1, struct tree_desc *t2,
diff --git a/git-format-patch.sh b/git-format-patch.sh
deleted file mode 100755
index 8a16ead..0000000
--- a/git-format-patch.sh
+++ /dev/null
@@ -1,344 +0,0 @@
-#!/bin/sh
-#
-# Copyright (c) 2005 Junio C Hamano
-#
-
-USAGE='[-n | -k] [-o <dir> | --stdout] [--signoff] [--check] [--diff-options] [--attach] <his> [<mine>]'
-LONG_USAGE='Prepare each commit with its patch since <mine> head forked from
-<his> head, one file per patch formatted to resemble UNIX mailbox
-format, for e-mail submission or use with git-am.
-
-Each output file is numbered sequentially from 1, and uses the
-first line of the commit message (massaged for pathname safety)
-as the filename.
-
-When -o is specified, output files are created in <dir>; otherwise
-they are created in the current working directory. This option
-is ignored if --stdout is specified.
-
-When -n is specified, instead of "[PATCH] Subject", the first
-line is formatted as "[PATCH N/M] Subject", unless you have only
-one patch.
-
-When --attach is specified, patches are attached, not inlined.'
-
-. git-sh-setup
-
-# Force diff to run in C locale.
-LANG=C LC_ALL=C
-export LANG LC_ALL
-
-diff_opts=
-LF='
-'
-
-outdir=./
-while case "$#" in 0) break;; esac
-do
- case "$1" in
- -c|--c|--ch|--che|--chec|--check)
- check=t ;;
- -a|--a|--au|--aut|--auth|--autho|--author|\
- -d|--d|--da|--dat|--date|\
- -m|--m|--mb|--mbo|--mbox) # now noop
- ;;
- --at|--att|--atta|--attac|--attach)
- attach=t ;;
- -k|--k|--ke|--kee|--keep|--keep-|--keep-s|--keep-su|--keep-sub|\
- --keep-subj|--keep-subje|--keep-subjec|--keep-subject)
- keep_subject=t ;;
- -n|--n|--nu|--num|--numb|--numbe|--number|--numbere|--numbered)
- numbered=t ;;
- -s|--s|--si|--sig|--sign|--signo|--signof|--signoff)
- signoff=t ;;
- --st|--std|--stdo|--stdou|--stdout)
- stdout=t ;;
- -o=*|--o=*|--ou=*|--out=*|--outp=*|--outpu=*|--output=*|--output-=*|\
- --output-d=*|--output-di=*|--output-dir=*|--output-dire=*|\
- --output-direc=*|--output-direct=*|--output-directo=*|\
- --output-director=*|--output-directory=*)
- outdir=`expr "$1" : '-[^=]*=\(.*\)'` ;;
- -o|--o|--ou|--out|--outp|--outpu|--output|--output-|--output-d|\
- --output-di|--output-dir|--output-dire|--output-direc|--output-direct|\
- --output-directo|--output-director|--output-directory)
- case "$#" in 1) usage ;; esac; shift
- outdir="$1" ;;
- -h|--h|--he|--hel|--help)
- usage
- ;;
- -*' '* | -*"$LF"* | -*' '*)
- # Ignore diff option that has whitespace for now.
- ;;
- -*) diff_opts="$diff_opts$1 " ;;
- *) break ;;
- esac
- shift
-done
-
-case "$keep_subject$numbered" in
-tt)
- die '--keep-subject and --numbered are incompatible.' ;;
-esac
-
-tmp=.tmp-series$$
-trap 'rm -f $tmp-*' 0 1 2 3 15
-
-series=$tmp-series
-commsg=$tmp-commsg
-filelist=$tmp-files
-
-# Backward compatible argument parsing hack.
-#
-# Historically, we supported:
-# 1. "rev1" is equivalent to "rev1..HEAD"
-# 2. "rev1..rev2"
-# 3. "rev1" "rev2 is equivalent to "rev1..rev2"
-#
-# We want to take a sequence of "rev1..rev2" in general.
-# Also, "rev1.." should mean "rev1..HEAD"; git-diff users are
-# familiar with that syntax.
-
-case "$#,$1$2" in
-1,?*..?*)
- # single "rev1..rev2"
- ;;
-1,?*..)
- # single "rev1.." should mean "rev1..HEAD"
- set x "$1"HEAD
- shift
- ;;
-1,*)
- # single rev1
- set x "$1..HEAD"
- shift
- ;;
-2,?*..?*)
- # not traditional "rev1" "rev2"
- ;;
-2,*)
- set x "$1..$2"
- shift
- ;;
-esac
-
-# Now we have what we want in $@
-for revpair
-do
- case "$revpair" in
- ?*..?*)
- rev1=`expr "z$revpair" : 'z\(.*\)\.\.'`
- rev2=`expr "z$revpair" : 'z.*\.\.\(.*\)'`
- ;;
- *)
- rev1="$revpair^"
- rev2="$revpair"
- ;;
- esac
- git-rev-parse --verify "$rev1^0" >/dev/null 2>&1 ||
- die "Not a valid rev $rev1 ($revpair)"
- git-rev-parse --verify "$rev2^0" >/dev/null 2>&1 ||
- die "Not a valid rev $rev2 ($revpair)"
- git-cherry -v "$rev1" "$rev2" |
- while read sign rev comment
- do
- case "$sign" in
- '-')
- echo >&2 "Merged already: $comment"
- ;;
- *)
- echo $rev
- ;;
- esac
- done
-done >$series
-
-me=`git-var GIT_AUTHOR_IDENT | sed -e 's/>.*/>/'`
-headers=`git-repo-config --get format.headers`
-case "$attach" in
-"") ;;
-*)
- mimemagic="050802040500080604070107"
-esac
-
-case "$outdir" in
-*/) ;;
-*) outdir="$outdir/" ;;
-esac
-test -d "$outdir" || mkdir -p "$outdir" || exit
-
-titleScript='
- /./d
- /^$/n
- s/^\[PATCH[^]]*\] *//
- s/[^-a-z.A-Z_0-9]/-/g
- s/\.\.\.*/\./g
- s/\.*$//
- s/--*/-/g
- s/^-//
- s/-$//
- s/$/./
- p
- q
-'
-
-process_one () {
- perl -w -e '
-my ($keep_subject, $num, $signoff, $headers, $mimemagic, $commsg) = @ARGV;
-my ($signoff_pattern, $done_header, $done_subject, $done_separator, $signoff_seen,
- $last_was_signoff);
-
-if ($signoff) {
- $signoff = "Signed-off-by: " . `git-var GIT_COMMITTER_IDENT`;
- $signoff =~ s/>.*/>/;
- $signoff_pattern = quotemeta($signoff);
-}
-
-my @weekday_names = qw(Sun Mon Tue Wed Thu Fri Sat);
-my @month_names = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
-
-sub show_date {
- my ($time, $tz) = @_;
- my $minutes = abs($tz);
- $minutes = int($minutes / 100) * 60 + ($minutes % 100);
- if ($tz < 0) {
- $minutes = -$minutes;
- }
- my $t = $time + $minutes * 60;
- my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = gmtime($t);
- return sprintf("%s, %d %s %d %02d:%02d:%02d %+05d",
- $weekday_names[$wday], $mday,
- $month_names[$mon], $year+1900,
- $hour, $min, $sec, $tz);
-}
-
-print "From nobody Mon Sep 17 00:00:00 2001\n";
-open FH, "git stripspace <$commsg |" or die "open $commsg pipe";
-while (<FH>) {
- unless ($done_header) {
- if (/^$/) {
- $done_header = 1;
- }
- elsif (/^author (.*>) (.*)$/) {
- my ($author_ident, $author_date) = ($1, $2);
- my ($utc, $off) = ($author_date =~ /^(\d+) ([-+]?\d+)$/);
- $author_date = show_date($utc, $off);
-
- print "From: $author_ident\n";
- print "Date: $author_date\n";
- }
- next;
- }
- unless ($done_subject) {
- unless ($keep_subject) {
- s/^\[PATCH[^]]*\]\s*//;
- s/^/[PATCH$num] /;
- }
- if ($headers) {
- print "$headers\n";
- }
- print "Subject: $_";
- if ($mimemagic) {
- print "MIME-Version: 1.0\n";
- print "Content-Type: multipart/mixed;\n";
- print " boundary=\"------------$mimemagic\"\n";
- print "\n";
- print "This is a multi-part message in MIME format.\n";
- print "--------------$mimemagic\n";
- print "Content-Type: text/plain; charset=UTF-8; format=fixed\n";
- print "Content-Transfer-Encoding: 8bit\n";
- }
- $done_subject = 1;
- next;
- }
- unless ($done_separator) {
- print "\n";
- $done_separator = 1;
- next if (/^$/);
- }
-
- $last_was_signoff = 0;
- if (/Signed-off-by:/i) {
- if ($signoff ne "" && /Signed-off-by:\s*$signoff_pattern$/i) {
- $signoff_seen = 1;
- }
- }
- print $_;
-}
-if (!$signoff_seen && $signoff ne "") {
- if (!$last_was_signoff) {
- print "\n";
- }
- print "$signoff\n";
-}
-print "\n---\n\n";
-close FH or die "close $commsg pipe";
-' "$keep_subject" "$num" "$signoff" "$headers" "$mimemagic" $commsg
-
- git-diff-tree -p --stat --summary $diff_opts "$commit"
- echo
- case "$mimemagic" in
- '');;
- *)
- echo "--------------$mimemagic"
- echo "Content-Type: text/x-patch;"
- echo " name=\"$commit.diff\""
- echo "Content-Transfer-Encoding: 8bit"
- echo "Content-Disposition: inline;"
- echo " filename=\"$commit.diff\""
- echo
- esac
- git-diff-tree -p $diff_opts "$commit"
- case "$mimemagic" in
- '')
- echo "-- "
- echo "@@GIT_VERSION@@"
- ;;
- *)
- echo
- echo "--------------$mimemagic--"
- echo
- ;;
- esac
- echo
-}
-
-total=`wc -l <$series | tr -dc "[0-9]"`
-case "$total,$numbered" in
-1,*)
- numfmt='' ;;
-*,t)
- numfmt=`echo "$total" | wc -c`
- numfmt=$(($numfmt-1))
- numfmt=" %0${numfmt}d/$total"
-esac
-
-i=1
-while read commit
-do
- git-cat-file commit "$commit" | git-stripspace >$commsg
- title=`sed -ne "$titleScript" <$commsg`
- case "$numbered" in
- '') num= ;;
- *)
- num=`printf "$numfmt" $i` ;;
- esac
-
- file=`printf '%04d-%stxt' $i "$title"`
- if test '' = "$stdout"
- then
- echo "$file"
- process_one >"$outdir$file"
- if test t = "$check"
- then
- # This is slightly modified from Andrew Morton's Perfect Patch.
- # Lines you introduce should not have trailing whitespace.
- # Also check for an indentation that has SP before a TAB.
- grep -n '^+\([ ]* .*\|.*[ ]\)$' "$outdir$file"
- :
- fi
- else
- echo >&2 "$file"
- process_one
- fi
- i=`expr "$i" + 1`
-done <$series
diff --git a/git-rebase.sh b/git-rebase.sh
index 6ff6088..e6b57b8 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -152,6 +152,6 @@ then
exit 0
fi
-git-format-patch -k --stdout --full-index "$upstream" ORIG_HEAD |
+git-format-patch -k --stdout --full-index "$upstream"..ORIG_HEAD |
git am --binary -3 -k --resolvemsg="$RESOLVEMSG"
diff --git a/git.c b/git.c
index 9ce458e..5a884bb 100644
--- a/git.c
+++ b/git.c
@@ -47,6 +47,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
{ "whatchanged", cmd_whatchanged },
{ "show", cmd_show },
{ "push", cmd_push },
+ { "format-patch", cmd_format_patch },
{ "count-objects", cmd_count_objects },
{ "diff", cmd_diff },
{ "grep", cmd_grep },
diff --git a/log-tree.c b/log-tree.c
index b90ba67..58b0163 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -20,6 +20,7 @@ void show_log(struct rev_info *opt, struct log_info *log, const char *sep)
int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40;
const char *extra;
int len;
+ char *subject = NULL, *after_subject = NULL;
opt->loginfo = NULL;
if (!opt->verbose_header) {
@@ -49,19 +50,67 @@ void show_log(struct rev_info *opt, struct log_info *log, const char *sep)
/*
* Print header line of header..
*/
- printf("%s%s",
- opt->commit_format == CMIT_FMT_ONELINE ? "" : "commit ",
- diff_unique_abbrev(commit->object.sha1, abbrev_commit));
- if (opt->parents)
- show_parents(commit, abbrev_commit);
- if (parent)
- printf(" (from %s)", diff_unique_abbrev(parent->object.sha1, abbrev_commit));
- putchar(opt->commit_format == CMIT_FMT_ONELINE ? ' ' : '\n');
+
+ if (opt->commit_format == CMIT_FMT_EMAIL) {
+ char *sha1 = sha1_to_hex(commit->object.sha1);
+ if (opt->total > 0) {
+ static char buffer[64];
+ snprintf(buffer, sizeof(buffer),
+ "Subject: [PATCH %d/%d] ",
+ opt->nr, opt->total);
+ subject = buffer;
+ } else if (opt->total == 0)
+ subject = "Subject: [PATCH] ";
+ else
+ subject = "Subject: ";
+
+ printf("From %s Mon Sep 17 00:00:00 2001\n", sha1);
+ if (opt->mime_boundary) {
+ static char subject_buffer[1024];
+ static char buffer[1024];
+ snprintf(subject_buffer, sizeof(subject_buffer) - 1,
+ "MIME-Version: 1.0\n"
+ "Content-Type: multipart/mixed;\n"
+ " boundary=\"%s%s\"\n"
+ "\n"
+ "This is a multi-part message in MIME "
+ "format.\n"
+ "--%s%s\n"
+ "Content-Type: text/plain; "
+ "charset=UTF-8; format=fixed\n"
+ "Content-Transfer-Encoding: 8bit\n\n",
+ mime_boundary_leader, opt->mime_boundary,
+ mime_boundary_leader, opt->mime_boundary);
+ after_subject = subject_buffer;
+
+ snprintf(buffer, sizeof(buffer) - 1,
+ "--%s%s\n"
+ "Content-Type: text/x-patch;\n"
+ " name=\"%s.diff\"\n"
+ "Content-Transfer-Encoding: 8bit\n"
+ "Content-Disposition: inline;\n"
+ " filename=\"%s.diff\"\n\n",
+ mime_boundary_leader, opt->mime_boundary,
+ sha1, sha1);
+ opt->diffopt.stat_sep = buffer;
+ }
+ } else {
+ printf("%s%s",
+ opt->commit_format == CMIT_FMT_ONELINE ? "" : "commit ",
+ diff_unique_abbrev(commit->object.sha1, abbrev_commit));
+ if (opt->parents)
+ show_parents(commit, abbrev_commit);
+ if (parent)
+ printf(" (from %s)",
+ diff_unique_abbrev(parent->object.sha1,
+ abbrev_commit));
+ putchar(opt->commit_format == CMIT_FMT_ONELINE ? ' ' : '\n');
+ }
/*
* And then the pretty-printed message itself
*/
- len = pretty_print_commit(opt->commit_format, commit, ~0u, this_header, sizeof(this_header), abbrev);
+ len = pretty_print_commit(opt->commit_format, commit, ~0u, this_header, sizeof(this_header), abbrev, subject, after_subject);
printf("%s%s%s", this_header, extra, sep);
}
@@ -166,15 +215,18 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
int log_tree_commit(struct rev_info *opt, struct commit *commit)
{
struct log_info log;
+ int shown;
log.commit = commit;
log.parent = NULL;
opt->loginfo = &log;
- if (!log_tree_diff(opt, commit, &log) && opt->loginfo && opt->always_show_header) {
+ shown = log_tree_diff(opt, commit, &log);
+ if (!shown && opt->loginfo && opt->always_show_header) {
log.parent = NULL;
show_log(opt, opt->loginfo, "");
+ shown = 1;
}
opt->loginfo = NULL;
- return 0;
+ return shown;
}
diff --git a/revision.h b/revision.h
index 48d7b4c..bdbdd23 100644
--- a/revision.h
+++ b/revision.h
@@ -58,6 +58,8 @@ struct rev_info {
unsigned int abbrev;
enum cmit_fmt commit_format;
struct log_info *loginfo;
+ int nr, total;
+ const char *mime_boundary;
/* special limits */
int max_count;