Add infrastructure for links to Git commits.

- Add a <githash> tag which accepts a Git hash.  Leave
  <revnumber> as is for svn revisions.  In theory we
  could add a new attribute to <revnumber> to say which
  VCS to use, but this would require tagging either all
  SVN revisions or all Git hashes explicitly which would
  be invasive.  A new tag going forward seems simpler.

- Revert svnweb.link back to generating svnweb links.  This
  fixes all the explicit <revnumber>'s referring to SVN src
  commits in existing documentation.

- Add a cgit.link which links to a Git commit in cgit.
  githash generates cgit.link's when asked to generate a
  href.

Reviewed by:	gjb, ygy
Differential Revision:	https://reviews.freebsd.org/D27703
This commit is contained in:
John Baldwin 2020-12-21 10:54:42 -08:00
parent e0a3a057a6
commit 86bba6a538
6 changed files with 67 additions and 4 deletions

View file

@ -265,6 +265,10 @@ html {
color: #007a00;
}
.gitref {
color: #007a00;
}
.guimenu, .guimenuitem, .guisubmenu,
.guilabel, .interface,
.shortcut, .shortcut .keycap {

View file

@ -321,7 +321,7 @@
>
<!ELEMENT para (#PCDATA|info|inlinemediaobject|remark|superscript|subscript|xref|link|olink|anchor|biblioref|alt|annotation|indexterm|abbrev|acronym|date|emphasis|footnote|footnoteref|foreignphrase|phrase|quote|wordasword|firstterm|glossterm|coref|trademark|productnumber|productname|database|application|hardware|citation|citerefentry|citetitle|citebiblioid|author|person|personname|org|orgname|editor|jobtitle|replaceable|package|parameter|termdef|nonterminal|systemitem|option|optional|property|inlineequation|tag|markup|token|symbol|literal|code|constant|email|uri|guiicon|guibutton|guimenuitem|guimenu|guisubmenu|guilabel|menuchoice|mousebutton|keycombo|keycap|keycode|keysym|shortcut|accel|prompt|envar|filename|command|computeroutput|userinput|function|varname|returnvalue|type|classname|exceptionname|interfacename|methodname|modifier|initializer|ooclass|ooexception|oointerface|errorcode|errortext|errorname|errortype|itemizedlist|orderedlist|procedure|simplelist|variablelist|segmentedlist|glosslist|bibliolist|calloutlist|qandaset|example|figure|table|equation|informalexample|informalfigure|informaltable|informalequation|sidebar|blockquote|address|epigraph|mediaobject|screenshot|task|productionset|constraintdef|msgset|screen|literallayout|programlistingco|screenco|programlisting|synopsis|bridgehead|revhistory|funcsynopsis|classsynopsis|methodsynopsis|constructorsynopsis|destructorsynopsis|fieldsynopsis|cmdsynopsis|caution|important|note|tip|warning|
revnumber|buildtarget|xi:include)*>
revnumber|buildtarget|xi:include|githash)*>
<!ATTLIST para
xmlns CDATA #FIXED "http://docbook.org/ns/docbook"
@ -1311,7 +1311,7 @@
>
<!ELEMENT revision ((revnumber)?, date, (authorinitials|author)*, ((revremark|revdescription))?)>
<!ELEMENT revision ((revnumber|githash)?, date, (authorinitials|author)*, ((revremark|revdescription))?)>
<!ATTLIST revision
xmlns CDATA #FIXED "http://docbook.org/ns/docbook"
@ -1331,6 +1331,16 @@
>
<!ELEMENT githash (#PCDATA|inlinemediaobject|remark|superscript|subscript|xref|link|olink|anchor|biblioref|alt|annotation|indexterm|phrase|replaceable)*>
<!ATTLIST githash
xmlns CDATA #FIXED "http://docbook.org/ns/docbook"
role CDATA #IMPLIED
%db.common.attributes;
%db.common.linking.attributes;
>
<!ELEMENT revremark (#PCDATA|inlinemediaobject|remark|superscript|subscript|xref|link|olink|anchor|biblioref|alt|annotation|indexterm|phrase|replaceable)*>
<!ATTLIST revremark
@ -2881,7 +2891,7 @@
>
<!ELEMENT entry (#PCDATA|inlinemediaobject|remark|superscript|subscript|xref|link|olink|anchor|biblioref|alt|annotation|indexterm|abbrev|acronym|date|emphasis|footnote|footnoteref|foreignphrase|phrase|quote|wordasword|firstterm|glossterm|coref|trademark|productnumber|productname|database|application|hardware|citation|citerefentry|citetitle|citebiblioid|author|person|personname|org|orgname|editor|jobtitle|replaceable|package|parameter|termdef|nonterminal|systemitem|option|optional|property|inlineequation|tag|markup|token|symbol|literal|code|constant|email|uri|guiicon|guibutton|guimenuitem|guimenu|guisubmenu|guilabel|menuchoice|mousebutton|keycombo|keycap|keycode|keysym|shortcut|accel|prompt|envar|filename|command|computeroutput|userinput|function|varname|returnvalue|type|classname|exceptionname|interfacename|methodname|modifier|initializer|ooclass|ooexception|oointerface|errorcode|errortext|errorname|errortype|itemizedlist|orderedlist|procedure|simplelist|variablelist|segmentedlist|glosslist|bibliolist|calloutlist|qandaset|example|figure|table|equation|informalexample|informalfigure|informaltable|informalequation|sidebar|blockquote|address|epigraph|mediaobject|screenshot|task|productionset|constraintdef|msgset|screen|literallayout|programlistingco|screenco|programlisting|synopsis|bridgehead|revhistory|funcsynopsis|classsynopsis|methodsynopsis|constructorsynopsis|destructorsynopsis|fieldsynopsis|cmdsynopsis|caution|important|note|tip|warning|para|formalpara|simpara|
revnumber|buildtarget)*>
revnumber|buildtarget|githash)*>
<!ATTLIST entry
xmlns CDATA #FIXED "http://docbook.org/ns/docbook"

View file

@ -16,6 +16,11 @@
<xsl:call-template name="svnref.genlink"/>
</xsl:template>
<!-- Generate link for githash -->
<xsl:template match="db:githash">
<xsl:call-template name="gitref.genlink"/>
</xsl:template>
<!-- Redefine variables, and replace templates as necessary here -->
<xsl:template match="db:buildtarget|db:command">
<xsl:call-template name="inline.monoseq"/>
@ -25,7 +30,15 @@
<xsl:param name="repo" select="'base'"/>
<xsl:param name="rev"/>
<xsl:value-of select="concat('https://cgit.freebsd.org/doc/commit/?id=',
<xsl:value-of select="concat('https://svnweb.freebsd.org/changeset/',
$repo, '/', $rev)"/>
</xsl:template>
<xsl:template name="cgit.link">
<xsl:param name="repo" select="'src'"/>
<xsl:param name="rev"/>
<xsl:value-of select="concat('https://cgit.freebsd.org/', $repo, '/commit/?id=',
$rev)"/>
</xsl:template>

