Replace sequences of {ui.warn, return 1} with raise of util.Abort.
authorBryan O'Sullivan <bos@serpentine.com>
Fri, 09 Sep 2005 11:34:34 -0700
changeset 1227 e3ea354d99b2
parent 1226 f3837564ed03
child 1228 db950da49539
Replace sequences of {ui.warn, return 1} with raise of util.Abort.
mercurial/commands.py
--- a/mercurial/commands.py	Fri Sep 09 10:59:05 2005 -0700
+++ b/mercurial/commands.py	Fri Sep 09 11:34:34 2005 -0700
@@ -592,8 +592,7 @@
         dest = os.path.basename(os.path.normpath(source))
 
     if os.path.exists(dest):
-        ui.warn("abort: destination '%s' already exists\n" % dest)
-        return 1
+        raise util.Abort("destination '%s' already exists")
 
     dest = os.path.realpath(dest)
 
@@ -1032,8 +1031,7 @@
     if not opts['force']:
         (c, a, d, u) = repo.changes()
         if c or a or d:
-            ui.warn("abort: outstanding uncommitted changes!\n")
-            return 1
+            raise util.Abort("outstanding uncommitted changes")
 
     d = opts["base"]
     strip = opts["strip"]
@@ -1100,9 +1098,7 @@
     source = ui.expandpath(source)
     other = hg.repository(ui, source)
     if not other.local():
-        ui.warn("abort: incoming doesn't work for remote"
-                + " repositories yet, sorry!\n")
-        return 1
+        raise util.Abort("incoming doesn't work for remote repositories yet")
     o = repo.findincoming(other)
     if not o:
         return
@@ -1284,8 +1280,7 @@
         except IOError:
             pass
     if not message and not rc['logfile']:
-        ui.warn("abort: missing commit message\n")
-        return 1
+        raise util.Abort("missing commit message")
 
     files = relpath(repo, list(flist))
     if rc['files']:
@@ -1506,16 +1501,14 @@
         ui.warn("Warning: -t and --text is deprecated,"
                 " please use -m or --message instead.\n")
     if name == "tip":
-        ui.warn("abort: 'tip' is a reserved name!\n")
-        return -1
+        raise util.Abort("the name 'tip' is reserved")
     if rev:
         r = hex(repo.lookup(rev))
     else:
         r = hex(repo.changelog.tip())
 
     if name.find(revrangesep) >= 0:
-        ui.warn("abort: '%s' cannot be used in a tag name\n" % revrangesep)
-        return -1
+        raise util.Abort("'%s' cannot be used in a tag name" % revrangesep)
 
     if opts['local']:
         repo.opener("localtags", "a").write("%s %s\n" % (r, name))
@@ -1524,9 +1517,8 @@
     (c, a, d, u) = repo.changes()
     for x in (c, a, d, u):
         if ".hgtags" in x:
-            ui.warn("abort: working copy of .hgtags is changed!\n")
-            ui.status("(please commit .hgtags manually)\n")
-            return -1
+            raise util.Abort("working copy of .hgtags is changed "
+                             "(please commit .hgtags manually)")
 
     repo.wfile(".hgtags", "ab").write("%s %s\n" % (r, name))
     if repo.dirstate.state(".hgtags") == '?':
@@ -1561,8 +1553,7 @@
     f = urllib.urlopen(fname)
 
     if f.read(4) != "HG10":
-        ui.warn("abort: not a Mercurial bundle file!\n")
-        return -1
+        raise util.Abort("%s: not a Mercurial bundle file" % fname)
 
     class bzread:
         def __init__(self, f):
@@ -1991,8 +1982,8 @@
                 try:
                     os.chdir(options['cwd'])
                 except OSError, inst:
-                    u.warn('abort: %s: %s\n' % (options['cwd'], inst.strerror))
-                    sys.exit(1)
+                    raise util.Abort('%s: %s' %
+                                     (options['cwd'], inst.strerror))
 
             if cmd not in norepo.split():
                 path = options["repository"] or ""