Skip to content
Snippets Groups Projects
Unverified Commit a6d322a7 authored by Jelmer Vernooij's avatar Jelmer Vernooij Committed by GitHub
Browse files

Handle SymrefLoop (#295)

Handle SymrefLoop. Fixes: #293
parent 32fef542
Branches codeql
No related tags found
No related merge requests found
......@@ -9,6 +9,14 @@ from dulwich.objects import Blob
from dulwich.errors import NotTreeError
import dulwich, dulwich.patch
try:
from dulwich.refs import SymrefLoop
except ImportError: # dulwich < 0.20.46
InaccessibleRef = KeyError
else:
InaccessibleRef = (SymrefLoop, KeyError)
from klaus.utils import (
force_unicode,
parent_directory,
......@@ -134,11 +142,15 @@ class FancyRepo(dulwich.repo.Repo):
try:
self.get_commit(candidate)
return candidate
except KeyError:
except InaccessibleRef:
pass
try:
return self.get_branch_names()[0]
except IndexError:
for name in self.get_branch_names():
try:
self.get_commit(name)
return name
except InaccessibleRef:
pass
else:
return None
def get_ref_names_ordered_by_last_commit(self, prefix, exclude=None):
......@@ -149,7 +161,7 @@ class FancyRepo(dulwich.repo.Repo):
def get_commit_time(refname):
try:
obj = self[refs[refname]]
except KeyError:
except InaccessibleRef:
# Default to 0, i.e. sorting refs that point at non-existant
# objects last.
return 0
......
......@@ -13,6 +13,12 @@ import dulwich.archive
import dulwich.config
from dulwich.object_store import tree_lookup_path
try:
from dulwich.refs import SymrefLoop
except ImportError: # dulwich < 0.20.46
class SymrefLoop(Exception):
"""Dummy exception."""
try:
import ctags
except ImportError:
......@@ -114,6 +120,10 @@ def _get_repo_and_rev(repo, namespace=None, rev=None, path=None):
rev = rev[:i]
except (KeyError, IOError):
i = rev.rfind("/", 0, i)
except SymrefLoop as e:
raise NotFound(
"symref loop for %s at depth %d"
% (e.ref, e.depth))
else:
break
else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment