none
[openafs-wiki.git] / TWiki / TWikiMergeDotPm.mdwn
1 # <a name="Package &lt;code&gt;TWiki::Merge="></a> Package =TWiki::Merge
2
3 Support for merging strings
4
5 <div>
6   <ul>
7     <li><a href="#Package =TWiki::Merge="> Package TWiki::Merge</a><ul>
8         <li><a href="#StaticMethod <strong>merge2</strong> ($arev,$a,"> StaticMethod merge2 <tt>($arev,$a,$brev,$b,$sep,$session,$info)</tt></a></li>
9         <li><a href="#StaticMethod <strong>simpleMerge</strong> ($a,$"> StaticMethod simpleMerge <tt>($a,$b,$sep) -&gt; \@arr</tt></a></li>
10         <li><a href="#StaticMethod <strong>merge3</strong> ($arev,$a,"> StaticMethod merge3 <tt>($arev,$a,$brev,$b,$crev,$c,$sep,</tt></a></li>
11       </ul>
12     </li>
13   </ul>
14 </div>
15
16 ## <a name="StaticMethod &lt;strong&gt;merge2&lt;/strong&gt; ($arev,$a,"></a> [[StaticMethod]] **merge2** `($arev,$a,$brev,$b,$sep,$session,$info)`
17
18 - `$arev` - rev for $a (string)
19 - `$a` - first ('original') string
20 - `$brev` - rev for $b (string)
21 - `$b` - second ('new') string
22 - `$sep` = separator, string RE e.g. '.\*?\\n' for lines
23 - `$session` - TWiki object
24 - `$info` - data block passed to plugins merge handler. Conventionally this will identify the source of the text being merged (the source form field, or undef for the body text)
25
26 Perform a merge of two versions of the same text, using HTML tags to mark conflicts.
27
28 The granularity of the merge depends on the setting of $sep. For example, if it is `"\\n"`, a line-by-line merge will be done.
29
30 Where conflicts exist, they are marked using HTML &lt;del&gt; and &lt;ins&gt; tags. &lt;del&gt; marks content from $a while &lt;ins&gt; marks content from $b.
31
32 Non-conflicting content (insertions from either set) are not marked.
33
34 The plugins `mergeHandler` is called for each merge.
35
36 Call it like this:
37
38     $newText = TWiki::Merge::merge2(
39        $oldrev, $old, $newrev, $new, '.*?\n', $session, $info );
40
41 ## <a name="StaticMethod &lt;strong&gt;simpleMerge&lt;/strong&gt; ($a,$"></a> [[StaticMethod]] **simpleMerge** `($a,$b,$sep) -> \@arr`
42
43 Perform a merge of two versions of the same text, returning an array of strings representing the blocks in the merged context where each string starts with one of "+", "-" or " " depending on whether it is an insertion, a deletion, or just text. Insertions and deletions alway happen in pairs, as text taken in from either version that does not replace text in the other version will simply be accepted.
44
45 The granularity of the merge depends on the setting of $sep. For example, if it is `"\\n"`, a line-by-line merge will be done. $sep characters are retained in the outout.
46
47 ## <a name="StaticMethod &lt;strong&gt;merge3&lt;/strong&gt; ($arev,$a,"></a> [[StaticMethod]] **merge3** `($arev,$a,$brev,$b,$crev,$c,$sep,`
48
49 $session, $info )
50
51 - `$arev` - rev for common ancestor (id e.g. ver no)
52 - `$a` - common ancestor
53 - `$brev` - rev no for first derivative string (id)
54 - `$b` - first derivative string
55 - `$crev` - rev no for second derivative string (id)
56 - `$c` - second derivative string
57 - `$sep` = separator, string RE e.g. '.\*?\\n' for lines
58 - `$session` - TWiki object
59 - `$info` - data block passed to plugins merge handler. Conventionally this will identify the source of the text being merged (the source form field, or undef for the body text)
60
61 Perform a merge of two versions (b and c) of the same text, using HTML &lt;div&gt; tags to mark conflicts. a is the common ancestor.
62
63 The granularity of the merge depends on the setting of $sep. For example, if it is `".*?\\n"`, a line-by-line merge will be done.
64
65 Where conflicts exist, they are labeled using the provided revision numbers.
66
67 The plugins `mergeHandler` is called for each merge.
68
69 Here's a little picture of a 3-way merge:
70
71 a &lt;- ancestor / b c &lt;- revisions \\ / d &lt;- merged result, returned.
72
73 call it like this:
74
75         my ( $ancestorMeta, $ancestorText ) =
76             $store->readTopic( undef, $webName, $topic, $originalrev );
77         $newText = TWiki::Merge::merge3(
78             $ancestorText, $prevText, $newText,
79             $originalrev, $rev, "new",
80             '.*?\n' );