]> git.neil.brown.name Git - wiggle.git/blob - wiggle.1
6951d30333e2a17f1ef7399b0af63f70c9bc0602
[wiggle.git] / wiggle.1
1 .\" -*- nroff -*-
2 .\" wiggle - apply rejected patches
3 .\"
4 .\" Copyright (C) 2003 Neil Brown <neilb@cse.unsw.edu.au>
5 .\" Copyright (C) 2010 Neil Brown <neilb@suse.de>
6 .\"
7 .\"
8 .\"    This program is free software; you can redistribute it and/or modify
9 .\"    it under the terms of the GNU General Public License as published by
10 .\"    the Free Software Foundation; either version 2 of the License, or
11 .\"    (at your option) any later version.
12 .\"
13 .\"    This program is distributed in the hope that it will be useful,
14 .\"    but WITHOUT ANY WARRANTY; without even the implied warranty of
15 .\"    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 .\"    GNU General Public License for more details.
17 .\"
18 .\"    You should have received a copy of the GNU General Public License
19 .\"    along with this program; if not, write to the Free Software
20 .\"    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 .\"
22 .\"    Author: Neil Brown
23 .\"    Email: <neilb@suse.de>
24 .\"
25 .TH WIGGLE 1 "" v0.9
26 .SH NAME
27 wiggle \- apply rejected patches and perform word-wise diffs
28
29 .SH SYNOPSIS
30
31 .BI wiggle " [function] [options] file [files]"
32
33 .SH DESCRIPTION
34 The main function of
35 .I wiggle
36 is to apply a patch to a file in a similar manner to the
37 .BR patch (1)
38 program.
39
40 The distinctive difference of
41 .I wiggle
42 is that it will attempt to apply a patch even if the "before" part of
43 the patch doesn't match the target file perfectly.
44 This is achieved by breaking the file and patch into words and finding
45 the best alignment of words in the file with words in the patch.
46 Once this alignment has been found, any differences (word-wise) in the
47 patch are applied to the file as best as possible.
48
49 Also,
50 .I wiggle
51 will (in some cases) detect changes that have already been applied,
52 and will ignore them.
53
54 .I wiggle
55 ensures that every change in the patch is applied to the target
56 file somehow.  If a particular change cannot be made in the file, the
57 file is annotated to show where the change should be made in a similar
58 way to the
59 .BR merge (1)
60 program with the
61 .B \-A
62 option.
63 Each annotation contains 3 components: a portion of the original file
64 where the change should be applied, a portion of the patch that
65 couldn't be matched precisely in the file, and the text that should
66 replace that portion of the patch.  These are separated by lines
67 containing precisely 7 identical characters, either '<', '|', '=', or '>', so
68 .in +5
69 .nf
70 .ft CW
71 <<<<<<<
72 Some portion of the original file
73 |||||||
74 text to replace
75 =======
76 text to replace it with
77 >>>>>>>
78 .ft
79 .fi
80 .in -5
81
82 indicates that "text to replace" should be replaced by "text to
83 replace it with" somewhere in the portion of the original file.
84 However
85 .I wiggle
86 was not able to find a place to make this change.
87
88 .I wiggle
89 can also produce conflict reports showing only the words that are
90 involved rather than showing whole lines.
91 In this case the output looks like:
92 .ft CW
93 .ti +5
94 <<<---original|||old===new--->>>
95 .ft
96
97 A typical usage of
98 .I wiggle
99 is to run
100 .I patch
101 to apply some patch, and to collect a list of rejects by monitoring
102 the error messages from patch.  Then for each file for which a
103 reject was found, run
104 .ti +5
105 wiggle \-\-replace originalfile originalfile.rej
106
107 Finally each file must be examined to resolve any unresolved
108 conflicts, and to make sure the applied patch is semantically correct.
109
110 Alternately, the original patch file can be feed to the
111 .B browse
112 mode as
113 .ti +5
114 wiggle \-B < patchfile
115
116 This will allow the changes and conflicts to be inspected and, to some
117 extent, modified; and then the results can be save.
118
119 .SS OPTIONS
120 The following options are understood by
121 .IR wiggle .
122 Some of these are explained in more detail in the following sections
123 on MERGE, DIFF, EXTRACT, and BROWSE.
124
125 .TP
126 .BR \-m ", " \-\-merge
127 Select the "merge" function.  This is the default function.
128
129 .TP
130 .BR \-d ", " \-\-diff
131 Select the "diff" function.  This displays the differences between
132 files.  This can be given after
133 .B \-\-browse
134 (see below) in which case a patch or diff of two files can be viewed
135 without the originals.
136
137
138 .TP
139 .BR \-x ", " \-\-extract
140 Select the "extract" function.  This extracts one branch of a patch or
141 merge file.
142
143 .TP
144 .BR \-B ", " \-\-browse
145 Select the "browse" function.  This is similar to "merge" (or "diff")
146 only with a different presentation.  Instead of the result simply
147 being sent to standard output, it is presented using an ncurses-based
148 GUI so that each hunk of the patch can be examined to understand what
149 conflicts where involved and what needed to be ignored in order of the
150 patch to be wiggled in to place.
151
152 .TP
153 .BR \-w ", " \-\-words
154 Request that all operations and display be word based.  This is the
155 default for the "diff" function.
156
157 .TP
158 .BR \-l ", " \-\-lines
159 Request that all operations and display be line based.
160
161 .TP
162 .BR \-b ", " \-\-ignore\-blanks
163 De-emphasise white space (space, tab, and newline) is determining
164 differences and changes.
165
166 Normally white space is treated like a word which can be matched or
167 changed by a patch.  When this flag is in force, white space serves
168 only as a separator between other words and is not matched itself.
169 The effect of this is that changes in the amount of white space are
170 not treated as significant.
171
172 To be precise, any white space is combined with the preceeding word
173 or, in the case of leading space on a line, with the following word.
174 However it is not involved in any comparisons of that word.  If a patch
175 deletes a word, the attached white space is deleted as well.  If a
176 patch adds a word, the attached white space is added as well.
177
178 An empty line, or one that contains only blanks, will be treated as a
179 single word that will match any other blank line, no matter how many
180 spaces it has.
181
182 .B \-b
183 has no effect in
184 .B \-\-line
185 mode.
186
187 .TP
188 .BR \-p ", " \-\-patch
189 Treat the last named file as a patch instead of a file (with \-\-diff)
190 or a merge (\-\-extract).
191 In
192 .I merge
193 or
194 .B browse
195 mode,
196 .B \-p
197 requires there be exactly one file which is a patch and which can
198 contain patches to multiple files.  The patches are merged into each
199 file.  When used in
200 .I merge
201 mode, this usage requires the
202 .B \-\-replace
203 option as writing lots of merged files to standard-out is impractical.
204
205 When processing a multi-file patch,
206 .B \-p
207 can be followed by a numeric argument indicating how many file name
208 components should be stripped from files named in the patch file.  If no
209 numeric argument is given,
210 .I wiggle
211 will deduce an appropriate number based what files are present in the
212 filesystem.
213
214 .TP
215 .BR \-r ", " \-\-replace
216 Normally the merged output is written to standard-output.  With
217 \-\-replace, the original file is replaced with the merge output.
218 In
219 .B browse
220 mode, this instructs
221 .I wiggle
222 to always save the resulting merge when exiting.
223
224 .TP
225 .BR \-o ", " \-\-output=
226 Rather than writing the result to stdout or to replace the original
227 file, this requests that the output be written to the given file.
228 This is only meaningful with
229 .B \-\-merge
230 or
231 .B \-\-browse
232 when given a single merge to browse.
233
234 This option overrides
235 .BR \-r .
236
237 .TP
238 .BR \-R ", " \-\-reverse
239 When used with the
240 .B diff
241 function, swap the files before calculating
242 the differences.
243 When used with the
244 .B merge
245 or
246 .B browse
247 functions,
248 .I wiggle
249 attempts to revert changes rather than apply them.
250
251 .TP
252 .BR \-i ", " \-\-no\-ignore
253 Normally wiggle will ignore changes in the patch which appear to
254 already have been applied in the original.  With this flag those
255 changes are reported as conflicts rather than being ignored.
256
257 .TP
258 .BR \-W ", " \-\-show\-wiggles
259 When used with
260 .IR \-\-merge ,
261 conflicts that can be wiggled into place are reported as conflicts
262 with an extra stanza which shows what the result would be if this flag
263 had not been used.  The extra stanza is introduce with a line
264 containing 7 ampersand
265 .RB ( & )
266 characters thus:
267 .in +5
268 .nf
269 .ft CW
270 <<<<<<<
271 Some portion of the original file
272 |||||||
273 text to replace
274 =======
275 text to replace it with
276 &&&&&&&
277 Text that would result from a successful wiggle
278 >>>>>>>
279 .ft
280 .fi
281 .in -5
282
283 .TP
284 .B \-\-report\-wiggles
285 If a merge is successful in applying all changes, it will normally exit
286 with a success status (0), only reporting failure (1) if a conflict
287 occurred and was annotated.  With
288 .B \-\-report\-wiggles
289 .I wiggle
290 will also report failure if any changes had to be wiggled in.  This
291 can be useful when
292 .I wiggle
293 is used for automatic merges as with
294 .IR git .
295 If any wiggles happen,
296 .I git
297 will report the failure, and the results can be examined to confirm
298 they are acceptable.
299
300 .TP
301 .BR \-h ", " \-\-help
302 Print a simple help message.  If given after one of the function
303 selectors
304 .RB ( \-\-merge ,
305 .BR \-\-diff ,
306 .BR \-\-extract ,
307 .BR \-\-browse )
308 help specific to that function is displayed.
309
310 .TP
311 .BR \-V ", " \-\-version
312 Display the version number of
313 .IR wiggle .
314
315 .TP
316 .BR \-v ", " \-\-verbose
317 Enable verbose mode.  Currently this makes no difference.
318
319 .TP
320 .BR \-q ", " \-\-quiet
321 Enable quiet mode.  This suppresses the message from the merge
322 function when there are unresolvable conflicts.
323
324 .SS WORDS
325 .I wiggle
326 can divide a text into lines or words when performing it's tasks.
327 A line is simply a string of characters terminated by a newline.
328 A word is either a maximal contiguous string of alphanumerics
329 (including underscore), a maximal contiguous string of space or tab
330 characters, or any other single character.
331
332 .SS MERGE
333 The merge function modifies a given text by finding all changes between
334 two other texts and imposing those changes on the given text.
335
336 Normally
337 .I wiggle
338 focuses on which words have changed so as to maximise the possibility
339 of finding a good match in the given text for the context of a given
340 change.  However it can consider only whole lines instead.
341
342 .I wiggle
343 extracts the three texts that it needs from files listed on the
344 command line.  Either 1, 2, or 3 files may be listed, and any one of
345 them may be a lone hyphen signifying standard-input.
346
347 If one file is given and the
348 .B \-p
349 option is not present, the file is treated as a
350 .B merge
351 file, i.e. the output of "merge \-A" or "wiggle".  Such a file
352 implicitly contains three streams and these are extracted and
353 compared.
354
355 If two files are given, then the first simply contains the primary
356 text, and the second is treated as a patch file (the output of "diff\ \-u"
357 or "diff\ \-c", or a ".rej" file from
358 .IR patch )
359 and the two other texts
360 are extracted from that.
361
362 If one file is given together with the
363 .B \-p
364 option, the file is treated as a patch file containing the names of
365 the files that it patches.  In this case multiple merge operations can
366 happen and each takes one stream from a file named in the patch, and
367 the other two from the patch itself.  The
368 .B \-\-replace
369 option is required and the results are written back to the
370 target files.
371
372 Finally if three files are listed, they are taken to contain the given
373 text and the two other texts, in order.
374
375 Normally the result of the merge is written to standard-output.
376 However if the
377 .B \-r
378 flag is given, the output is written to a file
379 which replaces the original given file. In this case the original file
380 is renamed to have a
381 .B .porig
382 suffix (for "patched original" which makes sense if you first use
383 .I patch
384 to apply a patch, and then use
385 .I wiggle
386 to wiggle the rejects in).
387
388 If no errors occur (such as file access errors)
389 .I wiggle
390 will exit with a status of 0 if all changes were successfully merged,
391 and with an exit status of 1 and a brief message if any changes could
392 not be fully merged and were instead inserted as annotations.
393 However if either
394 .B \-\-report\-wiggles
395 or
396 .B \-\-show\-wiggles
397 options were given,
398 .I wiggle
399 will also exist with status of 1 if any changes had to be wiggled in
400 even though this was successful.
401
402 The merge function can operate in three different modes with respect
403 to lines or words.
404
405 With the
406 .B \-\-lines
407 option, whole lines are compared and any conflicts
408 are reported as whole lines that need to be replaced.
409
410 With the
411 .B \-\-words
412 option, individual words are compared and any
413 conflicts are reported just covering the words affected.  This uses
414 the \f(CW <<<|||===>>> \fP conflict format.
415
416 Without either of these options, a hybrid approach is taken.
417 Individual words are compared and merged, but when a conflict is found
418 the whole surrounding line is reported as being in conflict.
419
420 .I wiggle
421 will ensure that every change between the two other texts is reflected
422 in the result of the merge somehow.  There are four different ways
423 that a change can be reflected.
424 .IP 1
425 If a change converts
426 .B A
427 to
428 .B B
429 and
430 .B A
431 is found at a suitable place in the original file, it is
432 replaced with
433 .BR B .
434 This includes the possibility that
435 .B B
436 is empty, but
437 not that
438 .B A
439 is empty.
440
441 .IP 2
442 If a change is found which simply adds
443 .B B
444 and the text immediately preceding and following the insertion are
445 found adjacent in the original file in a suitable place, then
446 .B B
447 is inserted between those adjacent texts.
448
449 .IP 3
450 If a change is found which changes
451 .B A
452 to
453 .B B
454 and this appears (based on context) to align with
455 .B B
456 in the original, then it is assumed that this change has already been
457 applied, and the change is ignored.  When this happens, a message
458 reflecting the number of ignored changes is printed by
459 .IR wiggle .
460 This optimisation can be suppressed with the
461 .B \-i
462 flag.
463
464 .IP 4
465 If a change is found that does not fit any of the above possibilities,
466 then a conflict is reported as described earlier.
467
468 .SS DIFF
469
470 The diff function is provided primarily to allow inspection of the
471 alignments that
472 .I wiggle
473 calculated between texts and that it uses for performing a merge.
474
475 The output of the diff function is similar to the unified output of
476 diff.  However while diff does not output long stretches of common text,
477 .IR wiggle 's
478 diff mode outputs everything.
479
480 When calculating a word-based alignment (the default),
481 .I wiggle
482 may need to show these word-based differences.  This is done using an
483 extension to the unified-diff format.  If a line starts with a
484 vertical bar, then it may contain sections surrounded by special
485 multi-character brackets.  The brackets "<<<++" and "++>>>" surround
486 added text while "<<<--" and "-->>>" surround removed text.
487
488 .I wiggle
489 can be given the two texts to compare in one of three ways.
490
491 If only one file is given, then it is treated as a patch and the two
492 branches of that diff are compared.  This effectively allows a patch
493 to be refined from a line-based patch to a word-based patch.
494
495 If two files are given, then they are normally assumed to be simple
496 texts to be compared.
497
498 If two files are given along with the \-\-patch option, then the second
499 file is assumed to be a patch and either the first (with \-1) or the
500 second (with \-2) branch is extracted and compared with text found in
501 the first file.
502
503 This last option causes
504 .I wiggle
505 to apply a "best-fit" algorithm for aligning patch hunks with the
506 file before computing the differences.  This algorithm is used when
507 merging a patch with a file, and its value can be seen by comparing
508 the difference produced this way with the difference produced by first
509 extracting one branch of a patch into a file, and then computing the
510 difference of that file with the main file.
511
512
513 .SS EXTRACT
514
515 The extract function of
516 .I wiggle
517 simply exposes the internal functionality for extracting one branch of
518 a patch or a merge file.
519
520 Precisely one file should be given, and it will be assumed to be a
521 merge file unless
522 .B  \-\-patch
523 is given, in which case a patch is assumed.
524
525 The choice of branch in made by providing one of
526 .BR \-1 ,
527 .BR \-2 ,
528 or
529 .B \-3
530 with obvious meanings.
531
532 .SS BROWSE
533
534 The browse function of
535 .I wiggle
536 presents the result of a merge or (with
537 .B \-d
538 a diff) in a text-based GUI that can be
539 navigated using keystrokes similar to vi(1) or emacs(1).
540
541 The browser allows each of the two or  three streams to be viewed individually
542 with colours used to highlight different sorts of text - green for
543 added text, red for deleted text etc.  It can also show the patch by
544 itself, the full result of the merge, or the merge and the patch
545 side-by-side.
546
547 The browser provides a number of context-sensitive help pages which
548 can be accessed by typing '?'
549
550 A limited amount of editing is permitted while in
551 .B browse
552 mode.  Currently any Conflict or Changed section can be converted to
553 Unchanged by using the
554 .B x
555 key (lower case), or all the Conflict and Changes sections in a line
556 can be converted to Unchanged.
557 .B X
558 (upper case).  The effect can be toggled by pressing
559 .B x
560 or
561 .B X
562 again.
563
564 A Conflict section can also be converted to Change (so the result is
565 accepted even though there wasn't a proper match) with the (lower
566 case)
567 .B c
568 key.  Pressing
569 .B c
570 effects a toggle.
571
572 If you make any changes, then wiggle will ask you if you want
573 to save the changes, even if
574 .B \-\-replace
575 was not given.
576
577 To make more sweeping changes you can use
578 .B v
579 which runs an editor, preferring
580 .B $VISUAL
581 or
582 .B $EDITOR
583 if they are set in the environment.
584
585 .SH WARNING
586
587 Caution should always be exercised when applying a rejected patch with
588 .IR wiggle .
589 When
590 .I patch
591 rejects a patch, it does so for a good reason.  Even though
592 .I wiggle
593 may be able to find a believable place to apply each textual change,
594 there is no guarantee that the result is correct in any semantic
595 sense.  The result should always be inspected to make sure it is
596 correct.
597
598 .SH EXAMPLES
599
600 .B "  wiggle \-\-replace file file.rej"
601 .br
602 This is the normal usage of
603 .I wiggle
604 and will take any changes in
605 .B file.rej
606 that
607 .I patch
608 could not apply, and merge them into
609 .BR file .
610
611 .B "  wiggle \-dp1 file file.rej"
612 .br
613 This will perform a word-wise comparison between the
614 .B file
615 and the
616 .I before
617 branch of the diff in
618 .B file.rej
619 and display the differences.  This allows you to see where a given
620 patch would apply.
621
622 .B "   wiggle \-\-merge \-\-help"
623 .br
624 Get help about the merge function of
625 .IR wiggle .
626
627 .B "   wiggle \-\-browse \-\-patch update.patch"
628 .br
629 Parse the
630 .B update.patch
631 file for patches and present a list of patched files which can be
632 browsed to examine each patch in detail.
633
634 .I wiggle
635 can be integrated with
636 .I git
637 so that it is used as the default merge tool and diff tool.
638 This can be achieved by adding the following lines to
639 .B .gitconfig
640 in the user's home directory.
641
642 .RS 4
643 .nf
644 [merge "wiggle"]
645         name = "Wiggle flexible merging"
646         driver = wiggle \-o %A %A %O %B
647         recursive = binary
648 [merge]
649         tool = wiggle
650 [mergetool "wiggle"]
651         cmd = wiggle \-B \-o $MERGED $LOCAL $BASE $REMOTE
652 [difftool "wiggle"]
653         cmd = wiggle \-Bd $LOCAL $REMOTE
654 .fi
655 .RE
656
657 This will make
658 .B "git mergetool"
659 and
660 .B "git difftool"
661 use
662 .IR wiggle .
663
664 If you want
665 .I git
666 to always use
667 .I wiggle
668 for merges (which may be dangerous), you can add
669 .RS 4
670 * merge=wiggle
671 .RE
672 to an appropriate
673 .I gitattributes
674 file such as
675 .BR $HOME/.config/git/attributes .
676
677
678
679 .SH QUOTE
680 The name of
681 .I wiggle
682 was inspired by the following quote.  However
683 .I wiggle
684 does not yet
685 .B help
686 you to wiggle a patch into place.  It either does the wiggle itself,
687 or leave it for you to finish off.
688
689 .nf
690 The problem I find is that I often want to take
691   (file1+patch) -> file2,
692 when I don't have file1.  But merge tools want to take
693   (file1|file2) -> file3.
694 I haven't seen a graphical tool which helps you to wiggle a patch
695 into a file.
696
697 \-\- Andrew Morton - 2002
698 .fi
699
700 .SH SHORTCOMINGS
701 .IP -
702 .I wiggle
703 cannot read the extended unified-diff output that it produces for
704 \-\-diff \-\-words.
705
706 .IP -
707 .I wiggle
708 cannot read the word-based merge format that it produces for \-\-merge
709 \-\-words.
710
711 .SH AUTHOR
712
713 Neil Brown at Computer Science and Engineering at
714 The University of New South Wales, Sydney, Australia;
715 and later and SUSE, still in Sydney, Australia.
716
717 .SH SEE ALSO
718 .IR patch (1),
719 .IR diff (1),
720 .IR merge (1),
721 .IR wdiff (1),
722 .IR diff3 (1),
723 .IR git-config (1),
724 .IR gitattributes (5).