Browse Source

2015-05-29 _NOWIKI/darcs2git (Konverter: darcs pull -> git commit)

Ignore-this: 2bd80a8dd1a30e68be5b896e9ebdfc43
freifunk 9 years ago
parent
commit
d61908e6b2

+ 27 - 0
_NOWIKI/darcs2git/darcs2git.init.sh

@@ -0,0 +1,27 @@
+#!/bin/sh
+
+set -e
+
+REPO=$1
+[ -n "$REPO" ] || exit 1
+
+DIR=`basename $REPO`
+
+mkdir $DIR
+cd $DIR
+### darcs ###
+darcs initialize
+echo "$REPO" > _darcs/prefs/defaultrepo
+patch _darcs/prefs/boring << -EOF-
+9a10,12
+> # wg. git
+> \.git$
+> 
+-EOF-
+### git ###
+# git config --global user.name "FF-DO-Wiki `hostname`"
+# git config --global user.email "$USER@`hostname`"
+git init
+echo "_darcs" > .gitignore
+git add .gitignore
+git commit -m "ignore _darcs" .gitignore

+ 56 - 0
_NOWIKI/darcs2git/darcs2git.sh

@@ -0,0 +1,56 @@
+#!/bin/sh
+
+[ -d _darcs -a -d .git ] || exit 1
+
+TMPDIR=/tmp/darcs2git
+[ -d $TMPDIR -a -w $TMPDIR ] || mkdir -p $TMPDIR
+
+DARCS2GIT_XSLT=`dirname $0`/darcs2git.xslt
+[ -r $DARCS2GIT_XSLT ] || exit 1
+
+darcs fetch --all --summary --quiet > /dev/null &&
+darcs pull --all --quiet --dry-run --xml-output > $TMPDIR/patches.xml
+if head -n 1 $TMPDIR/patches.xml | grep "No remote changes to pull in!"
+then
+	echo "No remote changes to pull in!" >&2
+	exit 0
+fi
+xsltproc --nonet --novalid --stringparam TMPDIR "$TMPDIR/" $DARCS2GIT_XSLT $TMPDIR/patches.xml > $TMPDIR/doit.sh
+sh -x $TMPDIR/doit.sh
+
+exit $?
+
+# Für jeden patch (identifiziert durch seinen hash):
+#  1. darcs fetch
+#  2. darcs pull --dry-run --xml-output > patches.xml
+#  3. xsltproc --nonet --novalid darcs2git.xslt patches.xml > doit.sh
+#
+#  2. darcs pull - -matches="hash $HASH" --post-hook="$DARCS_FILES und $DARCS_PATCHES_XML wegschreiben"
+#  3. git add $DARCS_FILES
+#  4. git commit -F "$name\n\n$comment" --author=$author --date=$date  $DARCS_FILES
+
+##### Praeliminiarien: s. darcs2git.init.sh #####
+#
+### wikidata ###
+# mkdir wikidata
+# cd wikidata
+### darcs ###
+# darcs initialize
+# echo "https://mesh-j-1.free.de/~freifunk/wiki/wikidata" > _darcs/prefs/defaultrepo
+# patch _darcs/prefs/boring
+9a10,12
+> # wg. git
+> \.git$
+> 
+^D
+Hmm...  Looks like a normal diff to me...
+Patching file _darcs/prefs/boring using Plan A...
+Hunk #1 succeeded at 10.
+done
+### git ###
+# git config --global user.name "FF-DO-Wiki `hostname`"
+# git config --global user.email "$USER@`hostname`"
+# git init
+# echo "_darcs" > .gitignore
+# git add .gitignore
+# git commit -m "ignore _darcs" .gitignore

+ 79 - 0
_NOWIKI/darcs2git/darcs2git.xslt

