comparison hgext/mq.py @ 4100:c30c922f907a

Modify qpush/qpop idempotent operations to return success Modify qpush/qpop such that idempotent instances of the operations return success. That is, repeated qpush -a, qpop -a, qpush patch-name or qpop patch-name will return success. The end goal of each of these operations is to reach a particular state. Whether or not the patches were already applied does not affect that state or operation status. Likewise, be careful to retain the error status on a qpush/qpop without arguments when the end/beginning of the series has been reached.
author Ben Thomas <bthomas@virtualiron.com>
date Tue, 13 Feb 2007 08:54:48 -0500
parents cf5580c16b13
children 9dc64c8414ca
comparison
equal deleted inserted replaced
4099:cf5580c16b13 4100:c30c922f907a
800 def push(self, repo, patch=None, force=False, list=False, 800 def push(self, repo, patch=None, force=False, list=False,
801 mergeq=None, wlock=None): 801 mergeq=None, wlock=None):
802 if not wlock: 802 if not wlock:
803 wlock = repo.wlock() 803 wlock = repo.wlock()
804 patch = self.lookup(patch) 804 patch = self.lookup(patch)
805 if patch and self.isapplied(patch): 805 # Suppose our series file is: A B C and the current 'top' patch is B.
806 raise util.Abort(_("patch %s is already applied") % patch) 806 # qpush C should be performed (moving forward)
807 # qpush B is a NOP (no change)
808 # qpush A is an error (can't go backwards with qpush)
809 if patch:
810 info = self.isapplied(patch)
811 if info:
812 if info[0] < len(self.applied) - 1:
813 raise util.Abort(_("cannot push to a previous patch: %s") %
814 patch)
815 if info[0] < len(self.series) - 1:
816 self.ui.warn(_('qpush: %s is already at the top\n') % patch)
817 else:
818 self.ui.warn(_('all patches are currently applied\n'))
819 return
820
821 # Following the above example, starting at 'top' of B:
822 # qpush should be performed (pushes C), but a subsequent qpush without
823 # an argument is an error (nothing to apply). This allows a loop
824 # of "...while hg qpush..." to work as it detects an error when done
807 if self.series_end() == len(self.series): 825 if self.series_end() == len(self.series):
808 raise util.Abort(_("patch series fully applied")) 826 self.ui.warn(_('patch series already fully applied\n'))
827 return 1
809 if not force: 828 if not force:
810 self.check_localchanges(repo) 829 self.check_localchanges(repo)
811 830
812 self.applied_dirty = 1; 831 self.applied_dirty = 1;
813 start = self.series_end() 832 start = self.series_end()
845 if not info: 864 if not info:
846 patch = self.lookup(patch) 865 patch = self.lookup(patch)
847 info = self.isapplied(patch) 866 info = self.isapplied(patch)
848 if not info: 867 if not info:
849 raise util.Abort(_("patch %s is not applied") % patch) 868 raise util.Abort(_("patch %s is not applied") % patch)
869
850 if len(self.applied) == 0: 870 if len(self.applied) == 0:
851 raise util.Abort(_("no patches applied")) 871 # Allow qpop -a to work repeatedly,
872 # but not qpop without an argument
873 self.ui.warn(_("no patches applied\n"))
874 return not all
852 875
853 if not update: 876 if not update:
854 parents = repo.dirstate.parents() 877 parents = repo.dirstate.parents()
855 rr = [ revlog.bin(x.rev) for x in self.applied ] 878 rr = [ revlog.bin(x.rev) for x in self.applied ]
856 for p in parents: 879 for p in parents:
1764 q = repo.mq 1787 q = repo.mq
1765 mergeq = None 1788 mergeq = None
1766 1789
1767 if opts['all']: 1790 if opts['all']:
1768 if not q.series: 1791 if not q.series:
1769 raise util.Abort(_('no patches in series')) 1792 ui.warn(_('no patches in series\n'))
1793 return 0
1770 patch = q.series[-1] 1794 patch = q.series[-1]
1771 if opts['merge']: 1795 if opts['merge']:
1772 if opts['name']: 1796 if opts['name']:
1773 newpath = opts['name'] 1797 newpath = opts['name']
1774 else: 1798 else: