summaryrefslogtreecommitdiff
path: root/support/vc/svn-unix/vc-svn.awk
blob: 37179028a201a1e9d67a6f8d896e41a1191effa0 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# This is file 'vc-svn.awk' from the vc bundle for TeX.
# The original file can be found at CTAN:support/vc.
# This file is Public Domain.
BEGIN {
    
### Process output of "svn info".
		if (script=="info") {
				MaxRevision = 0
		}
		
### Process output of "svn status".
		if (script=="status") {
				modified = 0
		}
		
}



### Process output of "svn info".
### Save all lines of the current record in a corresponding variable.
script=="info" && /^Path:/ { RecPath = $0; next }
script=="info" && /^Name:/ { RecName = $0; next }
script=="info" && /^URL:/ { RecUrl = $0; next }
script=="info" && /^Repository Root:/ { RecRepositoryRoot = $0; next }
script=="info" && /^Repository UUID:/ { RecRepositoryUuid = $0; next }
script=="info" && /^Revision:/ { RecRevision = $2; next }
script=="info" && /^Node Kind:/ { RecNodeKind = $0; next }
script=="info" && /^Last Changed Author:/ { RecLastChangedAuthor = $0; next }
script=="info" && /^Last Changed Rev:/ { RecLastChangedRevision = $0; next }
script=="info" && /^Last Changed Date:/ { RecLastChangedDate = $0; next }
script=="info" && /^[\r]*$/ {
### If revision number of the new record is higher,
### save all lines from the new record.
    if (RecRevision > MaxRevision) {
				MaxPath = RecPath
				MaxName = RecName
				MaxUrl = RecUrl
				MaxRepositoryRoot = RecRepositoryRoot
				MaxRepositoryUuid = RecRepositoryUuid
				MaxRevision = RecRevision
				MaxNodeKind = RecNodeKind
				MaxLastChangedAuthor = RecLastChangedAuthor
				MaxLastChangedRev = RecLastChangedRevision
				MaxLastChangedDate = RecLastChangedDate
    }
}

### Process output of "svn status".
### File with local modifications?
script=="status" && /^[^ ?]/ { modified = 1 }
### File with property modifications?
script=="status" && /^.[^ ]/ { modified = 2 }



END {
		
### Process output of "svn info".
		if (script=="info") {
### Remove possible Windows line endings (e.g., for Msys).
				gsub("\r$", "", MaxPath)
				gsub("\r$", "", MaxName)
				gsub("\r$", "", MaxUrl)
				gsub("\r$", "", MaxRepositoryRoot)
				gsub("\r$", "", MaxRepositoryUuid)
				gsub("\r$", "", MaxRevision)
				gsub("\r$", "", MaxNodeKind)
				gsub("\r$", "", MaxLastChangedAuthor)
				gsub("\r$", "", MaxLastChangedRev)
				gsub("\r$", "", MaxLastChangedDate)
### Escape % characters for TeX compatibility.
				gsub("%", "\\%", MaxUrl)
				gsub("%", "\\%", MaxRepositoryRoot)
### Extract relevant information from variables.
				Path = substr(MaxPath, 2+match(MaxPath, ":"))
				Name = substr(MaxName, 2+match(MaxName, ":"))
				Url = substr(MaxUrl, 2+match(MaxUrl, ":"))
				RepositoryRoot = substr(MaxRepositoryRoot, 2+match(MaxRepositoryRoot, ":"))
				RepositoryUuid = substr(MaxRepositoryUuid, 2+match(MaxRepositoryUuid, ":"))
				Revision = MaxRevision
				NodeKind = substr(MaxNodeKind, 2+match(MaxNodeKind, ":"))
				LastChangedAuthor = substr(MaxLastChangedAuthor, 2+match(MaxLastChangedAuthor, ":"))
				LastChangedRev = substr(MaxLastChangedRev, 2+match(MaxLastChangedRev, ":"))
				LastChangedDate = substr(MaxLastChangedDate, 2+match(MaxLastChangedDate, ":"))
				LongDate = substr(LastChangedDate, 1, 25)
				DateRAW = substr(LongDate, 1, 10)
				DateISO = DateRAW
				DateTEX = DateISO
				gsub("-", "/", DateTEX)
				Time = substr(LongDate, 12, 14)
### 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 Subversion specific macros.
				print "%%% Define Subversion specific macros."
				print "\\gdef\\SVNRevision{" Revision "}%"
				print "\\gdef\\SVNLastChangedRev{" LastChangedRev "}%"
				print "\\gdef\\SVNLastChangedAuthor{" LastChangedAuthor "}%"
				print "\\gdef\\SVNLastChangedDate{" LastChangedDate "}%"
				print "\\gdef\\SVNRepositoryUuid{" RepositoryUuid "}%"
				if (full==1) {
						print "\\gdef\\SVNPath{" Path "}%"
						print "\\gdef\\SVNName{" Name "}%"
						print "\\gdef\\SVNUrl{" Url "}%"
						print "\\gdef\\SVNNodeKind{" NodeKind "}%"
						print "\\gdef\\SVNRepositoryRoot{" RepositoryRoot "}%"
				}
### Write generic version control macros.
				print "%%% Define generic version control macros."
				print "\\gdef\\VCRevision{\\SVNRevision}%"
				print "\\gdef\\VCAuthor{\\SVNLastChangedAuthor}%"
				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}%"
				MaxRevision = 0
		}
		
### Process output of "svn 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}%"
				}
		}
		
}