Bug#1010751: clone: handle -b optional branch specification in VCS-Git
Hi, On Thu, Feb 29, 2024 at 10:49:32PM +0100, Nicolas Boulenguez wrote: > Package: git-buildpackage > Followup-For: Bug #1010751 > > Ping? I'll have a look over the next days (I missed your last update). Cheers, -- Guido
Bug#1010751: clone: handle -b optional branch specification in VCS-Git
Package: git-buildpackage Followup-For: Bug #1010751 Ping?
Bug#1010751: clone: handle -b optional branch specification in VCS-Git
Package: git-buildpackage Followup-For: Bug #1010751 Hello. The attached commit implements your suggestions. >From 3f8debeeeffbf57e77234848317b38d12b2d3363 Mon Sep 17 00:00:00 2001 From: Nicolas Boulenguez Date: Sun, 8 May 2022 16:51:26 +0200 Subject: [PATCH] clone: handle -b optional branch specification in VCS-Git --- gbp/scripts/clone.py | 35 --- tests/29_test_gbp_clone.py | 18 -- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/gbp/scripts/clone.py b/gbp/scripts/clone.py index 7e02f0e2..4825c572 100755 --- a/gbp/scripts/clone.py +++ b/gbp/scripts/clone.py @@ -47,10 +47,15 @@ def apt_showsrc(pkg): def vcs_git_url(pkg): +""" +(url, None) most of the time +(url, branch) when the VCS-Git contains -b +(None, None) when the VCS-Git field is missing +""" repos = {} out = apt_showsrc(pkg) -vcs_re = re.compile(r'(x-)?vcs-git:\s*(?P[^ ]+)$', re.I) +vcs_re = re.compile(r'(?:x-)?vcs-git:\s*([^ ]+)(?:\s+-b\s+([^ ]+))?$', re.I) version_re = re.compile(r'Version:\s*(?P.*)$', re.I) end_re = re.compile(r'\s*$') @@ -58,7 +63,7 @@ def vcs_git_url(pkg): for line in out.split('\n'): m = vcs_re.match(line) if m: -repo = m.group('repo') +repo = m.groups() continue m = version_re.match(line) if m: @@ -72,7 +77,7 @@ def vcs_git_url(pkg): if not repos: gbp.log.err("Can't find any vcs-git URL for '%s'" % pkg) -return None +return None, None s = sorted(repos, key=cmp_to_key(DpkgCompareVersions())) return repos[s[-1]] @@ -80,27 +85,31 @@ def vcs_git_url(pkg): def repo_to_url(repo): """ +(url, None) most of the time +(url, branch) when VCS-Git is required and contains a -b option +(None, None) when VCS-Git is required but missing. + >>> repo_to_url("https://foo.example.com;) -'https://foo.example.com' +('https://foo.example.com', None) >>> repo_to_url("salsa:agx/git-buildpackage") -'https://salsa.debian.org/agx/git-buildpackage.git' +('https://salsa.debian.org/agx/git-buildpackage.git', None) >>> repo_to_url("github:agx/git-buildpackage") -'https://github.com/agx/git-buildpackage.git' +('https://github.com/agx/git-buildpackage.git', None) """ parts = repo.split(":", 1) if len(parts) != 2: -return repo +return repo, None else: proto, path = parts if proto == 'salsa': -return 'https://salsa.debian.org/%s.git' % path +return 'https://salsa.debian.org/%s.git' % path, None if proto == 'github': -return 'https://github.com/%s.git' % path +return 'https://github.com/%s.git' % path, None elif proto in ['vcsgit', 'vcs-git']: return vcs_git_url(path) else: -return repo +return repo, None def add_upstream_vcs(repo): @@ -189,7 +198,7 @@ def main(argv): return 1 else: remote_repo = args[1] -source = repo_to_url(remote_repo) if options.aliases else remote_repo +source, vcs_git_branch = repo_to_url(remote_repo) if options.aliases else remote_repo, None if not source: return 1 @@ -212,6 +221,10 @@ def main(argv): postclone = options.postclone (options, args) = parse_args(argv) +if vcs_git_branch and vcs_git_branch != options.debian_branch: +gbp.log.warn(f'VCS-Git: -b {vcs_git_branch} overrides --debian-branch={options.debian_branch}') +options.debian_branch = vcs_git_branch + # Track all branches: if options.all: remotes = repo.get_remote_branches() diff --git a/tests/29_test_gbp_clone.py b/tests/29_test_gbp_clone.py index f1ac3925..b1930612 100644 --- a/tests/29_test_gbp_clone.py +++ b/tests/29_test_gbp_clone.py @@ -15,7 +15,7 @@ Vcs-Git: git://honk.sigxcpu.org/git/git-buildpackage.git Version: 0.8.14 Standards-Version: 3.9.8 -Vcs-Git: https://git.sigxcpu.org/cgit/git-buildpackage/ -b foo +Vcs-Git: https://git.sigxcpu.org/cgit/git-buildpackage/ unexpected_info Version: 0.8.12.2 Standards-Version: 3.9.8 @@ -31,4 +31,18 @@ Vcs-Git: git://honk.sigxcpu.org/git/git-buildpackage.git @patch('gbp.scripts.clone.apt_showsrc', return_value=show_src) def test_vcs_git_url(self, patch): self.assertEqual(vcs_git_url('git-buildpackage'), - 'https://git.sigxcpu.org/cgit/git-buildpackage/') + ('https://git.sigxcpu.org/cgit/git-buildpackage/', None)) + +@skip_without_cmd('dpkg') +@patch('gbp.scripts.clone.apt_showsrc', return_value=""" +Version: 0.7.6-4 +Vcs-Git: https://git.codelabs.ch/git/pcscada.git -b debian +""") +def test_vcs_git_url_branch(self, patch): +self.assertEqual(vcs_git_url('pcscada'), + ('https://git.codelabs.ch/git/pcscada.git', 'debian'))
Bug#1010751: clone: handle -b optional branch specification in VCS-Git
Hi, Thanks, makes sense, some comments: On Sun, May 08, 2022 at 05:21:15PM +0200, Nicolas Boulenguez wrote: > def vcs_git_url(pkg): > +""" > +Content of the latest available VCS-Git field, as a str. > +None when the field is missing. > +(url, branch) when the value specifies a branch with -b. > +""" I think we should always return a tuple and have branch = None when there's no -b so we can also avoid the isinstance() below. It would also be great to have a test (e.g. by just having a test that parses some pre fetched apt output (so we don't need to run it in the tests). Cheers, -- Guido > repos = {} > > out = apt_showsrc(pkg) > -vcs_re = re.compile(r'(x-)?vcs-git:\s*(?P[^ ]+)$', re.I) > +vcs_re = re.compile(r'(x-)?vcs-git:\s*(?P[^ > ]+)(\s*-b\s*(?P[^ ]+))?$', re.I) > version_re = re.compile(r'Version:\s*(?P.*)$', re.I) > end_re = re.compile(r'\s*$') > > @@ -58,6 +63,8 @@ def vcs_git_url(pkg): > m = vcs_re.match(line) > if m: > repo = m.group('repo') > +if m.group('branch'): > +repo = (repo, m.group('branch')) > continue > m = version_re.match(line) > if m: > @@ -85,6 +92,9 @@ def repo_to_url(repo): > 'https://salsa.debian.org/agx/git-buildpackage.git' > >>> repo_to_url("github:agx/git-buildpackage") > 'https://github.com/agx/git-buildpackage.git' > + > +None when VCS-Git is required but missing. > +(url, branch) when VCS-Git specifies a branch with -b. > """ > parts = repo.split(":", 1) > if len(parts) != 2: > @@ -167,6 +177,10 @@ def main(argv): > source = repo_to_url(args[1]) > if not source: > return 1 > +elif isinstance(source, tuple): > +source, vcs_git_branch = source > +else: > +vcs_git_branch = None > > clone_to, auto_name = (os.path.curdir, True) if len(args) < 3 else > (args[2], False) > try: > @@ -187,6 +201,10 @@ def main(argv): > postclone = options.postclone > (options, args) = parse_args(argv) > > +if vcs_git_branch not in (None, options.debian_branch): > +gbp.log.warn(f'VCS-Git: -b {vcs_git_branch} overrides > --debian-branch={options.debian_branch}') > +options.debian_branch = vcs_git_branch > + > # Track all branches: > if options.all: > remotes = repo.get_remote_branches() > -- > 2.30.2 >
Bug#1010751: clone: handle -b optional branch specification in VCS-Git
Package: git-buildpackage Version: 0.9.22 Severity: wishlist Tags: patch Hello. https://www.debian.org/doc/debian-policy/ch-controlfields.html#version-control-system-vcs-fields allows the VCS-Git to specify a branch and a relative path inside a given repository. # gbp clone vcs-git:pcscada gbp:error: Can't find any vcs-git URL for 'pcscada' The attached patch fixes the branch selection. It does not allow a relative path. >From 4550aaeedec99f7f48c456b6eae9d759ccf7de42 Mon Sep 17 00:00:00 2001 From: Nicolas Boulenguez Date: Sun, 8 May 2022 16:50:29 +0200 Subject: [PATCH 2/3] clone: add second allowed form for vcs-git protocol to manual page --- docs/manpages/gbp-clone.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/manpages/gbp-clone.xml b/docs/manpages/gbp-clone.xml index 849d990a..aa385cd5 100644 --- a/docs/manpages/gbp-clone.xml +++ b/docs/manpages/gbp-clone.xml @@ -197,6 +197,7 @@ Clone from the Git-Vcs URL of a package: + vcs-git:libvirt vcsgit:libvirt Clone a repository from salsa (Debian's code hosting): -- 2.30.2 >From ed04b5242adf466b2f141090840d5f4ed4cf62d4 Mon Sep 17 00:00:00 2001 From: Nicolas Boulenguez Date: Sun, 8 May 2022 16:51:26 +0200 Subject: [PATCH 3/3] clone: handle -b optional branch specification in VCS-Git --- gbp/scripts/clone.py | 20 +++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/gbp/scripts/clone.py b/gbp/scripts/clone.py index d538cdfe..f799fc6d 100755 --- a/gbp/scripts/clone.py +++ b/gbp/scripts/clone.py @@ -46,10 +46,15 @@ def apt_showsrc(pkg): def vcs_git_url(pkg): +""" +Content of the latest available VCS-Git field, as a str. +None when the field is missing. +(url, branch) when the value specifies a branch with -b. +""" repos = {} out = apt_showsrc(pkg) -vcs_re = re.compile(r'(x-)?vcs-git:\s*(?P[^ ]+)$', re.I) +vcs_re = re.compile(r'(x-)?vcs-git:\s*(?P[^ ]+)(\s*-b\s*(?P[^ ]+))?$', re.I) version_re = re.compile(r'Version:\s*(?P.*)$', re.I) end_re = re.compile(r'\s*$') @@ -58,6 +63,8 @@ def vcs_git_url(pkg): m = vcs_re.match(line) if m: repo = m.group('repo') +if m.group('branch'): +repo = (repo, m.group('branch')) continue m = version_re.match(line) if m: @@ -85,6 +92,9 @@ def repo_to_url(repo): 'https://salsa.debian.org/agx/git-buildpackage.git' >>> repo_to_url("github:agx/git-buildpackage") 'https://github.com/agx/git-buildpackage.git' + +None when VCS-Git is required but missing. +(url, branch) when VCS-Git specifies a branch with -b. """ parts = repo.split(":", 1) if len(parts) != 2: @@ -167,6 +177,10 @@ def main(argv): source = repo_to_url(args[1]) if not source: return 1 +elif isinstance(source, tuple): +source, vcs_git_branch = source +else: +vcs_git_branch = None clone_to, auto_name = (os.path.curdir, True) if len(args) < 3 else (args[2], False) try: @@ -187,6 +201,10 @@ def main(argv): postclone = options.postclone (options, args) = parse_args(argv) +if vcs_git_branch not in (None, options.debian_branch): +gbp.log.warn(f'VCS-Git: -b {vcs_git_branch} overrides --debian-branch={options.debian_branch}') +options.debian_branch = vcs_git_branch + # Track all branches: if options.all: remotes = repo.get_remote_branches() -- 2.30.2