From 9116d8ff976dbc11b41414e1e7a309c1fac005c2 Mon Sep 17 00:00:00 2001 From: Marcus Huewe Date: Sun, 3 Dec 2017 16:45:36 +0100 Subject: [PATCH] Support expansion/unexpansion of a link when updating to certain rev There is no good reason why "--revision " and "--expand-link" or "--revision " and "--unexpand-link" should be mutually exclusive during an "osc up" of a package wc. Introduce the new "--linkrev " option to specify a rev of the link target that is used during link expansion. --- osc/commandline.py | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/osc/commandline.py b/osc/commandline.py index 818fa9f6b8..c12061bc52 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -4737,6 +4737,8 @@ def _commit(self, subcmd, opts, args): help='update to specified revision (this option will be ignored ' 'if you are going to update the complete project or more than ' 'one package)') + @cmdln.option('', '--linkrev', metavar='REV', + help='revision of the link target that is used during link expansion') @cmdln.option('-u', '--unexpand-link', action='store_true', help='if a package is an expanded link, update to the raw _link file') @cmdln.option('-e', '--expand-link', action='store_true', @@ -4774,11 +4776,10 @@ def do_update(self, subcmd, opts, *args): ${cmd_option_list} """ - if (opts.expand_link and opts.unexpand_link) \ - or (opts.expand_link and opts.revision) \ - or (opts.unexpand_link and opts.revision): - raise oscerr.WrongOptions('Sorry, the options --expand-link, --unexpand-link and ' - '--revision are mutually exclusive.') + if opts.expand_link and opts.unexpand_link: + raise oscerr.WrongOptions('Sorry, the options --expand-link and ' + '--unexpand-link and are mutually ' + 'exclusive.') args = parseargs(args) arg_list = args[:] @@ -4809,6 +4810,28 @@ def do_update(self, subcmd, opts, *args): if not checkRevision(pacs[0].prjname, pacs[0].name, rev, pacs[0].apiurl): print('Revision \'%s\' does not exist' % rev, file=sys.stderr) sys.exit(1) + if opts.expand_link or opts.unexpand_link: + meta = show_files_meta(pacs[0].apiurl, pacs[0].prjname, + pacs[0].name, revision=rev, + linkrev=opts.linkrev, + expand=opts.server_side_source_service_files) + directory = ET.fromstring(meta) + li_node = directory.find('linkinfo') + if li_node is None: + print('Revision \'%s\' is no link' % rev, file=sys.stderr) + sys.exit(1) + li = Linkinfo() + li.read(li_node) + if li.haserror() and opts.expand_link: + raise oscerr.LinkExpandError(pacs[0].prjname, pacs[0].name, + li.error) + rev = li.lsrcmd5 + if opts.expand_link: + rev = li.xsrcmd5 + if rev is None: + # 2 cases: a) unexpand and passed rev has linkerror + # b) expand and passed rev is already expanded + rev = directory.get('srcmd5') else: rev = None