Skip to content

Commit

Permalink
Allow setlinkrev to set a specific vrev
Browse files Browse the repository at this point in the history
This helps mitigate OBS-305
and openSUSE/open-build-service#15079

Co-authored-by: Bernhard M. Wiedemann <[email protected]>
  • Loading branch information
adrianschroeter and bmwiedemann committed Mar 21, 2024
1 parent 1bf2264 commit ad1117f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion osc/commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -3601,6 +3601,8 @@ def do_request(self, subcmd, opts, *args):
help='Do not expand revision the specified or latest rev')
@cmdln.option('-u', '--unset', action='store_true',
help='remove revision in link, it will point always to latest revision')
@cmdln.option('--vrev', metavar='vrev',
help='Enforce a given vrev')
def do_setlinkrev(self, subcmd, opts, *args):
"""
Updates a revision number in a source link
Expand Down Expand Up @@ -3643,7 +3645,7 @@ def do_setlinkrev(self, subcmd, opts, *args):

for p in packages:
try:
rev = set_link_rev(apiurl, project, p, revision=rev, expand=not opts.use_plain_revision)
rev = set_link_rev(apiurl, project, p, revision=rev, expand=not opts.use_plain_revision, vrev=opts.vrev)

Check warning on line 3648 in osc/commandline.py

View check run for this annotation

Codecov / codecov/patch

osc/commandline.py#L3648

Added line #L3648 was not covered by tests
except HTTPError as e:
if e.code != 404:
raise
Expand Down
10 changes: 6 additions & 4 deletions osc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7717,15 +7717,15 @@ def owner(
return res


def set_link_rev(apiurl: str, project: str, package: str, revision="", expand=False, msg: str=None):
def set_link_rev(apiurl: str, project: str, package: str, revision="", expand=False, msg: str=None, vrev: str=None):
url = makeurl(apiurl, ["source", project, package, "_link"])
try:
f = http_GET(url)
root = ET.parse(f).getroot()
except HTTPError as e:
e.osc_msg = f'Unable to get _link file in package \'{package}\' for project \'{project}\''
raise
revision = _set_link_rev(apiurl, project, package, root, revision, expand=expand)
revision = _set_link_rev(apiurl, project, package, root, revision, expand=expand, setvrev=vrev)
l = ET.tostring(root, encoding=ET_ENCODING)

if not msg:
Expand All @@ -7738,7 +7738,7 @@ def set_link_rev(apiurl: str, project: str, package: str, revision="", expand=Fa
return revision


def _set_link_rev(apiurl: str, project: str, package: str, root, revision="", expand=False):
def _set_link_rev(apiurl: str, project: str, package: str, root, revision="", expand=False, setvrev: str=None):
"""
Updates the rev attribute of the _link xml. If revision is set to None
the rev and vrev attributes are removed from the _link xml.
Expand All @@ -7762,7 +7762,9 @@ def _set_link_rev(apiurl: str, project: str, package: str, root, revision="", ex
if revision:
root.set('rev', revision)
# add vrev when revision is a srcmd5
if not revision_is_empty(vrev) and not revision_is_empty(revision) and len(revision) >= 32:
if setvrev:
root.set('vrev', setvrev)

Check warning on line 7766 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L7766

Added line #L7766 was not covered by tests
elif not revision_is_empty(vrev) and not revision_is_empty(revision) and len(revision) >= 32:
root.set('vrev', vrev)
return revision

Expand Down

0 comments on commit ad1117f

Please sign in to comment.