|
15 | 15 | import inspect |
16 | 16 | import subprocess |
17 | 17 | from os.path import relpath, dirname |
| 18 | +from pygit2 import Repository |
18 | 19 |
|
19 | 20 | import gnss_lib_py |
20 | 21 |
|
|
114 | 115 |
|
115 | 116 | # Function to find URLs for the source code on GitHub for built docs |
116 | 117 |
|
117 | | -# The following code to find the head tag is taken from: |
| 118 | +# The original code to find the head tag was taken from: |
118 | 119 | # https://gist.github.com/nlgranger/55ff2e7ff10c280731348a16d569cb73 |
119 | | - |
120 | | -linkcode_revision = "main" |
| 120 | +# This code was modified to use branch names when the code differs from |
| 121 | +# main or a tag |
| 122 | + |
| 123 | +#Default to the main branch |
| 124 | +branch_name = "main" |
| 125 | + |
| 126 | + |
| 127 | +branch_name = Repository('.').head.shorthand |
| 128 | +# lock to commit number |
| 129 | +cmd = "git log -n1 --pretty=%H" |
| 130 | +head = subprocess.check_output(cmd.split()).strip().decode('utf-8') |
| 131 | +linkcode_revision = head |
| 132 | +# if we are on main's HEAD, use main as reference irrespective of |
| 133 | +# what branch you are on |
| 134 | +cmd = "git log --first-parent main -n1 --pretty=%H" |
| 135 | +main = subprocess.check_output(cmd.split()).strip().decode('utf-8') |
| 136 | +if head == main: |
| 137 | + branch_name = "main" |
| 138 | + |
| 139 | +# if we have a tag, use tag as reference, irrespective of what branch |
| 140 | +# you are actually on |
121 | 141 | try: |
122 | | - # lock to commit number |
123 | | - cmd = "git log -n1 --pretty=%H" |
124 | | - head = subprocess.check_output(cmd.split()).strip().decode('utf-8') |
125 | | - linkcode_revision = head |
126 | | - |
127 | | - # if we are on main's HEAD, use main as reference |
128 | | - cmd = "git log --first-parent main -n1 --pretty=%H" |
129 | | - main = subprocess.check_output(cmd.split()).strip().decode('utf-8') |
130 | | - if head == main: |
131 | | - linkcode_revision = "main" |
132 | | - |
133 | | - # if we have a tag, use tag as reference |
134 | 142 | cmd = "git describe --exact-match --tags " + head |
135 | 143 | tag = subprocess.check_output(cmd.split(" ")).strip().decode('utf-8') |
136 | | - linkcode_revision = tag |
137 | | - |
| 144 | + branch_name = tag |
138 | 145 | except subprocess.CalledProcessError: |
139 | 146 | pass |
140 | 147 |
|
141 | 148 | linkcode_url = "https://github.com/Stanford-NavLab/gnss_lib_py/blob/" \ |
142 | | - + linkcode_revision + "/{filepath}#L{linestart}-L{linestop}" |
| 149 | + + branch_name + "/{filepath}#L{linestart}-L{linestop}" |
143 | 150 |
|
144 | 151 |
|
145 | 152 | def linkcode_resolve(domain, info): |
|
0 commit comments