summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/gitinfo2/gitexinfo.sty
blob: 813fec35b57ae3e1118e5ed5a01818cc81902fa7 (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
% gitexinfo.sty
% Copyright 2014 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 gitPseudoHeadInfo.gin
% -----------------------------------------------------
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{gitexinfo}[2014/10/03 v2.0.4 Auxiliary package for gitinfo2]
\RequirePackage{kvoptions}
\RequirePackage{xstring}
\RequirePackage{etoolbox}
\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}{\gitInf@authname}
\renewcommand{\gitAuthorEmail}{\gitWrapEmail{\gitInf@authemail}}
\renewcommand{\gitAuthorDate}{\gitInf@authsdate}
\renewcommand{\gitAuthorIsoDate}{\gitInf@authidate}
\renewcommand{\gitAuthorUnixDate}{\gitInf@authudate}
\renewcommand{\gitCommitterName}{\gitInf@commname}
\renewcommand{\gitCommitterEmail}{\gitWrapEmail{\gitInf@commemail}}
\renewcommand{\gitCommitterDate}{\gitInf@commsdate}
\renewcommand{\gitCommitterIsoDate}{\gitInf@commidate}
\renewcommand{\gitCommitterUnixDate}{\gitInf@commudate}
\renewcommand{\gitFirstTagDescribe}{\gitInf@firsttagdescribe}
\renewcommand{\gitReferences}{\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}{(HEAD}[\bcut]%
    \StrCount{\bcut}{, }[\xcut]%
    \StrCut[\xcut]{\bcut}{, }{\bcut}{\xcut}%
    \IfEq{\xcut}{}{}{%
        \renewcommand{\gitBranch}{\xcut}%
    }%
}%
\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}{\gitInf@rel}
        \renewcommand{\gitRels}{\space\gitInf@rel}
        \renewcommand{\gitReln}{\space\gitInf@rel}
        \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}