Saturday, April 5, 2008

Code merging

Wanting to merge two branches of code, both of which have had concurrent commits going on them for some time. Code is kept in svn, so the branches actually live in separate directories. Most changesets have been merged back and forth, yet residual changes remain.

I get diff to tell the files which are different between the branches.

diff -q -r -x '\.svn' -x '*.pyx' -x '*~' branch1 branch2


This produces lines like:



Files zeroc-ice-python_3.2.1/config/Make.rules and zeroc-ice-python-3.2.1-new/config/Make.rules differ
Only in zeroc-ice-python-3.2.1-new/config: Make.rules.GNU
Only in zeroc-ice-python-3.2.1-new/config: Make.rules.GNU_kFreeBSD

I need to munge the output of diff. I want to have 4 columns: directory (sans the branchname), filename, link to the file in branch1 if it exists there, link to file in branch2 if it exists there. I want this ordered/sorted by directory, and I want the output in emacs org mode format. I filter the output of the above diff command through this perl script:


while (<>) {
if (/^Only in/) {
m/Only in (.*): (.*)$/; $dirname=$1; $fname=$2; # sep dirpath and filename
($branch = $dirname) =~ s/([^\/]+).*/$1/; # the branch name is the first part of the dirpath (e.g. branch-xy/dir/path/file)
$dirname =~ s/$branch\/?(.*)/$1/; # remove the 'branch-xy' from dirpath to get the remaining dirpath
$_ = "| $dirname/$fname | [[file:~/workspace/couffable/branches/$branch/$dirname/$fname][Only in: $branch]] |";
}

if (/^Files /) {
m/Files (.*) and (.*) differ/; $left=$1;
$left =~ m/release-3-11\/(.*\/)?([^\/]+)/;
if (defined($1)) { $dirname=$1; } else { $dirname = ""; }
$left=$2; # remove branch name, sep dir and file
$_ = "| $dirname$left | [[file:~/workspace/couffable/branches/release-3-11/$dirname$left][r311]] | [[file:~/workspace/couffable/branches/release-3-11-airtel/$dirname$left][r311-airtel]] |";
}
print $_ . "\n";
}

1 comment:

savecards said...

Send your cheap save the date cards with a floral flurry! This modern design is an elegant introduction to guests for a day that will sweep them off their feet. Help you stand out from the crowd.