comparison hgext/mq.py @ 2712:8e5cd8d11b51

mq: move many error messages to util.Abort
author Vadim Gelfer <vadim.gelfer@gmail.com>
date Thu, 27 Jul 2006 16:41:59 -0700
parents ca97be5babf8
children 35caf437a201
comparison
equal deleted inserted replaced
2711:ca97be5babf8 2712:8e5cd8d11b51
185 185
186 if err == 0: 186 if err == 0:
187 return (err, n) 187 return (err, n)
188 188
189 if n is None: 189 if n is None:
190 self.ui.warn("apply failed for patch %s\n" % patch) 190 raise util.Abort(_("apply failed for patch %s") % patch)
191 sys.exit(1)
192 191
193 self.ui.warn("patch didn't work out, merging %s\n" % patch) 192 self.ui.warn("patch didn't work out, merging %s\n" % patch)
194 193
195 # apply failed, strip away that rev and merge. 194 # apply failed, strip away that rev and merge.
196 repo.update(head, allow=False, force=True, wlock=wlock) 195 repo.update(head, allow=False, force=True, wlock=wlock)
197 self.strip(repo, n, update=False, backup='strip', wlock=wlock) 196 self.strip(repo, n, update=False, backup='strip', wlock=wlock)
198 197
199 c = repo.changelog.read(rev) 198 c = repo.changelog.read(rev)
200 ret = repo.update(rev, allow=True, wlock=wlock) 199 ret = repo.update(rev, allow=True, wlock=wlock)
201 if ret: 200 if ret:
202 self.ui.warn("update returned %d\n" % ret) 201 raise util.Abort(_("update returned %d") % ret)
203 sys.exit(1)
204 n = repo.commit(None, c[4], c[1], force=1, wlock=wlock) 202 n = repo.commit(None, c[4], c[1], force=1, wlock=wlock)
205 if n == None: 203 if n == None:
206 self.ui.warn("repo commit failed\n") 204 raise util.Abort(_("repo commit failed"))
207 sys.exit(1)
208 try: 205 try:
209 message, comments, user, date, patchfound = mergeq.readheaders(patch) 206 message, comments, user, date, patchfound = mergeq.readheaders(patch)
210 except: 207 except:
211 self.ui.warn("Unable to read %s\n" % patch) 208 raise util.Abort(_("unable to read %s") % patch)
212 sys.exit(1)
213 209
214 patchf = self.opener(patch, "w") 210 patchf = self.opener(patch, "w")
215 if comments: 211 if comments:
216 comments = "\n".join(comments) + '\n\n' 212 comments = "\n".join(comments) + '\n\n'
217 patchf.write(comments) 213 patchf.write(comments)
354 opts={}, wlock=wlock) 350 opts={}, wlock=wlock)
355 n = repo.commit(files, message, user, date, force=1, lock=lock, 351 n = repo.commit(files, message, user, date, force=1, lock=lock,
356 wlock=wlock) 352 wlock=wlock)
357 353
358 if n == None: 354 if n == None:
359 self.ui.warn("repo commit failed\n") 355 raise util.Abort(_("repo commit failed"))
360 sys.exit(1)
361 356
362 if update_status: 357 if update_status:
363 self.applied.append(revlog.hex(n) + ":" + patch) 358 self.applied.append(revlog.hex(n) + ":" + patch)
364 359
365 if patcherr: 360 if patcherr:
381 376
382 def delete(self, repo, patch): 377 def delete(self, repo, patch):
383 patch = self.lookup(patch, strict=True) 378 patch = self.lookup(patch, strict=True)
384 info = self.isapplied(patch) 379 info = self.isapplied(patch)
385 if info: 380 if info:
386 self.ui.warn("cannot delete applied patch %s\n" % patch) 381 raise util.Abort(_("cannot delete applied patch %s") % patch)
387 sys.exit(1)
388 if patch not in self.series: 382 if patch not in self.series:
389 self.ui.warn("patch %s not in series file\n" % patch) 383 raise util.Abort(_("patch %s not in series file") % patch)
390 sys.exit(1)
391 i = self.find_series(patch) 384 i = self.find_series(patch)
392 del self.full_series[i] 385 del self.full_series[i]
393 self.read_series(self.full_series) 386 self.read_series(self.full_series)
394 self.series_dirty = 1 387 self.series_dirty = 1
395 388
397 if len(self.applied) > 0: 390 if len(self.applied) > 0:
398 (top, patch) = self.applied[-1].split(':') 391 (top, patch) = self.applied[-1].split(':')
399 top = revlog.bin(top) 392 top = revlog.bin(top)
400 pp = repo.dirstate.parents() 393 pp = repo.dirstate.parents()
401 if top not in pp: 394 if top not in pp:
402 self.ui.warn("queue top not at dirstate parents. top %s dirstate %s %s\n" %( revlog.short(top), revlog.short(pp[0]), revlog.short(pp[1]))) 395 raise util.Abort(_("queue top not at same revision as working directory"))
403 sys.exit(1)
404 return top 396 return top
405 return None 397 return None
406 def check_localchanges(self, repo): 398 def check_localchanges(self, repo):
407 (c, a, r, d, u) = repo.changes(None, None) 399 (c, a, r, d, u) = repo.changes(None, None)
408 if c or a or d or r: 400 if c or a or d or r:
409 self.ui.write("Local changes found, refresh first\n") 401 raise util.Abort(_("local changes found, refresh first"))
410 sys.exit(1)
411 def new(self, repo, patch, msg=None, force=None): 402 def new(self, repo, patch, msg=None, force=None):
412 if os.path.exists(os.path.join(self.path, patch)): 403 if os.path.exists(os.path.join(self.path, patch)):
413 raise util.Abort(_('patch "%s" already exists') % patch) 404 raise util.Abort(_('patch "%s" already exists') % patch)
414 commitfiles = [] 405 commitfiles = []
415 (c, a, r, d, u) = repo.changes(None, None) 406 (c, a, r, d, u) = repo.changes(None, None)
416 if c or a or d or r: 407 if c or a or d or r:
417 if not force: 408 if not force:
418 raise util.Abort(_("Local changes found, refresh first")) 409 raise util.Abort(_("local changes found, refresh first"))
419 else: 410 commitfiles = c + a + r
420 commitfiles = c + a + r
421 self.check_toppatch(repo) 411 self.check_toppatch(repo)
422 wlock = repo.wlock() 412 wlock = repo.wlock()
423 insert = self.full_series_end() 413 insert = self.full_series_end()
424 if msg: 414 if msg:
425 n = repo.commit(commitfiles, "[mq]: %s" % msg, force=True, 415 n = repo.commit(commitfiles, "[mq]: %s" % msg, force=True,
426 wlock=wlock) 416 wlock=wlock)
427 else: 417 else:
428 n = repo.commit(commitfiles, 418 n = repo.commit(commitfiles,
429 "New patch: %s" % patch, force=True, wlock=wlock) 419 "New patch: %s" % patch, force=True, wlock=wlock)
430 if n == None: 420 if n == None:
431 self.ui.warn("repo commit failed\n") 421 raise util.Abort(_("repo commit failed"))
432 sys.exit(1)
433 self.full_series[insert:insert] = [patch] 422 self.full_series[insert:insert] = [patch]
434 self.applied.append(revlog.hex(n) + ":" + patch) 423 self.applied.append(revlog.hex(n) + ":" + patch)
435 self.read_series(self.full_series) 424 self.read_series(self.full_series)
436 self.series_dirty = 1 425 self.series_dirty = 1
437 self.applied_dirty = 1 426 self.applied_dirty = 1
532 revnum = chlog.rev(rev) 521 revnum = chlog.rev(rev)
533 522
534 if update: 523 if update:
535 (c, a, r, d, u) = repo.changes(None, None) 524 (c, a, r, d, u) = repo.changes(None, None)
536 if c or a or d or r: 525 if c or a or d or r:
537 raise util.Abort(_("Local changes found")) 526 raise util.Abort(_("local changes found"))
538 urev = self.qparents(repo, rev) 527 urev = self.qparents(repo, rev)
539 repo.update(urev, allow=False, force=True, wlock=wlock) 528 repo.update(urev, allow=False, force=True, wlock=wlock)
540 repo.dirstate.write() 529 repo.dirstate.write()
541 530
542 # save is a list of all the branches we are truncating away 531 # save is a list of all the branches we are truncating away
672 except(ValueError, OverflowError): 661 except(ValueError, OverflowError):
673 pass 662 pass
674 else: 663 else:
675 if i + off < len(self.series): 664 if i + off < len(self.series):
676 return self.series[i + off] 665 return self.series[i + off]
677 self.ui.warn("patch %s not in series\n" % patch) 666 raise util.Abort(_("patch %s not in series") % patch)
678 sys.exit(1)
679 667
680 def push(self, repo, patch=None, force=False, list=False, 668 def push(self, repo, patch=None, force=False, list=False,
681 mergeq=None, wlock=None): 669 mergeq=None, wlock=None):
682 if not wlock: 670 if not wlock:
683 wlock = repo.wlock() 671 wlock = repo.wlock()
684 patch = self.lookup(patch) 672 patch = self.lookup(patch)
685 if patch and self.isapplied(patch): 673 if patch and self.isapplied(patch):
686 self.ui.warn("patch %s is already applied\n" % patch) 674 self.ui.warn(_("patch %s is already applied\n") % patch)
687 sys.exit(1) 675 sys.exit(1)
688 if self.series_end() == len(self.series): 676 if self.series_end() == len(self.series):
689 self.ui.warn("File series fully applied\n") 677 self.ui.warn(_("patch series fully applied\n"))
690 sys.exit(1) 678 sys.exit(1)
691 if not force: 679 if not force:
692 self.check_localchanges(repo) 680 self.check_localchanges(repo)
693 681
694 self.applied_dirty = 1; 682 self.applied_dirty = 1;
733 info = self.isapplied(patch) 721 info = self.isapplied(patch)
734 if not info: 722 if not info:
735 patch = self.lookup(patch) 723 patch = self.lookup(patch)
736 info = self.isapplied(patch) 724 info = self.isapplied(patch)
737 if not info: 725 if not info:
738 self.ui.warn("patch %s is not applied\n" % patch) 726 raise util.Abort(_("patch %s is not applied") % patch)
739 sys.exit(1)
740 if len(self.applied) == 0: 727 if len(self.applied) == 0:
741 self.ui.warn("No patches applied\n") 728 self.ui.warn(_("no patches applied\n"))
742 sys.exit(1) 729 sys.exit(1)
743 730
744 if not update: 731 if not update:
745 parents = repo.dirstate.parents() 732 parents = repo.dirstate.parents()
746 rr = [ revlog.bin(x.split(':')[0]) for x in self.applied ] 733 rr = [ revlog.bin(x.split(':')[0]) for x in self.applied ]
910 self.pop(repo, force=True, wlock=wlock) 897 self.pop(repo, force=True, wlock=wlock)
911 self.push(repo, force=True, wlock=wlock) 898 self.push(repo, force=True, wlock=wlock)
912 899
913 def init(self, repo, create=False): 900 def init(self, repo, create=False):
914 if os.path.isdir(self.path): 901 if os.path.isdir(self.path):
915 raise util.Abort("patch queue directory already exists") 902 raise util.Abort(_("patch queue directory already exists"))
916 os.mkdir(self.path) 903 os.mkdir(self.path)
917 if create: 904 if create:
918 return self.qrepo(create=True) 905 return self.qrepo(create=True)
919 906
920 def unapplied(self, repo, patch=None): 907 def unapplied(self, repo, patch=None):
921 if patch and patch not in self.series: 908 if patch and patch not in self.series:
922 self.ui.warn("%s not in the series file\n" % patch) 909 raise util.Abort(_("patch %s is not in series file") % patch)
923 sys.exit(1)
924 if not patch: 910 if not patch:
925 start = self.series_end() 911 start = self.series_end()
926 else: 912 else:
927 start = self.series.index(patch) + 1 913 start = self.series.index(patch) + 1
928 for p in self.series[start:]: 914 for p in self.series[start:]:
1070 return end + 1 1056 return end + 1
1071 return end 1057 return end
1072 1058
1073 def qapplied(self, repo, patch=None): 1059 def qapplied(self, repo, patch=None):
1074 if patch and patch not in self.series: 1060 if patch and patch not in self.series:
1075 self.ui.warn("%s not in the series file\n" % patch) 1061 raise util.Abort(_("patch %s is not in series file") % patch)
1076 sys.exit(1)
1077 if not patch: 1062 if not patch:
1078 end = len(self.applied) 1063 end = len(self.applied)
1079 else: 1064 else:
1080 end = self.series.index(patch) + 1 1065 end = self.series.index(patch) + 1
1081 for x in xrange(end): 1066 for x in xrange(end):
1117 else: 1102 else:
1118 self.ui.write("No patches applied\n") 1103 self.ui.write("No patches applied\n")
1119 1104
1120 def qimport(self, repo, files, patch=None, existing=None, force=None): 1105 def qimport(self, repo, files, patch=None, existing=None, force=None):
1121 if len(files) > 1 and patch: 1106 if len(files) > 1 and patch:
1122 self.ui.warn("-n option not valid when importing multiple files\n") 1107 raise util.Abort(_('option "-n" not valid when importing multiple '
1123 sys.exit(1) 1108 'files'))
1124 i = 0 1109 i = 0
1125 added = [] 1110 added = []
1126 for filename in files: 1111 for filename in files:
1127 if existing: 1112 if existing:
1128 if not patch: 1113 if not patch:
1129 patch = filename 1114 patch = filename
1130 if not os.path.isfile(os.path.join(self.path, patch)): 1115 if not os.path.isfile(os.path.join(self.path, patch)):
1131 self.ui.warn("patch %s does not exist\n" % patch) 1116 raise util.Abort(_("patch %s does not exist") % patch)
1132 sys.exit(1)
1133 else: 1117 else:
1134 try: 1118 try:
1135 text = file(filename).read() 1119 text = file(filename).read()
1136 except IOError: 1120 except IOError:
1137 self.ui.warn("Unable to read %s\n" % patch) 1121 raise util.Abort(_("unable to read %s") % patch)
1138 sys.exit(1)
1139 if not patch: 1122 if not patch:
1140 patch = os.path.split(filename)[1] 1123 patch = os.path.split(filename)[1]
1141 if not force and os.path.isfile(os.path.join(self.path, patch)): 1124 if not force and os.path.exists(os.path.join(self.path, patch)):
1142 raise util.Abort(_('patch "%s" already exists') % patch) 1125 raise util.Abort(_('patch "%s" already exists') % patch)
1143 patchf = self.opener(patch, "w") 1126 patchf = self.opener(patch, "w")
1144 patchf.write(text) 1127 patchf.write(text)
1145 if patch in self.series: 1128 if patch in self.series:
1146 raise util.Abort(_('patch %s is already in the series file') 1129 raise util.Abort(_('patch %s is already in the series file')
1325 path = q.path 1308 path = q.path
1326 if opts['name']: 1309 if opts['name']:
1327 newpath = os.path.join(q.basepath, opts['name']) 1310 newpath = os.path.join(q.basepath, opts['name'])
1328 if os.path.exists(newpath): 1311 if os.path.exists(newpath):
1329 if not os.path.isdir(newpath): 1312 if not os.path.isdir(newpath):
1330 ui.warn("destination %s exists and is not a directory\n" % 1313 raise util.Abort(_('destination %s exists and is not '
1331 newpath) 1314 'a directory') % newpath)
1332 sys.exit(1)
1333 if not opts['force']: 1315 if not opts['force']:
1334 ui.warn("destination %s exists, use -f to force\n" % 1316 raise util.Abort(_('destination %s exists, '
1335 newpath) 1317 'use -f to force') % newpath)
1336 sys.exit(1)
1337 else: 1318 else:
1338 newpath = savename(path) 1319 newpath = savename(path)
1339 ui.warn("copy %s to %s\n" % (path, newpath)) 1320 ui.warn("copy %s to %s\n" % (path, newpath))
1340 util.copyfiles(path, newpath) 1321 util.copyfiles(path, newpath)
1341 if opts['empty']: 1322 if opts['empty']: