mirror of
https://github.com/postgres/pgweb.git
synced 2025-08-13 13:12:42 +00:00
Don't crash when .git/refs/heads/master doesn't exist
This happens after a git gc which moves this into packed-refs. So when this happens, look in packed-refs. If packed-refs also cannot be found, just return a made up value instead of crashing.
This commit is contained in:
@ -104,8 +104,21 @@ class NavContext(RequestContext):
|
|||||||
def _get_gitrev():
|
def _get_gitrev():
|
||||||
# Return the current git revision, that is used for
|
# Return the current git revision, that is used for
|
||||||
# cache-busting URLs.
|
# cache-busting URLs.
|
||||||
|
try:
|
||||||
with open('.git/refs/heads/master') as f:
|
with open('.git/refs/heads/master') as f:
|
||||||
return f.readline()[:8]
|
return f.readline()[:8]
|
||||||
|
except IOError:
|
||||||
|
# A "git gc" will remove the ref and replace it with a packed-refs.
|
||||||
|
try:
|
||||||
|
with open('.git/packed-refs') as f:
|
||||||
|
for l in f.readlines():
|
||||||
|
if l.endswith("refs/heads/master\n"):
|
||||||
|
return l[:8]
|
||||||
|
# Not found in packed-refs. Meh, just make one up.
|
||||||
|
return 'ffffffff'
|
||||||
|
except IOError:
|
||||||
|
# If packed-refs also can't be read, just give up
|
||||||
|
return 'eeeeeeee'
|
||||||
|
|
||||||
# Template context processor to add information about the root link and
|
# Template context processor to add information about the root link and
|
||||||
# the current git revision. git revision is returned as a lazy object so
|
# the current git revision. git revision is returned as a lazy object so
|
||||||
|
Reference in New Issue
Block a user