summaryrefslogtreecommitdiffstats
path: root/main.py
diff options
context:
space:
mode:
authorConley Owens <cco3@android.com>2012-11-14 16:22:41 -0800
committerGerrit Code Review <noreply-gerritcodereview@google.com>2012-11-14 16:22:41 -0800
commite66291f6d0f29938d6671cf8702d0fdab45a1199 (patch)
tree2e61f134ed4d472524296e3b8940614e16f6b4f4 /main.py
parent3794a78b80e8b8894a9707629fd8523547cf5cfa (diff)
parent7ba25bedf97643528ecef049cabe0b9d1c589131 (diff)
downloadgit-repo-e66291f6d0f29938d6671cf8702d0fdab45a1199.tar.gz
Merge "Simplify error handling in subcommand execution"
Diffstat (limited to 'main.py')
-rwxr-xr-xmain.py31
1 files changed, 15 insertions, 16 deletions
diff --git a/main.py b/main.py
index b5259870..95944546 100755
--- a/main.py
+++ b/main.py
@@ -131,32 +131,31 @@ class _Repo(object):
131 if use_pager: 131 if use_pager:
132 RunPager(config) 132 RunPager(config)
133 133
134 start = time.time()
134 try: 135 try:
135 start = time.time() 136 result = cmd.Execute(copts, cargs)
136 try:
137 result = cmd.Execute(copts, cargs)
138 finally:
139 elapsed = time.time() - start
140 hours, remainder = divmod(elapsed, 3600)
141 minutes, seconds = divmod(remainder, 60)
142 if gopts.time:
143 if hours == 0:
144 print('real\t%dm%.3fs' % (minutes, seconds), file=sys.stderr)
145 else:
146 print('real\t%dh%dm%.3fs' % (hours, minutes, seconds),
147 file=sys.stderr)
148 except DownloadError as e: 137 except DownloadError as e:
149 print('error: %s' % str(e), file=sys.stderr) 138 print('error: %s' % str(e), file=sys.stderr)
150 return 1 139 result = 1
151 except ManifestInvalidRevisionError as e: 140 except ManifestInvalidRevisionError as e:
152 print('error: %s' % str(e), file=sys.stderr) 141 print('error: %s' % str(e), file=sys.stderr)
153 return 1 142 result = 1
154 except NoSuchProjectError as e: 143 except NoSuchProjectError as e:
155 if e.name: 144 if e.name:
156 print('error: project %s not found' % e.name, file=sys.stderr) 145 print('error: project %s not found' % e.name, file=sys.stderr)
157 else: 146 else:
158 print('error: no project in current directory', file=sys.stderr) 147 print('error: no project in current directory', file=sys.stderr)
159 return 1 148 result = 1
149 finally:
150 elapsed = time.time() - start
151 hours, remainder = divmod(elapsed, 3600)
152 minutes, seconds = divmod(remainder, 60)
153 if gopts.time:
154 if hours == 0:
155 print('real\t%dm%.3fs' % (minutes, seconds), file=sys.stderr)
156 else:
157 print('real\t%dh%dm%.3fs' % (hours, minutes, seconds),
158 file=sys.stderr)
160 159
161 return result 160 return result
162 161