|
117 | 117 |
|
118 | 118 | # The original code to find the head tag was taken from: |
119 | 119 | # 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 |
121 | 121 | # main or a tag |
122 | 122 |
|
123 | 123 | #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 |
125 | 131 |
|
126 | 132 |
|
127 | | -branch_name = Repository('.').head.shorthand |
128 | 133 | # lock to commit number |
129 | 134 | cmd = "git log -n1 --pretty=%H" |
130 | 135 | head = subprocess.check_output(cmd.split()).strip().decode('utf-8') |
131 | | -linkcode_revision = head |
132 | 136 | # if we are on main's HEAD, use main as reference irrespective of |
133 | 137 | # what branch you are on |
134 | 138 | cmd = "git log --first-parent main -n1 --pretty=%H" |
135 | 139 | main = subprocess.check_output(cmd.split()).strip().decode('utf-8') |
136 | 140 | if head == main: |
137 | | - branch_name = "main" |
| 141 | + in_main = True |
138 | 142 |
|
139 | 143 | # if we have a tag, use tag as reference, irrespective of what branch |
140 | 144 | # you are actually on |
141 | 145 | try: |
142 | 146 | cmd = "git describe --exact-match --tags " + head |
143 | 147 | tag = subprocess.check_output(cmd.split(" ")).strip().decode('utf-8') |
144 | | - branch_name = tag |
| 148 | + linkcode_revision = tag |
| 149 | + tagged = True |
145 | 150 | except subprocess.CalledProcessError: |
146 | 151 | pass |
147 | 152 |
|
| 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 | + |
148 | 158 | 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}" |
150 | 160 |
|
151 | 161 |
|
152 | 162 | def linkcode_resolve(domain, info): |
|
0 commit comments