changeset 576:3e30e60c9f51

http://stackoverflow.com/questions/25306712/hg-convert-take-in-account-svnmergeinfo
author Oleksandr Gavenko <gavenkoa@gmail.com>
date Thu, 28 Aug 2014 15:02:35 +0300
parents 4caff13871e8
children c903e43d0e1a
files misc/hg-convert-svn-mergeinfo.bash
diffstat 1 files changed, 61 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/misc/hg-convert-svn-mergeinfo.bash	Thu Aug 28 15:02:35 2014 +0300
@@ -0,0 +1,61 @@
+#!/bin/bash
+
+uuid=svn:`svn info | sed -n '/UUID: /{s=.*UUID: ==;p;q}'`
+
+fbr=/branches/dev
+tbr=/trunk
+
+hunkstate=last-merged
+linestate=header
+
+error() {
+  echo ${BASH_SOURCE[0]}:${BASH_LINENO[0]}: hunkstate: $hunkstate, linestate: $linestate
+  exit 1
+}
+
+svn log -g | while read a1 a2 a3 rest; do
+  if [[ $linestate = header ]]; then
+    if [[ $a1 = '------------------------------------------------------------------------' ]]; then
+      linestate=rev
+    fi
+    continue
+  fi
+  case $hunkstate in
+    last-merged)
+      case $linestate in
+        rev)
+          rev=${a1#r}
+          linestate=merge
+          ;;
+        merge)
+          if [[ $a1 = Merged && $a2 = "via:" ]]; then
+            last_merged=$rev
+            merged_to=${a3#r}
+            hunkstate=merge
+          fi
+          linestate=header
+          ;;
+        *) error ;;
+      esac
+      ;;
+    merge)
+      case $linestate in
+        rev)
+          rev=${a1#r}
+          linestate=merge
+          ;;
+        merge)
+          if [[ $a1 = Merged && $a2 = "via:" ]]; then
+            :
+          else
+            echo $uuid$tbr@$merged_to $uuid$tbr@$rev $uuid$fbr@$last_merged
+            hunkstate=last-merged
+          fi
+          linestate=header
+          ;;
+        *) error ;;
+      esac
+      ;;
+    *) error ;;
+  esac
+done