From 2ca954faa53e958664600b6b573d38d10600f253 Mon Sep 17 00:00:00 2001 From: Tony Duckles Date: Wed, 8 Aug 2012 08:21:21 -0500 Subject: [PATCH] Use proper exit-codes Use proper exit-codes, so shell-based callers can infer success/failure of the command: "exit 0" for success "exit 1" for failure --- svn2svn/run/svnancest.py | 2 ++ svn2svn/run/svnreplay.py | 15 ++++++++++----- svnancest.py | 3 ++- svnreplay.py | 3 ++- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/svn2svn/run/svnancest.py b/svn2svn/run/svnancest.py index 5708edd..b0a2c8e 100755 --- a/svn2svn/run/svnancest.py +++ b/svn2svn/run/svnancest.py @@ -34,6 +34,8 @@ def real_main(args): else: ui.status("No ancestor-chain found: %s", repos_root+repos_path+"@"+str(options.revision)) + return 0 + def main(): # Defined as entry point. Must be callable without arguments. usage = "svn2svn, version %s\n" % str(full_version) + \ diff --git a/svn2svn/run/svnreplay.py b/svn2svn/run/svnreplay.py index 6a0922f..fd69c87 100644 --- a/svn2svn/run/svnreplay.py +++ b/svn2svn/run/svnreplay.py @@ -811,12 +811,12 @@ def real_main(args): source_start_rev = svnclient.get_rev(source_repos_url, options.rev_start if options.rev_start else 1) except ExternalCommandFailed: print "Error: Invalid start source revision value: %s" % (options.rev_start) - sys.exit(1) + return 1 try: source_end_rev = svnclient.get_rev(source_repos_url, options.rev_end if options.rev_end else "HEAD") except ExternalCommandFailed: print "Error: Invalid end source revision value: %s" % (options.rev_end) - sys.exit(1) + return 1 ui.status("Using source revision range %s:%s", source_start_rev, source_end_rev, level=ui.VERBOSE) # TODO: If options.keep_date, should we try doing a "svn propset" on an *existing* revision @@ -853,7 +853,7 @@ def real_main(args): if len(top_paths)>0: print "Error: Trying to replay (non-continue-mode) into a non-empty target_url location. " \ "Use --force if you're sure this is what you want." - sys.exit(1) + return 1 # Get the first log entry at/after source_start_rev, which is where # we'll do the initial import from. source_ancestors = find_svn_ancestors(source_repos_url, source_base, source_end_rev, prefix=" ") @@ -915,7 +915,7 @@ def real_main(args): build_rev_map(target_url, target_rev_last, source_info) if not rev_map: print "Error: Called with continue-mode, but no already-replayed source history found in target_url." - sys.exit(1) + return 1 source_start_rev = int(max(rev_map, key=rev_map.get)) assert source_start_rev ui.status("Continuing from source revision %s.", source_start_rev, level=ui.VERBOSE) @@ -928,6 +928,7 @@ def real_main(args): source_ancestors = find_svn_ancestors(source_repos_url, source_base, source_end_rev, prefix=" ") it_log_entries = svnclient.iter_svn_log_entries(source_url, source_start_rev+1, source_end_rev, get_revprops=True, ancestors=source_ancestors) if source_start_rev < source_end_rev else [] source_rev_last = source_start_rev + exit_code = 0 try: for log_entry in it_log_entries: @@ -942,7 +943,7 @@ def real_main(args): if source_rev < target_rev_last: print "Error: Last target revision (r%s) is equal-or-higher than starting source revision (r%s). " \ "Cannot use --keep-revnum mode." % (target_rev_last, source_start_rev) - sys.exit(1) + return 1 target_rev_last = keep_revnum(source_rev, target_rev_last, wc_target_tmp) disp_svn_log_summary(log_entry) # Process all the changed-paths in this log entry @@ -971,11 +972,13 @@ def real_main(args): verify_commit(source_rev_last, target_rev_last) except KeyboardInterrupt: + exit_code = 1 print "\nStopped by user." print "\nCleaning-up..." run_svn(["cleanup"]) full_svn_revert() except: + exit_code = 1 print "\nCommand failed with following error:\n" traceback.print_exc() print "\nCleaning-up..." @@ -985,6 +988,8 @@ def real_main(args): finally: print "\nFinished at source revision %s%s." % (source_rev_last, " (dry-run)" if options.dry_run else "") + return exit_code + def main(): # Defined as entry point. Must be callable without arguments. usage = "svn2svn, version %s\n" % str(full_version) + \ diff --git a/svnancest.py b/svnancest.py index 3a679f9..b25f30e 100755 --- a/svnancest.py +++ b/svnancest.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +import sys from svn2svn.run.svnancest import main -main() +sys.exit(main() or 0) diff --git a/svnreplay.py b/svnreplay.py index bb2b39f..0fb03dd 100755 --- a/svnreplay.py +++ b/svnreplay.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +import sys from svn2svn.run.svnreplay import main -main() +sys.exit(main() or 0) -- 2.45.2