# HG changeset patch # User mpm@selenic.com # Date 1119948959 28800 # Node ID 81c563a254be1b5669abdff49487bf69abbe1dd7 # Parent 8cf3999b3d03c852a0ac95ff16180d7fa7953556 Add exception class for repository errors -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Add exception class for repository errors This gives friendlier errors for repo exceptions manifest hash: f3bef1ddb0c3911b9866ebdafa1fe72df48c8ecd -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCwRCfywK+sNU5EO8RAg7fAJ9PMka8pJCy7mMTqFFJ5aQFemHpxwCfezPR cZRAXmbWTTI+/WnVFDjpfM0= =8crk -----END PGP SIGNATURE----- diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -851,13 +851,13 @@ def dispatch(args): help(u, cmd) sys.exit(-1) - if cmd not in norepo.split(): - repo = hg.repository(ui = u) - d = lambda: i[0](u, repo, *args, **cmdoptions) - else: - d = lambda: i[0](u, *args, **cmdoptions) + try: + if cmd not in norepo.split(): + repo = hg.repository(ui = u) + d = lambda: i[0](u, repo, *args, **cmdoptions) + else: + d = lambda: i[0](u, *args, **cmdoptions) - try: if options['profile']: import hotshot, hotshot.stats prof = hotshot.Profile("hg.prof") @@ -870,6 +870,8 @@ def dispatch(args): return r else: return d() + except hg.RepoError, inst: + u.warn("abort: ", inst, "!\n") except SignalInterrupt: u.warn("killed!\n") except KeyboardInterrupt: diff --git a/mercurial/hg.py b/mercurial/hg.py --- a/mercurial/hg.py +++ b/mercurial/hg.py @@ -318,6 +318,8 @@ def opener(base): return o +class RepoError(Exception): pass + class localrepository: def __init__(self, ui, path=None, create=0): self.remote = 0 @@ -330,12 +332,12 @@ class localrepository: while not os.path.isdir(os.path.join(p, ".hg")): oldp = p p = os.path.dirname(p) - if p == oldp: raise "No repo found" + if p == oldp: raise RepoError("no repo found") path = p self.path = os.path.join(path, ".hg") if not create and not os.path.isdir(self.path): - raise "repository %s not found" % self.path + raise RepoError("repository %s not found" % self.path) self.root = path self.ui = ui @@ -911,7 +913,7 @@ class localrepository: for f in fetch: if f in m: - raise "already have", short(f[:4]) + raise RepoError("already have changeset " + short(f[:4])) self.ui.note("adding new changesets starting at " + " ".join([short(f) for f in fetch]) + "\n")