* Re: [PATCH] The diff-raw format updates.
From: Linus Torvalds @ 2005-05-22 6:01 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Git Mailing List
In-Reply-To: <7vvf5cc779.fsf_-_@assigned-by-dhcp.cox.net>
On Sat, 21 May 2005, Junio C Hamano wrote:
>
> Update the diff-raw format as Linus and I discussed, except that
> it does not use sequence of underscore '_' letters to express
> nonexistence. All '0' mode is used for that purpose instead.
Ok, it all looks very nice, but it looks like -C is still broken ;)
Do
git-whatchanged -C -p
and you'll see this hilarious entry as the first "copy" entry:
diff --git a/Documentation/git-diff-cache.txt b/diffcore-pickaxe.c
similarity index 0%
copy from Documentation/git-diff-cache.txt
copy to diffcore-pickaxe.c
--- a/Documentation/git-diff-cache.txt
+++ b/diffcore-pickaxe.c
@@ -1,150 +1,56 @@
..
it even says "similarity index 0%", adn that sure is accurate ;)
Doing "-C50" to ask for at least 50% similarity makes it ok (and it finds
the "git-pull-script" -> "git-resolve-script" thing), but there's
something strange going on, becuase -C10 and -C90 don't work, even if -C40
and -C50 _do_ work.
Linus
^ permalink raw reply
* Re: cogito - how do I ???
From: Frank Sorenson @ 2005-05-22 5:27 UTC (permalink / raw)
To: Sean; +Cc: Sam Ravnborg, git
In-Reply-To: <2765.10.10.10.24.1116713164.squirrel@linux1>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Sean wrote:
> On Sat, May 21, 2005 5:47 pm, Sam Ravnborg said:
>
>>Hi all.
>>
>>While trying to get up to speed on cogito/git I stumbled across
>>a few things that I at least did not find available in cogito.
>>
>>1) Something similar to "bk changes -R". I use this to see what has
>>happened upstream - to see if I really want to merge stuff.
>
>
> Not sure what bk did here, but you can do something like:
>
> cg-pull origin
> cg-log -c -r origin
>
> To see what is at the head of the unmerged objects you just pulled down,
> and if you want to merge then "cg-merge origin". Although as far as I
> know there's no way to have the log stop automatically at the proper spot.
Here's what I use:
cg-log -c -f -r :origin
- -c = colorize the output
- -f = list files affected
- -r :origin = only display this range (equivalent to "-r HEAD:origin")
Frank
- --
Frank Sorenson - KD7TZK
Systems Manager, Computer Science Department
Brigham Young University
frank@tuxrocks.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFCkBhAaI0dwg4A47wRAtrdAJ9Hy/H4BNurGd+Ukjtz+0+6sUDIkgCdHJIr
KnponX5ITXEDe/r+0dAOmqc=
=jaNR
-----END PGP SIGNATURE-----
^ permalink raw reply
* [PATCH] The diff-raw format updates.
From: Junio C Hamano @ 2005-05-22 2:42 UTC (permalink / raw)
To: Linus Torvalds; +Cc: git
In-Reply-To: <7v1x80dluj.fsf@assigned-by-dhcp.cox.net>
Update the diff-raw format as Linus and I discussed, except that
it does not use sequence of underscore '_' letters to express
nonexistence. All '0' mode is used for that purpose instead.
The new diff-raw format can express rename/copy, and the earlier
restriction that -M and -C _must_ be used with the patch format
output is no longer necessary. The patch makes -M and -C flags
independent of -p flag, so you need to say git-whatchanged -M -p
to get the diff/patch format.
Updated are both documentations and tests.
Signed-off-by: Junio C Hamano <junkio@cox.net>
---
Documentation/diff-format.txt | 29 +++--
Documentation/git-diff-cache.txt | 4
Documentation/git-diff-files.txt | 4
Documentation/git-diff-tree.txt | 5
diff-cache.c | 12 --
diff-files.c | 12 --
diff-helper.c | 153 ++++++++++++----------------
diff-tree.c | 13 +-
diff.c | 132 +++++++++++++-----------
diff.h | 12 ++
diffcore-pickaxe.c | 6 -
diffcore-rename.c | 20 +--
diffcore.h | 2
t/t0000-basic.sh | 16 +-
t/t4002-diff-basic.sh | 209 +++++++++++++++++++--------------------
t/t4003-diff-rename-1.sh | 6 -
16 files changed, 322 insertions(+), 313 deletions(-)
diff --git a/Documentation/diff-format.txt b/Documentation/diff-format.txt
--- a/Documentation/diff-format.txt
+++ b/Documentation/diff-format.txt
@@ -16,25 +16,30 @@ git-diff-tree [-r] <tree-ish-1> <tree-is
git-diff-files [<pattern>...]::
compares the cache and the files on the filesystem.
-The following desription uses "old" and "new" to mean those
-compared entities.
-For files in old but not in new (i.e. removed):
+An output line is formatted this way:
- -<mode> \t <type> \t <object> \t <path>
+ ':' <mode> ' ' <mode> ' ' <sha1> ' ' <sha1> I <path> I <path> L
-For files not in old but in new (i.e. added):
+By default, I and L are '\t' and '\n' respectively. When '-z'
+flag is in effect, both I and L are '\0'.
- +<mode> \t <type> \t <object> \t <path>
+In each <mode>, <sha1> and <path> pair, left hand side describes
+the left hand side of what is being compared (<tree-ish> in
+git-diff-cache, <tree-ish-1> in git-diff-tree, cache contents in
+git-diff-files). Non-existence is shown by having 000000 in the
+<mode> column. That is, 000000 appears as the first <mode> for
+newly created files, and as the second <mode> for deleted files.
-For files that differ:
+Usually two <path> are the same. When rename/copy detection is
+used, however, an "create" and another "delete" records can be
+merged into a single record that has two <path>, old name and
+new name.
- *<old-mode>-><new-mode> \t <type> \t <old-sha1>-><new-sha1> \t <path>
+<sha1> is shown as all 0's if new is a file on the filesystem
+and it is out of sync with the cache. Example:
-<new-sha1> is shown as all 0's if new is a file on the
-filesystem and it is out of sync with the cache. Example:
-
- *100644->100644 blob 5be4a4.......->000000....... file.c
+ :100644 100644 5be4a4...... 000000...... file.c file.c
Generating patches with -p
diff --git a/Documentation/git-diff-cache.txt b/Documentation/git-diff-cache.txt
--- a/Documentation/git-diff-cache.txt
+++ b/Documentation/git-diff-cache.txt
@@ -34,10 +34,10 @@ OPTIONS
\0 line termination on output
-M::
- Detect renames; implies -p.
+ Detect renames.
-C::
- Detect copies as well as renames; implies -p.
+ Detect copies as well as renames.
-S<string>::
Look for differences that contains the change in <string>.
diff --git a/Documentation/git-diff-files.txt b/Documentation/git-diff-files.txt
--- a/Documentation/git-diff-files.txt
+++ b/Documentation/git-diff-files.txt
@@ -30,10 +30,10 @@ OPTIONS
Output diff in reverse.
-M::
- Detect renames; implies -p.
+ Detect renames.
-C::
- Detect copies as well as renames; implies -p.
+ Detect copies as well as renames.
-S<string>::
Look for differences that contains the change in <string>.
diff --git a/Documentation/git-diff-tree.txt b/Documentation/git-diff-tree.txt
--- a/Documentation/git-diff-tree.txt
+++ b/Documentation/git-diff-tree.txt
@@ -34,11 +34,10 @@ OPTIONS
git-diff-tree, this flag implies '-r' as well.
-M::
- Detect renames; implies -p, in turn implying also '-r'.
+ Detect renames.
-C::
- Detect copies as well as renames; implies -p, in turn
- implying also '-r'.
+ Detect copies as well as renames.
-R::
Output diff in reverse.
diff --git a/diff-cache.c b/diff-cache.c
--- a/diff-cache.c
+++ b/diff-cache.c
@@ -2,9 +2,8 @@
#include "diff.h"
static int cached_only = 0;
-static int generate_patch = 0;
+static int diff_output_format = DIFF_FORMAT_HUMAN;
static int match_nonexisting = 0;
-static int line_termination = '\n';
static int detect_rename = 0;
static int reverse_diff = 0;
static int diff_score_opt = 0;
@@ -174,22 +173,21 @@ int main(int argc, char **argv)
continue;
}
if (!strcmp(arg, "-p")) {
- generate_patch = 1;
+ diff_output_format = DIFF_FORMAT_PATCH;
continue;
}
if (!strncmp(arg, "-M", 2)) {
- generate_patch = detect_rename = 1;
+ detect_rename = 1;
diff_score_opt = diff_scoreopt_parse(arg);
continue;
}
if (!strncmp(arg, "-C", 2)) {
- generate_patch = 1;
detect_rename = 2;
diff_score_opt = diff_scoreopt_parse(arg);
continue;
}
if (!strcmp(arg, "-z")) {
- line_termination = '\0';
+ diff_output_format = DIFF_FORMAT_MACHINE;
continue;
}
if (!strcmp(arg, "-R")) {
@@ -214,7 +212,7 @@ int main(int argc, char **argv)
if (argc != 2 || get_sha1(argv[1], tree_sha1))
usage(diff_cache_usage);
- diff_setup(reverse_diff, (generate_patch ? -1 : line_termination));
+ diff_setup(reverse_diff, diff_output_format);
mark_merge_entries();
diff --git a/diff-files.c b/diff-files.c
--- a/diff-files.c
+++ b/diff-files.c
@@ -9,8 +9,7 @@
static const char *diff_files_usage =
"git-diff-files [-p] [-q] [-r] [-z] [-M] [-C] [-R] [-S<string>] [paths...]";
-static int generate_patch = 0;
-static int line_termination = '\n';
+static int diff_output_format = DIFF_FORMAT_HUMAN;
static int detect_rename = 0;
static int reverse_diff = 0;
static int diff_score_opt = 0;
@@ -57,7 +56,7 @@ int main(int argc, char **argv)
while (1 < argc && argv[1][0] == '-') {
if (!strcmp(argv[1], "-p"))
- generate_patch = 1;
+ diff_output_format = DIFF_FORMAT_PATCH;
else if (!strcmp(argv[1], "-q"))
silent = 1;
else if (!strcmp(argv[1], "-r"))
@@ -65,19 +64,18 @@ int main(int argc, char **argv)
else if (!strcmp(argv[1], "-s"))
; /* no-op */
else if (!strcmp(argv[1], "-z"))
- line_termination = 0;
+ diff_output_format = DIFF_FORMAT_MACHINE;
else if (!strcmp(argv[1], "-R"))
reverse_diff = 1;
else if (!strcmp(argv[1], "-S"))
pickaxe = argv[1] + 2;
else if (!strncmp(argv[1], "-M", 2)) {
diff_score_opt = diff_scoreopt_parse(argv[1]);
- detect_rename = generate_patch = 1;
+ detect_rename = 1;
}
else if (!strncmp(argv[1], "-C", 2)) {
diff_score_opt = diff_scoreopt_parse(argv[1]);
detect_rename = 2;
- generate_patch = 1;
}
else
usage(diff_files_usage);
@@ -92,7 +90,7 @@ int main(int argc, char **argv)
exit(1);
}
- diff_setup(reverse_diff, (generate_patch ? -1 : line_termination));
+ diff_setup(reverse_diff, diff_output_format);
for (i = 0; i < entries; i++) {
struct stat st;
diff --git a/diff-helper.c b/diff-helper.c
--- a/diff-helper.c
+++ b/diff-helper.c
@@ -8,88 +8,51 @@
static int detect_rename = 0;
static int diff_score_opt = 0;
-static int generate_patch = 1;
static const char *pickaxe = NULL;
+static int diff_output_style = DIFF_FORMAT_PATCH;
+static int line_termination = '\n';
+static int inter_name_termination = '\t';
-static int parse_oneside_change(const char *cp, int *mode,
- unsigned char *sha1, char *path)
+static int parse_diff_raw(char *buf1, char *buf2, char *buf3)
{
- int ch, m;
+ char old_path[PATH_MAX];
+ unsigned char old_sha1[20], new_sha1[20];
+ char *ep;
+ char *cp = buf1;
+ int ch, old_mode, new_mode;
- m = 0;
- while ((ch = *cp) && '0' <= ch && ch <= '7') {
- m = (m << 3) | (ch - '0');
+ old_mode = new_mode = 0;
+ while ((ch = *cp) && ('0' <= ch && ch <= '7')) {
+ old_mode = (old_mode << 3) | (ch - '0');
+ cp++;
+ }
+ if (*cp++ != ' ')
+ return -1;
+ while ((ch = *cp) && ('0' <= ch && ch <= '7')) {
+ new_mode = (new_mode << 3) | (ch - '0');
cp++;
}
- *mode = m;
- if (strncmp(cp, "\tblob\t", 6) && strncmp(cp, " blob ", 6) &&
- strncmp(cp, "\ttree\t", 6) && strncmp(cp, " tree ", 6))
+ if (*cp++ != ' ')
return -1;
- cp += 6;
- if (get_sha1_hex(cp, sha1))
+ if (get_sha1_hex(cp, old_sha1))
return -1;
cp += 40;
- if ((*cp != '\t') && *cp != ' ')
+ if (*cp++ != ' ')
return -1;
- strcpy(path, ++cp);
- return 0;
-}
-
-static int parse_diff_raw_output(const char *buf)
-{
- char path[PATH_MAX];
- unsigned char old_sha1[20], new_sha1[20];
- const char *cp = buf;
- int ch, old_mode, new_mode;
-
- switch (*cp++) {
- case 'U':
- diff_unmerge(cp + 1);
- break;
- case '+':
- if (parse_oneside_change(cp, &new_mode, new_sha1, path))
- return -1;
- diff_addremove('+', new_mode, new_sha1, path, NULL);
- break;
- case '-':
- if (parse_oneside_change(cp, &old_mode, old_sha1, path))
- return -1;
- diff_addremove('-', old_mode, old_sha1, path, NULL);
- break;
- case '*':
- old_mode = new_mode = 0;
- while ((ch = *cp) && ('0' <= ch && ch <= '7')) {
- old_mode = (old_mode << 3) | (ch - '0');
- cp++;
- }
- if (strncmp(cp, "->", 2))
- return -1;
- cp += 2;
- while ((ch = *cp) && ('0' <= ch && ch <= '7')) {
- new_mode = (new_mode << 3) | (ch - '0');
- cp++;
- }
- if (strncmp(cp, "\tblob\t", 6) && strncmp(cp, " blob ", 6) &&
- strncmp(cp, "\ttree\t", 6) && strncmp(cp, " tree ", 6))
- return -1;
- cp += 6;
- if (get_sha1_hex(cp, old_sha1))
- return -1;
- cp += 40;
- if (strncmp(cp, "->", 2))
- return -1;
- cp += 2;
- if (get_sha1_hex(cp, new_sha1))
- return -1;
- cp += 40;
- if ((*cp != '\t') && *cp != ' ')
- return -1;
- strcpy(path, ++cp);
- diff_change(old_mode, new_mode, old_sha1, new_sha1, path, NULL);
- break;
- default:
+ if (get_sha1_hex(cp, new_sha1))
return -1;
- }
+ cp += 40;
+ if (*cp++ != inter_name_termination)
+ return -1;
+ if (buf2)
+ cp = buf2;
+ ep = strchr(cp, inter_name_termination);
+ if (!ep)
+ return -1;
+ *ep++ = 0;
+ strcpy(old_path, cp);
+ diff_guif(old_mode, new_mode, old_sha1, new_sha1,
+ old_path, buf3 ? buf3 : ep);
return 0;
}
@@ -97,19 +60,22 @@ static const char *diff_helper_usage =
"git-diff-helper [-z] [-R] [-M] [-C] [-S<string>] paths...";
int main(int ac, const char **av) {
- struct strbuf sb;
- int reverse = 0;
- int line_termination = '\n';
+ struct strbuf sb1, sb2, sb3;
+ int reverse_diff = 0;
- strbuf_init(&sb);
+ strbuf_init(&sb1);
+ strbuf_init(&sb2);
+ strbuf_init(&sb3);
while (1 < ac && av[1][0] == '-') {
if (av[1][1] == 'R')
- reverse = 1;
+ reverse_diff = 1;
else if (av[1][1] == 'z')
- line_termination = 0;
+ line_termination = inter_name_termination = 0;
else if (av[1][1] == 'p') /* hidden from the help */
- generate_patch = 0;
+ diff_output_style = DIFF_FORMAT_HUMAN;
+ else if (av[1][1] == 'P') /* hidden from the help */
+ diff_output_style = DIFF_FORMAT_MACHINE;
else if (av[1][1] == 'M') {
detect_rename = 1;
diff_score_opt = diff_scoreopt_parse(av[1]);
@@ -127,19 +93,38 @@ int main(int ac, const char **av) {
}
/* the remaining parameters are paths patterns */
- diff_setup(reverse, (generate_patch ? -1 : line_termination));
+ diff_setup(reverse_diff, diff_output_style);
while (1) {
int status;
- read_line(&sb, stdin, line_termination);
- if (sb.eof)
+ read_line(&sb1, stdin, line_termination);
+ if (sb1.eof)
break;
- status = parse_diff_raw_output(sb.buf);
+ switch (sb1.buf[0]) {
+ case 'U':
+ diff_unmerge(sb1.buf + 2);
+ continue;
+ case ':':
+ break;
+ default:
+ goto unrecognized;
+ }
+ if (!line_termination) {
+ read_line(&sb2, stdin, line_termination);
+ if (sb2.eof)
+ break;
+ read_line(&sb3, stdin, line_termination);
+ if (sb3.eof)
+ break;
+ status = parse_diff_raw(sb1.buf+1, sb2.buf, sb3.buf);
+ }
+ else
+ status = parse_diff_raw(sb1.buf+1, NULL, NULL);
if (status) {
+ unrecognized:
diff_flush(av+1, ac-1);
- printf("%s%c", sb.buf, line_termination);
+ printf("%s%c", sb1.buf, line_termination);
}
}
-
if (detect_rename)
diff_detect_rename(detect_rename, diff_score_opt);
if (pickaxe)
diff --git a/diff-tree.c b/diff-tree.c
--- a/diff-tree.c
+++ b/diff-tree.c
@@ -8,8 +8,7 @@ static int verbose_header = 0;
static int ignore_merges = 1;
static int recursive = 0;
static int read_stdin = 0;
-static int line_termination = '\n';
-static int generate_patch = 0;
+static int diff_output_format = DIFF_FORMAT_HUMAN;
static int detect_rename = 0;
static int reverse_diff = 0;
static int diff_score_opt = 0;
@@ -269,7 +268,7 @@ static int diff_tree_sha1(const unsigned
static void call_diff_setup(void)
{
- diff_setup(reverse_diff, (generate_patch ? -1 : line_termination));
+ diff_setup(reverse_diff, diff_output_format);
}
static void call_diff_flush(void)
@@ -501,7 +500,8 @@ int main(int argc, char **argv)
continue;
}
if (!strcmp(arg, "-p")) {
- recursive = generate_patch = 1;
+ diff_output_format = DIFF_FORMAT_PATCH;
+ recursive = 1;
continue;
}
if (!strncmp(arg, "-S", 2)) {
@@ -509,18 +509,17 @@ int main(int argc, char **argv)
continue;
}
if (!strncmp(arg, "-M", 2)) {
- detect_rename = recursive = generate_patch = 1;
+ detect_rename = 1;
diff_score_opt = diff_scoreopt_parse(arg);
continue;
}
if (!strncmp(arg, "-C", 2)) {
detect_rename = 2;
- recursive = generate_patch = 1;
diff_score_opt = diff_scoreopt_parse(arg);
continue;
}
if (!strcmp(arg, "-z")) {
- line_termination = '\0';
+ diff_output_format = DIFF_FORMAT_MACHINE;
continue;
}
if (!strcmp(arg, "-m")) {
diff --git a/diff.c b/diff.c
--- a/diff.c
+++ b/diff.c
@@ -13,7 +13,9 @@ static const char *diff_opts = "-pu";
static unsigned char null_sha1[20] = { 0, };
static int reverse_diff;
-static int diff_raw_output = -1;
+static int generate_patch;
+static int line_termination = '\n';
+static int inter_name_termination = '\t';
static const char **pathspec;
static int speccnt;
@@ -163,20 +165,23 @@ struct diff_filespec *alloc_filespec(con
struct diff_filespec *spec = xmalloc(sizeof(*spec) + namelen + 1);
spec->path = (char *)(spec + 1);
strcpy(spec->path, path);
- spec->should_free = spec->should_munmap = spec->file_valid = 0;
+ spec->should_free = spec->should_munmap = 0;
spec->xfrm_flags = 0;
spec->size = 0;
spec->data = 0;
+ spec->mode = 0;
+ memset(spec->sha1, 0, 20);
return spec;
}
void fill_filespec(struct diff_filespec *spec, const unsigned char *sha1,
unsigned short mode)
{
- spec->mode = mode;
- memcpy(spec->sha1, sha1, 20);
- spec->sha1_valid = !!memcmp(sha1, null_sha1, 20);
- spec->file_valid = 1;
+ if (mode) { /* just playing defensive */
+ spec->mode = mode;
+ memcpy(spec->sha1, sha1, 20);
+ spec->sha1_valid = !!memcmp(sha1, null_sha1, 20);
+ }
}
/*
@@ -231,7 +236,7 @@ static int work_tree_matches(const char
int diff_populate_filespec(struct diff_filespec *s)
{
int err = 0;
- if (!s->file_valid)
+ if (!DIFF_FILE_VALID(s))
die("internal error: asking to populate invalid file.");
if (S_ISDIR(s->mode))
return -1;
@@ -316,7 +321,7 @@ static void prepare_temp_file(const char
struct diff_tempfile *temp,
struct diff_filespec *one)
{
- if (!one->file_valid) {
+ if (!DIFF_FILE_VALID(one)) {
not_a_valid_file:
/* A '-' entry produces this for file-2, and
* a '+' entry produces this for file-1.
@@ -509,10 +514,22 @@ int diff_scoreopt_parse(const char *opt)
return MAX_SCORE * num / scale;
}
-void diff_setup(int reverse_diff_, int diff_raw_output_)
+void diff_setup(int reverse_diff_, int diff_output_style)
{
reverse_diff = reverse_diff_;
- diff_raw_output = diff_raw_output_;
+ generate_patch = 0;
+ switch (diff_output_style) {
+ case DIFF_FORMAT_HUMAN:
+ line_termination = '\n';
+ inter_name_termination = '\t';
+ break;
+ case DIFF_FORMAT_MACHINE:
+ line_termination = inter_name_termination = 0;
+ break;
+ case DIFF_FORMAT_PATCH:
+ generate_patch = 1;
+ break;
+ }
}
struct diff_queue_struct diff_queued_diff;
@@ -536,43 +553,17 @@ struct diff_filepair *diff_queue(struct
return dp;
}
-static const char *git_object_type(unsigned mode)
-{
- return S_ISDIR(mode) ? "tree" : "blob";
-}
-
static void diff_flush_raw(struct diff_filepair *p)
{
- struct diff_filespec *it;
- int addremove;
-
- /* raw output does not have a way to express rename nor copy */
- if (strcmp(p->one->path, p->two->path))
- return;
-
- if (p->one->file_valid && p->two->file_valid) {
- char hex[41];
- strcpy(hex, sha1_to_hex(p->one->sha1));
- printf("*%06o->%06o %s %s->%s %s%c",
- p->one->mode, p->two->mode,
- git_object_type(p->one->mode),
- hex, sha1_to_hex(p->two->sha1),
- p->one->path, diff_raw_output);
- return;
- }
-
- if (p->one->file_valid) {
- it = p->one;
- addremove = '-';
- } else {
- it = p->two;
- addremove = '+';
- }
-
- printf("%c%06o %s %s %s%c",
- addremove,
- it->mode, git_object_type(it->mode),
- sha1_to_hex(it->sha1), it->path, diff_raw_output);
+ /*
+ * We used to reject rename/copy but new diff-raw can express them.
+ */
+ printf(":%06o %06o %s ",
+ p->one->mode, p->two->mode, sha1_to_hex(p->one->sha1));
+ printf("%s%c%s%c%s%c",
+ sha1_to_hex(p->two->sha1), inter_name_termination,
+ p->one->path, inter_name_termination,
+ p->two->path, line_termination);
}
static void diff_flush_patch(struct diff_filepair *p)
@@ -581,8 +572,8 @@ static void diff_flush_patch(struct diff
name = p->one->path;
other = (strcmp(name, p->two->path) ? p->two->path : NULL);
- if ((p->one->file_valid && S_ISDIR(p->one->mode)) ||
- (p->two->file_valid && S_ISDIR(p->two->mode)))
+ if ((DIFF_FILE_VALID(p->one) && S_ISDIR(p->one->mode)) ||
+ (DIFF_FILE_VALID(p->two) && S_ISDIR(p->two->mode)))
return; /* no tree diffs in patch format */
run_external_diff(name, other, p->one, p->two, p->xfrm_msg);
@@ -596,11 +587,12 @@ static int identical(struct diff_filespe
* and filter and clean them up here before producing the output.
*/
- if (!one->file_valid && !two->file_valid)
+ if (!DIFF_FILE_VALID(one) && !DIFF_FILE_VALID(two))
return 1; /* not interesting */
/* deletion, addition, mode change and renames are all interesting. */
- if ((one->file_valid != two->file_valid) || (one->mode != two->mode) ||
+ if (DIFF_FILE_VALID(one) != DIFF_FILE_VALID(two) ||
+ (one->mode != two->mode) ||
strcmp(one->path, two->path))
return 0;
@@ -619,10 +611,10 @@ static void diff_flush_one(struct diff_f
{
if (identical(p->one, p->two))
return;
- if (0 <= diff_raw_output)
- diff_flush_raw(p);
- else
+ if (generate_patch)
diff_flush_patch(p);
+ else
+ diff_flush_raw(p);
}
int diff_queue_is_empty(void)
@@ -697,10 +689,35 @@ void diff_addremove(int addremove, unsig
diff_queue(&diff_queued_diff, one, two);
}
+void diff_guif(unsigned old_mode,
+ unsigned new_mode,
+ const unsigned char *old_sha1,
+ const unsigned char *new_sha1,
+ const char *old_path,
+ const char *new_path)
+{
+ struct diff_filespec *one, *two;
+
+ if (reverse_diff) {
+ unsigned tmp;
+ const unsigned char *tmp_c;
+ tmp = old_mode; old_mode = new_mode; new_mode = tmp;
+ tmp_c = old_sha1; old_sha1 = new_sha1; new_sha1 = tmp_c;
+ }
+ one = alloc_filespec(old_path);
+ two = alloc_filespec(new_path);
+ if (old_mode)
+ fill_filespec(one, old_sha1, old_mode);
+ if (new_mode)
+ fill_filespec(two, new_sha1, new_mode);
+ diff_queue(&diff_queued_diff, one, two);
+}
+
void diff_change(unsigned old_mode, unsigned new_mode,
const unsigned char *old_sha1,
const unsigned char *new_sha1,
- const char *base, const char *path) {
+ const char *base, const char *path)
+{
char concatpath[PATH_MAX];
struct diff_filespec *one, *two;
@@ -722,9 +739,8 @@ void diff_change(unsigned old_mode, unsi
void diff_unmerge(const char *path)
{
- if (0 <= diff_raw_output) {
- printf("U %s%c", path, diff_raw_output);
- return;
- }
- run_external_diff(path, NULL, NULL, NULL, NULL);
+ if (generate_patch)
+ run_external_diff(path, NULL, NULL, NULL, NULL);
+ else
+ printf("U %s%c", path, line_termination);
}
diff --git a/diff.h b/diff.h
--- a/diff.h
+++ b/diff.h
@@ -15,11 +15,21 @@ extern void diff_change(unsigned mode1,
const unsigned char *sha2,
const char *base, const char *path);
+extern void diff_guif(unsigned mode1,
+ unsigned mode2,
+ const unsigned char *sha1,
+ const unsigned char *sha2,
+ const char *path1,
+ const char *path2);
+
extern void diff_unmerge(const char *path);
extern int diff_scoreopt_parse(const char *opt);
-extern void diff_setup(int reverse, int diff_raw_output);
+#define DIFF_FORMAT_HUMAN 0
+#define DIFF_FORMAT_MACHINE 1
+#define DIFF_FORMAT_PATCH 2
+extern void diff_setup(int reverse, int diff_output_style);
extern void diff_detect_rename(int, int);
extern void diff_pickaxe(const char *);
diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c
--- a/diffcore-pickaxe.c
+++ b/diffcore-pickaxe.c
@@ -32,14 +32,14 @@ void diff_pickaxe(const char *needle)
for (i = 0; i < q->nr; i++) {
struct diff_filepair *p = q->queue[i];
- if (!p->one->file_valid) {
- if (!p->two->file_valid)
+ if (!DIFF_FILE_VALID(p->one)) {
+ if (!DIFF_FILE_VALID(p->two))
continue; /* ignore nonsense */
/* created */
if (contains(p->two, needle, len))
diff_queue(&outq, p->one, p->two);
}
- else if (!p->two->file_valid) {
+ else if (!DIFF_FILE_VALID(p->two)) {
if (contains(p->one, needle, len))
diff_queue(&outq, p->one, p->two);
}
diff --git a/diffcore-rename.c b/diffcore-rename.c
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -142,7 +142,7 @@ static void debug_filespec(struct diff_f
fprintf(stderr, "queue[%d] %s (%s) %s %06o %s\n",
x, one,
s->path,
- s->file_valid ? "valid" : "invalid",
+ DIFF_FILE_VALID(s) ? "valid" : "invalid",
s->mode,
s->sha1_valid ? sha1_to_hex(s->sha1) : "");
fprintf(stderr, "queue[%d] %s size %lu flags %d\n",
@@ -210,7 +210,7 @@ static int needs_to_stay(struct diff_que
*/
while (i < q->nr) {
struct diff_filepair *p = q->queue[i++];
- if (!p->two->file_valid)
+ if (!DIFF_FILE_VALID(p->two))
continue; /* removed is fine */
if (strcmp(p->one->path, it->path))
continue; /* not relevant */
@@ -247,12 +247,12 @@ void diff_detect_rename(int detect_renam
for (i = 0; i < q->nr; i++) {
struct diff_filepair *p = q->queue[i];
- if (!p->one->file_valid)
- if (!p->two->file_valid)
+ if (!DIFF_FILE_VALID(p->one))
+ if (!DIFF_FILE_VALID(p->two))
continue; /* ignore nonsense */
else
diff_rename_pool_add(&created, p->two);
- else if (!p->two->file_valid)
+ else if (!DIFF_FILE_VALID(p->two))
diff_rename_pool_add(&deleted, p->one);
else if (1 < detect_rename) /* find copy, too */
diff_rename_pool_add(&stay, p->one);
@@ -340,15 +340,15 @@ void diff_detect_rename(int detect_renam
*/
for (i = 0; i < q->nr; i++) {
struct diff_filepair *dp, *p = q->queue[i];
- if (!p->one->file_valid) {
- if (p->two->file_valid) {
+ if (!DIFF_FILE_VALID(p->one)) {
+ if (DIFF_FILE_VALID(p->two)) {
/* creation */
dp = diff_queue(&outq, p->one, p->two);
dp->xfrm_work = 4;
}
/* otherwise it is a nonsense; just ignore it */
}
- else if (!p->two->file_valid) {
+ else if (!DIFF_FILE_VALID(p->two)) {
/* deletion */
dp = diff_queue(&outq, p->one, p->two);
dp->xfrm_work = 2;
@@ -374,14 +374,14 @@ void diff_detect_rename(int detect_renam
/* Copy it out to q, removing duplicates. */
for (i = 0; i < outq.nr; i++) {
struct diff_filepair *p = outq.queue[i];
- if (!p->one->file_valid) {
+ if (!DIFF_FILE_VALID(p->one)) {
/* created */
if (p->two->xfrm_flags & RENAME_DST_MATCHED)
; /* rename/copy created it already */
else
diff_queue(q, p->one, p->two);
}
- else if (!p->two->file_valid) {
+ else if (!DIFF_FILE_VALID(p->two)) {
/* deleted */
if (p->one->xfrm_flags & RENAME_SRC_GONE)
; /* rename/copy deleted it already */
diff --git a/diffcore.h b/diffcore.h
--- a/diffcore.h
+++ b/diffcore.h
@@ -26,7 +26,7 @@ struct diff_filespec {
* if false, use the name and read from
* the filesystem.
*/
- unsigned file_valid : 1; /* if false the file does not exist */
+#define DIFF_FILE_VALID(spec) (((spec)->mode) != 0)
unsigned should_free : 1; /* data should be free()'ed */
unsigned should_munmap : 1; /* data should be munmap()'ed */
};
diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
--- a/t/t0000-basic.sh
+++ b/t/t0000-basic.sh
@@ -155,14 +155,14 @@ test_expect_success \
test "$newtree" = "$tree"'
cat >expected <<\EOF
-*100644->100644 blob f87290f8eb2cbbea7857214459a0739927eab154->0000000000000000000000000000000000000000 path0
-*120000->120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01->0000000000000000000000000000000000000000 path0sym
-*100644->100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7->0000000000000000000000000000000000000000 path2/file2
-*120000->120000 blob d8ce161addc5173867a3c3c730924388daedbc38->0000000000000000000000000000000000000000 path2/file2sym
-*100644->100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376->0000000000000000000000000000000000000000 path3/file3
-*120000->120000 blob 8599103969b43aff7e430efea79ca4636466794f->0000000000000000000000000000000000000000 path3/file3sym
-*100644->100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f->0000000000000000000000000000000000000000 path3/subp3/file3
-*120000->120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c->0000000000000000000000000000000000000000 path3/subp3/file3sym
+:100644 100644 f87290f8eb2cbbea7857214459a0739927eab154 0000000000000000000000000000000000000000 path0 path0
+:120000 120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0000000000000000000000000000000000000000 path0sym path0sym
+:100644 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0000000000000000000000000000000000000000 path2/file2 path2/file2
+:120000 120000 d8ce161addc5173867a3c3c730924388daedbc38 0000000000000000000000000000000000000000 path2/file2sym path2/file2sym
+:100644 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0000000000000000000000000000000000000000 path3/file3 path3/file3
+:120000 120000 8599103969b43aff7e430efea79ca4636466794f 0000000000000000000000000000000000000000 path3/file3sym path3/file3sym
+:100644 100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0000000000000000000000000000000000000000 path3/subp3/file3 path3/subp3/file3
+:120000 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0000000000000000000000000000000000000000 path3/subp3/file3sym path3/subp3/file3sym
EOF
test_expect_success \
'validate git-diff-files output for a know cache/work tree state.' \
diff --git a/t/t4002-diff-basic.sh b/t/t4002-diff-basic.sh
--- a/t/t4002-diff-basic.sh
+++ b/t/t4002-diff-basic.sh
@@ -10,123 +10,122 @@ test_description='Test diff raw-output.
. ../lib-read-tree-m-3way.sh
cat >.test-plain-OA <<\EOF
-+100644 blob ccba72ad3888a3520b39efcf780b9ee64167535d AA
-+100644 blob 7e426fb079479fd67f6d81f984e4ec649a44bc25 AN
--100644 blob bcc68ef997017466d5c9094bcf7692295f588c9a DD
-+040000 tree 6d50f65d3bdab91c63444294d38f08aeff328e42 DF
--100644 blob 141c1f1642328e4bc46a7d801a71da392e66791e DM
--100644 blob 35abde1506ddf806572ff4d407bd06885d0f8ee9 DN
-+100644 blob 1d41122ebdd7a640f29d3c9cc4f9d70094374762 LL
-*100644->100644 blob 03f24c8c4700babccfd28b654e7e8eac402ad6cd->103d9f89b50b9aad03054b579be5e7aa665f2d57 MD
-*100644->100644 blob b258508afb7ceb449981bd9d63d2d3e971bf8d34->b431b272d829ff3aa4d1a5085f4394ab4d3305b6 MM
-*100644->100644 blob bd084b0c27c7b6cc34f11d6d0509a29be3caf970->a716d58de4a570e0038f5c307bd8db34daea021f MN
-*100644->100644 blob 40c959f984c8b89a2b02520d17f00d717f024397->2ac547ae9614a00d1b28275de608131f7a0e259f SS
-*100644->100644 blob 4ac13458899ab908ef3b1128fa378daefc88d356->4c86f9a85fbc5e6804ee2e17a797538fbe785bca TT
-*040000->040000 tree 7d670fdcdb9929f6c7dac196ff78689cd1c566a1->5e5f22072bb39f6e12cf663a57cb634c76eefb49 Z
+:000000 100644 0000000000000000000000000000000000000000 ccba72ad3888a3520b39efcf780b9ee64167535d AA AA
+:000000 100644 0000000000000000000000000000000000000000 7e426fb079479fd67f6d81f984e4ec649a44bc25 AN AN
+:100644 000000 bcc68ef997017466d5c9094bcf7692295f588c9a 0000000000000000000000000000000000000000 DD DD
+:000000 040000 0000000000000000000000000000000000000000 6d50f65d3bdab91c63444294d38f08aeff328e42 DF DF
+:100644 000000 141c1f1642328e4bc46a7d801a71da392e66791e 0000000000000000000000000000000000000000 DM DM
+:100644 000000 35abde1506ddf806572ff4d407bd06885d0f8ee9 0000000000000000000000000000000000000000 DN DN
+:000000 100644 0000000000000000000000000000000000000000 1d41122ebdd7a640f29d3c9cc4f9d70094374762 LL LL
+:100644 100644 03f24c8c4700babccfd28b654e7e8eac402ad6cd 103d9f89b50b9aad03054b579be5e7aa665f2d57 MD MD
+:100644 100644 b258508afb7ceb449981bd9d63d2d3e971bf8d34 b431b272d829ff3aa4d1a5085f4394ab4d3305b6 MM MM
+:100644 100644 bd084b0c27c7b6cc34f11d6d0509a29be3caf970 a716d58de4a570e0038f5c307bd8db34daea021f MN MN
+:100644 100644 40c959f984c8b89a2b02520d17f00d717f024397 2ac547ae9614a00d1b28275de608131f7a0e259f SS SS
+:100644 100644 4ac13458899ab908ef3b1128fa378daefc88d356 4c86f9a85fbc5e6804ee2e17a797538fbe785bca TT TT
+:040000 040000 7d670fdcdb9929f6c7dac196ff78689cd1c566a1 5e5f22072bb39f6e12cf663a57cb634c76eefb49 Z Z
EOF
cat >.test-recursive-OA <<\EOF
-+100644 blob ccba72ad3888a3520b39efcf780b9ee64167535d AA
-+100644 blob 7e426fb079479fd67f6d81f984e4ec649a44bc25 AN
--100644 blob bcc68ef997017466d5c9094bcf7692295f588c9a DD
-+100644 blob 68a6d8b91da11045cf4aa3a5ab9f2a781c701249 DF/DF
--100644 blob 141c1f1642328e4bc46a7d801a71da392e66791e DM
--100644 blob 35abde1506ddf806572ff4d407bd06885d0f8ee9 DN
-+100644 blob 1d41122ebdd7a640f29d3c9cc4f9d70094374762 LL
-*100644->100644 blob 03f24c8c4700babccfd28b654e7e8eac402ad6cd->103d9f89b50b9aad03054b579be5e7aa665f2d57 MD
-*100644->100644 blob b258508afb7ceb449981bd9d63d2d3e971bf8d34->b431b272d829ff3aa4d1a5085f4394ab4d3305b6 MM
-*100644->100644 blob bd084b0c27c7b6cc34f11d6d0509a29be3caf970->a716d58de4a570e0038f5c307bd8db34daea021f MN
-*100644->100644 blob 40c959f984c8b89a2b02520d17f00d717f024397->2ac547ae9614a00d1b28275de608131f7a0e259f SS
-*100644->100644 blob 4ac13458899ab908ef3b1128fa378daefc88d356->4c86f9a85fbc5e6804ee2e17a797538fbe785bca TT
-+100644 blob 8acb8e9750e3f644bf323fcf3d338849db106c77 Z/AA
-+100644 blob 087494262084cefee7ed484d20c8dc0580791272 Z/AN
--100644 blob 879007efae624d2b1307214b24a956f0a8d686a8 Z/DD
--100644 blob 9b541b2275c06e3a7b13f28badf5294e2ae63df4 Z/DM
--100644 blob beb5d38c55283d280685ea21a0e50cfcc0ca064a Z/DN
-*100644->100644 blob d41fda41b7ec4de46b43cb7ea42a45001ae393d5->a79ac3be9377639e1c7d1edf1ae1b3a5f0ccd8a9 Z/MD
-*100644->100644 blob 4ca22bae2527d3d9e1676498a0fba3b355bd1278->61422ba9c2c873416061a88cd40a59a35b576474 Z/MM
-*100644->100644 blob b16d7b25b869f2beb124efa53467d8a1550ad694->a5c544c21cfcb07eb80a4d89a5b7d1570002edfd Z/MN
+:000000 100644 0000000000000000000000000000000000000000 ccba72ad3888a3520b39efcf780b9ee64167535d AA AA
+:000000 100644 0000000000000000000000000000000000000000 7e426fb079479fd67f6d81f984e4ec649a44bc25 AN AN
+:100644 000000 bcc68ef997017466d5c9094bcf7692295f588c9a 0000000000000000000000000000000000000000 DD DD
+:000000 100644 0000000000000000000000000000000000000000 68a6d8b91da11045cf4aa3a5ab9f2a781c701249 DF/DF DF/DF
+:100644 000000 141c1f1642328e4bc46a7d801a71da392e66791e 0000000000000000000000000000000000000000 DM DM
+:100644 000000 35abde1506ddf806572ff4d407bd06885d0f8ee9 0000000000000000000000000000000000000000 DN DN
+:000000 100644 0000000000000000000000000000000000000000 1d41122ebdd7a640f29d3c9cc4f9d70094374762 LL LL
+:100644 100644 03f24c8c4700babccfd28b654e7e8eac402ad6cd 103d9f89b50b9aad03054b579be5e7aa665f2d57 MD MD
+:100644 100644 b258508afb7ceb449981bd9d63d2d3e971bf8d34 b431b272d829ff3aa4d1a5085f4394ab4d3305b6 MM MM
+:100644 100644 bd084b0c27c7b6cc34f11d6d0509a29be3caf970 a716d58de4a570e0038f5c307bd8db34daea021f MN MN
+:100644 100644 40c959f984c8b89a2b02520d17f00d717f024397 2ac547ae9614a00d1b28275de608131f7a0e259f SS SS
+:100644 100644 4ac13458899ab908ef3b1128fa378daefc88d356 4c86f9a85fbc5e6804ee2e17a797538fbe785bca TT TT
+:000000 100644 0000000000000000000000000000000000000000 8acb8e9750e3f644bf323fcf3d338849db106c77 Z/AA Z/AA
+:000000 100644 0000000000000000000000000000000000000000 087494262084cefee7ed484d20c8dc0580791272 Z/AN Z/AN
+:100644 000000 879007efae624d2b1307214b24a956f0a8d686a8 0000000000000000000000000000000000000000 Z/DD Z/DD
+:100644 000000 9b541b2275c06e3a7b13f28badf5294e2ae63df4 0000000000000000000000000000000000000000 Z/DM Z/DM
+:100644 000000 beb5d38c55283d280685ea21a0e50cfcc0ca064a 0000000000000000000000000000000000000000 Z/DN Z/DN
+:100644 100644 d41fda41b7ec4de46b43cb7ea42a45001ae393d5 a79ac3be9377639e1c7d1edf1ae1b3a5f0ccd8a9 Z/MD Z/MD
+:100644 100644 4ca22bae2527d3d9e1676498a0fba3b355bd1278 61422ba9c2c873416061a88cd40a59a35b576474 Z/MM Z/MM
+:100644 100644 b16d7b25b869f2beb124efa53467d8a1550ad694 a5c544c21cfcb07eb80a4d89a5b7d1570002edfd Z/MN Z/MN
EOF
cat >.test-plain-OB <<\EOF
-+100644 blob 6aa2b5335b16431a0ef71e5c0a28be69183cf6a2 AA
--100644 blob bcc68ef997017466d5c9094bcf7692295f588c9a DD
-+100644 blob 71420ab81e254145d26d6fc0cddee64c1acd4787 DF
-*100644->100644 blob 141c1f1642328e4bc46a7d801a71da392e66791e->3c4d8de5fbad08572bab8e10eef8dbb264cf0231 DM
-+100644 blob 1d41122ebdd7a640f29d3c9cc4f9d70094374762 LL
--100644 blob 03f24c8c4700babccfd28b654e7e8eac402ad6cd MD
-*100644->100644 blob b258508afb7ceb449981bd9d63d2d3e971bf8d34->19989d4559aae417fedee240ccf2ba315ea4dc2b MM
-+100644 blob 15885881ea69115351c09b38371f0348a3fb8c67 NA
--100644 blob a4e179e4291e5536a5e1c82e091052772d2c5a93 ND
-*100644->100644 blob c8f25781e8f1792e3e40b74225e20553041b5226->cdb9a8c3da571502ac30225e9c17beccb8387983 NM
-*100644->100644 blob 40c959f984c8b89a2b02520d17f00d717f024397->2ac547ae9614a00d1b28275de608131f7a0e259f SS
-*100644->100644 blob 4ac13458899ab908ef3b1128fa378daefc88d356->c4e4a12231b9fa79a0053cb6077fcb21bb5b135a TT
-*040000->040000 tree 7d670fdcdb9929f6c7dac196ff78689cd1c566a1->1ba523955d5160681af65cb776411f574c1e8155 Z
+:000000 100644 0000000000000000000000000000000000000000 6aa2b5335b16431a0ef71e5c0a28be69183cf6a2 AA AA
+:100644 000000 bcc68ef997017466d5c9094bcf7692295f588c9a 0000000000000000000000000000000000000000 DD DD
+:000000 100644 0000000000000000000000000000000000000000 71420ab81e254145d26d6fc0cddee64c1acd4787 DF DF
+:100644 100644 141c1f1642328e4bc46a7d801a71da392e66791e 3c4d8de5fbad08572bab8e10eef8dbb264cf0231 DM DM
+:000000 100644 0000000000000000000000000000000000000000 1d41122ebdd7a640f29d3c9cc4f9d70094374762 LL LL
+:100644 000000 03f24c8c4700babccfd28b654e7e8eac402ad6cd 0000000000000000000000000000000000000000 MD MD
+:100644 100644 b258508afb7ceb449981bd9d63d2d3e971bf8d34 19989d4559aae417fedee240ccf2ba315ea4dc2b MM MM
+:000000 100644 0000000000000000000000000000000000000000 15885881ea69115351c09b38371f0348a3fb8c67 NA NA
+:100644 000000 a4e179e4291e5536a5e1c82e091052772d2c5a93 0000000000000000000000000000000000000000 ND ND
+:100644 100644 c8f25781e8f1792e3e40b74225e20553041b5226 cdb9a8c3da571502ac30225e9c17beccb8387983 NM NM
+:100644 100644 40c959f984c8b89a2b02520d17f00d717f024397 2ac547ae9614a00d1b28275de608131f7a0e259f SS SS
+:100644 100644 4ac13458899ab908ef3b1128fa378daefc88d356 c4e4a12231b9fa79a0053cb6077fcb21bb5b135a TT TT
+:040000 040000 7d670fdcdb9929f6c7dac196ff78689cd1c566a1 1ba523955d5160681af65cb776411f574c1e8155 Z Z
EOF
cat >.test-recursive-OB <<\EOF
-+100644 blob 6aa2b5335b16431a0ef71e5c0a28be69183cf6a2 AA
--100644 blob bcc68ef997017466d5c9094bcf7692295f588c9a DD
-+100644 blob 71420ab81e254145d26d6fc0cddee64c1acd4787 DF
-*100644->100644 blob 141c1f1642328e4bc46a7d801a71da392e66791e->3c4d8de5fbad08572bab8e10eef8dbb264cf0231 DM
-+100644 blob 1d41122ebdd7a640f29d3c9cc4f9d70094374762 LL
--100644 blob 03f24c8c4700babccfd28b654e7e8eac402ad6cd MD
-*100644->100644 blob b258508afb7ceb449981bd9d63d2d3e971bf8d34->19989d4559aae417fedee240ccf2ba315ea4dc2b MM
-+100644 blob 15885881ea69115351c09b38371f0348a3fb8c67 NA
--100644 blob a4e179e4291e5536a5e1c82e091052772d2c5a93 ND
-*100644->100644 blob c8f25781e8f1792e3e40b74225e20553041b5226->cdb9a8c3da571502ac30225e9c17beccb8387983 NM
-*100644->100644 blob 40c959f984c8b89a2b02520d17f00d717f024397->2ac547ae9614a00d1b28275de608131f7a0e259f SS
-*100644->100644 blob 4ac13458899ab908ef3b1128fa378daefc88d356->c4e4a12231b9fa79a0053cb6077fcb21bb5b135a TT
-+100644 blob 6c0b99286d0bce551ac4a7b3dff8b706edff3715 Z/AA
--100644 blob 879007efae624d2b1307214b24a956f0a8d686a8 Z/DD
-*100644->100644 blob 9b541b2275c06e3a7b13f28badf5294e2ae63df4->d77371d15817fcaa57eeec27f770c505ba974ec1 Z/DM
--100644 blob d41fda41b7ec4de46b43cb7ea42a45001ae393d5 Z/MD
-*100644->100644 blob 4ca22bae2527d3d9e1676498a0fba3b355bd1278->697aad7715a1e7306ca76290a3dd4208fbaeddfa Z/MM
-+100644 blob d12979c22fff69c59ca9409e7a8fe3ee25eaee80 Z/NA
--100644 blob a18393c636b98e9bd7296b8b437ea4992b72440c Z/ND
-*100644->100644 blob 3fdbe17fd013303a2e981e1ca1c6cd6e72789087->7e09d6a3a14bd630913e8c75693cea32157b606d Z/NM
+:000000 100644 0000000000000000000000000000000000000000 6aa2b5335b16431a0ef71e5c0a28be69183cf6a2 AA AA
+:100644 000000 bcc68ef997017466d5c9094bcf7692295f588c9a 0000000000000000000000000000000000000000 DD DD
+:000000 100644 0000000000000000000000000000000000000000 71420ab81e254145d26d6fc0cddee64c1acd4787 DF DF
+:100644 100644 141c1f1642328e4bc46a7d801a71da392e66791e 3c4d8de5fbad08572bab8e10eef8dbb264cf0231 DM DM
+:000000 100644 0000000000000000000000000000000000000000 1d41122ebdd7a640f29d3c9cc4f9d70094374762 LL LL
+:100644 000000 03f24c8c4700babccfd28b654e7e8eac402ad6cd 0000000000000000000000000000000000000000 MD MD
+:100644 100644 b258508afb7ceb449981bd9d63d2d3e971bf8d34 19989d4559aae417fedee240ccf2ba315ea4dc2b MM MM
+:000000 100644 0000000000000000000000000000000000000000 15885881ea69115351c09b38371f0348a3fb8c67 NA NA
+:100644 000000 a4e179e4291e5536a5e1c82e091052772d2c5a93 0000000000000000000000000000000000000000 ND ND
+:100644 100644 c8f25781e8f1792e3e40b74225e20553041b5226 cdb9a8c3da571502ac30225e9c17beccb8387983 NM NM
+:100644 100644 40c959f984c8b89a2b02520d17f00d717f024397 2ac547ae9614a00d1b28275de608131f7a0e259f SS SS
+:100644 100644 4ac13458899ab908ef3b1128fa378daefc88d356 c4e4a12231b9fa79a0053cb6077fcb21bb5b135a TT TT
+:000000 100644 0000000000000000000000000000000000000000 6c0b99286d0bce551ac4a7b3dff8b706edff3715 Z/AA Z/AA
+:100644 000000 879007efae624d2b1307214b24a956f0a8d686a8 0000000000000000000000000000000000000000 Z/DD Z/DD
+:100644 100644 9b541b2275c06e3a7b13f28badf5294e2ae63df4 d77371d15817fcaa57eeec27f770c505ba974ec1 Z/DM Z/DM
+:100644 000000 d41fda41b7ec4de46b43cb7ea42a45001ae393d5 0000000000000000000000000000000000000000 Z/MD Z/MD
+:100644 100644 4ca22bae2527d3d9e1676498a0fba3b355bd1278 697aad7715a1e7306ca76290a3dd4208fbaeddfa Z/MM Z/MM
+:000000 100644 0000000000000000000000000000000000000000 d12979c22fff69c59ca9409e7a8fe3ee25eaee80 Z/NA Z/NA
+:100644 000000 a18393c636b98e9bd7296b8b437ea4992b72440c 0000000000000000000000000000000000000000 Z/ND Z/ND
+:100644 100644 3fdbe17fd013303a2e981e1ca1c6cd6e72789087 7e09d6a3a14bd630913e8c75693cea32157b606d Z/NM Z/NM
EOF
cat >.test-plain-AB <<\EOF
-*100644->100644 blob ccba72ad3888a3520b39efcf780b9ee64167535d->6aa2b5335b16431a0ef71e5c0a28be69183cf6a2 AA
--100644 blob 7e426fb079479fd67f6d81f984e4ec649a44bc25 AN
-+100644 blob 71420ab81e254145d26d6fc0cddee64c1acd4787 DF
--040000 tree 6d50f65d3bdab91c63444294d38f08aeff328e42 DF
-+100644 blob 3c4d8de5fbad08572bab8e10eef8dbb264cf0231 DM
-+100644 blob 35abde1506ddf806572ff4d407bd06885d0f8ee9 DN
--100644 blob 103d9f89b50b9aad03054b579be5e7aa665f2d57 MD
-*100644->100644 blob b431b272d829ff3aa4d1a5085f4394ab4d3305b6->19989d4559aae417fedee240ccf2ba315ea4dc2b MM
-*100644->100644 blob a716d58de4a570e0038f5c307bd8db34daea021f->bd084b0c27c7b6cc34f11d6d0509a29be3caf970 MN
-+100644 blob 15885881ea69115351c09b38371f0348a3fb8c67 NA
--100644 blob a4e179e4291e5536a5e1c82e091052772d2c5a93 ND
-*100644->100644 blob c8f25781e8f1792e3e40b74225e20553041b5226->cdb9a8c3da571502ac30225e9c17beccb8387983 NM
-*100644->100644 blob 4c86f9a85fbc5e6804ee2e17a797538fbe785bca->c4e4a12231b9fa79a0053cb6077fcb21bb5b135a TT
-*040000->040000 tree 5e5f22072bb39f6e12cf663a57cb634c76eefb49->1ba523955d5160681af65cb776411f574c1e8155 Z
+:100644 100644 ccba72ad3888a3520b39efcf780b9ee64167535d 6aa2b5335b16431a0ef71e5c0a28be69183cf6a2 AA AA
+:100644 000000 7e426fb079479fd67f6d81f984e4ec649a44bc25 0000000000000000000000000000000000000000 AN AN
+:000000 100644 0000000000000000000000000000000000000000 71420ab81e254145d26d6fc0cddee64c1acd4787 DF DF
+:040000 000000 6d50f65d3bdab91c63444294d38f08aeff328e42 0000000000000000000000000000000000000000 DF DF
+:000000 100644 0000000000000000000000000000000000000000 3c4d8de5fbad08572bab8e10eef8dbb264cf0231 DM DM
+:000000 100644 0000000000000000000000000000000000000000 35abde1506ddf806572ff4d407bd06885d0f8ee9 DN DN
+:100644 000000 103d9f89b50b9aad03054b579be5e7aa665f2d57 0000000000000000000000000000000000000000 MD MD
+:100644 100644 b431b272d829ff3aa4d1a5085f4394ab4d3305b6 19989d4559aae417fedee240ccf2ba315ea4dc2b MM MM
+:100644 100644 a716d58de4a570e0038f5c307bd8db34daea021f bd084b0c27c7b6cc34f11d6d0509a29be3caf970 MN MN
+:000000 100644 0000000000000000000000000000000000000000 15885881ea69115351c09b38371f0348a3fb8c67 NA NA
+:100644 000000 a4e179e4291e5536a5e1c82e091052772d2c5a93 0000000000000000000000000000000000000000 ND ND
+:100644 100644 c8f25781e8f1792e3e40b74225e20553041b5226 cdb9a8c3da571502ac30225e9c17beccb8387983 NM NM
+:100644 100644 4c86f9a85fbc5e6804ee2e17a797538fbe785bca c4e4a12231b9fa79a0053cb6077fcb21bb5b135a TT TT
+:040000 040000 5e5f22072bb39f6e12cf663a57cb634c76eefb49 1ba523955d5160681af65cb776411f574c1e8155 Z Z
EOF
cat >.test-recursive-AB <<\EOF
-*100644->100644 blob ccba72ad3888a3520b39efcf780b9ee64167535d->6aa2b5335b16431a0ef71e5c0a28be69183cf6a2 AA
--100644 blob 7e426fb079479fd67f6d81f984e4ec649a44bc25 AN
-+100644 blob 71420ab81e254145d26d6fc0cddee64c1acd4787 DF
--100644 blob 68a6d8b91da11045cf4aa3a5ab9f2a781c701249 DF/DF
-+100644 blob 3c4d8de5fbad08572bab8e10eef8dbb264cf0231 DM
-+100644 blob 35abde1506ddf806572ff4d407bd06885d0f8ee9 DN
--100644 blob 103d9f89b50b9aad03054b579be5e7aa665f2d57 MD
-*100644->100644 blob b431b272d829ff3aa4d1a5085f4394ab4d3305b6->19989d4559aae417fedee240ccf2ba315ea4dc2b MM
-*100644->100644 blob a716d58de4a570e0038f5c307bd8db34daea021f->bd084b0c27c7b6cc34f11d6d0509a29be3caf970 MN
-+100644 blob 15885881ea69115351c09b38371f0348a3fb8c67 NA
--100644 blob a4e179e4291e5536a5e1c82e091052772d2c5a93 ND
-*100644->100644 blob c8f25781e8f1792e3e40b74225e20553041b5226->cdb9a8c3da571502ac30225e9c17beccb8387983 NM
-*100644->100644 blob 4c86f9a85fbc5e6804ee2e17a797538fbe785bca->c4e4a12231b9fa79a0053cb6077fcb21bb5b135a TT
-*100644->100644 blob 8acb8e9750e3f644bf323fcf3d338849db106c77->6c0b99286d0bce551ac4a7b3dff8b706edff3715 Z/AA
--100644 blob 087494262084cefee7ed484d20c8dc0580791272 Z/AN
-+100644 blob d77371d15817fcaa57eeec27f770c505ba974ec1 Z/DM
-+100644 blob beb5d38c55283d280685ea21a0e50cfcc0ca064a Z/DN
--100644 blob a79ac3be9377639e1c7d1edf1ae1b3a5f0ccd8a9 Z/MD
-*100644->100644 blob 61422ba9c2c873416061a88cd40a59a35b576474->697aad7715a1e7306ca76290a3dd4208fbaeddfa Z/MM
-*100644->100644 blob a5c544c21cfcb07eb80a4d89a5b7d1570002edfd->b16d7b25b869f2beb124efa53467d8a1550ad694 Z/MN
-+100644 blob d12979c22fff69c59ca9409e7a8fe3ee25eaee80 Z/NA
--100644 blob a18393c636b98e9bd7296b8b437ea4992b72440c Z/ND
-*100644->100644 blob 3fdbe17fd013303a2e981e1ca1c6cd6e72789087->7e09d6a3a14bd630913e8c75693cea32157b606d Z/NM
+:100644 100644 ccba72ad3888a3520b39efcf780b9ee64167535d 6aa2b5335b16431a0ef71e5c0a28be69183cf6a2 AA AA
+:100644 000000 7e426fb079479fd67f6d81f984e4ec649a44bc25 0000000000000000000000000000000000000000 AN AN
+:000000 100644 0000000000000000000000000000000000000000 71420ab81e254145d26d6fc0cddee64c1acd4787 DF DF
+:100644 000000 68a6d8b91da11045cf4aa3a5ab9f2a781c701249 0000000000000000000000000000000000000000 DF/DF DF/DF
+:000000 100644 0000000000000000000000000000000000000000 3c4d8de5fbad08572bab8e10eef8dbb264cf0231 DM DM
+:000000 100644 0000000000000000000000000000000000000000 35abde1506ddf806572ff4d407bd06885d0f8ee9 DN DN
+:100644 000000 103d9f89b50b9aad03054b579be5e7aa665f2d57 0000000000000000000000000000000000000000 MD MD
+:100644 100644 b431b272d829ff3aa4d1a5085f4394ab4d3305b6 19989d4559aae417fedee240ccf2ba315ea4dc2b MM MM
+:100644 100644 a716d58de4a570e0038f5c307bd8db34daea021f bd084b0c27c7b6cc34f11d6d0509a29be3caf970 MN MN
+:000000 100644 0000000000000000000000000000000000000000 15885881ea69115351c09b38371f0348a3fb8c67 NA NA
+:100644 000000 a4e179e4291e5536a5e1c82e091052772d2c5a93 0000000000000000000000000000000000000000 ND ND
+:100644 100644 c8f25781e8f1792e3e40b74225e20553041b5226 cdb9a8c3da571502ac30225e9c17beccb8387983 NM NM
+:100644 100644 4c86f9a85fbc5e6804ee2e17a797538fbe785bca c4e4a12231b9fa79a0053cb6077fcb21bb5b135a TT TT
+:100644 100644 8acb8e9750e3f644bf323fcf3d338849db106c77 6c0b99286d0bce551ac4a7b3dff8b706edff3715 Z/AA Z/AA
+:100644 000000 087494262084cefee7ed484d20c8dc0580791272 0000000000000000000000000000000000000000 Z/AN Z/AN
+:000000 100644 0000000000000000000000000000000000000000 d77371d15817fcaa57eeec27f770c505ba974ec1 Z/DM Z/DM
+:000000 100644 0000000000000000000000000000000000000000 beb5d38c55283d280685ea21a0e50cfcc0ca064a Z/DN Z/DN
+:100644 000000 a79ac3be9377639e1c7d1edf1ae1b3a5f0ccd8a9 0000000000000000000000000000000000000000 Z/MD Z/MD
+:100644 100644 61422ba9c2c873416061a88cd40a59a35b576474 697aad7715a1e7306ca76290a3dd4208fbaeddfa Z/MM Z/MM
+:100644 100644 a5c544c21cfcb07eb80a4d89a5b7d1570002edfd b16d7b25b869f2beb124efa53467d8a1550ad694 Z/MN Z/MN
+:000000 100644 0000000000000000000000000000000000000000 d12979c22fff69c59ca9409e7a8fe3ee25eaee80 Z/NA Z/NA
+:100644 000000 a18393c636b98e9bd7296b8b437ea4992b72440c 0000000000000000000000000000000000000000 Z/ND Z/ND
+:100644 100644 3fdbe17fd013303a2e981e1ca1c6cd6e72789087 7e09d6a3a14bd630913e8c75693cea32157b606d Z/NM Z/NM
EOF
-
x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
x40="$x40$x40$x40$x40$x40$x40$x40$x40"
z40='0000000000000000000000000000000000000000'
@@ -135,7 +134,7 @@ cmp_diff_files_output () {
# object ID for the changed files because it wants you to look at the
# filesystem.
sed <"$2" >.test-tmp \
- -e '/^+/d;/\^*/s/\( '$x40'->\)'$x40' /\1'$z40' /' &&
+ -e '/^:000000 /d;s/'$x40' /'$z40' /' &&
diff "$1" .test-tmp
}
diff --git a/t/t4003-diff-rename-1.sh b/t/t4003-diff-rename-1.sh
--- a/t/t4003-diff-rename-1.sh
+++ b/t/t4003-diff-rename-1.sh
@@ -26,7 +26,7 @@ test_expect_success \
# both are slightly edited. So we say you copy-and-edit one,
# and rename-and-edit the other.
-GIT_DIFF_OPTS=--unified=0 git-diff-cache -M $tree |
+GIT_DIFF_OPTS=--unified=0 git-diff-cache -M -p $tree |
sed -e 's/\([0-9][0-9]*\)/#/g' >current &&
cat >expected <<\EOF
diff --git a/COPYING b/COPYING.#
@@ -68,7 +68,7 @@ test_expect_success \
# both are slightly edited. So we say you edited one,
# and copy-and-edit the other.
-GIT_DIFF_OPTS=--unified=0 git-diff-cache -C $tree |
+GIT_DIFF_OPTS=--unified=0 git-diff-cache -C -p $tree |
sed -e 's/\([0-9][0-9]*\)/#/g' >current
cat >expected <<\EOF
diff --git a/COPYING b/COPYING.#
@@ -108,7 +108,7 @@ test_expect_success \
# this is only possible because -C mode now reports the unmodified
# file to the diff-core.
-GIT_DIFF_OPTS=--unified=0 git-diff-cache -C $tree |
+GIT_DIFF_OPTS=--unified=0 git-diff-cache -C -p $tree |
sed -e 's/\([0-9][0-9]*\)/#/g' >current
cat >expected <<\EOF
diff --git a/COPYING b/COPYING.#
------------------------------------------------
^ permalink raw reply
* [PATCH] Prepare diffcore interface for diff-tree header supression.
From: Junio C Hamano @ 2005-05-22 2:40 UTC (permalink / raw)
To: Linus Torvalds; +Cc: git
In-Reply-To: <7vwtpsdvgm.fsf@assigned-by-dhcp.cox.net>
This does not actually supress the extra headers when pickaxe is
used, but prepares enough support for diff-tree to implement it.
Signed-off-by: Junio C Hamano <junkio@cox.net>
---
diff-cache.c | 10 ++++++----
diff-files.c | 10 ++++++----
diff-helper.c | 13 +++++++------
diff-tree.c | 26 ++++++++++++++++++--------
diff.c | 43 ++++++++++++++++++++++---------------------
diff.h | 12 +++++++-----
diffcore-pickaxe.c | 3 ++-
diffcore-rename.c | 4 ++--
diffcore.h | 3 +--
9 files changed, 71 insertions(+), 53 deletions(-)
diff --git a/diff-cache.c b/diff-cache.c
--- a/diff-cache.c
+++ b/diff-cache.c
@@ -214,9 +214,7 @@ int main(int argc, char **argv)
if (argc != 2 || get_sha1(argv[1], tree_sha1))
usage(diff_cache_usage);
- diff_setup(detect_rename, diff_score_opt, pickaxe,
- reverse_diff, (generate_patch ? -1 : line_termination),
- NULL, 0);
+ diff_setup(reverse_diff, (generate_patch ? -1 : line_termination));
mark_merge_entries();
@@ -227,6 +225,10 @@ int main(int argc, char **argv)
die("unable to read tree object %s", argv[1]);
ret = diff_cache(active_cache, active_nr);
- diff_flush();
+ if (detect_rename)
+ diff_detect_rename(detect_rename, diff_score_opt);
+ if (pickaxe)
+ diff_pickaxe(pickaxe);
+ diff_flush(NULL, 0);
return ret;
}
diff --git a/diff-files.c b/diff-files.c
--- a/diff-files.c
+++ b/diff-files.c
@@ -92,9 +92,7 @@ int main(int argc, char **argv)
exit(1);
}
- diff_setup(detect_rename, diff_score_opt, pickaxe,
- reverse_diff, (generate_patch ? -1 : line_termination),
- NULL, 0);
+ diff_setup(reverse_diff, (generate_patch ? -1 : line_termination));
for (i = 0; i < entries; i++) {
struct stat st;
@@ -136,6 +134,10 @@ int main(int argc, char **argv)
show_modified(oldmode, mode, ce->sha1, null_sha1,
ce->name);
}
- diff_flush();
+ if (detect_rename)
+ diff_detect_rename(detect_rename, diff_score_opt);
+ if (pickaxe)
+ diff_pickaxe(pickaxe);
+ diff_flush(NULL, 0);
return 0;
}
diff --git a/diff-helper.c b/diff-helper.c
--- a/diff-helper.c
+++ b/diff-helper.c
@@ -127,10 +127,7 @@ int main(int ac, const char **av) {
}
/* the remaining parameters are paths patterns */
- diff_setup(detect_rename, diff_score_opt, pickaxe,
- reverse, (generate_patch ? -1 : line_termination),
- av+1, ac-1);
-
+ diff_setup(reverse, (generate_patch ? -1 : line_termination));
while (1) {
int status;
read_line(&sb, stdin, line_termination);
@@ -138,11 +135,15 @@ int main(int ac, const char **av) {
break;
status = parse_diff_raw_output(sb.buf);
if (status) {
- diff_flush();
+ diff_flush(av+1, ac-1);
printf("%s%c", sb.buf, line_termination);
}
}
- diff_flush();
+ if (detect_rename)
+ diff_detect_rename(detect_rename, diff_score_opt);
+ if (pickaxe)
+ diff_pickaxe(pickaxe);
+ diff_flush(av+1, ac-1);
return 0;
}
diff --git a/diff-tree.c b/diff-tree.c
--- a/diff-tree.c
+++ b/diff-tree.c
@@ -267,16 +267,28 @@ static int diff_tree_sha1(const unsigned
return retval;
}
+static void call_diff_setup(void)
+{
+ diff_setup(reverse_diff, (generate_patch ? -1 : line_termination));
+}
+
+static void call_diff_flush(void)
+{
+ if (detect_rename)
+ diff_detect_rename(detect_rename, diff_score_opt);
+ if (pickaxe)
+ diff_pickaxe(pickaxe);
+ diff_flush(NULL, 0);
+}
+
static int diff_tree_sha1_top(const unsigned char *old,
const unsigned char *new, const char *base)
{
int ret;
- diff_setup(detect_rename, diff_score_opt, pickaxe,
- reverse_diff, (generate_patch ? -1 : line_termination),
- NULL, 0);
+ call_diff_setup();
ret = diff_tree_sha1(old, new, base);
- diff_flush();
+ call_diff_flush();
return ret;
}
@@ -286,15 +298,13 @@ static int diff_root_tree(const unsigned
void *tree;
unsigned long size;
- diff_setup(detect_rename, diff_score_opt, pickaxe,
- reverse_diff, (generate_patch ? -1 : line_termination),
- NULL, 0);
+ call_diff_setup();
tree = read_object_with_reference(new, "tree", &size, NULL);
if (!tree)
die("unable to read root tree (%s)", sha1_to_hex(new));
retval = diff_tree("", 0, tree, size, base);
free(tree);
- diff_flush();
+ call_diff_flush();
return retval;
}
diff --git a/diff.c b/diff.c
--- a/diff.c
+++ b/diff.c
@@ -12,13 +12,10 @@
static const char *diff_opts = "-pu";
static unsigned char null_sha1[20] = { 0, };
-static int detect_rename;
static int reverse_diff;
static int diff_raw_output = -1;
static const char **pathspec;
static int speccnt;
-static const char *pickaxe;
-static int minimum_score;
static const char *external_diff(void)
{
@@ -512,21 +509,13 @@ int diff_scoreopt_parse(const char *opt)
return MAX_SCORE * num / scale;
}
-void diff_setup(int detect_rename_, int minimum_score_,
- const char *pickaxe_,
- int reverse_diff_, int diff_raw_output_,
- const char **pathspec_, int speccnt_)
+void diff_setup(int reverse_diff_, int diff_raw_output_)
{
- detect_rename = detect_rename_;
reverse_diff = reverse_diff_;
- pathspec = pathspec_;
diff_raw_output = diff_raw_output_;
- speccnt = speccnt_;
- minimum_score = minimum_score_ ? : DEFAULT_MINIMUM_SCORE;
- pickaxe = pickaxe_;
}
-static struct diff_queue_struct queued_diff;
+struct diff_queue_struct diff_queued_diff;
struct diff_filepair *diff_queue(struct diff_queue_struct *queue,
struct diff_filespec *one,
@@ -636,15 +625,27 @@ static void diff_flush_one(struct diff_f
diff_flush_patch(p);
}
-void diff_flush(void)
+int diff_queue_is_empty(void)
{
- struct diff_queue_struct *q = &queued_diff;
+ struct diff_queue_struct *q = &diff_queued_diff;
int i;
- if (detect_rename)
- diff_detect_rename(q, detect_rename, minimum_score);
- if (pickaxe)
- diff_pickaxe(q, pickaxe);
+ for (i = 0; i < q->nr; i++) {
+ struct diff_filepair *p = q->queue[i];
+ if (!identical(p->one, p->two))
+ return 0;
+ }
+ return 1;
+}
+
+void diff_flush(const char **pathspec_, int speccnt_)
+{
+ struct diff_queue_struct *q = &diff_queued_diff;
+ int i;
+
+ pathspec = pathspec_;
+ speccnt = speccnt_;
+
for (i = 0; i < q->nr; i++)
diff_flush_one(q->queue[i]);
@@ -693,7 +694,7 @@ void diff_addremove(int addremove, unsig
if (addremove != '-')
fill_filespec(two, sha1, mode);
- diff_queue(&queued_diff, one, two);
+ diff_queue(&diff_queued_diff, one, two);
}
void diff_change(unsigned old_mode, unsigned new_mode,
@@ -716,7 +717,7 @@ void diff_change(unsigned old_mode, unsi
fill_filespec(one, old_sha1, old_mode);
fill_filespec(two, new_sha1, new_mode);
- diff_queue(&queued_diff, one, two);
+ diff_queue(&diff_queued_diff, one, two);
}
void diff_unmerge(const char *path)
diff --git a/diff.h b/diff.h
--- a/diff.h
+++ b/diff.h
@@ -19,11 +19,13 @@ extern void diff_unmerge(const char *pat
extern int diff_scoreopt_parse(const char *opt);
-extern void diff_setup(int detect_rename, int minimum_score,
- const char *pickaxe,
- int reverse, int raw_output,
- const char **spec, int cnt);
+extern void diff_setup(int reverse, int diff_raw_output);
-extern void diff_flush(void);
+extern void diff_detect_rename(int, int);
+extern void diff_pickaxe(const char *);
+
+extern int diff_queue_is_empty(void);
+
+extern void diff_flush(const char **, int);
#endif /* DIFF_H */
diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c
--- a/diffcore-pickaxe.c
+++ b/diffcore-pickaxe.c
@@ -21,8 +21,9 @@ static int contains(struct diff_filespec
return 0;
}
-void diff_pickaxe(struct diff_queue_struct *q, const char *needle)
+void diff_pickaxe(const char *needle)
{
+ struct diff_queue_struct *q = &diff_queued_diff;
unsigned long len = strlen(needle);
int i;
struct diff_queue_struct outq;
diff --git a/diffcore-rename.c b/diffcore-rename.c
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -224,10 +224,10 @@ static int needs_to_stay(struct diff_que
return 0;
}
-void diff_detect_rename(struct diff_queue_struct *q,
- int detect_rename,
+void diff_detect_rename(int detect_rename,
int minimum_score)
{
+ struct diff_queue_struct *q = &diff_queued_diff;
struct diff_queue_struct outq;
struct diff_rename_pool created, deleted, stay;
struct diff_rename_pool *(srcs[2]);
diff --git a/diffcore.h b/diffcore.h
--- a/diffcore.h
+++ b/diffcore.h
@@ -52,10 +52,9 @@ struct diff_queue_struct {
int nr;
};
+extern struct diff_queue_struct diff_queued_diff;
extern struct diff_filepair *diff_queue(struct diff_queue_struct *,
struct diff_filespec *,
struct diff_filespec *);
-extern void diff_detect_rename(struct diff_queue_struct *, int, int);
-extern void diff_pickaxe(struct diff_queue_struct *, const char *);
#endif
------------------------------------------------
^ permalink raw reply
* Re: [RFC] git-fsck-cache argument processing
From: Jeff Garzik @ 2005-05-21 23:53 UTC (permalink / raw)
To: Olivier Galibert; +Cc: Sean, git
In-Reply-To: <20050521184909.GA1729@dspnet.fr.eu.org>
Olivier Galibert wrote:
> On Sat, May 21, 2005 at 01:22:30PM -0400, Sean wrote:
>
>>Both of these options are generated automatically by argp.
>
>
> I see. Then I'll guess I'll have to put argp in the "crap" pile next
> to libtool and automake.
It's called "consistency with most other Linux apps."
Consistency and predictability are good things.
Jeff
^ permalink raw reply
* Re: cogito - how do I ???
From: Linus Torvalds @ 2005-05-21 23:41 UTC (permalink / raw)
To: Sean; +Cc: Sam Ravnborg, git
In-Reply-To: <2765.10.10.10.24.1116713164.squirrel@linux1>
On Sat, 21 May 2005, Sean wrote:
> On Sat, May 21, 2005 5:47 pm, Sam Ravnborg said:
> > Hi all.
> >
> > While trying to get up to speed on cogito/git I stumbled across
> > a few things that I at least did not find available in cogito.
> >
> > 1) Something similar to "bk changes -R". I use this to see what has
> > happened upstream - to see if I really want to merge stuff.
>
> Not sure what bk did here, but you can do something like:
>
> cg-pull origin
> cg-log -c -r origin
In the raw git interfaces, you'd basically have to do the same thing that
"git-pull-script" does, except that _instead_ of calling the
git-resolve-script thing, you'd do
git-rev-tree MERGE_HEAD ^HEAD | git-diff-tree -v -m -s --stdin
to show what is in the downloaded MERGE_HEAD but not in HEAD.
> > 2) Export of individual patches. "bk export -tpatch -r1.2345"
> > I have nu public git repository yet so I have to feed changes as
> > plain patches. Browsing cg-* I did not find the command to do this.
>
> cg-diff -p -r SHA1
And again, without the porcelain this is:
git-diff-tree -v -p <name>
(Basically, you can do _anything_ with "git-diff-tree". For example, you
want "cg log"? Do
git-rev-list HEAD | git-diff-tree --stdin -v -m -s
which is basically what "git-whatchanged" does).
Linus
^ permalink raw reply
* Re: updated design for the diff-raw format.
From: Junio C Hamano @ 2005-05-21 23:19 UTC (permalink / raw)
To: git
In-Reply-To: <7vwtpsdvgm.fsf@assigned-by-dhcp.cox.net>
(fourth of the replayed messages)
Date: Sat, 21 May 2005 15:03:06 -0700 (PDT)
From: Linus Torvalds <torvalds@osdl.org>
To: Junio C Hamano <junkio@cox.net>
Subject: Re: [PATCH 3/3] Diff overhaul, adding the other half of copy detection.
Message-ID: <Pine.LNX.4.58.0505211452180.2206@ppc970.osdl.org>
On Sat, 21 May 2005, Junio C Hamano wrote:
>
> - omit the inter_name_termination and second path if both
> paths are the same, only when doing human-readable
> (i.e. inter_name_termination != line_termination).
Hmm. I guess that's fair enough, since it's still easily parseable even if
you don't want to use the -z version in scripts (as many tools are better
at handling line-terminated stuff than handling zero-terminations).
It might become another flag too, if somebody ends up caring.
> Somehow I failed to CC the GIT list the message you are
> responding to. Discussing a change with an impact of this scale
> needs to be taken public before going further, so with your
> permission I would like to repost both my original ("Once we
> start to think of it this way...") and your response to the GIT
> list first. At least I feel that Petr needs to be in the loop
> about this one.
Sure. Although I doube people use the raw diff output except to (a) feed
to diff-helper or (b) check that it's non-empty.
But absolutely, post the previous (and this) one.
> Another reason is that, as I said, I still have problems about the
> diffcore interface, namely the lack of interface for the applications to
> ask diffcore what the final outcome is. The "diff-tree not being to
> omit its header output when pickaxe says the result is empty" problem is
> primarily what bothers me, but I think we want a more generic interface
> for the application to inspect the result (not just emptiness check),
> probably before starting to feed the resulting diff list to the external
> diff.
Why not just have a "is there anything pending" query before doing the
flush? And always put _everything_ in the pending category, regardless of
whether detect_rename/copy is in effect (but if it's not in effect, then
flushing the pending queue is obviously just a "go through it and flush
it" without any other complexity).
In other words, there would be four clear stages to this:
1) diff_setup()
remove "detect_rename" and "diff_score_opt" and "reverse_diff"
from this, since they are irrelevant until you _show_ the diffs
2) diff_queue() *n
tell diff-core about the files we are going to diff
3) diff_detect_rename()
this is what takes the "detect_rename" flag and "diff_score_opt",
and walks the list of diffs and potentially changes them into
"rename" and "copy" diffs.
4) diff_flush()
this just prints out the result (either as a raw diff or as
patches). This takes the "reverse_diff" flag that was removed from
diff_setup().
and then you can always query the state of the diff tree before stage 3 or
before stage 4.
In fact, there's no reason not to even _change_ the diff-queue in magic
ways before (3) or (4) depending on what you want to do. For example, your
"-S" thing might want to do it's thing between stages (3) and (4).
Linus
^ permalink raw reply
* Re: updated design for the diff-raw format.
From: Junio C Hamano @ 2005-05-21 23:18 UTC (permalink / raw)
To: git
In-Reply-To: <7vwtpsdvgm.fsf@assigned-by-dhcp.cox.net>
(third of the replayed messages)
To: Linus Torvalds <torvalds@osdl.org>
Subject: Re: [PATCH 3/3] Diff overhaul, adding the other half of copy
detection.
From: Junio C Hamano <junkio@cox.net>
Date: Sat, 21 May 2005 13:36:25 -0700
Message-ID: <7vfywggvue.fsf@assigned-by-dhcp.cox.net>
>>>>> "LT" == Linus Torvalds <torvalds@osdl.org> writes:
LT> On Sat, 21 May 2005, Junio C Hamano wrote:
>>
>> Once we start to think of it this way, it becomes quite tempting
>> to change the diff-raw format to actually match the above
>> concept.
LT> I agree, and I was going to suggest changing the "raw" diff output for all
LT> the same reasons. So I think you should do it, as the old format was based
LT> on not really knowing where this all would take us. I think your proposed
LT> format is visually nicer, and it's obviously more flexible.
LT> Small suggestion on termination of the thing:
LT> - add a "inter_name_termination" variable, which defaults to '\t' (the
LT> same way "line_termination" defaults to '\n')
LT> - make "-z" set both "inter_name_termination" _and_ "line_termination" to
LT> 0.
LT> - make the spacing be fixed (and add a test for it, so that there is
LT> never any confusion): regular spaces between the non-file-names, and
LT> "inter_name_termination" before the filenames, and "line_termination"
LT> after the second filename.
I am debating myself if I wanted to add this to the above list:
- omit the inter_name_termination and second path if both
paths are the same, only when doing human-readable
(i.e. inter_name_termination != line_termination).
I'm not going to do this immediately though, for two reasons.
Somehow I failed to CC the GIT list the message you are
responding to. Discussing a change with an impact of this scale
needs to be taken public before going further, so with your
permission I would like to repost both my original ("Once we
start to think of it this way...") and your response to the GIT
list first. At least I feel that Petr needs to be in the loop
about this one.
Another reason is that, as I said, I still have problems about
the diffcore interface, namely the lack of interface for the
applications to ask diffcore what the final outcome is. The
"diff-tree not being to omit its header output when pickaxe says
the result is empty" problem is primarily what bothers me, but I
think we want a more generic interface for the application to
inspect the result (not just emptiness check), probably before
starting to feed the resulting diff list to the external diff.
Note that this interface needs to be inspection only---if the
application wants to further manipulate the result, then we
should extend list of diffcore transformations called from
diff_flush(). Which takes me to another point --- maybe the
list of diffcore transformations called from diff_flush() should
be made stackable, like streams.
^ permalink raw reply
* Re: updated design for the diff-raw format.
From: Junio C Hamano @ 2005-05-21 23:17 UTC (permalink / raw)
To: git
In-Reply-To: <7vwtpsdvgm.fsf@assigned-by-dhcp.cox.net>
(second of the replayed message, with blessing from Linus)
Date: Sat, 21 May 2005 11:24:31 -0700 (PDT)
From: Linus Torvalds <torvalds@osdl.org>
To: Junio C Hamano <junkio@cox.net>
Subject: Re: [PATCH 3/3] Diff overhaul, adding the other half of copy detection.
Message-ID: <Pine.LNX.4.58.0505211107160.2206@ppc970.osdl.org>
On Sat, 21 May 2005, Junio C Hamano wrote:
>
> Once we start to think of it this way, it becomes quite tempting
> to change the diff-raw format to actually match the above
> concept.
I agree, and I was going to suggest changing the "raw" diff output for all
the same reasons. So I think you should do it, as the old format was based
on not really knowing where this all would take us. I think your proposed
format is visually nicer, and it's obviously more flexible.
Small suggestion on termination of the thing:
- add a "inter_name_termination" variable, which defaults to '\t' (the
same way "line_termination" defaults to '\n')
- make "-z" set both "inter_name_termination" _and_ "line_termination" to
0.
- make the spacing be fixed (and add a test for it, so that there is
never any confusion): regular spaces between the non-file-names, and
"inter_name_termination" before the filenames, and "line_termination"
after the second filename.
This has a few results:
- the default output is perfectly readable, if long
- "cut" (which defaults to TAB delimeter) can directly pick up the
three fields from a line: "state", "file1" and "file2"
- even if you use the "readable" output (as opposed to the "-z"
machine-readable one), spaces in filenames are unambiguous, and we only
screw up on TAB and NL.
Spaces in names are normal in many things. NL/TAB really _are_ unusual,
and I could imagine that some porcelain could actually disallow them
(and if that happens, we could support that by add a flag to
"update-cache" to refuse to touch such files, the same way we refuse
non-canonical filenames now).
- the -z flag results in fairly unreadable output, but is at least
totally parseable with all filename characters allowed.
With that in place, the new format would be a lot _easier_ to parse than
the old one, I think. And will be more flexible, and since it's a
fixed-column format, it's actually pretty readable for humans too, as long
as the terminal line is wide enough.
> 100644 100644 233a250... 66818b4... file0 file0
> 100755 100755 fc77389... 7b72d3d... file1 file1
> ______ 100644 _______... 233a250... file2 file2
> 100755 ______ fc77389... _______... file3 file3
> 100644 100644 233a250... 233a250... file4 file4
>
> Again, I am not even advocating this. It is more like me
> still thinking aloud.
No, I think it's really good. The _one_ thing I'd do is to maybe put a
special character at the beginning of the line, so that "diff-helper" has
an ever easier time to know whether it should care or not. Something that
normally wouldn't show up at the beginning of a line, like ':'.
(This would have the secondary advantage that yuou could run "diff-helper"
multiple times and not care whether it was already expanded or not. Right
now that is impossible: diff-helper can't know the difference between an
already-expanded diff that has a line that begins with a '+' or '-' and a
eleted/new object line).
Linus
^ permalink raw reply
* Re: updated design for the diff-raw format.
From: Junio C Hamano @ 2005-05-21 23:16 UTC (permalink / raw)
To: git
In-Reply-To: <7vwtpsdvgm.fsf@assigned-by-dhcp.cox.net>
(first of the replayed exchange)
To: Linus Torvalds <torvalds@osdl.org>
Subject: Re: [PATCH 3/3] Diff overhaul, adding the other half of copy
detection.
From: Junio C Hamano <junkio@cox.net>
Date: Sat, 21 May 2005 10:56:06 -0700
Message-ID: <7v4qcwihu1.fsf@assigned-by-dhcp.cox.net>
GIT_DIFF_OPTS=--unified=0 is good to me as well (GNU diffutils
2.8.1).
Now I think I am done with diff, except one thing. And this is
quite an incompatible change so I do not know how well it would
work in practice. I am not even advocating this. It is more
like me thinking aloud.
The diff-raw format we have been dealing with (sorry about '\t'
vs ' ' gotcha again) is internally enhanced by diff-core. It
first introduces entries for unmodified paths; '*' entries that
has the same mode/sha1 in from->to pair are such entries, and
that is what the change in the [PATCH 3/3] is about.
*100644->100644 blob 233a250...->66818b4... file0
*100755->100755 blob fc77389...->7b72d3d... file1
+100644 blob 233a250... file2
-100755 blob fc77389... file3
*100644->100644 blob 233a250...->233a250... file4
Then diff-core internally extends the format to make things all
look like this ('*' and '-' are gone and each record acquires
the second path).
100644->100644 233a250...->66818b4... file0 file0
100755->100755 fc77389...->7b72d3d... file1 file1
______->100644 _______...->233a250... file2 file2
100755->______ fc77389...->_______... file3 file3
100644->100644 233a250...->233a250... file4 file4
Internally "______" above are represented with a separate flag
(file_valid), and denotes the absense of either src or dst.
The diff-core is all about manipulating this type of list and
changing one such list into a different list.
For example, rename-edit of file3 into file2 is detected by
diffcore-rename module and these entries:
______->100644 _______...->233a250... file2 file2
100755->______ fc77389...->_______... file3 file3
become:
100755->100644 fc77389...->233a250... file3 file2
What the diffcore-pickaxe does can also be explained clearly
with this model. It takes such a list and works as a "grep".
Once we start to think of it this way, it becomes quite tempting
to change the diff-raw format to actually match the above
concept. Meaning, (1) drop the operation letter +/-/*
(inferrable by looking at the both sides of ->); (2) drop
blob/tree (inferrable it from mode); (3) give two paths (usually
they are the same paths); (4) and perhaps replace '->' with the
same column separator. Like this:
100644 100644 233a250... 66818b4... file0 file0
100755 100755 fc77389... 7b72d3d... file1 file1
______ 100644 _______... 233a250... file2 file2
100755 ______ fc77389... _______... file3 file3
100644 100644 233a250... 233a250... file4 file4
Again, I am not even advocating this. It is more like me
still thinking aloud.
^ permalink raw reply
* updated design for the diff-raw format.
From: Junio C Hamano @ 2005-05-21 23:12 UTC (permalink / raw)
To: git
After the introduction of the diff-core infrastructure, Linus
and I had a couple more back-and-forth, but by accident these
exchanges happened off the list. I'll be replaying a couple of
messages to let people know about these because this change will
affect all the Porcalain implementations.
^ permalink raw reply
* [PATCH] Tweak diffcore-rename heuristics.
From: Junio C Hamano @ 2005-05-21 22:55 UTC (permalink / raw)
To: Linus Torvalds; +Cc: git
In-Reply-To: <7vfywgkj90.fsf_-_@assigned-by-dhcp.cox.net>
The heuristics so far was to compare file size change and xdelta
size against the average of file size before and after the
change. This patch uses the smaller of pre- and post- change
file size instead.
It also makes a very small performance fix. I didn't measure
it; I do not expect it to make any practical difference, but
while scanning an already sorted list, breaking out in the
middle is the right thing.
Signed-off-by: Junio C Hamano <junkio@cox.net>
---
diffcore-rename.c | 38 ++++++++++++++++++++------------------
1 files changed, 20 insertions(+), 18 deletions(-)
diff --git a/diffcore-rename.c b/diffcore-rename.c
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -68,37 +68,39 @@ static int estimate_similarity(struct di
* else.
*/
void *delta;
- unsigned long delta_size;
+ unsigned long delta_size, base_size;
int score;
delta_size = ((src->size < dst->size) ?
(dst->size - src->size) : (src->size - dst->size));
+ base_size = ((src->size < dst->size) ? src->size : dst->size);
- /* We would not consider rename followed by more than
- * minimum_score/MAX_SCORE edits; that is, delta_size must be smaller
- * than (src->size + dst->size)/2 * minimum_score/MAX_SCORE,
- * which means...
+ /* We would not consider edits that change the file size so
+ * drastically. delta_size must be smaller than
+ * minimum_score/MAX_SCORE * min(src->size, dst->size).
+ * Note that base_size == 0 case is handled here already
+ * and the final score computation below would not have a
+ * divide-by-zero issue.
*/
-
- if ((src->size+dst->size)*minimum_score < delta_size*MAX_SCORE*2)
+ if (base_size * minimum_score < delta_size * MAX_SCORE)
return 0;
delta = diff_delta(src->data, src->size,
dst->data, dst->size,
&delta_size);
+ /*
+ * We currently punt here, but we may later end up parsing the
+ * delta to really assess the extent of damage. A big consecutive
+ * remove would produce small delta_size that affects quite a
+ * big portion of the file.
+ */
free(delta);
- /* This "delta" is really xdiff with adler32 and all the
- * overheads but it is a quick and dirty approximation.
- *
- * Now we will give some score to it. 100% edit gets
- * 0 points and 0% edit gets MAX_SCORE points. That is, every
- * 1/MAX_SCORE edit gets 1 point penalty. The amount of penalty is:
- *
- * (delta_size * 2 / (src->size + dst->size)) * MAX_SCORE
- *
+ /*
+ * Now we will give some score to it. 100% edit gets 0 points
+ * and 0% edit gets MAX_SCORE points.
*/
- score = MAX_SCORE-(MAX_SCORE*2*delta_size/(src->size+dst->size));
+ score = MAX_SCORE - (MAX_SCORE * delta_size / base_size);
if (score < 0) return 0;
if (MAX_SCORE < score) return MAX_SCORE;
return score;
@@ -314,7 +316,7 @@ void diff_detect_rename(struct diff_queu
if (mx[i].dst->xfrm_flags & RENAME_DST_MATCHED)
continue; /* alreayd done, either exact or fuzzy. */
if (mx[i].score < minimum_score)
- continue;
+ break; /* there is not any more diffs applicable. */
record_rename_pair(&outq,
mx[i].src, mx[i].dst, mx[i].rank,
mx[i].score);
------------------------------------------------
^ permalink raw reply
* Re: [RFC] git-fsck-cache argument processing
From: Joel Becker @ 2005-05-21 22:14 UTC (permalink / raw)
To: Olivier Galibert; +Cc: Sean, git
In-Reply-To: <20050521150926.GA96606@dspnet.fr.eu.org>
On Sat, May 21, 2005 at 05:09:26PM +0200, Olivier Galibert wrote:
> On Fri, May 20, 2005 at 11:38:52PM -0400, Sean wrote:
> > -?, --help Give this help list
>
> Could you make that '-h' please ?
I generally think supporting -? and -h is the usual thing. SysV
loves -?, most real folks like -h.
> > -V, --version Print program version
>
> And that '-v'. -V traditionally means verbose, -v version. Yes, I
> know there are counter-examples, but statistically...
I've never seen -V mean verbose. I just queried all of
coreutils, and as most folks expect, -v means verbose. Statistically,
I'd be interested in seeing statistics. I've never used a program where
-V meant verbose. I've never used a program that had '--verbose' where
'-v' didn't mean verbose. tar(1), rsync(1), chgrp(1), chown(1), cp(1),
mkdir(1), all use '-v' for verbose.
Joel
--
"The nearest approach to immortality on Earth is a government
bureau."
- James F. Byrnes
Joel Becker
Senior Member of Technical Staff
Oracle
E-mail: joel.becker@oracle.com
Phone: (650) 506-8127
^ permalink raw reply
* Re: [PATCH] Constness fix for pickaxe option.
From: Linus Torvalds @ 2005-05-21 22:16 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
In-Reply-To: <7v1x80gruc.fsf_-_@assigned-by-dhcp.cox.net>
On Sat, 21 May 2005, Junio C Hamano wrote:
>
> Constness fix for pickaxe option.
Btw, this:
static const char *pickaxe = 0;
may be legal C, but that doesn't make it less crap.
It's a pointer. If you want to make it a NULL pointer, make it a NULL
pointer:
static const char *pickaxe = NULL;
and don't try to stuff an integer into a pointer. Yeah, yeah, the integer
zero is magic and special, but that's a bug in the C language, and we
should try to not perpetuate it.
Linus
^ permalink raw reply
* Re: cogito - how do I ???
From: Sean @ 2005-05-21 22:06 UTC (permalink / raw)
To: Sam Ravnborg; +Cc: git
In-Reply-To: <20050521214700.GA18676@mars.ravnborg.org>
On Sat, May 21, 2005 5:47 pm, Sam Ravnborg said:
> Hi all.
>
> While trying to get up to speed on cogito/git I stumbled across
> a few things that I at least did not find available in cogito.
>
> 1) Something similar to "bk changes -R". I use this to see what has
> happened upstream - to see if I really want to merge stuff.
Not sure what bk did here, but you can do something like:
cg-pull origin
cg-log -c -r origin
To see what is at the head of the unmerged objects you just pulled down,
and if you want to merge then "cg-merge origin". Although as far as I
know there's no way to have the log stop automatically at the proper spot.
> 2) Export of individual patches. "bk export -tpatch -r1.2345"
> I have nu public git repository yet so I have to feed changes as
> plain patches. Browsing cg-* I did not find the command to do this.
cg-diff -p -r SHA1
Which asks for the diff from the parent (-p) to the revision (-r).
Sean
^ permalink raw reply
* [PATCH] Constness fix for pickaxe option.
From: Junio C Hamano @ 2005-05-21 22:02 UTC (permalink / raw)
To: Linus Torvalds; +Cc: git
In-Reply-To: <7voeb4kjda.fsf_-_@assigned-by-dhcp.cox.net>
Constness fix for pickaxe option.
Signed-off-by: Junio C Hamano <junkio@cox.net>
---
diff-cache.c | 2 +-
diff-files.c | 2 +-
diff-helper.c | 2 +-
diff-tree.c | 2 +-
diff.c | 2 +-
diff.h | 2 +-
6 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/diff-cache.c b/diff-cache.c
--- a/diff-cache.c
+++ b/diff-cache.c
@@ -8,7 +8,7 @@ static int line_termination = '\n';
static int detect_rename = 0;
static int reverse_diff = 0;
static int diff_score_opt = 0;
-static char *pickaxe = 0;
+static const char *pickaxe = 0;
/* A file entry went away or appeared */
static void show_file(const char *prefix, struct cache_entry *ce, unsigned char *sha1, unsigned int mode)
diff --git a/diff-files.c b/diff-files.c
--- a/diff-files.c
+++ b/diff-files.c
@@ -14,7 +14,7 @@ static int line_termination = '\n';
static int detect_rename = 0;
static int reverse_diff = 0;
static int diff_score_opt = 0;
-static char *pickaxe = 0;
+static const char *pickaxe = 0;
static int silent = 0;
static int matches_pathspec(struct cache_entry *ce, char **spec, int cnt)
diff --git a/diff-helper.c b/diff-helper.c
--- a/diff-helper.c
+++ b/diff-helper.c
@@ -9,7 +9,7 @@
static int detect_rename = 0;
static int diff_score_opt = 0;
static int generate_patch = 1;
-static char *pickaxe = 0;
+static const char *pickaxe = 0;
static int parse_oneside_change(const char *cp, int *mode,
unsigned char *sha1, char *path)
diff --git a/diff-tree.c b/diff-tree.c
--- a/diff-tree.c
+++ b/diff-tree.c
@@ -13,7 +13,7 @@ static int generate_patch = 0;
static int detect_rename = 0;
static int reverse_diff = 0;
static int diff_score_opt = 0;
-static char *pickaxe = 0;
+static const char *pickaxe = 0;
static const char *header = NULL;
static const char *header_prefix = "";
diff --git a/diff.c b/diff.c
--- a/diff.c
+++ b/diff.c
@@ -513,7 +513,7 @@ int diff_scoreopt_parse(const char *opt)
}
void diff_setup(int detect_rename_, int minimum_score_,
- char *pickaxe_,
+ const char *pickaxe_,
int reverse_diff_, int diff_raw_output_,
const char **pathspec_, int speccnt_)
{
diff --git a/diff.h b/diff.h
--- a/diff.h
+++ b/diff.h
@@ -20,7 +20,7 @@ extern void diff_unmerge(const char *pat
extern int diff_scoreopt_parse(const char *opt);
extern void diff_setup(int detect_rename, int minimum_score,
- char *pickaxe,
+ const char *pickaxe,
int reverse, int raw_output,
const char **spec, int cnt);
------------------------------------------------
^ permalink raw reply
* cogito - how do I ???
From: Sam Ravnborg @ 2005-05-21 21:47 UTC (permalink / raw)
To: git
Hi all.
While trying to get up to speed on cogito/git I stumbled across
a few things that I at least did not find available in cogito.
1) Something similar to "bk changes -R". I use this to see what has
happened upstream - to see if I really want to merge stuff.
2) Export of individual patches. "bk export -tpatch -r1.2345"
I have nu public git repository yet so I have to feed changes as
plain patches. Browsing cg-* I did not find the command to do this.
I do try to avoid having to develop my little army of shell scripts,
and due to this I have avoided the git- commands for now.
Any help appreciated,
Sam
^ permalink raw reply
* Re: [PATCH 3/3] - Convert git-checkout-cache to argp
From: Sean @ 2005-05-21 21:39 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Jeff Garzik, git
In-Reply-To: <7v7jhsgtlg.fsf@assigned-by-dhcp.cox.net>
[-- Attachment #1: Type: text/plain, Size: 1296 bytes --]
On Sat, May 21, 2005 5:24 pm, Junio C Hamano said:
>>>>>> "JG" == Jeff Garzik <jgarzik@pobox.com> writes:
>
> JG> Sean wrote:
>>> Use argp to process command line arguments for git-checkout-cache.
>>> Also,
>>> fix things up so that the order of options on the command line no
>>> longer
>>> matters. To this end, the "-f" (--force) switch only applies to the
>>> individual files given on the command line. A new forcing version of
>>> the
>>> "-a" (--all) switch is added as "-A" (--forceall).
>
> JG> I agree with Junio -- this patch breaks stuff.
>
> Yes, and that is exactly why I wanted to see the documentation
> changes first before the code.
>
Okay. Attached no longer tries to maintain the feature of unforced -a in
combination with forced file list. So:
Use argp to process command line arguments for git-checkout-cache. Also,
fix things up so that the order of options on the command line no longer
matters. To this end, the "-f" (--force) option always affects the -a
(--all) option no matter where it appears on the command line.
Signed-off-by: Sean Estabrooks <seanlkml@sympatico.ca>
Documentation/git-checkout-cache.txt | 16 ++--
checkout-cache.c | 120
++++++++++++++++-------------------
2 files changed, 64 insertions(+), 72 deletions(-)
[-- Attachment #2: argp-checkout-cache-v4.patch --]
[-- Type: text/plain, Size: 6207 bytes --]
Index: Documentation/git-checkout-cache.txt
===================================================================
--- 3abc6a8ee0f27eaba8d0a7d091413eb390447386/Documentation/git-checkout-cache.txt (mode:100644)
+++ uncommitted/Documentation/git-checkout-cache.txt (mode:100644)
@@ -24,7 +24,7 @@
the cache file.
-q::
- be quiet if files exist or are not in the cache
+ be quiet if files exist or are not in the cache.
-f::
forces overwrite of existing files
@@ -44,17 +44,15 @@
--::
Do not interpret any more arguments as options.
-Note that the order of the flags matters:
+Example:
- git-checkout-cache -a -f file.c
+ git-checkout-cache -a
-will first check out all files listed in the cache (but not overwrite
-any old ones), and then force-checkout `file.c` a second time (ie that
-one *will* overwrite any old contents with the same filename).
+Will check out all files listed in the cache.
-Also, just doing "git-checkout-cache" does nothing. You probably meant
+Just doing "git-checkout-cache" does nothing. You probably meant
"git-checkout-cache -a". And if you want to force it, you want
-"git-checkout-cache -f -a".
+"git-checkout-cache -a -f".
Intuitiveness is not the goal here. Repeatability is. The reason for
the "no arguments means no work" thing is that from scripts you are
@@ -68,7 +66,7 @@
To update and refresh only the files already checked out:
- git-checkout-cache -n -f -a && git-update-cache --ignore-missing --refresh
+ git-checkout-cache -n -a -f && git-update-cache --ignore-missing --refresh
Oh, and the "--" is just a good idea when you know the rest will be
filenames. Just so that you wouldn't have a filename of "-a" causing
Index: checkout-cache.c
===================================================================
--- 3abc6a8ee0f27eaba8d0a7d091413eb390447386/checkout-cache.c (mode:100644)
+++ uncommitted/checkout-cache.c (mode:100644)
@@ -3,18 +3,14 @@
*
* Copyright (C) 2005 Linus Torvalds
*
- * Careful: order of argument flags does matter. For example,
+ * git-checkout-cache -a
*
- * git-checkout-cache -a -f file.c
+ * Will check out all files listed in the cache, but not
+ * overwrite any existing files.
*
- * Will first check out all files listed in the cache (but not
- * overwrite any old ones), and then force-checkout "file.c" a
- * second time (ie that one _will_ overwrite any old contents
- * with the same filename).
- *
- * Also, just doing "git-checkout-cache" does nothing. You probably
- * meant "git-checkout-cache -a". And if you want to force it, you
- * want "git-checkout-cache -f -a".
+ * Just doing "git-checkout-cache" does nothing. You probably
+ * meant "git-checkout-cache -a". And if you want to force it,
+ * you want "git-checkout-cache -f -a".
*
* Intuitiveness is not the goal here. Repeatability is. The
* reason for the "no arguments means no work" thing is that
@@ -35,8 +31,11 @@
#include <sys/types.h>
#include <dirent.h>
#include "cache.h"
+#include <argp.h>
+const char *argp_program_version = VERSION;
-static int force = 0, quiet = 0, not_new = 0, refresh_cache = 0;
+static int force = 0, quiet = 0, not_new = 0, refresh_cache = 0, all = 0;
+static const char *base_opt = "";
static void create_directories(const char *path)
{
@@ -226,68 +225,63 @@
return 0;
}
+static const char doc[] = "Populate working tree with files from cache";
+
+static struct argp_option options[] = {
+ {"prefix", 1, "base", 0, "Prepend base to each file before checkout"},
+ {"all", 'a', 0, 0, "Checkout entire cache"},
+ {"force", 'f', 0, 0, "Allow checkout to overwrite existing files"},
+ {"quiet", 'q', 0, 0, "Suppress warnings"},
+ {"not-new", 'n', 0, 0, "Checkout existing files only"},
+ {"update", 'u', 0, 0, "Update cache with new stat info"},
+ { }
+};
+
+static error_t parse_opt (int key, char *arg, struct argp_state *state)
+{
+ switch (key) {
+ case 'a': all = 1; break;
+ case 'q': quiet = 1; break;
+ case 'n': not_new = 1; break;
+ case 'f': force = 1; break;
+ case 1: base_opt = arg; break;
+ case 'u': refresh_cache = 1; break;
+ default: return ARGP_ERR_UNKNOWN;
+ }
+ return 0;
+}
+
+static const struct argp argp = { options, parse_opt, "[FILES...]", doc };
+
int main(int argc, char **argv)
{
- int i, force_filename = 0;
- const char *base_dir = "";
struct cache_file cache_file;
- int newfd = -1;
+ int i, idx, newfd = -1;
if (read_cache() < 0) {
die("invalid cache");
}
- for (i = 1; i < argc; i++) {
- const char *arg = argv[i];
- if (!force_filename) {
- if (!strcmp(arg, "-a")) {
- checkout_all(base_dir);
- continue;
- }
- if (!strcmp(arg, "--")) {
- force_filename = 1;
- continue;
- }
- if (!strcmp(arg, "-f")) {
- force = 1;
- continue;
- }
- if (!strcmp(arg, "-q")) {
- quiet = 1;
- continue;
- }
- if (!strcmp(arg, "-n")) {
- not_new = 1;
- continue;
- }
- if (!strcmp(arg, "-u")) {
- refresh_cache = 1;
- if (newfd < 0)
- newfd = hold_index_file_for_update
- (&cache_file,
- get_index_file());
- if (newfd < 0)
- die("cannot open index.lock file.");
- continue;
- }
- if (!memcmp(arg, "--prefix=", 9)) {
- base_dir = arg+9;
- continue;
- }
- }
- if (base_dir[0]) {
- /* when --prefix is specified we do not
- * want to update cache.
- */
- if (refresh_cache) {
- close(newfd); newfd = -1;
- rollback_index_file(&cache_file);
- }
- refresh_cache = 0;
- }
- checkout_file(arg, base_dir);
+ error_t rc = argp_parse(&argp, argc, argv, 0, &idx, NULL);
+ if (rc) {
+ fprintf(stderr, "argument failed: %s\n", strerror(rc));
+ return 1;
}
+ if (refresh_cache) {
+ if (base_opt[0])
+ die("cannot update cache when --prefix option is used");
+ newfd = hold_index_file_for_update(&cache_file, get_index_file());
+ if (newfd < 0)
+ die("cannot open index.lock file.");
+ }
+
+ if (all)
+ checkout_all(base_opt);
+
+ for (i = idx; i < argc; i++)
+ checkout_file(argv[i], base_opt);
+
if (0 <= newfd &&
(write_cache(newfd, active_cache, active_nr) ||
commit_index_file(&cache_file)))
^ permalink raw reply
* Re: [PATCH 3/3] - Convert git-checkout-cache to argp
From: Junio C Hamano @ 2005-05-21 21:24 UTC (permalink / raw)
To: Sean; +Cc: Jeff Garzik, git
In-Reply-To: <428FA5C3.6010900@pobox.com>
>>>>> "JG" == Jeff Garzik <jgarzik@pobox.com> writes:
JG> Sean wrote:
>> Use argp to process command line arguments for git-checkout-cache. Also,
>> fix things up so that the order of options on the command line no longer
>> matters. To this end, the "-f" (--force) switch only applies to the
>> individual files given on the command line. A new forcing version of the
>> "-a" (--all) switch is added as "-A" (--forceall).
JG> I agree with Junio -- this patch breaks stuff.
Yes, and that is exactly why I wanted to see the documentation
changes first before the code.
^ permalink raw reply
* Re: [PATCH 3/3] - Convert git-checkout-cache to argp
From: Jeff Garzik @ 2005-05-21 21:18 UTC (permalink / raw)
To: Sean; +Cc: git
In-Reply-To: <2242.10.10.10.24.1116700408.squirrel@linux1>
Sean wrote:
> Use argp to process command line arguments for git-checkout-cache. Also,
> fix things up so that the order of options on the command line no longer
> matters. To this end, the "-f" (--force) switch only applies to the
> individual files given on the command line. A new forcing version of the
> "-a" (--all) switch is added as "-A" (--forceall).
I agree with Junio -- this patch breaks stuff.
Jeff
^ permalink raw reply
* Re: [RFC] git-fsck-cache argument processing
From: Sean @ 2005-05-21 21:09 UTC (permalink / raw)
To: Linus Torvalds; +Cc: GIT Mailing List
In-Reply-To: <2475.10.10.10.24.1116708368.squirrel@linux1>
[-- Attachment #1: Type: text/plain, Size: 301 bytes --]
On Sat, May 21, 2005 4:46 pm, Sean said:
> Right, fixed up in attached patch which basically punts with a
> description of "Show unreachable objects", and leaves it to the
> documentation to do better.
Linus,
Try 2 at that attachment thingy, hopefully this one will make your mailer
happy.
Sean
[-- Attachment #2: argp-fsck-cache-v4.patch --]
[-- Type: text/plain, Size: 3255 bytes --]
Index: Documentation/git-fsck-cache.txt
===================================================================
--- 85ec256656a7839ca7a2067792b828c9b63c8711/Documentation/git-fsck-cache.txt (mode:100644)
+++ uncommitted/Documentation/git-fsck-cache.txt (mode:100644)
@@ -9,7 +9,8 @@
SYNOPSIS
--------
-'git-fsck-cache' [--tags] [--root] [[--unreachable] [--cache] <object>\*]
+'git-fsck-cache' [--tags] [--root] [--delta-depth]
+ [[--unreachable] [--cache] <object>\*]
DESCRIPTION
-----------
@@ -34,6 +35,9 @@
Consider any object recorded in the cache also as a head node for
an unreachability trace.
+--delta-depth::
+ Show length of longest delta chain.
+
It tests SHA1 and general object sanity, and it does full tracking of
the resulting reachability and everything else. It prints out any
corruption it finds (missing or bad objects), and if you use the
Index: fsck-cache.c
===================================================================
--- 85ec256656a7839ca7a2067792b828c9b63c8711/fsck-cache.c (mode:100644)
+++ uncommitted/fsck-cache.c (mode:100644)
@@ -1,5 +1,7 @@
#include <sys/types.h>
#include <dirent.h>
+#include <argp.h>
+const char *argp_program_version = VERSION;
#include "cache.h"
#include "commit.h"
@@ -407,36 +409,42 @@
find_file_objects(git_dir, "refs");
}
+static const char doc[] = "Perform repository consistency check";
+
+static struct argp_option options[] = {
+ {"unreachable", 'u', 0, 0, "Show unreachable objects"},
+ {"tags", 't', 0, 0, "Show revision tags"},
+ {"root", 'r', 0, 0, "Show root objects, ie. those without parents"},
+ {"delta-depth", 'd', 0, 0, "Show length of longest delta chain"},
+ {"cache", 'c', 0, 0, "Mark all objects referenced by cache as reachable"},
+ { }
+};
+
+static error_t parse_opt (int key, char *arg, struct argp_state *state)
+{
+ switch (key) {
+ case 'u': show_unreachable = 1; break;
+ case 't': show_tags = 1; break;
+ case 'r': show_root = 1; break;
+ case 'd': show_max_delta_depth = 1; break;
+ case 'c': keep_cache_objects = 1; break;
+ default: return ARGP_ERR_UNKNOWN;
+ }
+ return 0;
+}
+
+static const struct argp argp = { options, parse_opt, "[HEAD-SHA1...]", doc };
+
int main(int argc, char **argv)
{
int i, heads;
char *sha1_dir;
+ int idx;
- for (i = 1; i < argc; i++) {
- const char *arg = argv[i];
-
- if (!strcmp(arg, "--unreachable")) {
- show_unreachable = 1;
- continue;
- }
- if (!strcmp(arg, "--tags")) {
- show_tags = 1;
- continue;
- }
- if (!strcmp(arg, "--root")) {
- show_root = 1;
- continue;
- }
- if (!strcmp(arg, "--delta-depth")) {
- show_max_delta_depth = 1;
- continue;
- }
- if (!strcmp(arg, "--cache")) {
- keep_cache_objects = 1;
- continue;
- }
- if (*arg == '-')
- usage("git-fsck-cache [--tags] [[--unreachable] [--cache] <head-sha1>*]");
+ error_t rc = argp_parse(&argp, argc, argv, 0, &idx, NULL);
+ if (rc) {
+ fprintf(stderr, "argument failed: %s\n", strerror(rc));
+ return 1;
}
sha1_dir = get_object_directory();
@@ -450,7 +458,7 @@
expand_deltas();
heads = 0;
- for (i = 1; i < argc; i++) {
+ for (i = idx; i < argc; i++) {
const char *arg = argv[i];
if (*arg == '-')
^ permalink raw reply
* Re: [RFC] git-fsck-cache argument processing
From: Sean @ 2005-05-21 20:46 UTC (permalink / raw)
To: Linus Torvalds; +Cc: git
In-Reply-To: <Pine.LNX.4.58.0505211245580.2206@ppc970.osdl.org>
[-- Attachment #1: Type: text/plain, Size: 779 bytes --]
On Sat, May 21, 2005 3:47 pm, Linus Torvalds said:
> On Fri, 20 May 2005, Sean wrote:
>>
>> -u, --unreachable Show missing objects or deltas
>
> That's the wrong description.
>
> fsck always shows missing objects, but "--unreachable" makes it also show
> objects that cannot be reached from any of the references (either passed
> in on the command line, or the implicit references we take if no explicit
> reference is given).
>
> So in many ways, "--unreachable" is about the _reverse_ of showing missing
> objects: it's about showing _extraneous_ objects that aren't needed by the
> ref that was passed in.
Right, fixed up in attached patch which basically punts with a description
of "Show unreachable objects", and leaves it to the documentation to do
better.
Sean
[-- Attachment #2: argp-fsck-cache-v4.patch --]
[-- Type: plain/text, Size: 3256 bytes --]
^ permalink raw reply
* Re: [PATCH 3/3] Diff overhaul, adding the other half...
From: Junio C Hamano @ 2005-05-21 20:10 UTC (permalink / raw)
To: Linus Torvalds; +Cc: git
In-Reply-To: <Pine.LNX.4.58.0505211137250.2206@ppc970.osdl.org>
>>>>> "LT" == Linus Torvalds <torvalds@osdl.org> writes:
LT> Hmm.. It's not working well. Not only does it take a lot of
LT> CPU time...
LT> torvalds@ppc970:~/v2.6/linux> wc -c drivers/media/dvb/bt8xx/dst_ca.h drivers/usb/misc/emi62_fw_m.h
LT> 1591 drivers/media/dvb/bt8xx/dst_ca.h
LT> 795679 drivers/usb/misc/emi62_fw_m.h
LT> 797270 total
Yup. diffcore-rename bases the similarity index on the average
of src and dst files. Maybe the similarity check should also
say they should be comparable size, like this upfront before
even going into delta:
abs(src-dst) < avg(src,dst) * (1 - minscore/maxscore)
^ permalink raw reply
* Re: [PATCH 3/3] - Convert git-checkout-cache to argp
From: Junio C Hamano @ 2005-05-21 19:57 UTC (permalink / raw)
To: Sean; +Cc: git
In-Reply-To: <2242.10.10.10.24.1116700408.squirrel@linux1>
>>>>> "S" == Sean <seanlkml@sympatico.ca> writes:
S> Use argp to process command line arguments for git-checkout-cache. Also,
S> fix things up so that the order of options on the command line no longer
S> matters. To this end, the "-f" (--force) switch only applies to the
S> individual files given on the command line. A new forcing version of the
S> "-a" (--all) switch is added as "-A" (--forceall).
I do not like that change at all. That would break existing
scripts.
Why not just say --force forces checkout even when it is used
with -a? I do not think anybody sane uses "-a -f" in their
existing scripts nor from the command line.
^ permalink raw reply
* Re: [PATCH 3/3] Diff overhaul, adding the other half...
From: Junio C Hamano @ 2005-05-21 19:54 UTC (permalink / raw)
To: Linus Torvalds; +Cc: git
In-Reply-To: <Pine.LNX.4.58.0505211124440.2206@ppc970.osdl.org>
>>>>> "LT" == Linus Torvalds <torvalds@osdl.org> writes:
LT> On Sat, 21 May 2005, Junio C Hamano wrote:
>>
LT> I'm also somewhat surprised by the fact that it even seems
LT> to be usable on the kernel tree:
>>
>> Surprised? Correctness-wise and/or performance-wise?
LT> Performance-wise. It seems to be quite usable, even doing just a plain
LT> "git-whatchanged -C" on the kernel with no limits on what it does.
That is probably because you do not have the feeding of "same"
in diff-tree.
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox