Skip to content

Commit

Permalink
Support expansion/unexpansion of a link when updating to certain rev
Browse files Browse the repository at this point in the history
There is no good reason why "--revision <rev>" and "--expand-link" or
"--revision <rev>" and "--unexpand-link" should be mutually exclusive
during an "osc up" of a package wc.
Introduce the new "--linkrev <rev>" option to specify a rev of the link
target that is used during link expansion.
  • Loading branch information
marcus-h committed Dec 3, 2017
1 parent f698103 commit 9116d8f
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions osc/commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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[:]
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 9116d8f

Please sign in to comment.