Skip to content

Instantly share code, notes, and snippets.

@gbluma
Created May 17, 2012 04:17
Show Gist options
  • Save gbluma/2716302 to your computer and use it in GitHub Desktop.
Save gbluma/2716302 to your computer and use it in GitHub Desktop.
Find conflicts between two directories
#!/bin/bash
set -e
function find_conflicts {
# verify that BASE, ROOT, COMPARISONS are set
# ...
# generate a timestamp
thedate=$(date +"%F_%X" | sed "s/:/-/g")
# hold onto previous matches so we don't need to match inverted pairs (x,y) == (y,x)
previous_matches=""
# Operate on a cartesian product of comparisons
for x in $COMPARISONS; do
for y in $COMPARISONS; do
# check if this has been done before
previous_matches="$previous_matches $x,$y"
matched=false
for match in $previous_matches; do
if [ "$match" == "$y,$x" ]; then
matched=true
break
fi
done
if [ $matched == true ]; then
break
fi
# don't compare with itself
if [ "$x" == "$y" ]; then
continue
fi
friendly_base=$(echo "$BASE" | sed "s/^\///g" | sed "s/\/$//g" | sed "s/\//-/g" )
friendly_x=$(echo "$x" | sed "s/^\///g" | sed "s/\/$//g" | sed "s/\//-/g" )
friendly_y=$(echo "$y" | sed "s/^\///g" | sed "s/\/$//g" | sed "s/\//-/g")
# get differences between base and branch 1
svn diff "${ROOT}${BASE}" "${ROOT}${x}" \
| grep -e "^-" \
> "./tmp/${thedate}_${friendly_base}_${friendly_x}.diff"
# get differences between base and branch 2
svn diff "${ROOT}${BASE}" "${ROOT}${y}" \
| grep -e "^-" \
> "./tmp/${thedate}_${friendly_base}_${friendly_y}.diff"
# get differences between diffs (crazy I kthedate)
perl -ne 'print if ($seen{$_} .= @ARGV) =~ /10$/' \
"./tmp/${thedate}_${friendly_base}_${friendly_x}.diff" \
"./tmp/${thedate}_${friendly_base}_${friendly_y}.diff" \
> "./tmp/${thedate}_${friendly_base}_${friendly_x}_${friendly_y}.conflicts"
done
done
}
function set_root {
ROOT="$1"
}
function set_base {
BASE="$1"
}
function compare {
COMPARISONS="$COMPARISONS $1"
}
function check {
find_conflicts
# do stuff
# clean up
COMPARISONS=""
BASE=""
ROOT=""
}
source conflict.conf
set_root "http://svn.garrettbluma.com/testing/repo"
set_base "/release/2"
compare "/testing/branch1"
compare "/testing/branch2"
compare "/testing/branch3"
check
diff -wurd -x".svn" path_release path_dev_x | grep -e "^-" > x.diff
diff -wurd -x".svn" path_release path_dev_y | grep -e "^-" > y.diff
perl -ne 'print if ($seen{$_} .= @ARGV) =~ /10$/' x.diff y.diff
svn diff path_release path_dev_x | grep -e "^-" > x.diff
svn diff path_release path_dev_y | grep -e "^-" > y.diff
perl -ne 'print if ($seen{$_} .= @ARGV) =~ /10$/' x.diff y.diff
@gbluma
Copy link
Author

gbluma commented May 17, 2012

The current implementation relies on destructive changes being detected in both x and y. This should be common if two branches include changes to the same lines of source code. It may return false positives however that should be fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment