/hg-windows/vc-hg.awk

https://bitbucket.org/kenko/latex-hg-vc · AWK · 78 lines · 58 code · 10 blank · 10 comment · 17 complexity · a06ee2f47d1d44f488cd52775768bce8 MD5 · raw file

  1. #! /usr/bin/awk
  2. BEGIN {
  3. ### Process output of "hg status".
  4. if (script=="status") {
  5. modified = 0
  6. }
  7. }
  8. ### Process output of "hg tip".
  9. script=="log" && /^Hash:/ { Hash = substr($0, 2+match($0, ":")) }
  10. script=="log" && /^Abr. Hash:/ { AbrHash = substr($0, 2+match($0, ":")) }
  11. script=="log" && /^Abr. Parent Hashes:/ { AbrParentHashes = substr($0, 2+match($0, ":")) }
  12. script=="log" && /^Committer Name:/ { CommitterName = substr($0, 2+match($0, ":")) }
  13. script=="log" && /^Committer Email:/ { CommitterEmail = substr($0, 2+match($0, ":")) }
  14. script=="log" && /^Commit Date:/ { CommitDate = substr($0, 2+match($0, ":")) }
  15. script=="log" && /^Commit Description:/ { CommitDesc = substr($0, 2+match($0, ":")) }
  16. script=="log" && /^Commit Date Raw:/ { CommitDateRaw = substr($0, 2+match($0,":")) }
  17. script=="log" && /^Tags:/ { Tags=substr($0, 2+match($0,":")) }
  18. script=="status" && /^.+/ { modified=1 }
  19. END {
  20. ### Process output of "hg tip".
  21. if (script=="log") {
  22. ### Standard encoding is UTF-8.
  23. if (Encoding == "") Encoding = "UTF-8"
  24. ### Extract relevant information from variables.
  25. LongDate = CommitDate
  26. DateRAW = CommitDateRaw
  27. DateISO = substr(LongDate, 1, 10)
  28. DateTEX = DateISO
  29. gsub("-", "/", DateTEX)
  30. Time = substr(LongDate, 12, 25)
  31. ### Write file identification to vc.tex.
  32. print "%%% This file has been generated by the vc bundle for TeX."
  33. print "%%% Do not edit this file!"
  34. print "%%%"
  35. ### Write Hg specific macros.
  36. print "%%% Define Hg specific macros."
  37. print "\\gdef\\HGHash{" Hash "}%"
  38. print "\\gdef\\HGAbrHash{" AbrHash "}%"
  39. print "\\gdef\\HGAbrParentHashes{" AbrParentHashes "}%"
  40. print "\\gdef\\HGCommitterName{" CommitterName "}%"
  41. print "\\gdef\\HGCommitterEmail{" CommitterEmail "}%"
  42. print "\\gdef\\HGCommitDate{" CommitDate "}%"
  43. print "\\gdef\\HGCommitDesc{" CommitDesc "}%"
  44. print "\\gdef\\HGTags{" Tags "}%"
  45. ### Write generic version control macros.
  46. print "%%% Define generic version control macros."
  47. print "\\gdef\\VCRevision{\\HGAbrHash}%"
  48. print "\\gdef\\VCAuthor{\\HGCommitterName}%"
  49. print "\\gdef\\VCDateRAW{" DateRAW "}%"
  50. print "\\gdef\\VCDateISO{" DateISO "}%"
  51. print "\\gdef\\VCDateTEX{" DateTEX "}%"
  52. print "\\gdef\\VCTime{" Time "}%"
  53. print "\\gdef\\VCModifiedText{\\textcolor{red}{with local modifications!}}%"
  54. print "%%% Assume clean working copy."
  55. print "\\gdef\\VCModified{0}%"
  56. print "\\gdef\\VCRevisionMod{\\VCRevision}%"
  57. }
  58. ### process output of "hg status"
  59. if (script=="status") {
  60. print "%%% Is working copy modified?"
  61. print "\\gdef\\VCModified{" modified "}%"
  62. if (modified==0) {
  63. print "\\gdef\\VCRevisionMod{\\VCRevision}%"
  64. } else {
  65. print "\\gdef\\VCRevisionMod{\\VCRevision~\\VCModifiedText}%"
  66. }
  67. }
  68. }