Skip to content

Commit 22eef0e

Browse files
committed
Changed branch names to commit numbers
1 parent 53b117a commit 22eef0e

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

docs/source/conf.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,36 +117,46 @@
117117

118118
# The original code to find the head tag was taken from:
119119
# https://gist.github.com/nlgranger/55ff2e7ff10c280731348a16d569cb73
120-
# This code was modified to use branch names when the code differs from
120+
# This code was modified to use the current commit when the code differs from
121121
# main or a tag
122122

123123
#Default to the main branch
124-
branch_name = "main"
124+
linkcode_revision = "main"
125+
126+
127+
#Default to the main branch, default to main and tags not existing
128+
linkcode_revision = "main"
129+
in_main = False
130+
tagged = False
125131

126132

127-
branch_name = Repository('.').head.shorthand
128133
# lock to commit number
129134
cmd = "git log -n1 --pretty=%H"
130135
head = subprocess.check_output(cmd.split()).strip().decode('utf-8')
131-
linkcode_revision = head
132136
# if we are on main's HEAD, use main as reference irrespective of
133137
# what branch you are on
134138
cmd = "git log --first-parent main -n1 --pretty=%H"
135139
main = subprocess.check_output(cmd.split()).strip().decode('utf-8')
136140
if head == main:
137-
branch_name = "main"
141+
in_main = True
138142

139143
# if we have a tag, use tag as reference, irrespective of what branch
140144
# you are actually on
141145
try:
142146
cmd = "git describe --exact-match --tags " + head
143147
tag = subprocess.check_output(cmd.split(" ")).strip().decode('utf-8')
144-
branch_name = tag
148+
linkcode_revision = tag
149+
tagged = True
145150
except subprocess.CalledProcessError:
146151
pass
147152

153+
# If the current branch is main, or a tag exists, use the branch name.
154+
# If not, use the commit number
155+
if not tagged and not in_main:
156+
linkcode_revision = head
157+
148158
linkcode_url = "https://github.com/Stanford-NavLab/gnss_lib_py/blob/" \
149-
+ branch_name + "/{filepath}#L{linestart}-L{linestop}"
159+
+ linkcode_revision + "/{filepath}#L{linestart}-L{linestop}"
150160

151161

152162
def linkcode_resolve(domain, info):

0 commit comments

Comments
 (0)