1 # Copyright 2002-2007 Interchange Development Group and others
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version. See the LICENSE file for details.
8 # $Id: diffmerge.coretag,v 1.4 2007-03-30 23:40:54 pajamian Exp $
10 # This tag uses GNU diff3 to merge two texts blocks that were
11 # modified from the same ancestral text together, and marks
12 # conflicts that may appear. This is similar to CVS's merging
13 # and conflict marking. The names the diff3 manpage uses are:
21 # You supply pointers to three text blocks, either as file names or
22 # database fields in the form Table::Column::Key. 'mine' can instead
23 # be provided in the body, between the opening and closing tags.
25 # The tag returns the merged text. You can find out whether a
26 # conflict was detected by providing the name of a scratch variable
27 # in the 'result' option where the return code from diff3 will be placed.
29 # Set the 'ascii' option to allow for different newline types and
30 # ignore whether the last line of the file has a newline.
32 # Set the 'safe_data' option to allow raw data to be pulled from the
33 # database without escaping left brackets (turning [ into [).
37 # [diffmerge /tmp/abcd2 /tmp/abcd1 /tmp/abcd3]
40 # yours="content::pagebody::00001"
41 # older="backup::pagebody::00001"
45 # ][scratch new_pagebody][/diffmerge]
47 UserTag diffmerge Interpolate 1
48 UserTag diffmerge hasEndTag
49 UserTag diffmerge addAttr
50 UserTag diffmerge Version $Revision: 1.4 $
52 # These designations come from the diff3 manpage.
53 # It seemed easier to use their names than to make up new ones.
54 UserTag diffmerge Order yours older mine
56 # But here I try to make up new ones anyway. :)
57 UserTag diffmerge attrAlias <<EOA
65 UserTag diffmerge Routine <<EOR
67 my ($yours, $older, $mine, $opt, $body) = @_;
69 unless ($opt->{flags} =~ /^[-\s\w.]*$/) {
70 Log("diffmerge tag: Security violation with flags: $opt->{flags}");
71 return "Security violation with flags: $opt->{flags}. Logged.";
74 my ($minefn, $yoursfn, $olderfn, $cmd, $merge);
75 my $tmpbasename = "tmp/$Vend::SessionName";
78 $data_opt->{safe_data} = 1 if $opt->{safe_data};
84 $_ .= "\n" unless substr($_, -1, 1) eq "\n";
90 my ($name, $passed, $fn) = @_;
91 if ($$passed =~ /^(\w+)::(.*?)::(.*)/) {
92 my ($table, $col, $key) = ($1, $2, $3);
93 my $data = $asciifix->( tag_data($table, $col, $key, $data_opt) );
94 $$fn = "$tmpbasename.$name";
95 Vend::Util::writefile(">$$fn", $data);
103 $body = $asciifix->($body);
104 $minefn = "tmp/$Vend::SessionName.mine";
105 Vend::Util::writefile(">$minefn", $body);
108 $putfile->('mine', \$mine, \$minefn);
111 $putfile->('yours', \$yours, \$yoursfn);
112 $putfile->('older', \$older, \$olderfn);
114 $cmd = "diff3 -m $opt->{flags} $minefn $olderfn $yoursfn";
115 #Debug("diffmerge command: '$cmd'");
118 if (defined $opt->{result}) {
119 unless ($opt->{result} =~ /\W/) {
120 $Scratch->{$opt->{result}} = $? >> 8;
121 #Debug("diffmerge put $Scratch->{$opt->{result}} into scratch $opt->{result}");
124 Log("diffmerge tag: Invalid 'result' option given; must be a valid name for a scratch variable");