2 .\" wiggle - apply rejected patches
4 .\" Copyright (C) 2003 Neil Brown <neilb@cse.unsw.edu.au>
5 .\" Copyright (C) 2010-2013 Neil Brown <neilb@suse.de>
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.
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.
18 .\" You should have received a copy of the GNU General Public License
19 .\" along with this program.
21 .\" Author: Neil Brown
22 .\" Email: <neilb@suse.de>
26 wiggle \- apply rejected patches and perform word-wise diffs
28 .BI wiggle " [function] [options] file [files]"
32 is to apply a patch to a file in a similar manner to the
36 The distinctive difference of
38 is that it will attempt to apply a patch even if the "before" part of
39 the patch doesn't match the target file perfectly.
40 This is achieved by breaking the file and patch into words and finding
41 the best alignment of words in the file with words in the patch.
42 Once this alignment has been found, any differences (word-wise) in the
43 patch are applied to the file as best as possible.
47 will (in some cases) detect changes that have already been applied,
51 ensures that every change in the patch is applied to the target
52 file somehow. If a particular change cannot be made in the file, the
53 file is annotated to show where the change should be made in a similar
59 Each annotation contains 3 components: a portion of the original file
60 where the change should be applied, a portion of the patch that
61 couldn't be matched precisely in the file, and the text that should
62 replace that portion of the patch. These are separated by lines
63 containing precisely 7 identical characters, either '<', '|', '=',
64 or '>', possibly followed by a descriptive word. So
69 Some portion of the original file
73 text to replace it with
78 indicates that "text to replace" should be replaced by "text to
79 replace it with" somewhere in the portion of the original file.
82 was not able to find a place to make this change.
85 can also produce conflict reports showing only the words that are
86 involved rather than showing whole lines.
87 In this case the output looks like:
90 <<<---original|||old===new--->>>
97 to apply some patch, and to collect a list of rejects by monitoring
98 the error messages from patch. Then for each file for which a
101 wiggle \-\-replace originalfile originalfile.rej
103 Finally each file must be examined to resolve any unresolved
104 conflicts, and to make sure the applied patch is semantically correct.
106 Alternately, the original patch file can be fed to the
110 wiggle \-B < patchfile
112 This will allow the changes and conflicts to be inspected and, to some
113 extent, modified; and then the results can be saved.
115 The following options are understood by
117 Some of these are explained in more detail in the following sections
118 on MERGE, DIFF, EXTRACT, and BROWSE.
120 .BR \-m ", " \-\-merge
121 Select the "merge" function. This is the default function.
123 .BR \-d ", " \-\-diff
124 Select the "diff" function. This displays the differences between
125 files. This can be given after
127 (see below) in which case a patch or diff of two files can be viewed
128 without the originals.
130 .BR \-x ", " \-\-extract
131 Select the "extract" function. This extracts one branch of a patch or
134 .BR \-B ", " \-\-browse
135 Select the "browse" function. This is similar to "merge" (or "diff")
136 only with a different presentation. Instead of the result simply
137 being sent to standard output, it is presented using an ncurses-based
138 GUI so that each hunk of the patch can be examined to understand what
139 conflicts where involved and what needed to be ignored in order of the
140 patch to be wiggled in to place.
142 .BR \-w ", " \-\-words
143 Request that all operations and display be word based. This is the
144 default for the "diff" function.
146 .BR \-l ", " \-\-lines
147 Request that all operations and display be line based.
149 .BR \-b ", " \-\-ignore\-blanks
150 De-emphasise white space (space, tab, and newline) is determining
151 differences and changes.
154 Normally white space is treated like a word which can be matched or
155 changed by a patch. When this flag is in force, white space serves
156 only as a separator between other words and is not matched itself.
157 The effect of this is that changes in the amount of white space are
158 not treated as significant.
160 To be precise, any white space is combined with the preceeding word
161 or, in the case of leading space on a line, with the following word.
162 However it is not involved in any comparisons of that word. If a patch
163 deletes a word, the attached white space is deleted as well. If a
164 patch adds a word, the attached white space is added as well.
166 An empty line, or one that contains only blanks, will be treated as a
167 single word that will match any other blank line, no matter how many
176 .BR \-p ", " \-\-patch
177 Treat the last named file as a patch instead of a file (with \-\-diff)
178 or a merge (\-\-extract).
185 requires there be exactly one file which is a patch and which can
186 contain patches to multiple files. The patches are merged into each
189 mode, this usage requires the
191 option as writing lots of merged files to standard-out is impractical.
194 When processing a multi-file patch,
196 can be followed by a numeric argument indicating how many file name
197 components should be stripped from files named in the patch file. If no
198 numeric argument is given,
200 will deduce an appropriate number based what files are present in the
204 .BR \-r ", " \-\-replace
205 Normally the merged output is written to standard-output. With
207 the original file is replaced with the merge output.
212 to always save the resulting merge when exiting.
214 .BR \-o ", " \-\-output=
215 Rather than writing the result to stdout or to replace the original
216 file, this requests that the output be written to the given file.
217 This is only meaningful with
221 when given a single merge to browse.
224 This option overrides
228 .BR \-R ", " \-\-reverse
231 function, swap the files before calculating
239 attempts to revert changes rather than apply them.
241 .BR \-i ", " \-\-no\-ignore
242 Normally wiggle will ignore changes in the patch which appear to
243 already have been applied in the original. With this flag those
244 changes are reported as conflicts rather than being ignored.
246 .BR \-W ", " \-\-show\-wiggles
249 conflicts that can be wiggled into place are reported as conflicts
250 with an extra stanza which shows what the result would be if this flag
251 had not been used. The extra stanza is introduce with a line
252 containing 7 ampersand
259 Some portion of the original file
263 text to replace it with
265 Text that would result from a successful wiggle
271 .B \-\-report\-wiggles
272 If a merge is successful in applying all changes, it will normally exit
273 with a success status (0), only reporting failure (1) if a conflict
274 occurred and was annotated. With
275 .B \-\-report\-wiggles
277 will also report failure if any changes had to be wiggled in. This
280 is used for automatic merges as with
282 If any wiggles happen,
284 will report the failure, and the results can be examined to confirm
287 .BR \-h ", " \-\-help
288 Print a simple help message. If given after one of the function
294 help specific to that function is displayed.
296 .BR \-V ", " \-\-version
297 Display the version number of
300 .BR \-v ", " \-\-verbose
301 Enable verbose mode. Currently this makes no difference.
303 .BR \-q ", " \-\-quiet
304 Enable quiet mode. This suppresses the message from the merge
305 function when there are unresolvable conflicts.
308 can divide a text into lines or words when performing it's tasks.
309 A line is simply a string of characters terminated by a newline.
310 A word is either a maximal contiguous string of alphanumerics
311 (including underscore), a maximal contiguous string of space or tab
312 characters, or any other single character.
314 The merge function modifies a given text by finding all changes between
315 two other texts and imposing those changes on the given text.
319 focuses on which words have changed so as to maximise the possibility
320 of finding a good match in the given text for the context of a given
321 change. However it can consider only whole lines instead.
324 extracts the three texts that it needs from files listed on the
325 command line. Either 1, 2, or 3 files may be listed, and any one of
326 them may be a lone hyphen signifying standard-input.
328 If one file is given and the
330 option is not present, the file is treated as a
332 file, i.e. the output of "merge \-A" or "wiggle". Such a file
333 implicitly contains three streams and these are extracted and
336 If two files are given, then the first simply contains the primary
337 text, and the second is treated as a patch file (the output of "diff\ \-u"
338 or "diff\ \-c", or a ".rej" file from
340 and the two other texts
341 are extracted from that.
343 If one file is given together with the
345 option, the file is treated as a patch file containing the names of
346 the files that it patches. In this case multiple merge operations can
347 happen and each takes one stream from a file named in the patch, and
348 the other two from the patch itself. The
350 option is required and the results are written back to the
353 Finally if three files are listed, they are taken to contain the given
354 text and the two other texts, in order.
356 Normally the result of the merge is written to standard-output.
359 flag is given, the output is written to a file
360 which replaces the original given file. In this case the original file
363 suffix (for "patched original" which makes sense if you first use
365 to apply a patch, and then use
367 to wiggle the rejects in).
371 option is given with a file name, the output will be written to that
372 file. In this case no backup is created.
374 If no errors occur (such as file access errors)
376 will exit with a status of 0 if all changes were successfully merged,
377 and with an exit status of 1 and a brief message if any changes could
378 not be fully merged and were instead inserted as annotations.
380 .B \-\-report\-wiggles
385 will also exist with status of 1 if any changes had to be wiggled in
386 even though this was successful.
388 The merge function can operate in three different modes with respect
393 option, whole lines are compared and any conflicts
394 are reported as whole lines that need to be replaced.
398 option, individual words are compared and any
399 conflicts are reported just covering the words affected. This uses
400 the \f(CW <<<|||===>>> \fP conflict format.
402 Without either of these options, a hybrid approach is taken.
403 Individual words are compared and merged, but when a conflict is found
404 the whole surrounding line is reported as being in conflict.
407 will ensure that every change between the two other texts is reflected
408 in the result of the merge somehow. There are four different ways
409 that a change can be reflected.
417 is found at a suitable place in the original file, it is
420 This includes the possibility that
427 If a change is found which simply adds
429 and the text immediately preceding and following the insertion are
430 found adjacent in the original file in a suitable place, then
432 is inserted between those adjacent texts.
434 If a change is found which changes
438 and this appears (based on context) to align with
440 in the original, then it is assumed that this change has already been
441 applied, and the change is ignored. When this happens, a message
442 reflecting the number of ignored changes is printed by
444 This optimisation can be suppressed with the
448 If a change is found that does not fit any of the above possibilities,
449 then a conflict is reported as described earlier.
451 The diff function is provided primarily to allow inspection of the
454 calculated between texts and that it uses for performing a merge.
456 The output of the diff function is similar to the unified output of
457 diff. However while diff does not output long stretches of common text,
459 diff mode outputs everything.
461 When calculating a word-based alignment (the default),
463 may need to show these word-based differences. This is done using an
464 extension to the unified-diff format. If a line starts with a
465 vertical bar, then it may contain sections surrounded by special
466 multi-character brackets. The brackets "<<<++" and "++>>>" surround
467 added text while "<<<--" and "-->>>" surround removed text.
470 can be given the two texts to compare in one of three ways.
472 If only one file is given, then it is treated as a patch and the two
473 branches of that patch are compared. This effectively allows a patch
474 to be refined from a line-based patch to a word-based patch.
476 If two files are given, then they are normally assumed to be simple
477 texts to be compared.
479 If two files are given along with the \-\-patch option, then the second
480 file is assumed to be a patch and either the first (with \-1) or the
481 second (with \-2) branch is extracted and compared with text found in
484 This last option causes
486 to apply a "best-fit" algorithm for aligning patch hunks with the
487 file before computing the differences. This algorithm is used when
488 merging a patch with a file, and its value can be seen by comparing
489 the difference produced this way with the difference produced by first
490 extracting one branch of a patch into a file, and then computing the
491 difference of that file with the main file.
493 The extract function of
495 simply exposes the internal functionality for extracting one branch of
496 a patch or a merge file.
498 Precisely one file should be given, and it will be assumed to be a
501 is given, in which case a patch is assumed.
503 The choice of branch in made by providing one of
508 with obvious meanings.
510 The browse function of
512 presents the result of a merge or (with
514 a diff in a text-based GUI that can be
515 navigated using keystrokes similar to
520 The browser allows each of the two or three streams to be viewed individually
521 with colours used to highlight different sorts of text - green for
522 added text, red for deleted text etc. It can also show the patch by
523 itself, the full result of the merge, or the merge and the patch
526 The browser provides a number of context-sensitive help pages which
527 can be accessed by typing '?'
529 The top right of the GUI will report the type of text under the
530 cursor, which is also indicated by the colour of the text. Options
531 are Unchanged, Changed, Unmatched, Extraneous, AlreadyApplied and
532 Conflict. If the meanings of these are clear a little
533 experimentations should help.
535 A limited amount of editing is permitted while in
537 mode. Currently any Conflict or Changed section can be converted to
538 Unchanged by using the
540 key (lower case), or all the Conflict and Changes sections in a line
541 can be converted to Unchanged.
543 (upper case). The effect can be toggled by pressing
549 A Conflict section can also be converted to Change (so the result is
550 accepted even though there wasn't a proper match) with the (lower
557 If you make any changes, then wiggle will ask you if you want
558 to save the changes, even if
562 To make more sweeping changes you can use
564 which runs an editor, preferring
568 if they are set in the environment.
570 Caution should always be exercised when applying a rejected patch with
574 rejects a patch, it does so for a good reason. Even though
576 may be able to find a believable place to apply each textual change,
577 there is no guarantee that the result is correct in any semantic
578 sense. The result should always be inspected to make sure it is
581 .B " wiggle \-\-replace file file.rej"
583 This is the normal usage of
585 and will take any changes in
589 could not apply, and merge them into
592 .B " wiggle \-dp1 file file.rej"
594 This will perform a word-wise comparison between the
598 branch of the diff in
600 and display the differences. This allows you to see where a given
603 .B " wiggle \-\-merge \-\-help"
605 Get help about the merge function of
608 .B " wiggle \-\-browse \-\-patch update.patch"
612 file for patches and present a list of patched files which can be
613 browsed to examine each patch in detail.
616 can be integrated with
618 so that it is used as the default merge tool and diff tool.
619 This can be achieved by adding the following lines to
621 in the user's home directory.
625 name = "Wiggle flexible merging"
626 driver = wiggle \-o %A %A %O %B
631 cmd = wiggle \-B \-o $MERGED $LOCAL $BASE $REMOTE
633 cmd = wiggle \-Bd $LOCAL $REMOTE
647 for merges (which may be dangerous), you can add
654 .BR $HOME/.config/git/attributes .
658 was inspired by the following quote.
661 The problem I find is that I often want to take
662 (file1+patch) -> file2,
663 when I don't have file1. But merge tools want to take
664 (file1|file2) -> file3.
665 I haven't seen a graphical tool which helps you to wiggle a patch
668 \-\- Andrew Morton - 2002
673 cannot read the extended unified-diff output that it produces for
677 cannot read the word-based merge format that it produces for \-\-merge
681 does not understand unicode and so will treat all non-ASCII characters
682 much the same as it treats punctuation - it will treat each one
683 as a separate word. The browser will not display non-ASCII characters
686 Neil Brown at Computer Science and Engineering at
687 The University of New South Wales, Sydney, Australia;
688 and later at SUSE, still in Sydney, Australia.
696 .IR gitattributes (5).