From b1be0f84eaa00fbc02aac91acb67fe86b81d4e58 Mon Sep 17 00:00:00 2001 From: Ludwig Nussel Date: Thu, 23 Dec 2010 10:33:31 +0100 Subject: [PATCH] refactor diff command --- osc/commandline.py | 48 ++++++---------------------------------------- osc/core.py | 32 ++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 43 deletions(-) diff --git a/osc/commandline.py b/osc/commandline.py index f15794b4..b39a6123 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -2670,26 +2670,8 @@ Please submit there instead, or use --nodevelproject to force direct submission. for i in pac.get_diff(rev1): sys.stdout.write(''.join(i)) else: - try: - diff += server_diff(pac.apiurl, pac.prjname, pac.name, rev1, - pac.prjname, pac.name, rev2, not opts.plain, opts.missingok) - except urllib2.HTTPError, e: - if not e.code in [ 400, 403, 404, 500 ]: - raise - - msg = None - body = None - try: - body = e.read() - if not 'bad link' in body: - raise e - except: - raise e - - diff = "## diff on expanded link not possible, showing unexpanded version\n" - diff += server_diff(pac.apiurl, pac.prjname, pac.name, rev1, - pac.prjname, pac.name, rev2, not opts.plain, opts.missingok, - expand=False) + diff += server_diff_noex(pac.apiurl, pac.prjname, pac.name, rev1, + pac.prjname, pac.name, rev2, not opts.plain, opts.missingok) run_pager(diff) @@ -2777,29 +2759,11 @@ Please submit there instead, or use --nodevelproject to force direct submission. if opts.revision: rev1, rev2 = parseRevisionOption(opts.revision) - try: - rdiff = server_diff(apiurl, - old_project, old_package, rev1, - new_project, new_package, rev2, not opts.plain, opts.missingok, - expand=not opts.unexpand) - except urllib2.HTTPError, e: - if opts.unexpand or not e.code in [ 400, 403, 404, 500 ]: - raise + rdiff = server_diff_noex(apiurl, + old_project, old_package, rev1, + new_project, new_package, rev2, not opts.plain, opts.missingok, + expand=not opts.unexpand) - msg = None - body = None - try: - body = e.read() - if not 'bad link' in body: - raise e - except: - raise e - - rdiff = "## diff on expanded link not possible, showing unexpanded version\n" - rdiff += server_diff(apiurl, - old_project, old_package, rev1, - new_project, new_package, rev2, not opts.plain, opts.missingok, - expand=False) run_pager(rdiff) @cmdln.hide(1) diff --git a/osc/core.py b/osc/core.py index c3afa161..e337b1ef 100644 --- a/osc/core.py +++ b/osc/core.py @@ -3916,7 +3916,8 @@ def get_source_file_diff(dir, filename, rev, oldfilename = None, olddir = None, def server_diff(apiurl, old_project, old_package, old_revision, - new_project, new_package, new_revision, unified=False, missingok=False, meta=False, expand=True): + new_project, new_package, new_revision, + unified=False, missingok=False, meta=False, expand=True): query = {'cmd': 'diff'} if expand: query['expand'] = 1 @@ -3940,6 +3941,35 @@ def server_diff(apiurl, f = http_POST(u) return f.read() +def server_diff_noex(apiurl, + old_project, old_package, old_revision, + new_project, new_package, new_revision, + unified=False, missingok=False, meta=False, expand=True): + print "diff %d\n" % expand + try: + return server_diff(apiurl, + old_project, old_package, old_revision, + new_project, new_package, new_revision, + unified, missingok, meta, expand) + except urllib2.HTTPError, e: + msg = None + body = None + try: + body = e.read() + if not 'bad link' in body: + return '# diff failed: ' + body + except: + return '# diff failed with unknown error' + + if expand: + rdiff = "## diff on expanded link not possible, showing unexpanded version\n" + print rdiff + rdiff += server_diff_noex(apiurl, + old_project, old_package, old_revision, + new_project, new_package, new_revision, + unified, missingok, meta, False) + return rdiff + def request_diff(apiurl, reqid): u = makeurl(apiurl, ['request', reqid], query={'cmd': 'diff'} )