/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
- #! /usr/bin/awk
-
- BEGIN {
-
- ### Process output of "hg status".
- if (script=="status") {
- modified = 0
- }
-
- }
-
-
-
- ### Process output of "hg tip".
- script=="log" && /^Hash:/ { Hash = substr($0, 2+match($0, ":")) }
- script=="log" && /^Abr. Hash:/ { AbrHash = substr($0, 2+match($0, ":")) }
- script=="log" && /^Abr. Parent Hashes:/ { AbrParentHashes = substr($0, 2+match($0, ":")) }
- script=="log" && /^Committer Name:/ { CommitterName = substr($0, 2+match($0, ":")) }
- script=="log" && /^Committer Email:/ { CommitterEmail = substr($0, 2+match($0, ":")) }
- script=="log" && /^Commit Date:/ { CommitDate = substr($0, 2+match($0, ":")) }
- script=="log" && /^Commit Description:/ { CommitDesc = substr($0, 2+match($0, ":")) }
- script=="log" && /^Commit Date Raw:/ { CommitDateRaw = substr($0, 2+match($0,":")) }
- script=="log" && /^Tags:/ { Tags=substr($0, 2+match($0,":")) }
-
-
- script=="status" && /^.+/ { modified=1 }
-
- END {
-
- ### Process output of "hg tip".
- if (script=="log") {
- ### Standard encoding is UTF-8.
- if (Encoding == "") Encoding = "UTF-8"
- ### Extract relevant information from variables.
- LongDate = CommitDate
- DateRAW = CommitDateRaw
- DateISO = substr(LongDate, 1, 10)
- DateTEX = DateISO
- gsub("-", "/", DateTEX)
- Time = substr(LongDate, 12, 25)
- ### Write file identification to vc.tex.
- print "%%% This file has been generated by the vc bundle for TeX."
- print "%%% Do not edit this file!"
- print "%%%"
- ### Write Hg specific macros.
- print "%%% Define Hg specific macros."
- print "\\gdef\\HGHash{" Hash "}%"
- print "\\gdef\\HGAbrHash{" AbrHash "}%"
- print "\\gdef\\HGAbrParentHashes{" AbrParentHashes "}%"
- print "\\gdef\\HGCommitterName{" CommitterName "}%"
- print "\\gdef\\HGCommitterEmail{" CommitterEmail "}%"
- print "\\gdef\\HGCommitDate{" CommitDate "}%"
- print "\\gdef\\HGCommitDesc{" CommitDesc "}%"
- print "\\gdef\\HGTags{" Tags "}%"
- ### Write generic version control macros.
- print "%%% Define generic version control macros."
- print "\\gdef\\VCRevision{\\HGAbrHash}%"
- print "\\gdef\\VCAuthor{\\HGCommitterName}%"
- print "\\gdef\\VCDateRAW{" DateRAW "}%"
- print "\\gdef\\VCDateISO{" DateISO "}%"
- print "\\gdef\\VCDateTEX{" DateTEX "}%"
- print "\\gdef\\VCTime{" Time "}%"
- print "\\gdef\\VCModifiedText{\\textcolor{red}{with local modifications!}}%"
- print "%%% Assume clean working copy."
- print "\\gdef\\VCModified{0}%"
- print "\\gdef\\VCRevisionMod{\\VCRevision}%"
- }
- ### process output of "hg status"
- if (script=="status") {
- print "%%% Is working copy modified?"
- print "\\gdef\\VCModified{" modified "}%"
- if (modified==0) {
- print "\\gdef\\VCRevisionMod{\\VCRevision}%"
- } else {
- print "\\gdef\\VCRevisionMod{\\VCRevision~\\VCModifiedText}%"
- }
- }
- }