summaryrefslogtreecommitdiff
path: root/support/vc/git-unix/vc-git.awk
blob: ec850712631b155053deab5be2195cdc70187f5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# This is file 'vc-git.awk' from the vc bundle for TeX.
# The original file can be found at CTAN:support/vc.
# This file is Public Domain.

BEGIN {
	modified = 0
}

### Process output of "git log"
script == "log" && /^Hash:/            { Hash            = substr($0, 2+match($0, ":")) }
script == "log" && /^AbrHash:/         { AbrHash         = substr($0, 2+match($0, ":")) }
script == "log" && /^ParentHashes:/    { ParentHashes    = substr($0, 2+match($0, ":")) }
script == "log" && /^AbrParentHashes:/ { AbrParentHashes = substr($0, 2+match($0, ":")) }
script == "log" && /^AuthorName:/      { AuthorName      = substr($0, 2+match($0, ":")) }
script == "log" && /^AuthorEmail:/     { AuthorEmail     = substr($0, 2+match($0, ":")) }
script == "log" && /^AuthorDate:/      { AuthorDate      = substr($0, 2+match($0, ":")) }
script == "log" && /^CommitterName:/   { CommitterName   = substr($0, 2+match($0, ":")) }
script == "log" && /^CommitterEmail:/  { CommitterEmail  = substr($0, 2+match($0, ":")) }
script == "log" && /^CommitterDate:/   { CommitterDate   = substr($0, 2+match($0, ":")) }

### Process output of "git status"
### Changed index?
script == "status" && /^[mMADRCU] /         { modified = 1 }
### Unstaged modifications?
script == "status" && /^ [mMADRCU]/         { modified = 1 }
### Unresolved merge conflicts?
script == "status" && /^[mMADRCU][mMADRCU]/ { modified = 1 }

END {
	### Process output of "git log"
	if (script == "log") {
		### Format dates
		LongDate = substr(CommitterDate, 1, 25)
		DateRAW = substr(LongDate, 1, 10)
		DateISO = DateRAW
		DateTEX = DateISO
		gsub("-", "/", DateTEX)
		Time = substr(LongDate, 12, 14)

		print "%%% This file has been generated by the vc bundle for TeX."
		print "%%% Do not edit this file!"
		print "%%%"

		print "%%% Define Git specific macros."
		print "\\gdef\\GITHash{" Hash "}%"
		print "\\gdef\\GITAbrHash{" AbrHash "}%"
		print "\\gdef\\GITParentHashes{" ParentHashes "}%"
		print "\\gdef\\GITAbrParentHashes{" AbrParentHashes "}%"
		print "\\gdef\\GITAuthorName{" AuthorName "}%"
		print "\\gdef\\GITAuthorEmail{" AuthorEmail "}%"
		print "\\gdef\\GITAuthorDate{" AuthorDate "}%"
		print "\\gdef\\GITCommitterName{" CommitterName "}%"
		print "\\gdef\\GITCommitterEmail{" CommitterEmail "}%"
		print "\\gdef\\GITCommitterDate{" CommitterDate "}%"

		print "%%% Define generic version control macros."
		print "\\gdef\\VCRevision{\\GITAbrHash}%"
		print "\\gdef\\VCAuthor{\\GITAuthorName}%"
		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 "git 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}%"
		}
	}
		
}