PageRenderTime 8ms CodeModel.GetById 1ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/hg-windows/vc-hg.awk

https://bitbucket.org/kenko/latex-hg-vc
AWK | 78 lines | 58 code | 10 blank | 10 comment | 0 complexity | a06ee2f47d1d44f488cd52775768bce8 MD5 | raw file
 1#! /usr/bin/awk

 2
 3BEGIN {
 4		
 5### Process output of "hg status".

 6		if (script=="status") {
 7				modified = 0
 8		}
 9
10}
11
12
13
14### Process output of "hg tip".

15script=="log" && /^Hash:/ { Hash = substr($0, 2+match($0, ":")) }
16script=="log" && /^Abr. Hash:/ { AbrHash = substr($0, 2+match($0, ":")) }
17script=="log" && /^Abr. Parent Hashes:/ { AbrParentHashes = substr($0, 2+match($0, ":")) }
18script=="log" && /^Committer Name:/ { CommitterName = substr($0, 2+match($0, ":")) }
19script=="log" && /^Committer Email:/ { CommitterEmail = substr($0, 2+match($0, ":")) }
20script=="log" && /^Commit Date:/ { CommitDate = substr($0, 2+match($0, ":")) }
21script=="log" && /^Commit Description:/ { CommitDesc = substr($0, 2+match($0, ":")) }
22script=="log" && /^Commit Date Raw:/ { CommitDateRaw = substr($0, 2+match($0,":")) }
23script=="log" && /^Tags:/ { Tags=substr($0, 2+match($0,":")) }
24
25
26script=="status" && /^.+/ { modified=1 }
27
28END {
29		
30### Process output of "hg tip".

31		if (script=="log") {
32### Standard encoding is UTF-8.

33				if (Encoding == "") Encoding = "UTF-8"
34### Extract relevant information from variables.

35        LongDate  = CommitDate
36        DateRAW = CommitDateRaw
37        DateISO = substr(LongDate, 1, 10)
38        DateTEX = DateISO
39        gsub("-", "/", DateTEX)
40				Time = substr(LongDate, 12, 25)
41### Write file identification to vc.tex.

42				print "%%% This file has been generated by the vc bundle for TeX."
43				print "%%% Do not edit this file!"
44				print "%%%"
45### Write Hg specific macros.

46				print "%%% Define Hg specific macros."
47				print "\\gdef\\HGHash{" Hash "}%"
48				print "\\gdef\\HGAbrHash{" AbrHash "}%"
49				print "\\gdef\\HGAbrParentHashes{" AbrParentHashes "}%"
50				print "\\gdef\\HGCommitterName{" CommitterName "}%"
51				print "\\gdef\\HGCommitterEmail{" CommitterEmail "}%"
52				print "\\gdef\\HGCommitDate{" CommitDate "}%"
53                                print "\\gdef\\HGCommitDesc{" CommitDesc "}%"
54                                print "\\gdef\\HGTags{" Tags "}%"
55### Write generic version control macros.

56				print "%%% Define generic version control macros."
57				print "\\gdef\\VCRevision{\\HGAbrHash}%"
58				print "\\gdef\\VCAuthor{\\HGCommitterName}%"
59        print "\\gdef\\VCDateRAW{" DateRAW "}%"
60        print "\\gdef\\VCDateISO{" DateISO "}%"
61        print "\\gdef\\VCDateTEX{" DateTEX "}%"
62				print "\\gdef\\VCTime{" Time "}%"
63				print "\\gdef\\VCModifiedText{\\textcolor{red}{with local modifications!}}%"
64				print "%%% Assume clean working copy."
65				print "\\gdef\\VCModified{0}%"
66				print "\\gdef\\VCRevisionMod{\\VCRevision}%"
67		}
68### process output of "hg status"

69                if (script=="status")  {
70				print "%%% Is working copy modified?"
71				print "\\gdef\\VCModified{" modified "}%"
72				if (modified==0) {
73						print "\\gdef\\VCRevisionMod{\\VCRevision}%"
74				} else {
75						print "\\gdef\\VCRevisionMod{\\VCRevision~\\VCModifiedText}%"
76				}
77                }
78}