Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetch: try use gix to fetch package src #21

Open
wants to merge 6 commits into
base: production
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions acbs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


class ACBSSourceInfo(object):
def __init__(self, type: str, url: str, revision=None, branch=None, depth=None) -> None:
def __init__(self, type: str, url: str, revision=None, branch=None, depth=None, no_gix=False) -> None:
self.type = type
self.url = url
self.revision: Optional[str] = revision
Expand All @@ -21,9 +21,10 @@ def __init__(self, type: str, url: str, revision=None, branch=None, depth=None)
self.copy_repo: bool = False
# this is a tristate: 0 - off; 1 - on (non-recursive); 2 - recursive
self.submodule: int = 2
self.no_gix: bool = no_gix

def __repr__(self) -> str:
return '<ACBSSourceInfo {type}: {url}:{branch}@{revision} integrity: {checksum}>'.format(type=self.type, url=self.url, branch=self.branch, revision=self.revision, checksum=self.chksum)
return '<ACBSSourceInfo {type}: {url}:{branch}@{revision} integrity: {checksum} no_gix: {no_gix}>'.format(type=self.type, url=self.url, branch=self.branch, revision=self.revision, checksum=self.chksum, no_gix=self.no_gix)


class ACBSPackageInfo(object):
Expand Down
54 changes: 51 additions & 3 deletions acbs/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,62 @@ def blob_processor(package: ACBSPackageInfo, index: int, source_name: str) -> No
return tarball_processor_innner(package, index, source_name, False)


def git_fetch(info: ACBSSourceInfo, source_location: str, name: str) -> Optional[ACBSSourceInfo]:
def git_fetch_fallback(info: ACBSSourceInfo, source_location: str, name: str) -> Optional[ACBSSourceInfo]:
if info.no_gix:
return git_fetch(info, source_location, name)
else:
try:
# Try use gix
return gix_fetch(info, source_location, name)
except:
# Fallback to git
return git_fetch(info, source_location, name)


def git_fetch(info, source_location, name):
full_path = os.path.join(source_location, name)
if not os.path.exists(full_path):
subprocess.check_call(['git', 'clone', '--bare', info.url, full_path])
else:
logging.info('Updating repository...')
subprocess.check_call(
['git', 'fetch', 'origin', '+refs/heads/*:refs/heads/*', '--prune'], cwd=full_path)
['git', 'fetch', 'origin', '+refs/heads/*:refs/heads/*', '--prune'], cwd=full_path)
info.source_location = full_path
return info


def gix_hack(path: str):
# FIXME: reset HEAD to the first valid branch to fix gix can't second fetch src issue.
subprocess.check_call(
['git', 'symbolic-ref', 'HEAD', 'refs/heads/HEAD'], cwd=path)
valid_branches = subprocess.check_output(
['git', 'branch'], cwd=path, encoding='utf-8').splitlines()
invalid: bool = True
for word in valid_branches:
word = word.strip()
if len(word) > 0:
branch: str = word
invalid = False
break
if invalid:
logging.warn(
'No valid branches found. Falling back to traditional git.')
raise ValueError('No valid branches found')
subprocess.check_call(
['git', 'symbolic-ref', 'HEAD', 'refs/heads/' + branch], cwd=path)
os.remove(os.path.join(path, "index"))


def gix_fetch(info: ACBSSourceInfo, source_location: str, name: str) -> Optional[ACBSSourceInfo]:
full_path = os.path.join(source_location, name)
if not os.path.exists(full_path):
subprocess.check_call(['gix', 'clone', '--bare', info.url, full_path])
else:
logging.info('Updating repository with gix...')
# gix doesn't have the --prune option yet.
gix_hack(full_path)
subprocess.check_call(
['gix', 'fetch', 'origin', '+refs/heads/*:refs/heads/*'], cwd=full_path)
info.source_location = full_path
return info

Expand Down Expand Up @@ -293,7 +341,7 @@ def fossil_processor(package: ACBSPackageInfo, index: int, source_name: str) ->


handlers: Dict[str, pair_signature] = {
'GIT': (git_fetch, git_processor),
'GIT': (git_fetch_fallback, git_processor),
'SVN': (svn_fetch, svn_processor),
'BZR': (bzr_fetch, bzr_processor),
'HG': (hg_fetch, hg_processor),
Expand Down
3 changes: 3 additions & 0 deletions acbs/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ def parse_fetch_options(options: str, acbs_source_info: ACBSSourceInfo):
if translated is None:
raise ValueError(f'Invalid submodule directive: {v}')
acbs_source_info.submodule = translated
elif k == 'nogix':
acbs_source_info.no_gix = v.strip() == 'true'

return acbs_source_info


Expand Down