Autogenerated HTML docs for v1.2.0-g6a9b
[git.git] / diffcore.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"\r
2     "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">\r
3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">\r
4 <head>\r
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />\r
6 <meta name="generator" content="AsciiDoc 7.0.1" />\r
7 <style type="text/css">\r
8 /* Debug borders */\r
9 p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {\r
10 /*\r
11   border: 1px solid red;\r
12 */\r
13 }\r
14 \r
15 body {\r
16   margin: 1em 5% 1em 5%;\r
17 }\r
18 \r
19 a { color: blue; }\r
20 a:visited { color: fuchsia; }\r
21 \r
22 em {\r
23   font-style: italic;\r
24 }\r
25 \r
26 strong {\r
27   font-weight: bold;\r
28 }\r
29 \r
30 tt {\r
31   color: navy;\r
32 }\r
33 \r
34 h1, h2, h3, h4, h5, h6 {\r
35   color: #527bbd;\r
36   font-family: sans-serif;\r
37   margin-top: 1.2em;\r
38   margin-bottom: 0.5em;\r
39   line-height: 1.3;\r
40 }\r
41 \r
42 h1 {\r
43   border-bottom: 2px solid silver;\r
44 }\r
45 h2 {\r
46   border-bottom: 2px solid silver;\r
47   padding-top: 0.5em;\r
48 }\r
49 \r
50 div.sectionbody {\r
51   font-family: serif;\r
52   margin-left: 0;\r
53 }\r
54 \r
55 hr {\r
56   border: 1px solid silver;\r
57 }\r
58 \r
59 p {\r
60   margin-top: 0.5em;\r
61   margin-bottom: 0.5em;\r
62 }\r
63 \r
64 pre {\r
65   padding: 0;\r
66   margin: 0;\r
67 }\r
68 \r
69 span#author {\r
70   color: #527bbd;\r
71   font-family: sans-serif;\r
72   font-weight: bold;\r
73   font-size: 1.2em;\r
74 }\r
75 span#email {\r
76 }\r
77 span#revision {\r
78   font-family: sans-serif;\r
79 }\r
80 \r
81 div#footer {\r
82   font-family: sans-serif;\r
83   font-size: small;\r
84   border-top: 2px solid silver;\r
85   padding-top: 0.5em;\r
86   margin-top: 4.0em;\r
87 }\r
88 div#footer-text {\r
89   float: left;\r
90   padding-bottom: 0.5em;\r
91 }\r
92 div#footer-badges {\r
93   float: right;\r
94   padding-bottom: 0.5em;\r
95 }\r
96 \r
97 div#preamble,\r
98 div.tableblock, div.imageblock, div.exampleblock, div.verseblock,\r
99 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,\r
100 div.admonitionblock {\r
101   margin-right: 10%;\r
102   margin-top: 1.5em;\r
103   margin-bottom: 1.5em;\r
104 }\r
105 div.admonitionblock {\r
106   margin-top: 2.5em;\r
107   margin-bottom: 2.5em;\r
108 }\r
109 \r
110 div.content { /* Block element content. */\r
111   padding: 0;\r
112 }\r
113 \r
114 /* Block element titles. */\r
115 div.title, caption.title {\r
116   font-family: sans-serif;\r
117   font-weight: bold;\r
118   text-align: left;\r
119   margin-top: 1.0em;\r
120   margin-bottom: 0.5em;\r
121 }\r
122 div.title + * {\r
123   margin-top: 0;\r
124 }\r
125 \r
126 td div.title:first-child {\r
127   margin-top: 0.0em;\r
128 }\r
129 div.content div.title:first-child {\r
130   margin-top: 0.0em;\r
131 }\r
132 div.content + div.title {\r
133   margin-top: 0.0em;\r
134 }\r
135 \r
136 div.sidebarblock > div.content {\r
137   background: #ffffee;\r
138   border: 1px solid silver;\r
139   padding: 0.5em;\r
140 }\r
141 \r
142 div.listingblock > div.content {\r
143   border: 1px solid silver;\r
144   background: #f4f4f4;\r
145   padding: 0.5em;\r
146 }\r
147 \r
148 div.quoteblock > div.content {\r
149   padding-left: 2.0em;\r
150 }\r
151 div.quoteblock .attribution {\r
152   text-align: right;\r
153 }\r
154 \r
155 div.admonitionblock .icon {\r
156   vertical-align: top;\r
157   font-size: 1.1em;\r
158   font-weight: bold;\r
159   text-decoration: underline;\r
160   color: #527bbd;\r
161   padding-right: 0.5em;\r
162 }\r
163 div.admonitionblock td.content {\r
164   padding-left: 0.5em;\r
165   border-left: 2px solid silver;\r
166 }\r
167 \r
168 div.exampleblock > div.content {\r
169   border-left: 2px solid silver;\r
170   padding: 0.5em;\r
171 }\r
172 \r
173 div.verseblock div.content {\r
174   white-space: pre;\r
175 }\r
176 \r
177 div.imageblock div.content { padding-left: 0; }\r
178 div.imageblock img { border: 1px solid silver; }\r
179 span.image img { border-style: none; }\r
180 \r
181 dl {\r
182   margin-top: 0.8em;\r
183   margin-bottom: 0.8em;\r
184 }\r
185 dt {\r
186   margin-top: 0.5em;\r
187   margin-bottom: 0;\r
188   font-style: italic;\r
189 }\r
190 dd > *:first-child {\r
191   margin-top: 0;\r
192 }\r
193 \r
194 ul, ol {\r
195     list-style-position: outside;\r
196 }\r
197 ol.olist2 {\r
198   list-style-type: lower-alpha;\r
199 }\r
200 \r
201 div.tableblock > table {\r
202   border-color: #527bbd;\r
203   border-width: 3px;\r
204 }\r
205 thead {\r
206   font-family: sans-serif;\r
207   font-weight: bold;\r
208 }\r
209 tfoot {\r
210   font-weight: bold;\r
211 }\r
212 \r
213 div.hlist {\r
214   margin-top: 0.8em;\r
215   margin-bottom: 0.8em;\r
216 }\r
217 td.hlist1 {\r
218   vertical-align: top;\r
219   font-style: italic;\r
220   padding-right: 0.8em;\r
221 }\r
222 td.hlist2 {\r
223   vertical-align: top;\r
224 }\r
225 \r
226 @media print {\r
227   div#footer-badges { display: none; }\r
228 }\r
229 /* Workarounds for IE6's broken and incomplete CSS2. */\r
230 \r
231 div.sidebar-content {\r
232   background: #ffffee;\r
233   border: 1px solid silver;\r
234   padding: 0.5em;\r
235 }\r
236 div.sidebar-title, div.image-title {\r
237   font-family: sans-serif;\r
238   font-weight: bold;\r
239   margin-top: 0.0em;\r
240   margin-bottom: 0.5em;\r
241 }\r
242 \r
243 div.listingblock div.content {\r
244   border: 1px solid silver;\r
245   background: #f4f4f4;\r
246   padding: 0.5em;\r
247 }\r
248 \r
249 div.quoteblock-content {\r
250   padding-left: 2.0em;\r
251 }\r
252 \r
253 div.exampleblock-content {\r
254   border-left: 2px solid silver;\r
255   padding-left: 0.5em;\r
256 }\r
257 </style>\r
258 <title>Tweaking diff output</title>\r
259 </head>\r
260 <body>\r
261 <div id="header">\r
262 <h1>Tweaking diff output</h1>\r
263 <span id="author">June 2005</span><br />\r
264 </div>\r
265 <h2>Introduction</h2>\r
266 <div class="sectionbody">\r
267 <p>The diff commands git-diff-index, git-diff-files, git-diff-tree, and\r
268 git-diff-stages can be told to manipulate differences they find in\r
269 unconventional ways before showing diff(1) output.  The manipulation\r
270 is collectively called "diffcore transformation".  This short note\r
271 describes what they are and how to use them to produce diff outputs\r
272 that are easier to understand than the conventional kind.</p>\r
273 </div>\r
274 <h2>The chain of operation</h2>\r
275 <div class="sectionbody">\r
276 <p>The git-diff-* family works by first comparing two sets of\r
277 files:</p>\r
278 <ul>\r
279 <li>\r
280 <p>\r
281 git-diff-index compares contents of a "tree" object and the\r
282    working directory (when <em>--cached</em> flag is not used) or a\r
283    "tree" object and the index file (when <em>--cached</em> flag is\r
284    used);\r
285 </p>\r
286 </li>\r
287 <li>\r
288 <p>\r
289 git-diff-files compares contents of the index file and the\r
290    working directory;\r
291 </p>\r
292 </li>\r
293 <li>\r
294 <p>\r
295 git-diff-tree compares contents of two "tree" objects;\r
296 </p>\r
297 </li>\r
298 <li>\r
299 <p>\r
300 git-diff-stages compares contents of blobs at two stages in an\r
301    unmerged index file.\r
302 </p>\r
303 </li>\r
304 </ul>\r
305 <p>In all of these cases, the commands themselves compare\r
306 corresponding paths in the two sets of files.  The result of\r
307 comparison is passed from these commands to what is internally\r
308 called "diffcore", in a format similar to what is output when\r
309 the -p option is not used.  E.g.</p>\r
310 <div class="listingblock">\r
311 <div class="content">\r
312 <pre><tt>in-place edit  :100644 100644 bcd1234... 0123456... M file0\r
313 create         :000000 100644 0000000... 1234567... A file4\r
314 delete         :100644 000000 1234567... 0000000... D file5\r
315 unmerged       :000000 000000 0000000... 0000000... U file6</tt></pre>\r
316 </div></div>\r
317 <p>The diffcore mechanism is fed a list of such comparison results\r
318 (each of which is called "filepair", although at this point each\r
319 of them talks about a single file), and transforms such a list\r
320 into another list.  There are currently 6 such transformations:</p>\r
321 <ul>\r
322 <li>\r
323 <p>\r
324 diffcore-pathspec\r
325 </p>\r
326 </li>\r
327 <li>\r
328 <p>\r
329 diffcore-break\r
330 </p>\r
331 </li>\r
332 <li>\r
333 <p>\r
334 diffcore-rename\r
335 </p>\r
336 </li>\r
337 <li>\r
338 <p>\r
339 diffcore-merge-broken\r
340 </p>\r
341 </li>\r
342 <li>\r
343 <p>\r
344 diffcore-pickaxe\r
345 </p>\r
346 </li>\r
347 <li>\r
348 <p>\r
349 diffcore-order\r
350 </p>\r
351 </li>\r
352 </ul>\r
353 <p>These are applied in sequence.  The set of filepairs git-diff-*\r
354 commands find are used as the input to diffcore-pathspec, and\r
355 the output from diffcore-pathspec is used as the input to the\r
356 next transformation.  The final result is then passed to the\r
357 output routine and generates either diff-raw format (see Output\r
358 format sections of the manual for git-diff-* commands) or\r
359 diff-patch format.</p>\r
360 </div>\r
361 <h2>diffcore-pathspec: For Ignoring Files Outside Our Consideration</h2>\r
362 <div class="sectionbody">\r
363 <p>The first transformation in the chain is diffcore-pathspec, and\r
364 is controlled by giving the pathname parameters to the\r
365 git-diff-* commands on the command line.  The pathspec is used\r
366 to limit the world diff operates in.  It removes the filepairs\r
367 outside the specified set of pathnames.  E.g. If the input set\r
368 of filepairs included:</p>\r
369 <div class="listingblock">\r
370 <div class="content">\r
371 <pre><tt>:100644 100644 bcd1234... 0123456... M junkfile</tt></pre>\r
372 </div></div>\r
373 <p>but the command invocation was "git-diff-files myfile", then the\r
374 junkfile entry would be removed from the list because only "myfile"\r
375 is under consideration.</p>\r
376 <p>Implementation note.  For performance reasons, git-diff-tree\r
377 uses the pathname parameters on the command line to cull set of\r
378 filepairs it feeds the diffcore mechanism itself, and does not\r
379 use diffcore-pathspec, but the end result is the same.</p>\r
380 </div>\r
381 <h2>diffcore-break: For Splitting Up "Complete Rewrites"</h2>\r
382 <div class="sectionbody">\r
383 <p>The second transformation in the chain is diffcore-break, and is\r
384 controlled by the -B option to the git-diff-* commands.  This is\r
385 used to detect a filepair that represents "complete rewrite" and\r
386 break such filepair into two filepairs that represent delete and\r
387 create.  E.g.  If the input contained this filepair:</p>\r
388 <div class="listingblock">\r
389 <div class="content">\r
390 <pre><tt>:100644 100644 bcd1234... 0123456... M file0</tt></pre>\r
391 </div></div>\r
392 <p>and if it detects that the file "file0" is completely rewritten,\r
393 it changes it to:</p>\r
394 <div class="listingblock">\r
395 <div class="content">\r
396 <pre><tt>:100644 000000 bcd1234... 0000000... D file0\r
397 :000000 100644 0000000... 0123456... A file0</tt></pre>\r
398 </div></div>\r
399 <p>For the purpose of breaking a filepair, diffcore-break examines\r
400 the extent of changes between the contents of the files before\r
401 and after modification (i.e. the contents that have "bcd1234&#8230;"\r
402 and "0123456&#8230;" as their SHA1 content ID, in the above\r
403 example).  The amount of deletion of original contents and\r
404 insertion of new material are added together, and if it exceeds\r
405 the "break score", the filepair is broken into two.  The break\r
406 score defaults to 50% of the size of the smaller of the original\r
407 and the result (i.e. if the edit shrinks the file, the size of\r
408 the result is used; if the edit lengthens the file, the size of\r
409 the original is used), and can be customized by giving a number\r
410 after "-B" option (e.g. "-B75" to tell it to use 75%).</p>\r
411 </div>\r
412 <h2>diffcore-rename: For Detection Renames and Copies</h2>\r
413 <div class="sectionbody">\r
414 <p>This transformation is used to detect renames and copies, and is\r
415 controlled by the -M option (to detect renames) and the -C option\r
416 (to detect copies as well) to the git-diff-* commands.  If the\r
417 input contained these filepairs:</p>\r
418 <div class="listingblock">\r
419 <div class="content">\r
420 <pre><tt>:100644 000000 0123456... 0000000... D fileX\r
421 :000000 100644 0000000... 0123456... A file0</tt></pre>\r
422 </div></div>\r
423 <p>and the contents of the deleted file fileX is similar enough to\r
424 the contents of the created file file0, then rename detection\r
425 merges these filepairs and creates:</p>\r
426 <div class="listingblock">\r
427 <div class="content">\r
428 <pre><tt>:100644 100644 0123456... 0123456... R100 fileX file0</tt></pre>\r
429 </div></div>\r
430 <p>When the "-C" option is used, the original contents of modified files,\r
431 and deleted files (and also unmodified files, if the\r
432 "--find-copies-harder" option is used) are considered as candidates\r
433 of the source files in rename/copy operation.  If the input were like\r
434 these filepairs, that talk about a modified file fileY and a newly\r
435 created file file0:</p>\r
436 <div class="listingblock">\r
437 <div class="content">\r
438 <pre><tt>:100644 100644 0123456... 1234567... M fileY\r
439 :000000 100644 0000000... bcd3456... A file0</tt></pre>\r
440 </div></div>\r
441 <p>the original contents of fileY and the resulting contents of\r
442 file0 are compared, and if they are similar enough, they are\r
443 changed to:</p>\r
444 <div class="listingblock">\r
445 <div class="content">\r
446 <pre><tt>:100644 100644 0123456... 1234567... M fileY\r
447 :100644 100644 0123456... bcd3456... C100 fileY file0</tt></pre>\r
448 </div></div>\r
449 <p>In both rename and copy detection, the same "extent of changes"\r
450 algorithm used in diffcore-break is used to determine if two\r
451 files are "similar enough", and can be customized to use\r
452 a similarity score different from the default of 50% by giving a\r
453 number after the "-M" or "-C" option (e.g. "-M8" to tell it to use\r
454 8/10 = 80%).</p>\r
455 <p>Note.  When the "-C" option is used with <tt>--find-copies-harder</tt>\r
456 option, git-diff-* commands feed unmodified filepairs to\r
457 diffcore mechanism as well as modified ones.  This lets the copy\r
458 detector consider unmodified files as copy source candidates at\r
459 the expense of making it slower.  Without <tt>--find-copies-harder</tt>,\r
460 git-diff-* commands can detect copies only if the file that was\r
461 copied happened to have been modified in the same changeset.</p>\r
462 </div>\r
463 <h2>diffcore-merge-broken: For Putting "Complete Rewrites" Back Together</h2>\r
464 <div class="sectionbody">\r
465 <p>This transformation is used to merge filepairs broken by\r
466 diffcore-break, and not transformed into rename/copy by\r
467 diffcore-rename, back into a single modification.  This always\r
468 runs when diffcore-break is used.</p>\r
469 <p>For the purpose of merging broken filepairs back, it uses a\r
470 different "extent of changes" computation from the ones used by\r
471 diffcore-break and diffcore-rename.  It counts only the deletion\r
472 from the original, and does not count insertion.  If you removed\r
473 only 10 lines from a 100-line document, even if you added 910\r
474 new lines to make a new 1000-line document, you did not do a\r
475 complete rewrite.  diffcore-break breaks such a case in order to\r
476 help diffcore-rename to consider such filepairs as candidate of\r
477 rename/copy detection, but if filepairs broken that way were not\r
478 matched with other filepairs to create rename/copy, then this\r
479 transformation merges them back into the original\r
480 "modification".</p>\r
481 <p>The "extent of changes" parameter can be tweaked from the\r
482 default 80% (that is, unless more than 80% of the original\r
483 material is deleted, the broken pairs are merged back into a\r
484 single modification) by giving a second number to -B option,\r
485 like these:</p>\r
486 <ul>\r
487 <li>\r
488 <p>\r
489 -B50/60 (give 50% "break score" to diffcore-break, use 60%\r
490   for diffcore-merge-broken).\r
491 </p>\r
492 </li>\r
493 <li>\r
494 <p>\r
495 -B/60 (the same as above, since diffcore-break defaults to 50%).\r
496 </p>\r
497 </li>\r
498 </ul>\r
499 <p>Note that earlier implementation left a broken pair as a separate\r
500 creation and deletion patches.  This was an unnecessary hack and\r
501 the latest implementation always merges all the broken pairs\r
502 back into modifications, but the resulting patch output is\r
503 formatted differently for easier review in case of such\r
504 a complete rewrite by showing the entire contents of old version\r
505 prefixed with <em>-</em>, followed by the entire contents of new\r
506 version prefixed with <em>+</em>.</p>\r
507 </div>\r
508 <h2>diffcore-pickaxe: For Detecting Addition/Deletion of Specified String</h2>\r
509 <div class="sectionbody">\r
510 <p>This transformation is used to find filepairs that represent\r
511 changes that touch a specified string, and is controlled by the\r
512 -S option and the <tt>--pickaxe-all</tt> option to the git-diff-*\r
513 commands.</p>\r
514 <p>When diffcore-pickaxe is in use, it checks if there are\r
515 filepairs whose "original" side has the specified string and\r
516 whose "result" side does not.  Such a filepair represents "the\r
517 string appeared in this changeset".  It also checks for the\r
518 opposite case that loses the specified string.</p>\r
519 <p>When <tt>--pickaxe-all</tt> is not in effect, diffcore-pickaxe leaves\r
520 only such filepairs that touch the specified string in its\r
521 output.  When <tt>--pickaxe-all</tt> is used, diffcore-pickaxe leaves all\r
522 filepairs intact if there is such a filepair, or makes the\r
523 output empty otherwise.  The latter behaviour is designed to\r
524 make reviewing of the changes in the context of the whole\r
525 changeset easier.</p>\r
526 </div>\r
527 <h2>diffcore-order: For Sorting the Output Based on Filenames</h2>\r
528 <div class="sectionbody">\r
529 <p>This is used to reorder the filepairs according to the user's\r
530 (or project's) taste, and is controlled by the -O option to the\r
531 git-diff-* commands.</p>\r
532 <p>This takes a text file each of whose lines is a shell glob\r
533 pattern.  Filepairs that match a glob pattern on an earlier line\r
534 in the file are output before ones that match a later line, and\r
535 filepairs that do not match any glob pattern are output last.</p>\r
536 <p>As an example, a typical orderfile for the core git probably\r
537 would look like this:</p>\r
538 <div class="listingblock">\r
539 <div class="content">\r
540 <pre><tt>README\r
541 Makefile\r
542 Documentation\r
543 *.h\r
544 *.c\r
545 t</tt></pre>\r
546 </div></div>\r
547 </div>\r
548 <div id="footer">\r
549 <div id="footer-text">\r
550 Last updated 27-Dec-2005 00:17:07 PDT\r
551 </div>\r
552 </div>\r
553 </body>\r
554 </html>\r