Add -B flag to diff-* brothers.
Subsystems (2)
PATCH 1/1 Add -B flag to diff-* brothers.
This introduces diffcore-break.c, a new diffcore
transformation.
When the -B flag is given, a patch that represents a complete rewrite is broken into a deletion followed by a creation. This makes it easier to review such a complete rewrite patch.
The -B flag takes the same syntax as the -M and -C flags to specify the maximum amount of source material the resulting file can still have to be considered a complete rewrite, and defaults to 15% if not specified. For example, this detects the complete rewrite of ls-tree.c I sent earlier.
---
Makefile | 3 - diff-cache.c | 7 +++ diff-files.c | 5 ++ diff-tree.c | 7 +++ diff.h | 2 diffcore-break.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ diffcore-rename.c | 4 - diffcore.h | 3 - 8 files changed, 137 insertions(+), 4 deletions(-)
new file (100644): diffcore-break.c
Makefile +2 -1
@@ -48,7 +48,7 @@ LIB_OBJS += strbuf.o LIB_H += diff.h count-delta.h LIB_OBJS += diff.o diffcore-rename.o diffcore-pickaxe.o diffcore-pathspec.o \ - count-delta.o diffcore-order.o + count-delta.o diffcore-order.o diffcore-break.o LIB_OBJS += gitenv.o
@@ -131,6 +131,7 @@ diffcore-rename.o : $(LIB_H) diffcore.h diffcore-pathspec.o : $(LIB_H) diffcore.h diffcore-pickaxe.o : $(LIB_H) diffcore.h diffcore-order.o : $(LIB_H) diffcore.h +diffcore-break.o : $(LIB_H) diffcore.h test: all $(MAKE) -C t/ all
diff-cache.c +7 -0
@@ -9,6 +9,7 @@ static int diff_setup_opt = 0;static int diff_score_opt =0 ;static const char *pickaxe =NULL ;static int pickaxe_opts =0 ; +static int diff_break_opt =-1 ;static const char *orderfile =NULL ;/* A file entry went away or appeared */
@@ -189,6 +190,10 @@ int main(int argc, const char **argv) diff_output_format =DIFF_FORMAT_PATCH ;continue ; } +if (!strncmp (arg,"-B" ,2 )) { + diff_break_opt =diff_scoreopt_parse (arg); +continue ; + }if (!strncmp (arg,"-M" ,2 )) { detect_rename =DIFF_DETECT_RENAME ; diff_score_opt =diff_scoreopt_parse (arg);
@@ -251,6 +256,8 @@ int main(int argc, const char **argv)diffcore_rename (detect_rename, diff_score_opt);if (pickaxe)diffcore_pickaxe (pickaxe, pickaxe_opts); +if (0 <= diff_break_opt) +diffcore_break (diff_break_opt);if (orderfile)diffcore_order (orderfile);diff_flush (diff_output_format,1 );
diff-files.c +5 -0
@@ -15,6 +15,7 @@ static int diff_setup_opt = 0;static int diff_score_opt =0 ;static const char *pickaxe =NULL ;static int pickaxe_opts =0 ; +static int diff_break_opt =-1 ;static const char *orderfile =NULL ;static int silent =0 ;
@@ -60,6 +61,8 @@ int main(int argc, const char **argv) orderfile = argv[1 ] +2 ; else if (!strcmp(argv[1], "--pickaxe-all")) pickaxe_opts =DIFF_PICKAXE_ALL ; + else if (!strncmp(argv[1], "-B", 2)) + diff_break_opt =diff_scoreopt_parse (argv[1 ]); else if (!strncmp(argv[1], "-M", 2)) { diff_score_opt =diff_scoreopt_parse (argv[1 ]); detect_rename =DIFF_DETECT_RENAME ;
@@ -125,6 +128,8 @@ int main(int argc, const char **argv)diffcore_rename (detect_rename, diff_score_opt);if (pickaxe)diffcore_pickaxe (pickaxe, pickaxe_opts); +if (0 <= diff_break_opt) +diffcore_break (diff_break_opt);if (orderfile)diffcore_order (orderfile);diff_flush (diff_output_format,1 );
diff-tree.c +7 -0
@@ -14,6 +14,7 @@ static int diff_setup_opt = 0;static int diff_score_opt =0 ;static const char *pickaxe =NULL ;static int pickaxe_opts =0 ; +static int diff_break_opt =-1 ;static const char *orderfile =NULL ;static const char *header =NULL ;static const char *header_prefix ="" ;
@@ -266,6 +267,8 @@ static int call_diff_flush(void)diffcore_rename (detect_rename, diff_score_opt);if (pickaxe)diffcore_pickaxe (pickaxe, pickaxe_opts); +if (0 <= diff_break_opt) +diffcore_break (diff_break_opt);if (diff_queue_is_empty ()) {diff_flush (DIFF_FORMAT_NO_OUTPUT ,0 );return 0 ;
@@ -531,6 +534,10 @@ int main(int argc, const char **argv) diff_score_opt =diff_scoreopt_parse (arg);continue ; } +if (!strncmp (arg,"-B" ,2 )) { + diff_break_opt =diff_scoreopt_parse (arg); +continue ; + }if (!strcmp (arg,"-z" )) { diff_output_format =DIFF_FORMAT_MACHINE ;continue ;
diff.h +2 -0
@@ -45,6 +45,8 @@ extern void diffcore_pathspec(const charextern void diffcore_order (const char *orderfile); +extern void diffcore_break (int max_score); +extern int diff_queue_is_empty (void );#define DIFF_FORMAT_HUMAN 0
diffcore-break.c new file +110 -0
110 lines not on this page · raw message
diffcore-rename.c +2 -2
@@ -208,8 +208,8 @@ static int score_compare(const void *a_,int diff_scoreopt_parse (const char *opt) {int diglen, num, scale, i; -if (opt[0 ] !='-' || (opt[1 ] !='M' && opt[1 ] !='C' )) -return -1 ;/* that is not a -M nor -C option */ +if (opt[0 ] !='-' || (opt[1 ] !='M' && opt[1 ] !='C' && opt[1 ] !='B' )) +return -1 ;/* that is not a -M, -C nor -B option */ diglen =strspn (opt+2 ,"0123456789" );if (diglen ==0 ||strlen (opt+2 ) != diglen)return 0 ;/* use default */
diffcore.h +2 -1
@@ -9,7 +9,8 @@* in anything else. */ #define MAX_SCORE 10000 -#define DEFAULT_MINIMUM_SCORE 5000 +#define DEFAULT_MINIMUM_SCORE 5000/* rename/copy similarity minimum */ +#define DEFAULT_MAXIMUM_SCORE 1500/* similarity maximum for break to happen */ #define RENAME_DST_MATCHED 01
------------------------------------------------
Dear diary, on Sat, May 28, 2005 at 09:33:44PM CEST, I got a letter where Junio C Hamano <[email protected]> told me that...
Quoted 7 lines
This introduces
diffcore-break.c, a new diffcore
transformation.When the -B flag is given, a patch that represents a complete rewrite is broken into a deletion followed by a creation. This makes it easier to review such a complete rewrite patch.
Quoted 7 lines
The -B flag takes the same syntax as the -M and -C flags to specify the maximum amount of source material the resulting file can still have to be considered a complete rewrite, and defaults to 15% if not specified. For example, this detects the complete rewrite of
ls-tree.cI sent earlier.Signed-off-by Junio C Hamano <[email protected]>
Actually, I like this one - contrary to -O I can see how this could be quite useful - I have wished for this many times when people would send me some "complete rewrite" patches which I actually wanted to review.
Please don't give up on it. :-)
Signature · 3 lines
Petr "Pasky" Baudis Stuff: http://pasky.or.cz/ C++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"PB" == Petr Baudis <[email protected]> writes:
PB> Actually, I like this one - contrary to -O I can see how this could be PB> quite useful - I have wished for this many times when people would send PB> me some "complete rewrite" patches which I actually wanted to review.
PB> Please don't give up on it. :-)
Well, although I do not do Porcelain ;-), I do want to have -O to help my use pattern. I envision that Porcelain noticing the existence of ${GIT-.git}/patch-order file and adding -O to its diff-* argument would make the world a better place.
And I am not giving up on -B yet, but as you can imagine, it has interesting interaction with -M/-C, since rename detection code must be prepared to deal with broken pairs (earlier it did not have to worry about the same path that is a regular file appearing twice in its input). Since I have tested -B only in the context of full set of patches I sent out, and have not tested it with only the subset Linus decided to swallow, I would recommend against applying it on top of the Linus tip as is. I'll be rebasing it to his tip, test it again and then resubmit later. I'll do the same for -O changes.
PATCH 1/1 diff: move diffcore-break before diffcore-rename.
In reply to Junio C HamanoThe order diffcore-break is applied has changed. Earlier it came fairly late in the diffcore chain, but now it comes before diffcore-rename, which makes diffcore-break far more useful than before.
As the new test t4008-diff-break-rewrite demonstrates, if a file is a complete rewrite, it is broken and then can be subjected to the usual rename detection. For example, if file0 gets completely rewritten to make it as if it was rather based on file1 which disappeared, diff-* -B -M would do the following:
The original change would look like this:
file0 --> file0' (quite different from file0)
file1 --> /dev/null
After diffcore-break, it would become this:
file0 --> /dev/null
/dev/null --> file0'
file1 --> /dev/null
Then diffcore-rename matches them up:
file1 --> file0'The meaning of the parameter the -B option takes has changed from the previous one. Earlier it meant the amount of source materials permitted to remain for the file and still be considered a rewrite, which meant that the lower the number, the tighter the detection criteria. This was changed to match the way the parameters to the -C and the -M options are used, where larger parameter value means tighter detection criteria. The parameter for the -B option now means how much new material must be in the resulting file for the filepair to be considered a rewrite, and defaults to 99%.
The internal score values are finer grained now. Earlier maximum of 10000 has been raised to 60000; there is no user visible changes but there is no reason to waste available bits.
Documentation now mentions the -B option.
---
Documentation/git-diff-cache.txt | 5 - Documentation/git-diff-files.txt | 5 - Documentation/git-diff-tree.txt | 5 - diff.c | 20 +++- diffcore-break.c | 101 +++++++++++++---------- diffcore-rename.c | 64 ++++++++++++-- diffcore.h | 13 ++- t/t4008-diff-break-rewrite.sh | 169 +++++++++++++++++++++++++++++++++++++++ 8 files changed, 317 insertions(+), 65 deletions(-)
new file (100755): t/t4008-diff-break-rewrite.sh
Documentation/git-diff-cache.txt +4 -1
@@ -9,7 +9,7 @@ git-diff-cache - Compares content and mo SYNOPSIS -------- -'git-diff-cache' [-p] [-r] [-z] [-m] [-M] [-R] [-C] [-O<orderfile>] [-S<string>] [--pickaxe-all] [--cached] <tree-ish> [<path>...] +'git-diff-cache' [-p] [-r] [-z] [-m] [-B] [-M] [-R] [-C] [-O<orderfile>] [-S<string>] [--pickaxe-all] [--cached] <tree-ish> [<path>...] DESCRIPTION -----------
@@ -35,6 +35,9 @@ OPTIONS -z:: \0 line termination on output +-B:: + Break complete rewrite changes into pairs of delete and create. + -M:: Detect renames.
Documentation/git-diff-files.txt +4 -1
@@ -9,7 +9,7 @@ git-diff-files - Compares files in the w SYNOPSIS -------- -'git-diff-files' [-p] [-q] [-r] [-z] [-M] [-C] [-R] [-O<orderfile>] [-S<string>] [--pickaxe-all] [<pattern>...] +'git-diff-files' [-p] [-q] [-r] [-z] [-B] [-M] [-C] [-R] [-O<orderfile>] [-S<string>] [--pickaxe-all] [<pattern>...] DESCRIPTION -----------
@@ -29,6 +29,9 @@ OPTIONS -R:: Output diff in reverse. +-B:: + Break complete rewrite changes into pairs of delete and create. + -M:: Detect renames.
Documentation/git-diff-tree.txt +4 -1
@@ -9,7 +9,7 @@ git-diff-tree - Compares the content and SYNOPSIS -------- -'git-diff-tree' [-p] [-r] [-z] [--stdin] [-M] [-R] [-C] [-O<orderfile>] [-S<string>] [--pickaxe-all] [-m] [-s] [-v] [-t] <tree-ish> <tree-ish> [<pattern>]\* +'git-diff-tree' [-p] [-r] [-z] [--stdin] [-B] [-M] [-R] [-C] [-O<orderfile>] [-S<string>] [--pickaxe-all] [-m] [-s] [-v] [-t] <tree-ish> <tree-ish> [<pattern>]\* DESCRIPTION -----------
@@ -33,6 +33,9 @@ OPTIONS generate patch (see section on generating patches). For git-diff-tree, this flag implies '-r' as well. +-B:: + Break complete rewrite changes into pairs of delete and create. + -M:: Detect renames.
diff.c +16 -4
@@ -609,6 +609,7 @@ struct diff_filepair *diff_queue(struct dp->two = two; dp->score =0 ; dp->source_stays =0 ; + dp->broken_pair =0 ;diff_q (queue, dp);return dp; }
@@ -643,6 +644,16 @@ static void diff_flush_raw(struct diff_fsprintf (status,"%c%03d" , p->status, (int )(0.5 + p->score *100.0 /MAX_SCORE ));break ; +case 'N' :case 'D' : + two_paths =0 ; +if (p->score) +sprintf (status,"%c%03d" , p->status, + (int )(0.5 + p->score *100.0 /MAX_SCORE )); +else { + status[0 ] = p->status; + status[1 ] =0 ; + } +break ;default : two_paths =0 ; status[0 ] = p->status;
@@ -799,8 +810,9 @@ void diff_debug_filepair(const struct di {diff_debug_filespec (p->one, i,"one" );diff_debug_filespec (p->two, i,"two" ); -fprintf (stderr,"score %d, status %c source_stays %d\n" , - p->score, p->status ? :'?' , p->source_stays); +fprintf (stderr,"score %d, status %c stays %d broken %d\n" , + p->score, p->status ? :'?' , + p->source_stays, p->broken_pair); }void diff_debug_queue (const char *msg,struct diff_queue_struct *q)
@@ -939,12 +951,12 @@ void diffcore_std(const char **paths, {if (paths)diffcore_pathspec (paths); +if (0 <= break_opt) +diffcore_break (break_opt);if (detect_rename)diffcore_rename (detect_rename, rename_score);if (pickaxe)diffcore_pickaxe (pickaxe, pickaxe_opts); -if (0 <= break_opt) -diffcore_break (break_opt);if (orderfile)diffcore_order (orderfile); }
diffcore-break.c +59 -42
147 lines not on this page · raw message
diffcore-rename.c +52 -12
85 lines not on this page · raw message
diffcore.h +9 -4
@@ -8,9 +8,9 @@* (e.g. diffcore-rename, diffcore-pickaxe). Never include this header * in anything else. */ -#define MAX_SCORE 10000 -#define DEFAULT_MINIMUM_SCORE 5000/* rename/copy similarity minimum */ -#define DEFAULT_MAXIMUM_SCORE 1500/* similarity maximum for break to happen */ +#define MAX_SCORE 60000 +#define DEFAULT_RENAME_SCORE 30000/* rename/copy similarity minimum (50%) */ +#define DEFAULT_BREAK_SCORE 59400/* minimum for break to happen (99%)*/ #define RENAME_DST_MATCHED 01
@@ -43,14 +43,19 @@ struct diff_filepair {struct diff_filespec *one;struct diff_filespec *two;unsigned short int score; -char source_stays;/* all of R/C are copies */ char status;/* M C R N D U (see Documentation/diff-format.txt) */ + unsigned source_stays : 1; /* all of R/C are copies */ + unsigned broken_pair : 1; };#define DIFF_PAIR_UNMERGED (p) \ (!DIFF_FILE_VALID((p)->one) && !DIFF_FILE_VALID((p)->two))#define DIFF_PAIR_RENAME (p) (strcmp((p)->one->path, (p)->two->path)) +#define DIFF_PAIR_BROKEN (p) \ + ( (!DIFF_FILE_VALID((p)->one) != !DIFF_FILE_VALID((p)->two)) && \ + ((p)->broken_pair != 0) ) +#define DIFF_PAIR_TYPE_CHANGED (p) \ ((S_IFMT & (p)->one->mode) != (S_IFMT & (p)->two->mode))
t/t4008-diff-break-rewrite.sh new file +169 -0
169 lines not on this page · raw message