@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet
+    version="1.0"
+    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+>
+ <xsl:param name="TMPDIR" select="'/tmp/darcs2git/'"/>
+
+ <xsl:output method="text"/>
+
+ <xsl:template match="/patches|/changelog">
+  <xsl:text>TMPDIR="</xsl:text>
+  <xsl:value-of select="$TMPDIR"/>
+  <xsl:text>"
+ulimit -c 0
+</xsl:text>
+  <xsl:apply-templates select="patch" />
+  <xsl:text>
+rm -rf $TMPDIR
+</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="patch">
+  <xsl:text>darcs pull --all --quiet --matches="hash </xsl:text>
+  <xsl:value-of select="@hash"/>
+  <xsl:text>" --posthook=': &gt; '"${TMPDIR}darcs_files.txt"' ; for fnl in "$DARCS_FILES" ; do echo -n "$fnl" &gt;&gt; '"${TMPDIR}darcs_files.txt"' ; done' || exit 1
+sed -E -e 's%^\./%%' ${TMPDIR}darcs_files.txt | \
+sed -E -e $'s%(\\$|`|"|\\\\)%\\\\\\1%g' \
+    -e $'s%\'%\"\'\"%g' | \
+awk '{ printf " \"%s\"", $0 }' \
+&gt; ${TMPDIR}darcs_files.args
+{ echo -n "git add --all" ; cat ${TMPDIR}darcs_files.args ; } &gt; ${TMPDIR}git-add.sh
+sh -x ${TMPDIR}git-add.sh || exit 1
+cat &gt; ${TMPDIR}git_commit.cmd &lt;&lt; '-EOF-'
+git commit --allow-empty -m !:&amp;#_</xsl:text>
+  <xsl:value-of select="name"/>
+  <xsl:text>!:&amp;#_ -m !:&amp;#_</xsl:text>
+  <xsl:value-of select="comment"/>
+  <xsl:text>!:&amp;#_ --author=!:&amp;#_</xsl:text>
+  <xsl:choose>
+   <xsl:when test="normalize-space(@author) = ''">
+    <xsl:text>darcs2git &lt;&gt;</xsl:text>
+   </xsl:when>
+   <xsl:when test="not(contains(@author,'&lt;'))">
+    <xsl:choose>
+     <xsl:when test="contains(@author,'@') and not(contains(substring-after(@author,'@'),'@'))">
+      <xsl:value-of select="normalize-space(substring-before(@author,'@'))"/>
+      <xsl:text> &lt;</xsl:text>
+      <xsl:value-of select="normalize-space(@author)"/>
+      <xsl:text>&gt;</xsl:text>
+     </xsl:when>
+     <xsl:otherwise>
+      <xsl:value-of select="@author"/>
+      <xsl:text> &lt;&gt;</xsl:text>
+     </xsl:otherwise>
+    </xsl:choose>
+   </xsl:when>
+   <xsl:when test="not(normalize-space(substring-before(@author,'&lt;')))">
+    <xsl:text>darcs2git </xsl:text>
+    <xsl:value-of select="@author"/>
+   </xsl:when>
+   <xsl:otherwise>
+    <xsl:value-of select="@author"/>
+   </xsl:otherwise>
+  </xsl:choose>
+  <xsl:text>!:&amp;#_ --date=!:&amp;#_</xsl:text>
+  <xsl:value-of select="@local_date"/>
+  <xsl:text>!:&amp;#_
+-EOF-
+sed -E -e $'s%(\\$|`|"|\\\\)%\\\\\\1%g' \
+    -e $'s%\'%\"\'\"%g' \
+    -e 's%!:&amp;#_%"%g' ${TMPDIR}git_commit.cmd \
+    &gt; ${TMPDIR}git-commit.sh
+truncate -s -1 ${TMPDIR}git-commit.sh
+cat ${TMPDIR}darcs_files.args &gt;&gt; ${TMPDIR}git-commit.sh
+sh -x ${TMPDIR}git-commit.sh || exit 1
+</xsl:text>
+ </xsl:template>
+
+</xsl:stylesheet>