Skip to content

Commit

Permalink
- do_setlinkrev, set_link_rev: fixed #72
Browse files Browse the repository at this point in the history
Also refactored set_link_rev code a bit so that the new _set_link_rev
function could be used by link_pac in the future.
  • Loading branch information
marcus-h committed Mar 3, 2014
1 parent 570e3e5 commit 8b058b3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
13 changes: 4 additions & 9 deletions osc/commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2390,7 +2390,7 @@ def do_editmeta(self, subcmd, opts, *args):
@cmdln.option('-r', '--revision', metavar='rev',
help='use the specified revision.')
@cmdln.option('-R', '--use-plain-revision', action='store_true',
help='Don\'t expand revsion based on baserev, the revision which was used when commit happened.')
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')
def do_setlinkrev(self, subcmd, opts, *args):
Expand All @@ -2408,12 +2408,6 @@ def do_setlinkrev(self, subcmd, opts, *args):
args = slash_split(args)
apiurl = self.get_api_url()
package = None
expand = True
baserev = True
if opts.use_plain_revision:
expand = False
baserev = False

rev = parseRevisionOption(opts.revision)[0] or ''
if opts.unset:
rev = None
Expand All @@ -2440,7 +2434,8 @@ def do_setlinkrev(self, subcmd, opts, *args):
packages = meta_get_packagelist(apiurl, project)

for p in packages:
rev = set_link_rev(apiurl, project, p, revision=rev, expand=expand, baserev=baserev)
rev = set_link_rev(apiurl, project, p, revision=rev,
expand=not opts.use_plain_revision)
if rev is None:
print('removed revision from link')
else:
Expand Down Expand Up @@ -2585,7 +2580,7 @@ def do_linkpac(self, subcmd, opts, *args):
opts.cicount = "copy"

if opts.current and not opts.new_package:
rev, vrev = show_upstream_rev_vrev(apiurl, src_project, src_package, expand=1)
rev, vrev = show_upstream_rev_vrev(apiurl, src_project, src_package, expand=True)
if rev == None or len(rev) < 32:
# vrev is only needed for srcmd5 and OBS instances < 2.1.17 do not support it
vrev = None
Expand Down
42 changes: 23 additions & 19 deletions osc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3485,8 +3485,8 @@ def show_upstream_xsrcmd5(apiurl, prj, pac, revision=None, linkrev=None, linkrep
return li.xsrcmd5


def show_upstream_rev_vrev(apiurl, prj, pac, revision=None, expand=False, linkrev=None, meta=False):
m = show_files_meta(apiurl, prj, pac, revision=revision, expand=expand, linkrev=linkrev, meta=meta)
def show_upstream_rev_vrev(apiurl, prj, pac, revision=None, expand=False, meta=False):
m = show_files_meta(apiurl, prj, pac, revision=revision, expand=expand, meta=meta)
et = ET.fromstring(''.join(m))
return et.get('rev'), et.get('vrev')

Expand Down Expand Up @@ -5953,42 +5953,46 @@ def owner(apiurl, binary, mode="binary", attribute=None, project=None, usefilter
pass
return res

def set_link_rev(apiurl, project, package, revision='', expand=False, baserev=False):
"""
updates the rev attribute of the _link xml. If revision is set to None
the rev attribute is removed from the _link xml. If revision is set to ''
the "plain" upstream revision is used (if xsrcmd5 and baserev aren't specified).
"""
def set_link_rev(apiurl, project, package, revision='', expand=False):
url = makeurl(apiurl, ['source', project, package, '_link'])
try:
f = http_GET(url)
root = ET.parse(f).getroot()
except HTTPError as e:
e.osc_msg = 'Unable to get _link file in package \'%s\' for project \'%s\'' % (package, project)
raise
revision = _set_link_rev(apiurl, project, package, root, revision, expand=expand)
l = ET.tostring(root, encoding=ET_ENCODING)
http_PUT(url, data=l)

# set revision element
def _set_link_rev(apiurl, project, package, root, revision='', expand=False):
"""
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.
updates the rev attribute of the _link xml. If revision is the empty
string the latest rev of the link's source package is used (or the
xsrcmd5 if expand is True). If revision is neither None nor the empty
string the _link's rev attribute is set to this revision (or to the
xsrcmd5 if expand is True).
"""
src_project = root.get('project', project)
src_package = root.get('package', package)
linkrev = None
vrev = None
if baserev:
linkrev = 'base'
expand = True
if revision == '':
revision = root.get('rev', '')
if revision is None:
if 'rev' in root.keys():
del root.attrib['rev']
elif revision == '' or expand:
revision, vrev = show_upstream_rev_vrev(apiurl, src_project, src_package, revision=revision, linkrev=linkrev, expand=expand)
if 'vrev' in root.keys():
del root.attrib['vrev']
elif not revision or expand:
revision, vrev = show_upstream_rev_vrev(apiurl, src_project, src_package, revision=revision, expand=expand)

if revision:
root.set('rev', revision)
# add vrev when revision is a srcmd5
if vrev and revision and len(revision) >= 32:
if vrev is not None and revision is not None and len(revision) >= 32:
root.set('vrev', vrev)

l = ET.tostring(root, encoding=ET_ENCODING)
http_PUT(url, data=l)
return revision


Expand Down

0 comments on commit 8b058b3

Please sign in to comment.