View file

@ -581,6 +581,23 @@
</fo:basic-link>
</xsl:template>
<xsl:template name="gitref.genlink">
<xsl:param name="rev" select="."/>
<xsl:param name="repo" select="'src'"/>
<xsl:variable name="href">
<xsl:call-template name="cgit.link">
<xsl:with-param name="repo" select="$repo"/>
<xsl:with-param name="rev" select="$rev"/>
</xsl:call-template>
</xsl:variable>
<fo:basic-link external-destination="url({$href})">
<fo:inline color="blue">
<xsl:value-of select="$rev"/>
</fo:inline>
</fo:basic-link>
</xsl:template>
<xsl:template name="chapter.authorgroup">
<fo:inline font-style="italic">
<xsl:call-template name="freebsd.authorgroup"/>

View file

@ -212,6 +212,24 @@
</a>
</xsl:template>
<xsl:template name="gitref.genlink">
<xsl:param name="rev" select="."/>
<xsl:param name="repo" select="'src'"/>
<a>
<xsl:attribute name="href">
<xsl:call-template name="cgit.link">
<xsl:with-param name="repo" select="$repo"/>
<xsl:with-param name="rev" select="$rev"/>
</xsl:call-template>
</xsl:attribute>
<span class="gitref">
<xsl:value-of select="$rev"/>
</span>
</a>
</xsl:template>
<xsl:template name="generate.citerefentry.link">
<xsl:text>https://www.FreeBSD.org/cgi/man.cgi?query=</xsl:text>
<xsl:value-of select="db:refentrytitle"/>

View file

@ -39,6 +39,7 @@ include "/usr/local/share/xml/docbook/5.0/rng/docbook.rnc" inherit = db {
# FreeBSD extension: add buildtarget element to allowed inlines
db.extension.inlines = db.buildtarget
| db.revnumber
| db.githash
# | db.trademark