diff options
author | Jannis Pohlmann <jannis.pohlmann@codethink.co.uk> | 2012-04-09 18:29:30 +0100 |
---|---|---|
committer | Jannis Pohlmann <jannis.pohlmann@codethink.co.uk> | 2012-04-09 18:29:30 +0100 |
commit | fd933e5c3e161ac90d6bee18133d9209af086a93 (patch) | |
tree | 5de9854ee25766889a1689cc4262b544a8f9afe2 /morphlib/cachedrepo.py | |
parent | 8311e0ceea0285f981251399ab793883420de01d (diff) | |
download | morph-fd933e5c3e161ac90d6bee18133d9209af086a93.tar.gz |
Get rid of nested try/except blocks.
Diffstat (limited to 'morphlib/cachedrepo.py')
-rw-r--r-- | morphlib/cachedrepo.py | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/morphlib/cachedrepo.py b/morphlib/cachedrepo.py index 998ba892..f7bec455 100644 --- a/morphlib/cachedrepo.py +++ b/morphlib/cachedrepo.py @@ -77,27 +77,30 @@ class CachedRepo(object): binascii.unhexlify(refs[0][0]) return refs[0][0] except morphlib.execute.CommandFailure: - if not self.is_valid_sha1(ref): - raise InvalidReferenceError(self, ref) - try: - binascii.unhexlify(ref) - return self._rev_list(ref) - except morphlib.execute.CommandFailure: - raise InvalidReferenceError(self, ref) + pass + + if not self.is_valid_sha1(ref): + raise InvalidReferenceError(self, ref) + try: + binascii.unhexlify(ref) + return self._rev_list(ref) + except morphlib.execute.CommandFailure: + raise InvalidReferenceError(self, ref) def cat(self, ref, filename): if not self.is_valid_sha1(ref): raise UnresolvedNamedReferenceError(self, ref) try: sha1 = self._rev_list(ref) - try: - return self._cat_file(sha1, filename) - except morphlib.execute.CommandFailure: - raise IOError('File %s does not exist in ref %s of repo %s' % - (filename, ref, self)) except morphlib.execute.CommandFailure: raise InvalidReferenceError(self, ref) + try: + return self._cat_file(sha1, filename) + except morphlib.execute.CommandFailure: + raise IOError('File %s does not exist in ref %s of repo %s' % + (filename, ref, self)) + def checkout(self, ref, target_dir): if not self.is_valid_sha1(ref): raise UnresolvedNamedReferenceError(self, ref) @@ -109,13 +112,14 @@ class CachedRepo(object): try: sha1 = self._rev_list(ref) - try: - self._copy_repository(self.path, target_dir) - self._checkout_ref(sha1, target_dir) - except morphlib.execute.CommandFailure: - raise CheckoutError(self, ref, target_dir) except morphlib.execute.CommandFailure: raise InvalidReferenceError(self, ref) + + try: + self._copy_repository(self.path, target_dir) + self._checkout_ref(sha1, target_dir) + except morphlib.execute.CommandFailure: + raise CheckoutError(self, ref, target_dir) def update(self): try: |