Mercurial > hg
comparison hgext/mq.py @ 10686:0c68c2c36ed8
mq: don't use len(list) unless necessary
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Sun, 14 Mar 2010 14:45:01 +0100 |
parents | 10248fc845db |
children | 583adcf63f80 |
comparison
equal
deleted
inserted
replaced
10685:10248fc845db | 10686:0c68c2c36ed8 |
---|---|
537 def qparents(self, repo, rev=None): | 537 def qparents(self, repo, rev=None): |
538 if rev is None: | 538 if rev is None: |
539 (p1, p2) = repo.dirstate.parents() | 539 (p1, p2) = repo.dirstate.parents() |
540 if p2 == nullid: | 540 if p2 == nullid: |
541 return p1 | 541 return p1 |
542 if len(self.applied) == 0: | 542 if not self.applied: |
543 return None | 543 return None |
544 return self.applied[-1].node | 544 return self.applied[-1].node |
545 p1, p2 = repo.changelog.parents(rev) | 545 p1, p2 = repo.changelog.parents(rev) |
546 if p2 != nullid and p2 in [x.node for x in self.applied]: | 546 if p2 != nullid and p2 in [x.node for x in self.applied]: |
547 return p2 | 547 return p2 |
548 return p1 | 548 return p1 |
549 | 549 |
550 def mergepatch(self, repo, mergeq, series, diffopts): | 550 def mergepatch(self, repo, mergeq, series, diffopts): |
551 if len(self.applied) == 0: | 551 if not self.applied: |
552 # each of the patches merged in will have two parents. This | 552 # each of the patches merged in will have two parents. This |
553 # can confuse the qrefresh, qdiff, and strip code because it | 553 # can confuse the qrefresh, qdiff, and strip code because it |
554 # needs to know which parent is actually in the patch queue. | 554 # needs to know which parent is actually in the patch queue. |
555 # so, we insert a merge marker with only one parent. This way | 555 # so, we insert a merge marker with only one parent. This way |
556 # the first patch in the queue is never a merge patch | 556 # the first patch in the queue is never a merge patch |
777 numrevs = len(revpatches) | 777 numrevs = len(revpatches) |
778 | 778 |
779 self._cleanup(realpatches, numrevs, opts.get('keep')) | 779 self._cleanup(realpatches, numrevs, opts.get('keep')) |
780 | 780 |
781 def check_toppatch(self, repo): | 781 def check_toppatch(self, repo): |
782 if len(self.applied) > 0: | 782 if self.applied: |
783 top = self.applied[-1].node | 783 top = self.applied[-1].node |
784 patch = self.applied[-1].name | 784 patch = self.applied[-1].name |
785 pp = repo.dirstate.parents() | 785 pp = repo.dirstate.parents() |
786 if top not in pp: | 786 if top not in pp: |
787 raise util.Abort(_("working directory revision is not qtip")) | 787 raise util.Abort(_("working directory revision is not qtip")) |
938 for m in matches: | 938 for m in matches: |
939 self.ui.warn(' %s\n' % m) | 939 self.ui.warn(' %s\n' % m) |
940 return None | 940 return None |
941 if matches: | 941 if matches: |
942 return matches[0] | 942 return matches[0] |
943 if len(self.series) > 0 and len(self.applied) > 0: | 943 if self.series and self.applied: |
944 if s == 'qtip': | 944 if s == 'qtip': |
945 return self.series[self.series_end(True)-1] | 945 return self.series[self.series_end(True)-1] |
946 if s == 'qbase': | 946 if s == 'qbase': |
947 return self.series[0] | 947 return self.series[0] |
948 return None | 948 return None |
1099 patch = self.lookup(patch) | 1099 patch = self.lookup(patch) |
1100 info = self.isapplied(patch) | 1100 info = self.isapplied(patch) |
1101 if not info: | 1101 if not info: |
1102 raise util.Abort(_("patch %s is not applied") % patch) | 1102 raise util.Abort(_("patch %s is not applied") % patch) |
1103 | 1103 |
1104 if len(self.applied) == 0: | 1104 if not self.applied: |
1105 # Allow qpop -a to work repeatedly, | 1105 # Allow qpop -a to work repeatedly, |
1106 # but not qpop without an argument | 1106 # but not qpop without an argument |
1107 self.ui.warn(_("no patches applied\n")) | 1107 self.ui.warn(_("no patches applied\n")) |
1108 return not all | 1108 return not all |
1109 | 1109 |
1177 repo.dirstate.setparents(qp, nullid) | 1177 repo.dirstate.setparents(qp, nullid) |
1178 for patch in reversed(self.applied[start:end]): | 1178 for patch in reversed(self.applied[start:end]): |
1179 self.ui.status(_("popping %s\n") % patch.name) | 1179 self.ui.status(_("popping %s\n") % patch.name) |
1180 del self.applied[start:end] | 1180 del self.applied[start:end] |
1181 self.strip(repo, rev, update=False, backup='strip') | 1181 self.strip(repo, rev, update=False, backup='strip') |
1182 if len(self.applied): | 1182 if self.applied: |
1183 self.ui.write(_("now at: %s\n") % self.applied[-1].name) | 1183 self.ui.write(_("now at: %s\n") % self.applied[-1].name) |
1184 else: | 1184 else: |
1185 self.ui.write(_("patch queue now empty\n")) | 1185 self.ui.write(_("patch queue now empty\n")) |
1186 finally: | 1186 finally: |
1187 wlock.release() | 1187 wlock.release() |
1198 node1, node2 = qp, None | 1198 node1, node2 = qp, None |
1199 diffopts = self.diffopts(opts, patch) | 1199 diffopts = self.diffopts(opts, patch) |
1200 self.printdiff(repo, diffopts, node1, node2, files=pats, opts=opts) | 1200 self.printdiff(repo, diffopts, node1, node2, files=pats, opts=opts) |
1201 | 1201 |
1202 def refresh(self, repo, pats=None, **opts): | 1202 def refresh(self, repo, pats=None, **opts): |
1203 if len(self.applied) == 0: | 1203 if not self.applied: |
1204 self.ui.write(_("no patches applied\n")) | 1204 self.ui.write(_("no patches applied\n")) |
1205 return 1 | 1205 return 1 |
1206 msg = opts.get('msg', '').rstrip() | 1206 msg = opts.get('msg', '').rstrip() |
1207 newuser = opts.get('user') | 1207 newuser = opts.get('user') |
1208 newdate = opts.get('date') | 1208 newdate = opts.get('date') |
1520 self.ui.warn(_("Unable to load queue repository\n")) | 1520 self.ui.warn(_("Unable to load queue repository\n")) |
1521 return 1 | 1521 return 1 |
1522 hg.clean(r, qpp[0]) | 1522 hg.clean(r, qpp[0]) |
1523 | 1523 |
1524 def save(self, repo, msg=None): | 1524 def save(self, repo, msg=None): |
1525 if len(self.applied) == 0: | 1525 if not self.applied: |
1526 self.ui.warn(_("save: no patches applied, exiting\n")) | 1526 self.ui.warn(_("save: no patches applied, exiting\n")) |
1527 return 1 | 1527 return 1 |
1528 if self.issaveline(self.applied[-1]): | 1528 if self.issaveline(self.applied[-1]): |
1529 self.ui.warn(_("status is already saved\n")) | 1529 self.ui.warn(_("status is already saved\n")) |
1530 return 1 | 1530 return 1 |
1547 self.applied.append(statusentry(n, '.hg.patches.save.line')) | 1547 self.applied.append(statusentry(n, '.hg.patches.save.line')) |
1548 self.applied_dirty = 1 | 1548 self.applied_dirty = 1 |
1549 self.removeundo(repo) | 1549 self.removeundo(repo) |
1550 | 1550 |
1551 def full_series_end(self): | 1551 def full_series_end(self): |
1552 if len(self.applied) > 0: | 1552 if self.applied: |
1553 p = self.applied[-1].name | 1553 p = self.applied[-1].name |
1554 end = self.find_series(p) | 1554 end = self.find_series(p) |
1555 if end is None: | 1555 if end is None: |
1556 return len(self.full_series) | 1556 return len(self.full_series) |
1557 return end + 1 | 1557 return end + 1 |
1572 if p: | 1572 if p: |
1573 break | 1573 break |
1574 self.explain_pushable(i) | 1574 self.explain_pushable(i) |
1575 i += 1 | 1575 i += 1 |
1576 return i | 1576 return i |
1577 if len(self.applied) > 0: | 1577 if self.applied: |
1578 p = self.applied[-1].name | 1578 p = self.applied[-1].name |
1579 try: | 1579 try: |
1580 end = self.series.index(p) | 1580 end = self.series.index(p) |
1581 except ValueError: | 1581 except ValueError: |
1582 return 0 | 1582 return 0 |