darcs2git.xslt 2.6 KB

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