darcs2git.xslt 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet
  3. version="1.0"
  4. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  5. >
  6. <xsl:param name="DARCS" select="'/usr/local/bin/darcs'"/>
  7. <xsl:param name="GIT" select="'/usr/local/bin/git'"/>
  8. <xsl:param name="TMPDIR" select="'/tmp/darcs2git/'"/>
  9. <xsl:output method="text"/>
  10. <xsl:template match="/patches|/changelog">
  11. <xsl:text>DARCS="</xsl:text>
  12. <xsl:value-of select="$DARCS"/>
  13. <xsl:text>"
  14. </xsl:text>
  15. <xsl:text>GIT="</xsl:text>
  16. <xsl:value-of select="$GIT"/>
  17. <xsl:text>"
  18. </xsl:text>
  19. <xsl:text>TMPDIR="</xsl:text>
  20. <xsl:value-of select="$TMPDIR"/>
  21. <xsl:text>"
  22. ulimit -c 0
  23. </xsl:text>
  24. <xsl:apply-templates select="patch" />
  25. <xsl:text>
  26. rm -rf $TMPDIR
  27. </xsl:text>
  28. </xsl:template>
  29. <xsl:template match="patch">
  30. <xsl:text>$DARCS pull --all --quiet --matches="hash </xsl:text>
  31. <xsl:value-of select="@hash"/>
  32. <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
  33. sed -E -e 's%^\./%%' ${TMPDIR}darcs_files.txt | \
  34. sed -E -e $'s%(\\$|`|"|\\\\)%\\\\\\1%g' \
  35. -e $'s%\'%\"\'\"%g' | \
  36. awk '{ printf " \"%s\"", $0 }' \
  37. &gt; ${TMPDIR}darcs_files.args
  38. { echo -n "$GIT add --all" ; cat ${TMPDIR}darcs_files.args ; } &gt; ${TMPDIR}git-add.sh
  39. sh -x ${TMPDIR}git-add.sh || exit 1
  40. echo -n "$GIT commit --allow-empty -m " &gt; ${TMPDIR}git_commit.cmd
  41. cat &gt;&gt; ${TMPDIR}git_commit.cmd &lt;&lt; '-EOF-'
  42. !:&amp;#_</xsl:text>
  43. <xsl:value-of select="name"/>
  44. <xsl:text>!:&amp;#_ -m !:&amp;#_</xsl:text>
  45. <xsl:value-of select="comment"/>
  46. <xsl:text>!:&amp;#_ --author=!:&amp;#_</xsl:text>
  47. <xsl:choose>
  48. <xsl:when test="normalize-space(@author) = ''">
  49. <xsl:text>darcs2git &lt;&gt;</xsl:text>
  50. </xsl:when>
  51. <xsl:when test="not(contains(@author,'&lt;'))">
  52. <xsl:choose>
  53. <xsl:when test="contains(@author,'@') and not(contains(substring-after(@author,'@'),'@'))">
  54. <xsl:value-of select="normalize-space(substring-before(@author,'@'))"/>
  55. <xsl:text> &lt;</xsl:text>
  56. <xsl:value-of select="normalize-space(@author)"/>
  57. <xsl:text>&gt;</xsl:text>
  58. </xsl:when>
  59. <xsl:otherwise>
  60. <xsl:value-of select="@author"/>
  61. <xsl:text> &lt;&gt;</xsl:text>
  62. </xsl:otherwise>
  63. </xsl:choose>
  64. </xsl:when>
  65. <xsl:when test="not(normalize-space(substring-before(@author,'&lt;')))">
  66. <xsl:text>darcs2git </xsl:text>
  67. <xsl:value-of select="@author"/>
  68. </xsl:when>
  69. <xsl:otherwise>
  70. <xsl:value-of select="@author"/>
  71. </xsl:otherwise>
  72. </xsl:choose>
  73. <xsl:text>!:&amp;#_ --date=!:&amp;#_</xsl:text>
  74. <xsl:value-of select="@local_date"/>
  75. <xsl:text>!:&amp;#_
  76. -EOF-
  77. sed -E -e $'s%(\\$|`|"|\\\\)%\\\\\\1%g' \
  78. -e $'s%\'%\"\'\"%g' \
  79. -e 's%!:&amp;#_%"%g' ${TMPDIR}git_commit.cmd \
  80. &gt; ${TMPDIR}git-commit.sh
  81. truncate -s -1 ${TMPDIR}git-commit.sh
  82. cat ${TMPDIR}darcs_files.args &gt;&gt; ${TMPDIR}git-commit.sh
  83. sh -x ${TMPDIR}git-commit.sh || exit 1
  84. </xsl:text>
  85. </xsl:template>
  86. </xsl:stylesheet>