From 762b2f74d0e11efbcb2c4f0030d41ac3d9cc5d46 Mon Sep 17 00:00:00 2001 From: eatradish Date: Wed, 16 Aug 2023 14:46:44 +0800 Subject: [PATCH 1/6] fetch: try use gix to fetch package src --- acbs/fetch.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/acbs/fetch.py b/acbs/fetch.py index 4c14adb..67485ab 100644 --- a/acbs/fetch.py +++ b/acbs/fetch.py @@ -120,17 +120,32 @@ def blob_processor(package: ACBSPackageInfo, index: int, source_name: str) -> No def git_fetch(info: ACBSSourceInfo, source_location: str, name: str) -> Optional[ACBSSourceInfo]: + try: + return gix_fetch(info, source_location, name) + except: + 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) + info.source_location = full_path + return info + + +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(['git', 'clone', '--bare', info.url, full_path]) + subprocess.check_call(['gix', 'clone', '--bare', info.url, full_path]) else: logging.info('Updating repository...') + # gix doesn't have the --prune option yet. subprocess.check_call( - ['git', 'fetch', 'origin', '+refs/heads/*:refs/heads/*', '--prune'], cwd=full_path) + ['gix', 'fetch', 'origin', '+refs/heads/*:refs/heads/*'], cwd=full_path) info.source_location = full_path return info - def git_processor(package: ACBSPackageInfo, index: int, source_name: str) -> None: info = package.source_uri[index] if not info.revision: From d83c9a715567c9e059c6fbf0301fcea316019b39 Mon Sep 17 00:00:00 2001 From: eatradish Date: Wed, 16 Aug 2023 17:05:47 +0800 Subject: [PATCH 2/6] fetch: add some hack to gix_fetch function try to fix second time clone --- acbs/fetch.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/acbs/fetch.py b/acbs/fetch.py index 67485ab..1863bea 100644 --- a/acbs/fetch.py +++ b/acbs/fetch.py @@ -121,8 +121,10 @@ def blob_processor(package: ACBSPackageInfo, index: int, source_name: str) -> No def git_fetch(info: ACBSSourceInfo, source_location: str, name: str) -> Optional[ACBSSourceInfo]: try: + # Try use gix return gix_fetch(info, source_location, name) except: + # Fallback to git 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]) @@ -139,8 +141,11 @@ def gix_fetch(info: ACBSSourceInfo, source_location: str, name: str) -> Optional if not os.path.exists(full_path): subprocess.check_call(['gix', 'clone', '--bare', info.url, full_path]) else: - logging.info('Updating repository...') + logging.info('Updating repository with gix...') # gix doesn't have the --prune option yet. + # FIXME: reset HEAD to master to fix gix can't second fetch src issue. + subprocess.check_call(['git', 'symbolic-ref', 'HEAD'], cwd=full_path) + os.remove(os.path.join(full_path, "index")) subprocess.check_call( ['gix', 'fetch', 'origin', '+refs/heads/*:refs/heads/*'], cwd=full_path) info.source_location = full_path From 47c7b652e3bdfc9a423e44650a75cf0deb9c560b Mon Sep 17 00:00:00 2001 From: chenx97 Date: Wed, 16 Aug 2023 17:40:13 +0800 Subject: [PATCH 3/6] fetch: select a valid branch to workaround a gix bug --- acbs/fetch.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/acbs/fetch.py b/acbs/fetch.py index 1863bea..a7d8c86 100644 --- a/acbs/fetch.py +++ b/acbs/fetch.py @@ -143,14 +143,29 @@ def gix_fetch(info: ACBSSourceInfo, source_location: str, name: str) -> Optional else: logging.info('Updating repository with gix...') # gix doesn't have the --prune option yet. - # FIXME: reset HEAD to master to fix gix can't second fetch src issue. - subprocess.check_call(['git', 'symbolic-ref', 'HEAD'], cwd=full_path) + # 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=full_path) + valid_branches: list(str) = subprocess.check_output( + ['git', 'branch'], cwd=full_path, encoding='utf-8').splitlines() + for word in valid_branches: + word = word.strip() + if len(word) > 0: + valid_branches: str = word + break + if isinstance(valid_branches, list): + 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/' + valid_branches], cwd=full_path) os.remove(os.path.join(full_path, "index")) subprocess.check_call( ['gix', 'fetch', 'origin', '+refs/heads/*:refs/heads/*'], cwd=full_path) info.source_location = full_path return info + def git_processor(package: ACBSPackageInfo, index: int, source_name: str) -> None: info = package.source_uri[index] if not info.revision: From 511faa27738684626bea5f5e6e02e6030c6ccd55 Mon Sep 17 00:00:00 2001 From: chenx97 Date: Wed, 16 Aug 2023 19:33:53 +0800 Subject: [PATCH 4/6] fetch: fix style and put workaround into a function --- acbs/fetch.py | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/acbs/fetch.py b/acbs/fetch.py index a7d8c86..64c8ffc 100644 --- a/acbs/fetch.py +++ b/acbs/fetch.py @@ -136,6 +136,28 @@ def git_fetch(info: ACBSSourceInfo, source_location: str, name: str) -> Optional 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: list[str] = 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): @@ -143,23 +165,7 @@ def gix_fetch(info: ACBSSourceInfo, source_location: str, name: str) -> Optional else: logging.info('Updating repository with gix...') # gix doesn't have the --prune option yet. - # 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=full_path) - valid_branches: list(str) = subprocess.check_output( - ['git', 'branch'], cwd=full_path, encoding='utf-8').splitlines() - for word in valid_branches: - word = word.strip() - if len(word) > 0: - valid_branches: str = word - break - if isinstance(valid_branches, list): - 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/' + valid_branches], cwd=full_path) - os.remove(os.path.join(full_path, "index")) + gix_hack(full_path) subprocess.check_call( ['gix', 'fetch', 'origin', '+refs/heads/*:refs/heads/*'], cwd=full_path) info.source_location = full_path From 2326d95c2789d7084eab776fef1905022996ddc4 Mon Sep 17 00:00:00 2001 From: chenx97 Date: Wed, 16 Aug 2023 19:47:01 +0800 Subject: [PATCH 5/6] fetch: make mypy happy --- acbs/fetch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acbs/fetch.py b/acbs/fetch.py index 64c8ffc..75326f2 100644 --- a/acbs/fetch.py +++ b/acbs/fetch.py @@ -140,7 +140,7 @@ 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: list[str] = subprocess.check_output( + valid_branches = subprocess.check_output( ['git', 'branch'], cwd=path, encoding='utf-8').splitlines() invalid: bool = True for word in valid_branches: From 45295496f564e07c5fefcb903c808776a838a2bf Mon Sep 17 00:00:00 2001 From: eatradish Date: Thu, 17 Aug 2023 14:12:44 +0800 Subject: [PATCH 6/6] base, parser, fetch: add nogix in SRCS git option in spec file to control use gix fetch src --- acbs/base.py | 5 +++-- acbs/fetch.py | 37 ++++++++++++++++++++++--------------- acbs/parser.py | 3 +++ 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/acbs/base.py b/acbs/base.py index 0a20c47..a534434 100644 --- a/acbs/base.py +++ b/acbs/base.py @@ -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 @@ -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 ''.format(type=self.type, url=self.url, branch=self.branch, revision=self.revision, checksum=self.chksum) + return ''.format(type=self.type, url=self.url, branch=self.branch, revision=self.revision, checksum=self.chksum, no_gix=self.no_gix) class ACBSPackageInfo(object): diff --git a/acbs/fetch.py b/acbs/fetch.py index 75326f2..53b4ede 100644 --- a/acbs/fetch.py +++ b/acbs/fetch.py @@ -119,21 +119,28 @@ 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]: - try: - # Try use gix - return gix_fetch(info, source_location, name) - except: - # Fallback to git - 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( +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) - info.source_location = full_path - return info + info.source_location = full_path + return info def gix_hack(path: str): @@ -334,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), diff --git a/acbs/parser.py b/acbs/parser.py index 7b58e90..46a3f4b 100644 --- a/acbs/parser.py +++ b/acbs/parser.py @@ -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