2006-04-09 10:11:11 +02:00
|
|
|
#include "cache.h"
|
|
|
|
#include "diff.h"
|
|
|
|
#include "commit.h"
|
|
|
|
#include "log-tree.h"
|
2007-01-11 11:47:48 +01:00
|
|
|
#include "reflog-walk.h"
|
2006-04-09 10:11:11 +02:00
|
|
|
|
2007-04-17 01:05:10 +02:00
|
|
|
struct decoration name_decoration = { "object names" };
|
|
|
|
|
2006-05-03 16:59:00 +02:00
|
|
|
static void show_parents(struct commit *commit, int abbrev)
|
|
|
|
{
|
|
|
|
struct commit_list *p;
|
|
|
|
for (p = commit->parents; p ; p = p->next) {
|
|
|
|
struct commit *parent = p->item;
|
|
|
|
printf(" %s", diff_unique_abbrev(parent->object.sha1, abbrev));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-22 07:47:56 +02:00
|
|
|
void show_decorations(struct commit *commit)
|
2007-04-17 01:05:10 +02:00
|
|
|
{
|
|
|
|
const char *prefix;
|
|
|
|
struct name_decoration *decoration;
|
|
|
|
|
|
|
|
decoration = lookup_decoration(&name_decoration, &commit->object);
|
|
|
|
if (!decoration)
|
|
|
|
return;
|
|
|
|
prefix = " (";
|
|
|
|
while (decoration) {
|
|
|
|
printf("%s%s", prefix, decoration->name);
|
|
|
|
prefix = ", ";
|
|
|
|
decoration = decoration->next;
|
|
|
|
}
|
|
|
|
putchar(')');
|
|
|
|
}
|
|
|
|
|
2006-08-29 13:37:06 +02:00
|
|
|
/*
|
|
|
|
* Search for "^[-A-Za-z]+: [^@]+@" pattern. It usually matches
|
|
|
|
* Signed-off-by: and Acked-by: lines.
|
|
|
|
*/
|
|
|
|
static int detect_any_signoff(char *letter, int size)
|
|
|
|
{
|
|
|
|
char ch, *cp;
|
|
|
|
int seen_colon = 0;
|
|
|
|
int seen_at = 0;
|
|
|
|
int seen_name = 0;
|
|
|
|
int seen_head = 0;
|
|
|
|
|
|
|
|
cp = letter + size;
|
|
|
|
while (letter <= --cp && (ch = *cp) == '\n')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
while (letter <= cp) {
|
|
|
|
ch = *cp--;
|
|
|
|
if (ch == '\n')
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!seen_at) {
|
|
|
|
if (ch == '@')
|
|
|
|
seen_at = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!seen_colon) {
|
|
|
|
if (ch == '@')
|
|
|
|
return 0;
|
|
|
|
else if (ch == ':')
|
|
|
|
seen_colon = 1;
|
|
|
|
else
|
|
|
|
seen_name = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (('A' <= ch && ch <= 'Z') ||
|
|
|
|
('a' <= ch && ch <= 'z') ||
|
|
|
|
ch == '-') {
|
|
|
|
seen_head = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* no empty last line doesn't match */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return seen_head && seen_name;
|
|
|
|
}
|
|
|
|
|
2007-09-10 12:35:06 +02:00
|
|
|
static void append_signoff(struct strbuf *sb, const char *signoff)
|
2006-06-01 00:11:49 +02:00
|
|
|
{
|
|
|
|
static const char signed_off_by[] = "Signed-off-by: ";
|
2007-06-11 09:34:54 +02:00
|
|
|
size_t signoff_len = strlen(signoff);
|
2006-08-29 13:37:06 +02:00
|
|
|
int has_signoff = 0;
|
2007-06-11 09:34:54 +02:00
|
|
|
char *cp;
|
2006-06-01 00:11:49 +02:00
|
|
|
|
2007-09-10 12:35:06 +02:00
|
|
|
cp = sb->buf;
|
2006-06-01 00:11:49 +02:00
|
|
|
|
|
|
|
/* First see if we already have the sign-off by the signer */
|
2006-08-29 13:37:06 +02:00
|
|
|
while ((cp = strstr(cp, signed_off_by))) {
|
|
|
|
|
|
|
|
has_signoff = 1;
|
|
|
|
|
2006-06-01 00:11:49 +02:00
|
|
|
cp += strlen(signed_off_by);
|
2007-09-10 12:35:06 +02:00
|
|
|
if (cp + signoff_len >= sb->buf + sb->len)
|
2006-08-29 13:37:06 +02:00
|
|
|
break;
|
|
|
|
if (strncmp(cp, signoff, signoff_len))
|
|
|
|
continue;
|
|
|
|
if (!isspace(cp[signoff_len]))
|
|
|
|
continue;
|
|
|
|
/* we already have him */
|
2007-09-10 12:35:06 +02:00
|
|
|
return;
|
2006-06-01 00:11:49 +02:00
|
|
|
}
|
|
|
|
|
2006-08-29 13:37:06 +02:00
|
|
|
if (!has_signoff)
|
2007-09-10 12:35:06 +02:00
|
|
|
has_signoff = detect_any_signoff(sb->buf, sb->len);
|
2006-08-29 13:37:06 +02:00
|
|
|
|
|
|
|
if (!has_signoff)
|
2007-09-10 12:35:06 +02:00
|
|
|
strbuf_addch(sb, '\n');
|
2006-08-13 20:30:27 +02:00
|
|
|
|
2007-09-10 12:35:06 +02:00
|
|
|
strbuf_addstr(sb, signed_off_by);
|
|
|
|
strbuf_add(sb, signoff, signoff_len);
|
|
|
|
strbuf_addch(sb, '\n');
|
2006-06-01 00:11:49 +02:00
|
|
|
}
|
|
|
|
|
2007-02-09 01:43:54 +01:00
|
|
|
static unsigned int digits_in_number(unsigned int number)
|
|
|
|
{
|
|
|
|
unsigned int i = 10, result = 1;
|
|
|
|
while (i <= number) {
|
|
|
|
i *= 10;
|
|
|
|
result++;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-10-31 22:55:17 +01:00
|
|
|
static int has_non_ascii(const char *s)
|
|
|
|
{
|
|
|
|
int ch;
|
|
|
|
if (!s)
|
|
|
|
return 0;
|
|
|
|
while ((ch = *s++) != '\0') {
|
|
|
|
if (non_ascii(ch))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-06-25 12:54:14 +02:00
|
|
|
void show_log(struct rev_info *opt, const char *sep)
|
Log message printout cleanups
On Sun, 16 Apr 2006, Junio C Hamano wrote:
>
> In the mid-term, I am hoping we can drop the generate_header()
> callchain _and_ the custom code that formats commit log in-core,
> found in cmd_log_wc().
Ok, this was nastier than expected, just because the dependencies between
the different log-printing stuff were absolutely _everywhere_, but here's
a patch that does exactly that.
The patch is not very easy to read, and the "--patch-with-stat" thing is
still broken (it does not call the "show_log()" thing properly for
merges). That's not a new bug. In the new world order it _should_ do
something like
if (rev->logopt)
show_log(rev, rev->logopt, "---\n");
but it doesn't. I haven't looked at the --with-stat logic, so I left it
alone.
That said, this patch removes more lines than it adds, and in particular,
the "cmd_log_wc()" loop is now a very clean:
while ((commit = get_revision(rev)) != NULL) {
log_tree_commit(rev, commit);
free(commit->buffer);
commit->buffer = NULL;
}
so it doesn't get much prettier than this. All the complexity is entirely
hidden in log-tree.c, and any code that needs to flush the log literally
just needs to do the "if (rev->logopt) show_log(...)" incantation.
I had to make the combined_diff() logic take a "struct rev_info" instead
of just a "struct diff_options", but that part is pretty clean.
This does change "git whatchanged" from using "diff-tree" as the commit
descriptor to "commit", and I changed one of the tests to reflect that new
reality. Otherwise everything still passes, and my other tests look fine
too.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-17 20:59:32 +02:00
|
|
|
{
|
2007-09-10 12:35:06 +02:00
|
|
|
struct strbuf msgbuf;
|
2006-06-25 12:54:14 +02:00
|
|
|
struct log_info *log = opt->loginfo;
|
Log message printout cleanups
On Sun, 16 Apr 2006, Junio C Hamano wrote:
>
> In the mid-term, I am hoping we can drop the generate_header()
> callchain _and_ the custom code that formats commit log in-core,
> found in cmd_log_wc().
Ok, this was nastier than expected, just because the dependencies between
the different log-printing stuff were absolutely _everywhere_, but here's
a patch that does exactly that.
The patch is not very easy to read, and the "--patch-with-stat" thing is
still broken (it does not call the "show_log()" thing properly for
merges). That's not a new bug. In the new world order it _should_ do
something like
if (rev->logopt)
show_log(rev, rev->logopt, "---\n");
but it doesn't. I haven't looked at the --with-stat logic, so I left it
alone.
That said, this patch removes more lines than it adds, and in particular,
the "cmd_log_wc()" loop is now a very clean:
while ((commit = get_revision(rev)) != NULL) {
log_tree_commit(rev, commit);
free(commit->buffer);
commit->buffer = NULL;
}
so it doesn't get much prettier than this. All the complexity is entirely
hidden in log-tree.c, and any code that needs to flush the log literally
just needs to do the "if (rev->logopt) show_log(...)" incantation.
I had to make the combined_diff() logic take a "struct rev_info" instead
of just a "struct diff_options", but that part is pretty clean.
This does change "git whatchanged" from using "diff-tree" as the commit
descriptor to "commit", and I changed one of the tests to reflect that new
reality. Otherwise everything still passes, and my other tests look fine
too.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-17 20:59:32 +02:00
|
|
|
struct commit *commit = log->commit, *parent = log->parent;
|
|
|
|
int abbrev = opt->diffopt.abbrev;
|
|
|
|
int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40;
|
Log message printout cleanups (#3): fix --pretty=oneline
This option is very special, since pretty_print_commit() will _remove_
the newline at the end of it, so we want to have an extra separator
between the things.
I added a honking big comment this time, so that (a) I don't forget this
_again_ (I broke "oneline" several times during this printout cleanup),
and so that people can understand _why_ the code does what it does.
Now, arguably the alternate fix is to always have the '\n' at the end in
pretty-print-commit, but git-rev-list depends on the current behaviour
(but we could have git-rev-list remove it, whatever).
With the big comment, the code hopefully doesn't get broken again. And now
things like
git log --pretty=oneline --cc --patch-with-stat
works (even if that is admittedly a totally insane combination: if you
want the patch, having the "oneline" log format is just crazy, but hey,
it _works_. Even insane people are people).
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-18 02:43:40 +02:00
|
|
|
const char *extra;
|
2006-06-02 15:21:17 +02:00
|
|
|
const char *subject = NULL, *extra_headers = opt->extra_headers;
|
Log message printout cleanups
On Sun, 16 Apr 2006, Junio C Hamano wrote:
>
> In the mid-term, I am hoping we can drop the generate_header()
> callchain _and_ the custom code that formats commit log in-core,
> found in cmd_log_wc().
Ok, this was nastier than expected, just because the dependencies between
the different log-printing stuff were absolutely _everywhere_, but here's
a patch that does exactly that.
The patch is not very easy to read, and the "--patch-with-stat" thing is
still broken (it does not call the "show_log()" thing properly for
merges). That's not a new bug. In the new world order it _should_ do
something like
if (rev->logopt)
show_log(rev, rev->logopt, "---\n");
but it doesn't. I haven't looked at the --with-stat logic, so I left it
alone.
That said, this patch removes more lines than it adds, and in particular,
the "cmd_log_wc()" loop is now a very clean:
while ((commit = get_revision(rev)) != NULL) {
log_tree_commit(rev, commit);
free(commit->buffer);
commit->buffer = NULL;
}
so it doesn't get much prettier than this. All the complexity is entirely
hidden in log-tree.c, and any code that needs to flush the log literally
just needs to do the "if (rev->logopt) show_log(...)" incantation.
I had to make the combined_diff() logic take a "struct rev_info" instead
of just a "struct diff_options", but that part is pretty clean.
This does change "git whatchanged" from using "diff-tree" as the commit
descriptor to "commit", and I changed one of the tests to reflect that new
reality. Otherwise everything still passes, and my other tests look fine
too.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-17 20:59:32 +02:00
|
|
|
|
|
|
|
opt->loginfo = NULL;
|
|
|
|
if (!opt->verbose_header) {
|
2006-12-17 00:31:25 +01:00
|
|
|
if (opt->left_right) {
|
|
|
|
if (commit->object.flags & BOUNDARY)
|
|
|
|
putchar('-');
|
|
|
|
else if (commit->object.flags & SYMMETRIC_LEFT)
|
|
|
|
putchar('<');
|
|
|
|
else
|
|
|
|
putchar('>');
|
|
|
|
}
|
2006-05-03 16:59:00 +02:00
|
|
|
fputs(diff_unique_abbrev(commit->object.sha1, abbrev_commit), stdout);
|
|
|
|
if (opt->parents)
|
|
|
|
show_parents(commit, abbrev_commit);
|
2007-04-17 01:05:10 +02:00
|
|
|
show_decorations(commit);
|
2006-08-07 14:11:23 +02:00
|
|
|
putchar(opt->diffopt.line_termination);
|
Log message printout cleanups
On Sun, 16 Apr 2006, Junio C Hamano wrote:
>
> In the mid-term, I am hoping we can drop the generate_header()
> callchain _and_ the custom code that formats commit log in-core,
> found in cmd_log_wc().
Ok, this was nastier than expected, just because the dependencies between
the different log-printing stuff were absolutely _everywhere_, but here's
a patch that does exactly that.
The patch is not very easy to read, and the "--patch-with-stat" thing is
still broken (it does not call the "show_log()" thing properly for
merges). That's not a new bug. In the new world order it _should_ do
something like
if (rev->logopt)
show_log(rev, rev->logopt, "---\n");
but it doesn't. I haven't looked at the --with-stat logic, so I left it
alone.
That said, this patch removes more lines than it adds, and in particular,
the "cmd_log_wc()" loop is now a very clean:
while ((commit = get_revision(rev)) != NULL) {
log_tree_commit(rev, commit);
free(commit->buffer);
commit->buffer = NULL;
}
so it doesn't get much prettier than this. All the complexity is entirely
hidden in log-tree.c, and any code that needs to flush the log literally
just needs to do the "if (rev->logopt) show_log(...)" incantation.
I had to make the combined_diff() logic take a "struct rev_info" instead
of just a "struct diff_options", but that part is pretty clean.
This does change "git whatchanged" from using "diff-tree" as the commit
descriptor to "commit", and I changed one of the tests to reflect that new
reality. Otherwise everything still passes, and my other tests look fine
too.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-17 20:59:32 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
Log message printout cleanups (#3): fix --pretty=oneline
This option is very special, since pretty_print_commit() will _remove_
the newline at the end of it, so we want to have an extra separator
between the things.
I added a honking big comment this time, so that (a) I don't forget this
_again_ (I broke "oneline" several times during this printout cleanup),
and so that people can understand _why_ the code does what it does.
Now, arguably the alternate fix is to always have the '\n' at the end in
pretty-print-commit, but git-rev-list depends on the current behaviour
(but we could have git-rev-list remove it, whatever).
With the big comment, the code hopefully doesn't get broken again. And now
things like
git log --pretty=oneline --cc --patch-with-stat
works (even if that is admittedly a totally insane combination: if you
want the patch, having the "oneline" log format is just crazy, but hey,
it _works_. Even insane people are people).
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-18 02:43:40 +02:00
|
|
|
* The "oneline" format has several special cases:
|
|
|
|
* - The pretty-printed commit lacks a newline at the end
|
|
|
|
* of the buffer, but we do want to make sure that we
|
|
|
|
* have a newline there. If the separator isn't already
|
|
|
|
* a newline, add an extra one.
|
|
|
|
* - unlike other log messages, the one-line format does
|
|
|
|
* not have an empty line between entries.
|
Log message printout cleanups
On Sun, 16 Apr 2006, Junio C Hamano wrote:
>
> In the mid-term, I am hoping we can drop the generate_header()
> callchain _and_ the custom code that formats commit log in-core,
> found in cmd_log_wc().
Ok, this was nastier than expected, just because the dependencies between
the different log-printing stuff were absolutely _everywhere_, but here's
a patch that does exactly that.
The patch is not very easy to read, and the "--patch-with-stat" thing is
still broken (it does not call the "show_log()" thing properly for
merges). That's not a new bug. In the new world order it _should_ do
something like
if (rev->logopt)
show_log(rev, rev->logopt, "---\n");
but it doesn't. I haven't looked at the --with-stat logic, so I left it
alone.
That said, this patch removes more lines than it adds, and in particular,
the "cmd_log_wc()" loop is now a very clean:
while ((commit = get_revision(rev)) != NULL) {
log_tree_commit(rev, commit);
free(commit->buffer);
commit->buffer = NULL;
}
so it doesn't get much prettier than this. All the complexity is entirely
hidden in log-tree.c, and any code that needs to flush the log literally
just needs to do the "if (rev->logopt) show_log(...)" incantation.
I had to make the combined_diff() logic take a "struct rev_info" instead
of just a "struct diff_options", but that part is pretty clean.
This does change "git whatchanged" from using "diff-tree" as the commit
descriptor to "commit", and I changed one of the tests to reflect that new
reality. Otherwise everything still passes, and my other tests look fine
too.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-17 20:59:32 +02:00
|
|
|
*/
|
Log message printout cleanups (#3): fix --pretty=oneline
This option is very special, since pretty_print_commit() will _remove_
the newline at the end of it, so we want to have an extra separator
between the things.
I added a honking big comment this time, so that (a) I don't forget this
_again_ (I broke "oneline" several times during this printout cleanup),
and so that people can understand _why_ the code does what it does.
Now, arguably the alternate fix is to always have the '\n' at the end in
pretty-print-commit, but git-rev-list depends on the current behaviour
(but we could have git-rev-list remove it, whatever).
With the big comment, the code hopefully doesn't get broken again. And now
things like
git log --pretty=oneline --cc --patch-with-stat
works (even if that is admittedly a totally insane combination: if you
want the patch, having the "oneline" log format is just crazy, but hey,
it _works_. Even insane people are people).
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-18 02:43:40 +02:00
|
|
|
extra = "";
|
|
|
|
if (*sep != '\n' && opt->commit_format == CMIT_FMT_ONELINE)
|
|
|
|
extra = "\n";
|
Log message printout cleanups
On Sun, 16 Apr 2006, Junio C Hamano wrote:
>
> In the mid-term, I am hoping we can drop the generate_header()
> callchain _and_ the custom code that formats commit log in-core,
> found in cmd_log_wc().
Ok, this was nastier than expected, just because the dependencies between
the different log-printing stuff were absolutely _everywhere_, but here's
a patch that does exactly that.
The patch is not very easy to read, and the "--patch-with-stat" thing is
still broken (it does not call the "show_log()" thing properly for
merges). That's not a new bug. In the new world order it _should_ do
something like
if (rev->logopt)
show_log(rev, rev->logopt, "---\n");
but it doesn't. I haven't looked at the --with-stat logic, so I left it
alone.
That said, this patch removes more lines than it adds, and in particular,
the "cmd_log_wc()" loop is now a very clean:
while ((commit = get_revision(rev)) != NULL) {
log_tree_commit(rev, commit);
free(commit->buffer);
commit->buffer = NULL;
}
so it doesn't get much prettier than this. All the complexity is entirely
hidden in log-tree.c, and any code that needs to flush the log literally
just needs to do the "if (rev->logopt) show_log(...)" incantation.
I had to make the combined_diff() logic take a "struct rev_info" instead
of just a "struct diff_options", but that part is pretty clean.
This does change "git whatchanged" from using "diff-tree" as the commit
descriptor to "commit", and I changed one of the tests to reflect that new
reality. Otherwise everything still passes, and my other tests look fine
too.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-17 20:59:32 +02:00
|
|
|
if (opt->shown_one && opt->commit_format != CMIT_FMT_ONELINE)
|
Fix "git log -z" behaviour
For commit messages, we should really put the "line_termination" when we
output the character in between different commits, *not* between the
commit and the diff. The diff goes hand-in-hand with the commit, it
shouldn't be separated from it with the termination character.
So this:
- uses the termination character for true inter-commit spacing
- uses a regular newline between the commit log and the diff
We had it the other way around.
For the normal case where the termination character is '\n', this
obviously doesn't change anything at all, since we just switched two
identical characters around. So it's very safe - it doesn't change any
normal usage, but it definitely fixes "git log -z".
By fixing "git log -z", you can now also do insane things like
git log -p -z |
grep -z "some patch expression" |
tr '\0' '\n' |
less -S
and you will see only those commits that have the "some patch expression"
in their commit message _or_ their patches.
(This is slightly different from 'git log -S"some patch expression"',
since the latter requires the expression to literally *change* in the
patch, while the "git log -p -z | grep .." approach will see it if it's
just an unchanged _part_ of the patch context)
Of course, if you actually do something like the above, you're probably
insane, but hey, it works!
Try the above command line for a demonstration (of course, you need to
change the "some patch expression" to be something relevant). The old
behaviour of "git log -p -z" was useless (and got things completely wrong
for log entries without patches).
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-07 20:49:56 +01:00
|
|
|
putchar(opt->diffopt.line_termination);
|
Log message printout cleanups
On Sun, 16 Apr 2006, Junio C Hamano wrote:
>
> In the mid-term, I am hoping we can drop the generate_header()
> callchain _and_ the custom code that formats commit log in-core,
> found in cmd_log_wc().
Ok, this was nastier than expected, just because the dependencies between
the different log-printing stuff were absolutely _everywhere_, but here's
a patch that does exactly that.
The patch is not very easy to read, and the "--patch-with-stat" thing is
still broken (it does not call the "show_log()" thing properly for
merges). That's not a new bug. In the new world order it _should_ do
something like
if (rev->logopt)
show_log(rev, rev->logopt, "---\n");
but it doesn't. I haven't looked at the --with-stat logic, so I left it
alone.
That said, this patch removes more lines than it adds, and in particular,
the "cmd_log_wc()" loop is now a very clean:
while ((commit = get_revision(rev)) != NULL) {
log_tree_commit(rev, commit);
free(commit->buffer);
commit->buffer = NULL;
}
so it doesn't get much prettier than this. All the complexity is entirely
hidden in log-tree.c, and any code that needs to flush the log literally
just needs to do the "if (rev->logopt) show_log(...)" incantation.
I had to make the combined_diff() logic take a "struct rev_info" instead
of just a "struct diff_options", but that part is pretty clean.
This does change "git whatchanged" from using "diff-tree" as the commit
descriptor to "commit", and I changed one of the tests to reflect that new
reality. Otherwise everything still passes, and my other tests look fine
too.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-17 20:59:32 +02:00
|
|
|
opt->shown_one = 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print header line of header..
|
|
|
|
*/
|
2006-04-19 01:45:27 +02:00
|
|
|
|
2006-05-05 04:30:52 +02:00
|
|
|
if (opt->commit_format == CMIT_FMT_EMAIL) {
|
2006-05-20 15:40:29 +02:00
|
|
|
char *sha1 = sha1_to_hex(commit->object.sha1);
|
2006-05-05 04:30:52 +02:00
|
|
|
if (opt->total > 0) {
|
|
|
|
static char buffer[64];
|
|
|
|
snprintf(buffer, sizeof(buffer),
|
2007-04-12 01:58:07 +02:00
|
|
|
"Subject: [%s %0*d/%d] ",
|
|
|
|
opt->subject_prefix,
|
2007-02-09 01:43:54 +01:00
|
|
|
digits_in_number(opt->total),
|
2006-05-05 04:30:52 +02:00
|
|
|
opt->nr, opt->total);
|
|
|
|
subject = buffer;
|
2007-07-04 12:33:46 +02:00
|
|
|
} else if (opt->total == 0 && opt->subject_prefix && *opt->subject_prefix) {
|
2007-04-12 01:58:07 +02:00
|
|
|
static char buffer[256];
|
|
|
|
snprintf(buffer, sizeof(buffer),
|
|
|
|
"Subject: [%s] ",
|
|
|
|
opt->subject_prefix);
|
|
|
|
subject = buffer;
|
|
|
|
} else {
|
2006-05-05 04:31:29 +02:00
|
|
|
subject = "Subject: ";
|
2007-04-12 01:58:07 +02:00
|
|
|
}
|
2006-05-05 04:31:29 +02:00
|
|
|
|
2006-05-20 15:40:29 +02:00
|
|
|
printf("From %s Mon Sep 17 00:00:00 2001\n", sha1);
|
2006-07-15 02:48:51 +02:00
|
|
|
if (opt->message_id)
|
|
|
|
printf("Message-Id: <%s>\n", opt->message_id);
|
|
|
|
if (opt->ref_message_id)
|
|
|
|
printf("In-Reply-To: <%s>\nReferences: <%s>\n",
|
|
|
|
opt->ref_message_id, opt->ref_message_id);
|
2006-05-20 15:40:29 +02:00
|
|
|
if (opt->mime_boundary) {
|
|
|
|
static char subject_buffer[1024];
|
|
|
|
static char buffer[1024];
|
|
|
|
snprintf(subject_buffer, sizeof(subject_buffer) - 1,
|
2006-06-02 15:21:17 +02:00
|
|
|
"%s"
|
2006-05-20 15:40:29 +02:00
|
|
|
"MIME-Version: 1.0\n"
|
2007-03-05 01:08:04 +01:00
|
|
|
"Content-Type: multipart/mixed;"
|
2006-05-20 15:40:29 +02:00
|
|
|
" 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",
|
2006-06-02 15:21:17 +02:00
|
|
|
extra_headers ? extra_headers : "",
|
2006-05-20 15:40:29 +02:00
|
|
|
mime_boundary_leader, opt->mime_boundary,
|
|
|
|
mime_boundary_leader, opt->mime_boundary);
|
2006-06-02 15:21:17 +02:00
|
|
|
extra_headers = subject_buffer;
|
2006-05-20 15:40:29 +02:00
|
|
|
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1,
|
|
|
|
"--%s%s\n"
|
2007-03-05 01:08:04 +01:00
|
|
|
"Content-Type: text/x-patch;"
|
2006-05-20 15:40:29 +02:00
|
|
|
" name=\"%s.diff\"\n"
|
|
|
|
"Content-Transfer-Encoding: 8bit\n"
|
2007-03-05 01:08:04 +01:00
|
|
|
"Content-Disposition: %s;"
|
2006-05-20 15:40:29 +02:00
|
|
|
" filename=\"%s.diff\"\n\n",
|
|
|
|
mime_boundary_leader, opt->mime_boundary,
|
2007-03-04 00:12:06 +01:00
|
|
|
sha1,
|
|
|
|
opt->no_inline ? "attachment" : "inline",
|
|
|
|
sha1);
|
2006-05-20 15:40:29 +02:00
|
|
|
opt->diffopt.stat_sep = buffer;
|
|
|
|
}
|
2007-02-23 01:35:03 +01:00
|
|
|
} else if (opt->commit_format != CMIT_FMT_USERFORMAT) {
|
2007-11-10 20:05:14 +01:00
|
|
|
fputs(diff_get_color_opt(&opt->diffopt, DIFF_COMMIT), stdout);
|
2006-12-17 00:31:25 +01:00
|
|
|
if (opt->commit_format != CMIT_FMT_ONELINE)
|
|
|
|
fputs("commit ", stdout);
|
2007-05-06 00:18:03 +02:00
|
|
|
if (commit->object.flags & BOUNDARY)
|
|
|
|
putchar('-');
|
|
|
|
else if (opt->left_right) {
|
|
|
|
if (commit->object.flags & SYMMETRIC_LEFT)
|
2006-12-17 00:31:25 +01:00
|
|
|
putchar('<');
|
|
|
|
else
|
|
|
|
putchar('>');
|
|
|
|
}
|
|
|
|
fputs(diff_unique_abbrev(commit->object.sha1, abbrev_commit),
|
|
|
|
stdout);
|
2006-05-06 23:42:08 +02:00
|
|
|
if (opt->parents)
|
|
|
|
show_parents(commit, abbrev_commit);
|
2006-05-24 21:19:47 +02:00
|
|
|
if (parent)
|
2006-04-19 01:45:27 +02:00
|
|
|
printf(" (from %s)",
|
|
|
|
diff_unique_abbrev(parent->object.sha1,
|
|
|
|
abbrev_commit));
|
2007-04-17 01:05:10 +02:00
|
|
|
show_decorations(commit);
|
2007-11-10 20:05:14 +01:00
|
|
|
printf("%s", diff_get_color_opt(&opt->diffopt, DIFF_RESET));
|
2006-07-24 14:41:41 +02:00
|
|
|
putchar(opt->commit_format == CMIT_FMT_ONELINE ? ' ' : '\n');
|
2007-01-28 04:40:36 +01:00
|
|
|
if (opt->reflog_info) {
|
2007-01-20 09:51:41 +01:00
|
|
|
show_reflog_message(opt->reflog_info,
|
2007-02-08 21:58:33 +01:00
|
|
|
opt->commit_format == CMIT_FMT_ONELINE,
|
2007-04-25 08:36:22 +02:00
|
|
|
opt->date_mode);
|
2007-01-28 04:40:36 +01:00
|
|
|
if (opt->commit_format == CMIT_FMT_ONELINE) {
|
|
|
|
printf("%s", sep);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2006-04-19 01:45:27 +02:00
|
|
|
}
|
Log message printout cleanups
On Sun, 16 Apr 2006, Junio C Hamano wrote:
>
> In the mid-term, I am hoping we can drop the generate_header()
> callchain _and_ the custom code that formats commit log in-core,
> found in cmd_log_wc().
Ok, this was nastier than expected, just because the dependencies between
the different log-printing stuff were absolutely _everywhere_, but here's
a patch that does exactly that.
The patch is not very easy to read, and the "--patch-with-stat" thing is
still broken (it does not call the "show_log()" thing properly for
merges). That's not a new bug. In the new world order it _should_ do
something like
if (rev->logopt)
show_log(rev, rev->logopt, "---\n");
but it doesn't. I haven't looked at the --with-stat logic, so I left it
alone.
That said, this patch removes more lines than it adds, and in particular,
the "cmd_log_wc()" loop is now a very clean:
while ((commit = get_revision(rev)) != NULL) {
log_tree_commit(rev, commit);
free(commit->buffer);
commit->buffer = NULL;
}
so it doesn't get much prettier than this. All the complexity is entirely
hidden in log-tree.c, and any code that needs to flush the log literally
just needs to do the "if (rev->logopt) show_log(...)" incantation.
I had to make the combined_diff() logic take a "struct rev_info" instead
of just a "struct diff_options", but that part is pretty clean.
This does change "git whatchanged" from using "diff-tree" as the commit
descriptor to "commit", and I changed one of the tests to reflect that new
reality. Otherwise everything still passes, and my other tests look fine
too.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-17 20:59:32 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* And then the pretty-printed message itself
|
|
|
|
*/
|
2007-09-10 12:35:06 +02:00
|
|
|
strbuf_init(&msgbuf, 0);
|
|
|
|
pretty_print_commit(opt->commit_format, commit, &msgbuf,
|
2007-10-31 22:55:17 +01:00
|
|
|
abbrev, subject, extra_headers, opt->date_mode,
|
|
|
|
has_non_ascii(opt->add_signoff));
|
2006-06-01 00:11:49 +02:00
|
|
|
|
|
|
|
if (opt->add_signoff)
|
2007-09-10 12:35:06 +02:00
|
|
|
append_signoff(&msgbuf, opt->add_signoff);
|
2007-07-20 20:15:13 +02:00
|
|
|
if (opt->show_log_size)
|
2007-09-10 12:35:06 +02:00
|
|
|
printf("log size %i\n", (int)msgbuf.len);
|
2007-07-20 20:15:13 +02:00
|
|
|
|
2007-10-03 13:28:24 +02:00
|
|
|
if (msgbuf.len)
|
|
|
|
printf("%s%s%s", msgbuf.buf, extra, sep);
|
2007-09-10 12:35:06 +02:00
|
|
|
strbuf_release(&msgbuf);
|
Log message printout cleanups
On Sun, 16 Apr 2006, Junio C Hamano wrote:
>
> In the mid-term, I am hoping we can drop the generate_header()
> callchain _and_ the custom code that formats commit log in-core,
> found in cmd_log_wc().
Ok, this was nastier than expected, just because the dependencies between
the different log-printing stuff were absolutely _everywhere_, but here's
a patch that does exactly that.
The patch is not very easy to read, and the "--patch-with-stat" thing is
still broken (it does not call the "show_log()" thing properly for
merges). That's not a new bug. In the new world order it _should_ do
something like
if (rev->logopt)
show_log(rev, rev->logopt, "---\n");
but it doesn't. I haven't looked at the --with-stat logic, so I left it
alone.
That said, this patch removes more lines than it adds, and in particular,
the "cmd_log_wc()" loop is now a very clean:
while ((commit = get_revision(rev)) != NULL) {
log_tree_commit(rev, commit);
free(commit->buffer);
commit->buffer = NULL;
}
so it doesn't get much prettier than this. All the complexity is entirely
hidden in log-tree.c, and any code that needs to flush the log literally
just needs to do the "if (rev->logopt) show_log(...)" incantation.
I had to make the combined_diff() logic take a "struct rev_info" instead
of just a "struct diff_options", but that part is pretty clean.
This does change "git whatchanged" from using "diff-tree" as the commit
descriptor to "commit", and I changed one of the tests to reflect that new
reality. Otherwise everything still passes, and my other tests look fine
too.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-17 20:59:32 +02:00
|
|
|
}
|
|
|
|
|
Common option parsing for "git log --diff" and friends
This basically does a few things that are sadly somewhat interdependent,
and nontrivial to split out
- get rid of "struct log_tree_opt"
The fields in "log_tree_opt" are moved into "struct rev_info", and all
users of log_tree_opt are changed to use the rev_info struct instead.
- add the parsing for the log_tree_opt arguments to "setup_revision()"
- make setup_revision set a flag (revs->diff) if the diff-related
arguments were used. This allows "git log" to decide whether it wants
to show diffs or not.
- make setup_revision() also initialize the diffopt part of rev_info
(which we had from before, but we just didn't initialize it)
- make setup_revision() do all the "finishing touches" on it all (it will
do the proper flag combination logic, and call "diff_setup_done()")
Now, that was the easy and straightforward part.
The slightly more involved part is that some of the programs that want to
use the new-and-improved rev_info parsing don't actually want _commits_,
they may want tree'ish arguments instead. That meant that I had to change
setup_revision() to parse the arguments not into the "revs->commits" list,
but into the "revs->pending_objects" list.
Then, when we do "prepare_revision_walk()", we walk that list, and create
the sorted commit list from there.
This actually cleaned some stuff up, but it's the less obvious part of the
patch, and re-organized the "revision.c" logic somewhat. It actually paves
the way for splitting argument parsing _entirely_ out of "revision.c",
since now the argument parsing really is totally independent of the commit
walking: that didn't use to be true, since there was lots of overlap with
get_commit_reference() handling etc, now the _only_ overlap is the shared
(and trivial) "add_pending_object()" thing.
However, I didn't do that file split, just because I wanted the diff
itself to be smaller, and show the actual changes more clearly. If this
gets accepted, I'll do further cleanups then - that includes the file
split, but also using the new infrastructure to do a nicer "git diff" etc.
Even in this form, it actually ends up removing more lines than it adds.
It's nice to note how simple and straightforward this makes the built-in
"git log" command, even though it continues to support all the diff flags
too. It doesn't get much simpler that this.
I think this is worth merging soonish, because it does allow for future
cleanup and even more sharing of code. However, it obviously touches
"revision.c", which is subtle. I've tested that it passes all the tests we
have, and it passes my "looks sane" detector, but somebody else should
also give it a good look-over.
[jc: squashed the original and three "oops this too" updates, with
another fix-up.]
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-15 01:52:13 +02:00
|
|
|
int log_tree_diff_flush(struct rev_info *opt)
|
2006-04-09 10:11:11 +02:00
|
|
|
{
|
|
|
|
diffcore_std(&opt->diffopt);
|
Log message printout cleanups
On Sun, 16 Apr 2006, Junio C Hamano wrote:
>
> In the mid-term, I am hoping we can drop the generate_header()
> callchain _and_ the custom code that formats commit log in-core,
> found in cmd_log_wc().
Ok, this was nastier than expected, just because the dependencies between
the different log-printing stuff were absolutely _everywhere_, but here's
a patch that does exactly that.
The patch is not very easy to read, and the "--patch-with-stat" thing is
still broken (it does not call the "show_log()" thing properly for
merges). That's not a new bug. In the new world order it _should_ do
something like
if (rev->logopt)
show_log(rev, rev->logopt, "---\n");
but it doesn't. I haven't looked at the --with-stat logic, so I left it
alone.
That said, this patch removes more lines than it adds, and in particular,
the "cmd_log_wc()" loop is now a very clean:
while ((commit = get_revision(rev)) != NULL) {
log_tree_commit(rev, commit);
free(commit->buffer);
commit->buffer = NULL;
}
so it doesn't get much prettier than this. All the complexity is entirely
hidden in log-tree.c, and any code that needs to flush the log literally
just needs to do the "if (rev->logopt) show_log(...)" incantation.
I had to make the combined_diff() logic take a "struct rev_info" instead
of just a "struct diff_options", but that part is pretty clean.
This does change "git whatchanged" from using "diff-tree" as the commit
descriptor to "commit", and I changed one of the tests to reflect that new
reality. Otherwise everything still passes, and my other tests look fine
too.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-17 20:59:32 +02:00
|
|
|
|
2006-04-09 10:11:11 +02:00
|
|
|
if (diff_queue_is_empty()) {
|
|
|
|
int saved_fmt = opt->diffopt.output_format;
|
|
|
|
opt->diffopt.output_format = DIFF_FORMAT_NO_OUTPUT;
|
|
|
|
diff_flush(&opt->diffopt);
|
|
|
|
opt->diffopt.output_format = saved_fmt;
|
|
|
|
return 0;
|
|
|
|
}
|
Log message printout cleanups
On Sun, 16 Apr 2006, Junio C Hamano wrote:
>
> In the mid-term, I am hoping we can drop the generate_header()
> callchain _and_ the custom code that formats commit log in-core,
> found in cmd_log_wc().
Ok, this was nastier than expected, just because the dependencies between
the different log-printing stuff were absolutely _everywhere_, but here's
a patch that does exactly that.
The patch is not very easy to read, and the "--patch-with-stat" thing is
still broken (it does not call the "show_log()" thing properly for
merges). That's not a new bug. In the new world order it _should_ do
something like
if (rev->logopt)
show_log(rev, rev->logopt, "---\n");
but it doesn't. I haven't looked at the --with-stat logic, so I left it
alone.
That said, this patch removes more lines than it adds, and in particular,
the "cmd_log_wc()" loop is now a very clean:
while ((commit = get_revision(rev)) != NULL) {
log_tree_commit(rev, commit);
free(commit->buffer);
commit->buffer = NULL;
}
so it doesn't get much prettier than this. All the complexity is entirely
hidden in log-tree.c, and any code that needs to flush the log literally
just needs to do the "if (rev->logopt) show_log(...)" incantation.
I had to make the combined_diff() logic take a "struct rev_info" instead
of just a "struct diff_options", but that part is pretty clean.
This does change "git whatchanged" from using "diff-tree" as the commit
descriptor to "commit", and I changed one of the tests to reflect that new
reality. Otherwise everything still passes, and my other tests look fine
too.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-17 20:59:32 +02:00
|
|
|
|
2006-06-28 00:08:19 +02:00
|
|
|
if (opt->loginfo && !opt->no_commit_id) {
|
|
|
|
/* When showing a verbose header (i.e. log message),
|
|
|
|
* and not in --pretty=oneline format, we would want
|
|
|
|
* an extra newline between the end of log and the
|
|
|
|
* output for readability.
|
|
|
|
*/
|
2006-06-25 12:54:14 +02:00
|
|
|
show_log(opt, opt->diffopt.msg_sep);
|
2007-10-09 18:35:22 +02:00
|
|
|
if ((opt->diffopt.output_format & ~DIFF_FORMAT_NO_OUTPUT) &&
|
|
|
|
opt->verbose_header &&
|
2006-06-28 00:08:19 +02:00
|
|
|
opt->commit_format != CMIT_FMT_ONELINE) {
|
|
|
|
int pch = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_PATCH;
|
|
|
|
if ((pch & opt->diffopt.output_format) == pch)
|
Fix "git log -z" behaviour
For commit messages, we should really put the "line_termination" when we
output the character in between different commits, *not* between the
commit and the diff. The diff goes hand-in-hand with the commit, it
shouldn't be separated from it with the termination character.
So this:
- uses the termination character for true inter-commit spacing
- uses a regular newline between the commit log and the diff
We had it the other way around.
For the normal case where the termination character is '\n', this
obviously doesn't change anything at all, since we just switched two
identical characters around. So it's very safe - it doesn't change any
normal usage, but it definitely fixes "git log -z".
By fixing "git log -z", you can now also do insane things like
git log -p -z |
grep -z "some patch expression" |
tr '\0' '\n' |
less -S
and you will see only those commits that have the "some patch expression"
in their commit message _or_ their patches.
(This is slightly different from 'git log -S"some patch expression"',
since the latter requires the expression to literally *change* in the
patch, while the "git log -p -z | grep .." approach will see it if it's
just an unchanged _part_ of the patch context)
Of course, if you actually do something like the above, you're probably
insane, but hey, it works!
Try the above command line for a demonstration (of course, you need to
change the "some patch expression" to be something relevant). The old
behaviour of "git log -p -z" was useless (and got things completely wrong
for log entries without patches).
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-07 20:49:56 +01:00
|
|
|
printf("---");
|
|
|
|
putchar('\n');
|
2006-06-28 00:08:19 +02:00
|
|
|
}
|
|
|
|
}
|
2006-04-09 10:11:11 +02:00
|
|
|
diff_flush(&opt->diffopt);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
Common option parsing for "git log --diff" and friends
This basically does a few things that are sadly somewhat interdependent,
and nontrivial to split out
- get rid of "struct log_tree_opt"
The fields in "log_tree_opt" are moved into "struct rev_info", and all
users of log_tree_opt are changed to use the rev_info struct instead.
- add the parsing for the log_tree_opt arguments to "setup_revision()"
- make setup_revision set a flag (revs->diff) if the diff-related
arguments were used. This allows "git log" to decide whether it wants
to show diffs or not.
- make setup_revision() also initialize the diffopt part of rev_info
(which we had from before, but we just didn't initialize it)
- make setup_revision() do all the "finishing touches" on it all (it will
do the proper flag combination logic, and call "diff_setup_done()")
Now, that was the easy and straightforward part.
The slightly more involved part is that some of the programs that want to
use the new-and-improved rev_info parsing don't actually want _commits_,
they may want tree'ish arguments instead. That meant that I had to change
setup_revision() to parse the arguments not into the "revs->commits" list,
but into the "revs->pending_objects" list.
Then, when we do "prepare_revision_walk()", we walk that list, and create
the sorted commit list from there.
This actually cleaned some stuff up, but it's the less obvious part of the
patch, and re-organized the "revision.c" logic somewhat. It actually paves
the way for splitting argument parsing _entirely_ out of "revision.c",
since now the argument parsing really is totally independent of the commit
walking: that didn't use to be true, since there was lots of overlap with
get_commit_reference() handling etc, now the _only_ overlap is the shared
(and trivial) "add_pending_object()" thing.
However, I didn't do that file split, just because I wanted the diff
itself to be smaller, and show the actual changes more clearly. If this
gets accepted, I'll do further cleanups then - that includes the file
split, but also using the new infrastructure to do a nicer "git diff" etc.
Even in this form, it actually ends up removing more lines than it adds.
It's nice to note how simple and straightforward this makes the built-in
"git log" command, even though it continues to support all the diff flags
too. It doesn't get much simpler that this.
I think this is worth merging soonish, because it does allow for future
cleanup and even more sharing of code. However, it obviously touches
"revision.c", which is subtle. I've tested that it passes all the tests we
have, and it passes my "looks sane" detector, but somebody else should
also give it a good look-over.
[jc: squashed the original and three "oops this too" updates, with
another fix-up.]
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-15 01:52:13 +02:00
|
|
|
static int do_diff_combined(struct rev_info *opt, struct commit *commit)
|
2006-04-09 10:11:11 +02:00
|
|
|
{
|
|
|
|
unsigned const char *sha1 = commit->object.sha1;
|
|
|
|
|
Log message printout cleanups
On Sun, 16 Apr 2006, Junio C Hamano wrote:
>
> In the mid-term, I am hoping we can drop the generate_header()
> callchain _and_ the custom code that formats commit log in-core,
> found in cmd_log_wc().
Ok, this was nastier than expected, just because the dependencies between
the different log-printing stuff were absolutely _everywhere_, but here's
a patch that does exactly that.
The patch is not very easy to read, and the "--patch-with-stat" thing is
still broken (it does not call the "show_log()" thing properly for
merges). That's not a new bug. In the new world order it _should_ do
something like
if (rev->logopt)
show_log(rev, rev->logopt, "---\n");
but it doesn't. I haven't looked at the --with-stat logic, so I left it
alone.
That said, this patch removes more lines than it adds, and in particular,
the "cmd_log_wc()" loop is now a very clean:
while ((commit = get_revision(rev)) != NULL) {
log_tree_commit(rev, commit);
free(commit->buffer);
commit->buffer = NULL;
}
so it doesn't get much prettier than this. All the complexity is entirely
hidden in log-tree.c, and any code that needs to flush the log literally
just needs to do the "if (rev->logopt) show_log(...)" incantation.
I had to make the combined_diff() logic take a "struct rev_info" instead
of just a "struct diff_options", but that part is pretty clean.
This does change "git whatchanged" from using "diff-tree" as the commit
descriptor to "commit", and I changed one of the tests to reflect that new
reality. Otherwise everything still passes, and my other tests look fine
too.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-17 20:59:32 +02:00
|
|
|
diff_tree_combined_merge(sha1, opt->dense_combined_merges, opt);
|
|
|
|
return !opt->loginfo;
|
2006-04-09 10:11:11 +02:00
|
|
|
}
|
|
|
|
|
Log message printout cleanups
On Sun, 16 Apr 2006, Junio C Hamano wrote:
>
> In the mid-term, I am hoping we can drop the generate_header()
> callchain _and_ the custom code that formats commit log in-core,
> found in cmd_log_wc().
Ok, this was nastier than expected, just because the dependencies between
the different log-printing stuff were absolutely _everywhere_, but here's
a patch that does exactly that.
The patch is not very easy to read, and the "--patch-with-stat" thing is
still broken (it does not call the "show_log()" thing properly for
merges). That's not a new bug. In the new world order it _should_ do
something like
if (rev->logopt)
show_log(rev, rev->logopt, "---\n");
but it doesn't. I haven't looked at the --with-stat logic, so I left it
alone.
That said, this patch removes more lines than it adds, and in particular,
the "cmd_log_wc()" loop is now a very clean:
while ((commit = get_revision(rev)) != NULL) {
log_tree_commit(rev, commit);
free(commit->buffer);
commit->buffer = NULL;
}
so it doesn't get much prettier than this. All the complexity is entirely
hidden in log-tree.c, and any code that needs to flush the log literally
just needs to do the "if (rev->logopt) show_log(...)" incantation.
I had to make the combined_diff() logic take a "struct rev_info" instead
of just a "struct diff_options", but that part is pretty clean.
This does change "git whatchanged" from using "diff-tree" as the commit
descriptor to "commit", and I changed one of the tests to reflect that new
reality. Otherwise everything still passes, and my other tests look fine
too.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-17 20:59:32 +02:00
|
|
|
/*
|
|
|
|
* Show the diff of a commit.
|
|
|
|
*
|
|
|
|
* Return true if we printed any log info messages
|
|
|
|
*/
|
|
|
|
static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log_info *log)
|
2006-04-09 10:11:11 +02:00
|
|
|
{
|
Log message printout cleanups
On Sun, 16 Apr 2006, Junio C Hamano wrote:
>
> In the mid-term, I am hoping we can drop the generate_header()
> callchain _and_ the custom code that formats commit log in-core,
> found in cmd_log_wc().
Ok, this was nastier than expected, just because the dependencies between
the different log-printing stuff were absolutely _everywhere_, but here's
a patch that does exactly that.
The patch is not very easy to read, and the "--patch-with-stat" thing is
still broken (it does not call the "show_log()" thing properly for
merges). That's not a new bug. In the new world order it _should_ do
something like
if (rev->logopt)
show_log(rev, rev->logopt, "---\n");
but it doesn't. I haven't looked at the --with-stat logic, so I left it
alone.
That said, this patch removes more lines than it adds, and in particular,
the "cmd_log_wc()" loop is now a very clean:
while ((commit = get_revision(rev)) != NULL) {
log_tree_commit(rev, commit);
free(commit->buffer);
commit->buffer = NULL;
}
so it doesn't get much prettier than this. All the complexity is entirely
hidden in log-tree.c, and any code that needs to flush the log literally
just needs to do the "if (rev->logopt) show_log(...)" incantation.
I had to make the combined_diff() logic take a "struct rev_info" instead
of just a "struct diff_options", but that part is pretty clean.
This does change "git whatchanged" from using "diff-tree" as the commit
descriptor to "commit", and I changed one of the tests to reflect that new
reality. Otherwise everything still passes, and my other tests look fine
too.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-17 20:59:32 +02:00
|
|
|
int showed_log;
|
2006-04-09 10:11:11 +02:00
|
|
|
struct commit_list *parents;
|
|
|
|
unsigned const char *sha1 = commit->object.sha1;
|
|
|
|
|
Log message printout cleanups
On Sun, 16 Apr 2006, Junio C Hamano wrote:
>
> In the mid-term, I am hoping we can drop the generate_header()
> callchain _and_ the custom code that formats commit log in-core,
> found in cmd_log_wc().
Ok, this was nastier than expected, just because the dependencies between
the different log-printing stuff were absolutely _everywhere_, but here's
a patch that does exactly that.
The patch is not very easy to read, and the "--patch-with-stat" thing is
still broken (it does not call the "show_log()" thing properly for
merges). That's not a new bug. In the new world order it _should_ do
something like
if (rev->logopt)
show_log(rev, rev->logopt, "---\n");
but it doesn't. I haven't looked at the --with-stat logic, so I left it
alone.
That said, this patch removes more lines than it adds, and in particular,
the "cmd_log_wc()" loop is now a very clean:
while ((commit = get_revision(rev)) != NULL) {
log_tree_commit(rev, commit);
free(commit->buffer);
commit->buffer = NULL;
}
so it doesn't get much prettier than this. All the complexity is entirely
hidden in log-tree.c, and any code that needs to flush the log literally
just needs to do the "if (rev->logopt) show_log(...)" incantation.
I had to make the combined_diff() logic take a "struct rev_info" instead
of just a "struct diff_options", but that part is pretty clean.
This does change "git whatchanged" from using "diff-tree" as the commit
descriptor to "commit", and I changed one of the tests to reflect that new
reality. Otherwise everything still passes, and my other tests look fine
too.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-17 20:59:32 +02:00
|
|
|
if (!opt->diff)
|
|
|
|
return 0;
|
|
|
|
|
2006-04-09 10:11:11 +02:00
|
|
|
/* Root commit? */
|
Log message printout cleanups
On Sun, 16 Apr 2006, Junio C Hamano wrote:
>
> In the mid-term, I am hoping we can drop the generate_header()
> callchain _and_ the custom code that formats commit log in-core,
> found in cmd_log_wc().
Ok, this was nastier than expected, just because the dependencies between
the different log-printing stuff were absolutely _everywhere_, but here's
a patch that does exactly that.
The patch is not very easy to read, and the "--patch-with-stat" thing is
still broken (it does not call the "show_log()" thing properly for
merges). That's not a new bug. In the new world order it _should_ do
something like
if (rev->logopt)
show_log(rev, rev->logopt, "---\n");
but it doesn't. I haven't looked at the --with-stat logic, so I left it
alone.
That said, this patch removes more lines than it adds, and in particular,
the "cmd_log_wc()" loop is now a very clean:
while ((commit = get_revision(rev)) != NULL) {
log_tree_commit(rev, commit);
free(commit->buffer);
commit->buffer = NULL;
}
so it doesn't get much prettier than this. All the complexity is entirely
hidden in log-tree.c, and any code that needs to flush the log literally
just needs to do the "if (rev->logopt) show_log(...)" incantation.
I had to make the combined_diff() logic take a "struct rev_info" instead
of just a "struct diff_options", but that part is pretty clean.
This does change "git whatchanged" from using "diff-tree" as the commit
descriptor to "commit", and I changed one of the tests to reflect that new
reality. Otherwise everything still passes, and my other tests look fine
too.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-17 20:59:32 +02:00
|
|
|
parents = commit->parents;
|
|
|
|
if (!parents) {
|
2006-10-26 18:52:39 +02:00
|
|
|
if (opt->show_root_diff) {
|
|
|
|
diff_root_tree_sha1(sha1, "", &opt->diffopt);
|
|
|
|
log_tree_diff_flush(opt);
|
|
|
|
}
|
Log message printout cleanups
On Sun, 16 Apr 2006, Junio C Hamano wrote:
>
> In the mid-term, I am hoping we can drop the generate_header()
> callchain _and_ the custom code that formats commit log in-core,
> found in cmd_log_wc().
Ok, this was nastier than expected, just because the dependencies between
the different log-printing stuff were absolutely _everywhere_, but here's
a patch that does exactly that.
The patch is not very easy to read, and the "--patch-with-stat" thing is
still broken (it does not call the "show_log()" thing properly for
merges). That's not a new bug. In the new world order it _should_ do
something like
if (rev->logopt)
show_log(rev, rev->logopt, "---\n");
but it doesn't. I haven't looked at the --with-stat logic, so I left it
alone.
That said, this patch removes more lines than it adds, and in particular,
the "cmd_log_wc()" loop is now a very clean:
while ((commit = get_revision(rev)) != NULL) {
log_tree_commit(rev, commit);
free(commit->buffer);
commit->buffer = NULL;
}
so it doesn't get much prettier than this. All the complexity is entirely
hidden in log-tree.c, and any code that needs to flush the log literally
just needs to do the "if (rev->logopt) show_log(...)" incantation.
I had to make the combined_diff() logic take a "struct rev_info" instead
of just a "struct diff_options", but that part is pretty clean.
This does change "git whatchanged" from using "diff-tree" as the commit
descriptor to "commit", and I changed one of the tests to reflect that new
reality. Otherwise everything still passes, and my other tests look fine
too.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-17 20:59:32 +02:00
|
|
|
return !opt->loginfo;
|
2006-04-09 10:11:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* More than one parent? */
|
Log message printout cleanups
On Sun, 16 Apr 2006, Junio C Hamano wrote:
>
> In the mid-term, I am hoping we can drop the generate_header()
> callchain _and_ the custom code that formats commit log in-core,
> found in cmd_log_wc().
Ok, this was nastier than expected, just because the dependencies between
the different log-printing stuff were absolutely _everywhere_, but here's
a patch that does exactly that.
The patch is not very easy to read, and the "--patch-with-stat" thing is
still broken (it does not call the "show_log()" thing properly for
merges). That's not a new bug. In the new world order it _should_ do
something like
if (rev->logopt)
show_log(rev, rev->logopt, "---\n");
but it doesn't. I haven't looked at the --with-stat logic, so I left it
alone.
That said, this patch removes more lines than it adds, and in particular,
the "cmd_log_wc()" loop is now a very clean:
while ((commit = get_revision(rev)) != NULL) {
log_tree_commit(rev, commit);
free(commit->buffer);
commit->buffer = NULL;
}
so it doesn't get much prettier than this. All the complexity is entirely
hidden in log-tree.c, and any code that needs to flush the log literally
just needs to do the "if (rev->logopt) show_log(...)" incantation.
I had to make the combined_diff() logic take a "struct rev_info" instead
of just a "struct diff_options", but that part is pretty clean.
This does change "git whatchanged" from using "diff-tree" as the commit
descriptor to "commit", and I changed one of the tests to reflect that new
reality. Otherwise everything still passes, and my other tests look fine
too.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-17 20:59:32 +02:00
|
|
|
if (parents && parents->next) {
|
2006-04-09 10:11:11 +02:00
|
|
|
if (opt->ignore_merges)
|
|
|
|
return 0;
|
|
|
|
else if (opt->combine_merges)
|
|
|
|
return do_diff_combined(opt, commit);
|
Log message printout cleanups
On Sun, 16 Apr 2006, Junio C Hamano wrote:
>
> In the mid-term, I am hoping we can drop the generate_header()
> callchain _and_ the custom code that formats commit log in-core,
> found in cmd_log_wc().
Ok, this was nastier than expected, just because the dependencies between
the different log-printing stuff were absolutely _everywhere_, but here's
a patch that does exactly that.
The patch is not very easy to read, and the "--patch-with-stat" thing is
still broken (it does not call the "show_log()" thing properly for
merges). That's not a new bug. In the new world order it _should_ do
something like
if (rev->logopt)
show_log(rev, rev->logopt, "---\n");
but it doesn't. I haven't looked at the --with-stat logic, so I left it
alone.
That said, this patch removes more lines than it adds, and in particular,
the "cmd_log_wc()" loop is now a very clean:
while ((commit = get_revision(rev)) != NULL) {
log_tree_commit(rev, commit);
free(commit->buffer);
commit->buffer = NULL;
}
so it doesn't get much prettier than this. All the complexity is entirely
hidden in log-tree.c, and any code that needs to flush the log literally
just needs to do the "if (rev->logopt) show_log(...)" incantation.
I had to make the combined_diff() logic take a "struct rev_info" instead
of just a "struct diff_options", but that part is pretty clean.
This does change "git whatchanged" from using "diff-tree" as the commit
descriptor to "commit", and I changed one of the tests to reflect that new
reality. Otherwise everything still passes, and my other tests look fine
too.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-17 20:59:32 +02:00
|
|
|
|
|
|
|
/* If we show individual diffs, show the parent info */
|
|
|
|
log->parent = parents->item;
|
2006-04-09 10:11:11 +02:00
|
|
|
}
|
|
|
|
|
Log message printout cleanups
On Sun, 16 Apr 2006, Junio C Hamano wrote:
>
> In the mid-term, I am hoping we can drop the generate_header()
> callchain _and_ the custom code that formats commit log in-core,
> found in cmd_log_wc().
Ok, this was nastier than expected, just because the dependencies between
the different log-printing stuff were absolutely _everywhere_, but here's
a patch that does exactly that.
The patch is not very easy to read, and the "--patch-with-stat" thing is
still broken (it does not call the "show_log()" thing properly for
merges). That's not a new bug. In the new world order it _should_ do
something like
if (rev->logopt)
show_log(rev, rev->logopt, "---\n");
but it doesn't. I haven't looked at the --with-stat logic, so I left it
alone.
That said, this patch removes more lines than it adds, and in particular,
the "cmd_log_wc()" loop is now a very clean:
while ((commit = get_revision(rev)) != NULL) {
log_tree_commit(rev, commit);
free(commit->buffer);
commit->buffer = NULL;
}
so it doesn't get much prettier than this. All the complexity is entirely
hidden in log-tree.c, and any code that needs to flush the log literally
just needs to do the "if (rev->logopt) show_log(...)" incantation.
I had to make the combined_diff() logic take a "struct rev_info" instead
of just a "struct diff_options", but that part is pretty clean.
This does change "git whatchanged" from using "diff-tree" as the commit
descriptor to "commit", and I changed one of the tests to reflect that new
reality. Otherwise everything still passes, and my other tests look fine
too.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-17 20:59:32 +02:00
|
|
|
showed_log = 0;
|
|
|
|
for (;;) {
|
2006-04-09 10:11:11 +02:00
|
|
|
struct commit *parent = parents->item;
|
|
|
|
|
Log message printout cleanups
On Sun, 16 Apr 2006, Junio C Hamano wrote:
>
> In the mid-term, I am hoping we can drop the generate_header()
> callchain _and_ the custom code that formats commit log in-core,
> found in cmd_log_wc().
Ok, this was nastier than expected, just because the dependencies between
the different log-printing stuff were absolutely _everywhere_, but here's
a patch that does exactly that.
The patch is not very easy to read, and the "--patch-with-stat" thing is
still broken (it does not call the "show_log()" thing properly for
merges). That's not a new bug. In the new world order it _should_ do
something like
if (rev->logopt)
show_log(rev, rev->logopt, "---\n");
but it doesn't. I haven't looked at the --with-stat logic, so I left it
alone.
That said, this patch removes more lines than it adds, and in particular,
the "cmd_log_wc()" loop is now a very clean:
while ((commit = get_revision(rev)) != NULL) {
log_tree_commit(rev, commit);
free(commit->buffer);
commit->buffer = NULL;
}
so it doesn't get much prettier than this. All the complexity is entirely
hidden in log-tree.c, and any code that needs to flush the log literally
just needs to do the "if (rev->logopt) show_log(...)" incantation.
I had to make the combined_diff() logic take a "struct rev_info" instead
of just a "struct diff_options", but that part is pretty clean.
This does change "git whatchanged" from using "diff-tree" as the commit
descriptor to "commit", and I changed one of the tests to reflect that new
reality. Otherwise everything still passes, and my other tests look fine
too.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-17 20:59:32 +02:00
|
|
|
diff_tree_sha1(parent->object.sha1, sha1, "", &opt->diffopt);
|
|
|
|
log_tree_diff_flush(opt);
|
|
|
|
|
|
|
|
showed_log |= !opt->loginfo;
|
|
|
|
|
|
|
|
/* Set up the log info for the next parent, if any.. */
|
|
|
|
parents = parents->next;
|
|
|
|
if (!parents)
|
|
|
|
break;
|
|
|
|
log->parent = parents->item;
|
|
|
|
opt->loginfo = log;
|
|
|
|
}
|
|
|
|
return showed_log;
|
|
|
|
}
|
|
|
|
|
|
|
|
int log_tree_commit(struct rev_info *opt, struct commit *commit)
|
|
|
|
{
|
|
|
|
struct log_info log;
|
2006-04-19 01:45:27 +02:00
|
|
|
int shown;
|
Log message printout cleanups
On Sun, 16 Apr 2006, Junio C Hamano wrote:
>
> In the mid-term, I am hoping we can drop the generate_header()
> callchain _and_ the custom code that formats commit log in-core,
> found in cmd_log_wc().
Ok, this was nastier than expected, just because the dependencies between
the different log-printing stuff were absolutely _everywhere_, but here's
a patch that does exactly that.
The patch is not very easy to read, and the "--patch-with-stat" thing is
still broken (it does not call the "show_log()" thing properly for
merges). That's not a new bug. In the new world order it _should_ do
something like
if (rev->logopt)
show_log(rev, rev->logopt, "---\n");
but it doesn't. I haven't looked at the --with-stat logic, so I left it
alone.
That said, this patch removes more lines than it adds, and in particular,
the "cmd_log_wc()" loop is now a very clean:
while ((commit = get_revision(rev)) != NULL) {
log_tree_commit(rev, commit);
free(commit->buffer);
commit->buffer = NULL;
}
so it doesn't get much prettier than this. All the complexity is entirely
hidden in log-tree.c, and any code that needs to flush the log literally
just needs to do the "if (rev->logopt) show_log(...)" incantation.
I had to make the combined_diff() logic take a "struct rev_info" instead
of just a "struct diff_options", but that part is pretty clean.
This does change "git whatchanged" from using "diff-tree" as the commit
descriptor to "commit", and I changed one of the tests to reflect that new
reality. Otherwise everything still passes, and my other tests look fine
too.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-17 20:59:32 +02:00
|
|
|
|
|
|
|
log.commit = commit;
|
|
|
|
log.parent = NULL;
|
|
|
|
opt->loginfo = &log;
|
|
|
|
|
2006-04-19 01:45:27 +02:00
|
|
|
shown = log_tree_diff(opt, commit, &log);
|
|
|
|
if (!shown && opt->loginfo && opt->always_show_header) {
|
Log message printout cleanups
On Sun, 16 Apr 2006, Junio C Hamano wrote:
>
> In the mid-term, I am hoping we can drop the generate_header()
> callchain _and_ the custom code that formats commit log in-core,
> found in cmd_log_wc().
Ok, this was nastier than expected, just because the dependencies between
the different log-printing stuff were absolutely _everywhere_, but here's
a patch that does exactly that.
The patch is not very easy to read, and the "--patch-with-stat" thing is
still broken (it does not call the "show_log()" thing properly for
merges). That's not a new bug. In the new world order it _should_ do
something like
if (rev->logopt)
show_log(rev, rev->logopt, "---\n");
but it doesn't. I haven't looked at the --with-stat logic, so I left it
alone.
That said, this patch removes more lines than it adds, and in particular,
the "cmd_log_wc()" loop is now a very clean:
while ((commit = get_revision(rev)) != NULL) {
log_tree_commit(rev, commit);
free(commit->buffer);
commit->buffer = NULL;
}
so it doesn't get much prettier than this. All the complexity is entirely
hidden in log-tree.c, and any code that needs to flush the log literally
just needs to do the "if (rev->logopt) show_log(...)" incantation.
I had to make the combined_diff() logic take a "struct rev_info" instead
of just a "struct diff_options", but that part is pretty clean.
This does change "git whatchanged" from using "diff-tree" as the commit
descriptor to "commit", and I changed one of the tests to reflect that new
reality. Otherwise everything still passes, and my other tests look fine
too.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-17 20:59:32 +02:00
|
|
|
log.parent = NULL;
|
2006-06-25 12:54:14 +02:00
|
|
|
show_log(opt, "");
|
2006-04-19 01:45:27 +02:00
|
|
|
shown = 1;
|
2006-04-09 10:11:11 +02:00
|
|
|
}
|
Log message printout cleanups
On Sun, 16 Apr 2006, Junio C Hamano wrote:
>
> In the mid-term, I am hoping we can drop the generate_header()
> callchain _and_ the custom code that formats commit log in-core,
> found in cmd_log_wc().
Ok, this was nastier than expected, just because the dependencies between
the different log-printing stuff were absolutely _everywhere_, but here's
a patch that does exactly that.
The patch is not very easy to read, and the "--patch-with-stat" thing is
still broken (it does not call the "show_log()" thing properly for
merges). That's not a new bug. In the new world order it _should_ do
something like
if (rev->logopt)
show_log(rev, rev->logopt, "---\n");
but it doesn't. I haven't looked at the --with-stat logic, so I left it
alone.
That said, this patch removes more lines than it adds, and in particular,
the "cmd_log_wc()" loop is now a very clean:
while ((commit = get_revision(rev)) != NULL) {
log_tree_commit(rev, commit);
free(commit->buffer);
commit->buffer = NULL;
}
so it doesn't get much prettier than this. All the complexity is entirely
hidden in log-tree.c, and any code that needs to flush the log literally
just needs to do the "if (rev->logopt) show_log(...)" incantation.
I had to make the combined_diff() logic take a "struct rev_info" instead
of just a "struct diff_options", but that part is pretty clean.
This does change "git whatchanged" from using "diff-tree" as the commit
descriptor to "commit", and I changed one of the tests to reflect that new
reality. Otherwise everything still passes, and my other tests look fine
too.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-17 20:59:32 +02:00
|
|
|
opt->loginfo = NULL;
|
2007-06-29 19:40:46 +02:00
|
|
|
maybe_flush_or_die(stdout, "stdout");
|
2006-04-19 01:45:27 +02:00
|
|
|
return shown;
|
2006-04-09 10:11:11 +02:00
|
|
|
}
|