summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/gitinfo2/gitexinfo.sty
blob: 0f80141185dfc1466202619352bb6ad0bc2b2c46 (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
137
138
% gitexinfo.sty
% Copyright 2015 Brent Longborough
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
% The Current Maintainer of this work is Brent Longborough.
%
% This work consists of these files:
%     gitinfo2.sty, gitexinfo.sty, gitinfo2.tex, gitinfo2.pdf,
%     gitinfo2test.tex, post-xxx-sample.txt,
%     and gitHeadLocal.gin
% -----------------------------------------------------
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{gitexinfo}[2015/11/22 v2.0.7 Auxiliary package for gitinfo2]
\SetupKeyvalOptions{family=gitinfo,prefix=gitInf@}
\DeclareStringOption{shash}
\DeclareStringOption{lhash}
\DeclareStringOption{authname}
\DeclareStringOption{authemail}
\DeclareStringOption{authsdate}
\DeclareStringOption{authidate}
\DeclareStringOption{authudate}
\DeclareStringOption{commname}
\DeclareStringOption{commemail}
\DeclareStringOption{commsdate}
\DeclareStringOption{commidate}
\DeclareStringOption{commudate}
\DeclareStringOption{refnames}
\DeclareStringOption{firsttagdescribe}
\DeclareStringOption{reltag}
\ProcessKeyvalOptions*
\renewcommand{\gitAbbrevHash}{\gitInf@shash}
\renewcommand{\gitHash}{\gitInf@lhash}
\renewcommand{\gitAuthorName}{\detokenize\expandafter{\gitInf@authname}}
\renewcommand{\gitAuthorEmail}{\gitWrapEmail{\gitInf@authemail}}
\renewcommand{\gitAuthorDate}{\gitInf@authsdate}
\renewcommand{\gitAuthorIsoDate}{\gitInf@authidate}
\renewcommand{\gitAuthorUnixDate}{\gitInf@authudate}
\renewcommand{\gitCommitterName}{\detokenize\expandafter{\gitInf@commname}}
\renewcommand{\gitCommitterEmail}{\gitWrapEmail{\gitInf@commemail}}
\renewcommand{\gitCommitterDate}{\gitInf@commsdate}
\renewcommand{\gitCommitterIsoDate}{\gitInf@commidate}
\renewcommand{\gitCommitterUnixDate}{\gitInf@commudate}
\renewcommand{\gitFirstTagDescribe}{\detokenize\expandafter{\gitInf@firsttagdescribe}}
\renewcommand{\gitReferences}{\detokenize\expandafter{\gitInf@refnames}}
\newcommand{\git@vtag}[1]{%
    \def\do##1{%
        \StrCut{##1}{tag: }\lcut\rcut%
        \IfEq{\rcut}{}{%
            \IfDecimal{\lcut}{% case where we have decimal e.g. 1.0
                \renewcommand{\gitVtag}{\lcut}
                \renewcommand{\gitVtags}{\space\lcut}
                \renewcommand{\gitVtagn}{\space\lcut}
                \listbreak
            }{}%
        }{%
            \IfDecimal\rcut{% case where we have string: decimal e.g. tag: 1.0
                \renewcommand{\gitVtag}{\rcut}
                \renewcommand{\gitVtags}{\space\rcut}
                \renewcommand{\gitVtagn}{\space\rcut}
                \listbreak
            }{}%
        }%
    }%
    \expandafter\docsvlist\expandafter{#1}%
    \StrDel{#1}{(}[\bcut]%
    \StrDel{\bcut}{)}[\bcut]%
    \IfSubStr{\bcut}{->}{%              git version 2+?
        \StrBetween{\bcut,}{HEAD -> }{,}[\bcut]%  yes - no problem
    }{%
        \StrCount{\bcut}{, }[\xcut]%
        \IfEq{\xcut}{0}{%               detached head?
        }{%                             no
            \StrCut[\xcut]{\bcut}{, }{\lcut}{\bcut}%  git vv < 2 - take last token
        }%                                            (not always accurate)
    }
    \IfEq{\bcut}{}{}{%
        \IfEq{\bcut}{HEAD}{%            detached head?
        }{%                             no - we have the branch name
            \renewcommand{\gitBranch}{\detokenize\expandafter{\bcut}}%
        }%
    }%
}%
\newcommand{\git@taglist}[1]{%
    \def\do##1{%
        \StrCut{##1}{tag: }\llcut\rrcut%
        \IfEq{\rrcut}{}{%
            \IfDecimal{\llcut}{% case where we have decimal e.g. 1.0
                \StrGobbleLeft{\gitTags,\space\llcut}{0}[\gitTags]
            }{}%
        }{%
        \StrGobbleLeft{\gitTags,\space\rrcut}{0}[\gitTags]
        }%
    }%
    \expandafter\docsvlist\expandafter{#1}%
    \StrGobbleLeft{\gitTags}{2}[\gitTags]
}%
\newcommand{\git@rtag}[1]{%
    \IfEq{#1}{}{}{%
        \StrRight{#1}{2}[\gitInf@dirtflag]
        \StrDel{#1}{-*}[\gitInf@describe]
        \IfEq{\gitInf@dirtflag}{-*}{\renewcommand{\gitDirty}{\gitInf@dirty}}{}
        \StrGobbleRight{\gitInf@describe}{9}[\gitInf@describe]%   Remove -g<hash>
        \StrCount{\gitInf@describe}{-}[\gitInf@mcount]%           Find last -
        \StrCut[\gitInf@mcount]{\gitInf@describe}{-}{\gitInf@rel}{\gitInf@off}
        \renewcommand{\gitRel}{\detokenize\expandafter{\gitInf@rel}}
        \renewcommand{\gitRels}{\space\gitRel}
        \renewcommand{\gitReln}{\space\gitRel}
        \renewcommand{\gitRoff}{\gitInf@off}
        \renewcommand{\gitDescribe}{#1}
    }%
}%
\git@vtag{\gitInf@refnames}
\git@taglist{\gitInf@refnames}
\git@rtag{\gitInf@reltag}
\newcommand{\git@tagmark}{}
\IfEq{\gitTags}{}{%
    \renewcommand{\gitTags}{\gitInf@notags}
    \ifbool{gitInf@marknotags}{%
       \renewcommand{\git@tagmark}{\\Head tags: \gitTags}
    }{%
    }
}{%
    \renewcommand{\git@tagmark}{\\Head tags: \gitTags}
}
\renewcommand{\gitMark}{%
    Branch: \gitBranch\,@\,\gitAbbrevHash{} 
    \textbullet{} 
    Release:\gitReln{} 
    (\gitAuthorDate)\git@tagmark%
    }