2005-04-09 22:00:54 +02:00
|
|
|
#include "cache.h"
|
2005-04-27 18:21:00 +02:00
|
|
|
#include "diff.h"
|
2005-06-01 17:34:23 +02:00
|
|
|
#include "commit.h"
|
2006-04-09 10:11:11 +02:00
|
|
|
#include "log-tree.h"
|
2005-04-09 22:00:54 +02:00
|
|
|
|
2006-04-09 10:11:11 +02:00
|
|
|
static struct log_tree_opt log_tree_opt;
|
2005-05-18 22:06:47 +02:00
|
|
|
|
2006-02-06 08:00:41 +01:00
|
|
|
static int diff_tree_commit_sha1(const unsigned char *sha1)
|
|
|
|
{
|
|
|
|
struct commit *commit = lookup_commit_reference(sha1);
|
|
|
|
if (!commit)
|
|
|
|
return -1;
|
2006-04-09 10:11:11 +02:00
|
|
|
return log_tree_commit(&log_tree_opt, commit);
|
2006-02-06 08:00:41 +01:00
|
|
|
}
|
|
|
|
|
2005-05-18 22:06:47 +02:00
|
|
|
static int diff_tree_stdin(char *line)
|
|
|
|
{
|
|
|
|
int len = strlen(line);
|
2006-02-06 08:00:41 +01:00
|
|
|
unsigned char sha1[20];
|
|
|
|
struct commit *commit;
|
2005-05-18 22:06:47 +02:00
|
|
|
|
|
|
|
if (!len || line[len-1] != '\n')
|
|
|
|
return -1;
|
|
|
|
line[len-1] = 0;
|
2006-02-06 08:00:41 +01:00
|
|
|
if (get_sha1_hex(line, sha1))
|
|
|
|
return -1;
|
|
|
|
commit = lookup_commit(sha1);
|
|
|
|
if (!commit || parse_commit(commit))
|
2005-05-18 22:06:47 +02:00
|
|
|
return -1;
|
2006-02-06 08:00:41 +01:00
|
|
|
if (isspace(line[40]) && !get_sha1_hex(line+41, sha1)) {
|
|
|
|
/* Graft the fake parents locally to the commit */
|
|
|
|
int pos = 41;
|
|
|
|
struct commit_list **pptr, *parents;
|
|
|
|
|
|
|
|
/* Free the real parent list */
|
|
|
|
for (parents = commit->parents; parents; ) {
|
|
|
|
struct commit_list *tmp = parents->next;
|
|
|
|
free(parents);
|
|
|
|
parents = tmp;
|
|
|
|
}
|
|
|
|
commit->parents = NULL;
|
|
|
|
pptr = &(commit->parents);
|
|
|
|
while (line[pos] && !get_sha1_hex(line + pos, sha1)) {
|
|
|
|
struct commit *parent = lookup_commit(sha1);
|
|
|
|
if (parent) {
|
|
|
|
pptr = &commit_list_insert(parent, pptr)->next;
|
|
|
|
}
|
|
|
|
pos += 41;
|
|
|
|
}
|
2005-05-18 22:06:47 +02:00
|
|
|
}
|
2006-04-09 10:11:11 +02:00
|
|
|
return log_tree_commit(&log_tree_opt, commit);
|
2005-05-06 19:03:17 +02:00
|
|
|
}
|
|
|
|
|
2005-07-29 11:01:26 +02:00
|
|
|
static const char diff_tree_usage[] =
|
2006-01-24 10:22:04 +01:00
|
|
|
"git-diff-tree [--stdin] [-m] [-c] [--cc] [-s] [-v] [--pretty] [-t] [-r] [--root] "
|
2005-10-28 19:04:49 +02:00
|
|
|
"[<common diff options>] <tree-ish> [<tree-ish>] [<path>...]\n"
|
|
|
|
" -r diff recursively\n"
|
|
|
|
" --root include the initial commit as diff against /dev/null\n"
|
2005-07-13 21:52:35 +02:00
|
|
|
COMMON_DIFF_OPTIONS_HELP;
|
2005-06-13 02:44:21 +02:00
|
|
|
|
2005-09-21 09:00:47 +02:00
|
|
|
int main(int argc, const char **argv)
|
2005-04-10 23:03:58 +02:00
|
|
|
{
|
2005-05-18 22:10:17 +02:00
|
|
|
int nr_sha1;
|
2005-05-06 19:03:17 +02:00
|
|
|
char line[1000];
|
2005-05-18 22:10:17 +02:00
|
|
|
unsigned char sha1[2][20];
|
2005-08-17 03:06:34 +02:00
|
|
|
const char *prefix = setup_git_directory();
|
2006-04-09 10:11:11 +02:00
|
|
|
static struct log_tree_opt *opt = &log_tree_opt;
|
|
|
|
int read_stdin = 0;
|
2005-04-10 23:03:58 +02:00
|
|
|
|
2005-11-22 07:52:37 +01:00
|
|
|
git_config(git_diff_config);
|
2005-05-18 22:10:17 +02:00
|
|
|
nr_sha1 = 0;
|
2006-04-09 10:11:11 +02:00
|
|
|
init_log_tree_opt(opt);
|
2005-09-21 09:00:47 +02:00
|
|
|
|
2005-04-24 07:08:00 +02:00
|
|
|
for (;;) {
|
2006-04-09 10:11:11 +02:00
|
|
|
int opt_cnt;
|
2005-05-22 19:04:37 +02:00
|
|
|
const char *arg;
|
2005-04-24 07:08:00 +02:00
|
|
|
|
2005-05-06 19:03:17 +02:00
|
|
|
argv++;
|
|
|
|
argc--;
|
|
|
|
arg = *argv;
|
2005-05-18 22:10:17 +02:00
|
|
|
if (!arg)
|
2005-04-24 07:08:00 +02:00
|
|
|
break;
|
|
|
|
|
2005-05-18 22:10:17 +02:00
|
|
|
if (*arg != '-') {
|
|
|
|
if (nr_sha1 < 2 && !get_sha1(arg, sha1[nr_sha1])) {
|
|
|
|
nr_sha1++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-04-09 10:11:11 +02:00
|
|
|
opt_cnt = log_tree_opt_parse(opt, argv, argc);
|
|
|
|
if (opt_cnt < 0)
|
2005-09-21 09:00:47 +02:00
|
|
|
usage(diff_tree_usage);
|
2006-04-09 10:11:11 +02:00
|
|
|
else if (opt_cnt) {
|
|
|
|
argv += opt_cnt - 1;
|
|
|
|
argc -= opt_cnt - 1;
|
2005-09-21 09:00:47 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2005-05-18 22:10:17 +02:00
|
|
|
if (!strcmp(arg, "--")) {
|
2005-05-06 19:03:17 +02:00
|
|
|
argv++;
|
|
|
|
argc--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!strcmp(arg, "--stdin")) {
|
|
|
|
read_stdin = 1;
|
|
|
|
continue;
|
|
|
|
}
|
2005-04-21 04:49:16 +02:00
|
|
|
usage(diff_tree_usage);
|
2005-04-10 23:03:58 +02:00
|
|
|
}
|
|
|
|
|
2006-04-09 10:11:11 +02:00
|
|
|
if (opt->combine_merges)
|
|
|
|
opt->ignore_merges = 0;
|
diff-tree -c raw output
NOTE! This makes "-c" be the default, which effectively means that merges
are never ignored any more, and "-m" is a no-op. So it changes semantics.
I would also like to make "--cc" the default if you do patches, but didn't
actually do that.
The raw output format is not wonderfully pretty, but it's distinguishable
from a "normal patch" in that a normal patch with just one parent has just
one colon at the beginning, while a multi-parent raw diff has <n> colons
for <n> parents.
So now, in the kernel, when you do
git-diff-tree cce0cac125623f9b68f25dd1350f6d616220a8dd
(to see the manual ARM merge that had a conflict in arch/arm/Kconfig), you
get
cce0cac125623f9b68f25dd1350f6d616220a8dd
::100644 100644 100644 4a63a8e2e45247a11c068c6ed66c6e7aba29ddd9 77eee38762d69d3de95ae45dd9278df9b8225e2c 2f61726d2f4b636f6e66696700dbf71a59dad287 arch/arm/Kconfig
ie you see two colons (two parents), then three modes (parent modes
followed by result mode), then three sha1s (parent sha1s followed by
result sha1).
Which is pretty close to the normal raw diff output.
Cool/stupid exercise:
$ git-whatchanged | grep '^::' | cut -f2- | sort |
uniq -c | sort -n | less -S
will show which files have needed the most file-level merge conflict
resolution. Useful? Probably not. But kind of interesting.
For the kernel, it's
....
10 arch/ia64/Kconfig
11 drivers/scsi/Kconfig
12 drivers/net/Makefile
17 include/linux/libata.h
18 include/linux/pci_ids.h
23 drivers/net/Kconfig
24 drivers/scsi/libata-scsi.c
28 drivers/scsi/libata-core.c
43 MAINTAINERS
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-02-09 19:30:28 +01:00
|
|
|
|
|
|
|
/* We can only do dense combined merges with diff output */
|
2006-04-09 10:11:11 +02:00
|
|
|
if (opt->dense_combined_merges)
|
|
|
|
opt->diffopt.output_format = DIFF_FORMAT_PATCH;
|
diff-tree -c: show a merge commit a bit more sensibly.
A new option '-c' to diff-tree changes the way a merge commit is
displayed when generating a patch output. It shows a "combined
diff" (hence the option letter 'c'), which looks like this:
$ git-diff-tree --pretty -c -p fec9ebf1 | head -n 18
diff-tree fec9ebf... (from parents)
Merge: 0620db3... 8a263ae...
Author: Junio C Hamano <junkio@cox.net>
Date: Sun Jan 15 22:25:35 2006 -0800
Merge fixes up to GIT 1.1.3
diff --combined describe.c
@@@ +98,7 @@@
return (a_date > b_date) ? -1 : (a_date == b_date) ? 0 : 1;
}
- static void describe(char *arg)
- static void describe(struct commit *cmit, int last_one)
++ static void describe(char *arg, int last_one)
{
+ unsigned char sha1[20];
+ struct commit *cmit;
There are a few things to note about this feature:
- The '-c' option implies '-p'. It also implies '-m' halfway
in the sense that "interesting" merges are shown, but not all
merges.
- When a blob matches one of the parents, we do not show a diff
for that path at all. For a merge commit, this option shows
paths with real file-level merge (aka "interesting things").
- As a concequence of the above, an "uninteresting" merge is
not shown at all. You can use '-m' in addition to '-c' to
show the commit log for such a merge, but there will be no
combined diff output.
- Unlike "gitk", the output is monochrome.
A '-' character in the nth column means the line is from the nth
parent and does not appear in the merge result (i.e. removed
from that parent's version).
A '+' character in the nth column means the line appears in the
merge result, and the nth parent does not have that line
(i.e. added by the merge itself or inherited from another
parent).
The above example output shows that the function signature was
changed from either parents (hence two "-" lines and a "++"
line), and "unsigned char sha1[20]", prefixed by a " +", was
inherited from the first parent.
The code as sent to the list was buggy in few corner cases,
which I have fixed since then.
It does not bother to keep track of and show the line numbers
from parent commits, which it probably should.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-01-24 10:22:04 +01:00
|
|
|
|
2006-04-09 10:11:11 +02:00
|
|
|
if (opt->diffopt.output_format == DIFF_FORMAT_PATCH)
|
|
|
|
opt->diffopt.recursive = 1;
|
2006-02-07 19:26:41 +01:00
|
|
|
|
2006-04-11 01:39:11 +02:00
|
|
|
diff_tree_setup_paths(get_pathspec(prefix, argv), opt);
|
2006-04-09 10:11:11 +02:00
|
|
|
diff_setup_done(&opt->diffopt);
|
2005-04-24 07:08:00 +02:00
|
|
|
|
2005-05-18 22:10:17 +02:00
|
|
|
switch (nr_sha1) {
|
|
|
|
case 0:
|
|
|
|
if (!read_stdin)
|
|
|
|
usage(diff_tree_usage);
|
|
|
|
break;
|
|
|
|
case 1:
|
2006-02-06 08:00:41 +01:00
|
|
|
diff_tree_commit_sha1(sha1[0]);
|
2005-05-18 22:10:17 +02:00
|
|
|
break;
|
|
|
|
case 2:
|
2006-04-09 10:11:11 +02:00
|
|
|
diff_tree_sha1(sha1[0], sha1[1], "", &opt->diffopt);
|
|
|
|
log_tree_diff_flush(opt);
|
2005-05-18 22:10:17 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-05-06 19:03:17 +02:00
|
|
|
if (!read_stdin)
|
2005-05-18 22:10:17 +02:00
|
|
|
return 0;
|
2005-05-06 19:03:17 +02:00
|
|
|
|
2006-04-09 10:11:11 +02:00
|
|
|
if (opt->diffopt.detect_rename)
|
|
|
|
opt->diffopt.setup |= (DIFF_SETUP_USE_SIZE_CACHE |
|
2005-09-21 09:00:47 +02:00
|
|
|
DIFF_SETUP_USE_CACHE);
|
2005-05-06 19:03:17 +02:00
|
|
|
while (fgets(line, sizeof(line), stdin))
|
|
|
|
diff_tree_stdin(line);
|
|
|
|
|
|
|
|
return 0;
|
2005-04-09 22:00:54 +02:00
|
|
|
}
|