Mercurial > hg
comparison hgext/mq.py @ 6001:30d2fecaab76
merge with crew-stable
author | Alexis S. L. Carvalho <alexis@cecm.usp.br> |
---|---|
date | Sun, 03 Feb 2008 21:47:07 -0200 |
parents | d39af2eabb8c f2201aee3dc8 |
children | 36a60bd5b707 2da5b19a6460 |
comparison
equal
deleted
inserted
replaced
6000:8e7d64989bb8 | 6001:30d2fecaab76 |
---|---|
598 raise util.Abort(_("local changes found, refresh first")) | 598 raise util.Abort(_("local changes found, refresh first")) |
599 else: | 599 else: |
600 raise util.Abort(_("local changes found")) | 600 raise util.Abort(_("local changes found")) |
601 return m, a, r, d | 601 return m, a, r, d |
602 | 602 |
603 _reserved = ('series', 'status', 'guards') | |
604 def check_reserved_name(self, name): | |
605 if (name in self._reserved or name.startswith('.hg') | |
606 or name.startswith('.mq')): | |
607 raise util.Abort(_('"%s" cannot be used as the name of a patch') | |
608 % name) | |
609 | |
603 def new(self, repo, patch, *pats, **opts): | 610 def new(self, repo, patch, *pats, **opts): |
604 msg = opts.get('msg') | 611 msg = opts.get('msg') |
605 force = opts.get('force') | 612 force = opts.get('force') |
606 user = opts.get('user') | 613 user = opts.get('user') |
607 date = opts.get('date') | 614 date = opts.get('date') |
615 self.check_reserved_name(patch) | |
608 if os.path.exists(self.join(patch)): | 616 if os.path.exists(self.join(patch)): |
609 raise util.Abort(_('patch "%s" already exists') % patch) | 617 raise util.Abort(_('patch "%s" already exists') % patch) |
610 if opts.get('include') or opts.get('exclude') or pats: | 618 if opts.get('include') or opts.get('exclude') or pats: |
611 fns, match, anypats = cmdutil.matchpats(repo, pats, opts) | 619 fns, match, anypats = cmdutil.matchpats(repo, pats, opts) |
612 m, a, r, d = repo.status(files=fns, match=match)[:4] | 620 m, a, r, d = repo.status(files=fns, match=match)[:4] |
870 info = [ popi ] + [self.applied[popi].rev, self.applied[popi].name] | 878 info = [ popi ] + [self.applied[popi].rev, self.applied[popi].name] |
871 | 879 |
872 start = info[0] | 880 start = info[0] |
873 rev = revlog.bin(info[1]) | 881 rev = revlog.bin(info[1]) |
874 | 882 |
883 if update: | |
884 top = self.check_toppatch(repo) | |
885 | |
886 if repo.changelog.heads(rev) != [revlog.bin(self.applied[-1].rev)]: | |
887 raise util.Abort("popping would remove a revision not " | |
888 "managed by this patch queue") | |
889 | |
875 # we know there are no local changes, so we can make a simplified | 890 # we know there are no local changes, so we can make a simplified |
876 # form of hg.update. | 891 # form of hg.update. |
877 if update: | 892 if update: |
878 top = self.check_toppatch(repo) | |
879 qp = self.qparents(repo, rev) | 893 qp = self.qparents(repo, rev) |
880 changes = repo.changelog.read(qp) | 894 changes = repo.changelog.read(qp) |
881 mmap = repo.manifest.read(changes[0]) | 895 mmap = repo.manifest.read(changes[0]) |
882 m, a, r, d, u = repo.status(qp, top)[:5] | 896 m, a, r, d, u = repo.status(qp, top)[:5] |
883 if d: | 897 if d: |
896 raise | 910 raise |
897 try: os.removedirs(os.path.dirname(repo.wjoin(f))) | 911 try: os.removedirs(os.path.dirname(repo.wjoin(f))) |
898 except: pass | 912 except: pass |
899 repo.dirstate.forget(f) | 913 repo.dirstate.forget(f) |
900 repo.dirstate.setparents(qp, revlog.nullid) | 914 repo.dirstate.setparents(qp, revlog.nullid) |
915 del self.applied[start:end] | |
901 self.strip(repo, rev, update=False, backup='strip') | 916 self.strip(repo, rev, update=False, backup='strip') |
902 del self.applied[start:end] | |
903 if len(self.applied): | 917 if len(self.applied): |
904 self.ui.write("Now at: %s\n" % self.applied[-1].name) | 918 self.ui.write("Now at: %s\n" % self.applied[-1].name) |
905 else: | 919 else: |
906 self.ui.write("Patch queue now empty\n") | 920 self.ui.write("Patch queue now empty\n") |
907 finally: | 921 finally: |
924 wlock = repo.wlock() | 938 wlock = repo.wlock() |
925 try: | 939 try: |
926 self.check_toppatch(repo) | 940 self.check_toppatch(repo) |
927 (top, patchfn) = (self.applied[-1].rev, self.applied[-1].name) | 941 (top, patchfn) = (self.applied[-1].rev, self.applied[-1].name) |
928 top = revlog.bin(top) | 942 top = revlog.bin(top) |
943 if repo.changelog.heads(top) != [top]: | |
944 raise util.Abort("cannot refresh a revision with children") | |
929 cparents = repo.changelog.parents(top) | 945 cparents = repo.changelog.parents(top) |
930 patchparent = self.qparents(repo, top) | 946 patchparent = self.qparents(repo, top) |
931 message, comments, user, date, patchfound = self.readheaders(patchfn) | 947 message, comments, user, date, patchfound = self.readheaders(patchfn) |
932 | 948 |
933 patchf = self.opener(patchfn, 'r+') | 949 patchf = self.opener(patchfn, 'r+') |
1110 message = msg | 1126 message = msg |
1111 | 1127 |
1112 if not user: | 1128 if not user: |
1113 user = changes[1] | 1129 user = changes[1] |
1114 | 1130 |
1131 self.applied.pop() | |
1132 self.applied_dirty = 1 | |
1115 self.strip(repo, top, update=False, | 1133 self.strip(repo, top, update=False, |
1116 backup='strip') | 1134 backup='strip') |
1117 n = repo.commit(filelist, message, user, date, match=matchfn, | 1135 n = repo.commit(filelist, message, user, date, match=matchfn, |
1118 force=1) | 1136 force=1) |
1119 self.applied[-1] = statusentry(revlog.hex(n), patchfn) | 1137 self.applied.append(statusentry(revlog.hex(n), patchfn)) |
1120 self.applied_dirty = 1 | |
1121 self.removeundo(repo) | 1138 self.removeundo(repo) |
1122 else: | 1139 else: |
1123 self.printdiff(repo, patchparent, fp=patchf) | 1140 self.printdiff(repo, patchparent, fp=patchf) |
1124 patchf.close() | 1141 patchf.close() |
1125 added = repo.status()[1] | 1142 added = repo.status()[1] |
1404 % (r, lastparent)) | 1421 % (r, lastparent)) |
1405 lastparent = p1 | 1422 lastparent = p1 |
1406 | 1423 |
1407 if not patchname: | 1424 if not patchname: |
1408 patchname = normname('%d.diff' % r) | 1425 patchname = normname('%d.diff' % r) |
1426 self.check_reserved_name(patchname) | |
1409 checkseries(patchname) | 1427 checkseries(patchname) |
1410 checkfile(patchname) | 1428 checkfile(patchname) |
1411 self.full_series.insert(0, patchname) | 1429 self.full_series.insert(0, patchname) |
1412 | 1430 |
1413 patchf = self.opener(patchname, "w") | 1431 patchf = self.opener(patchname, "w") |
1426 if existing: | 1444 if existing: |
1427 if filename == '-': | 1445 if filename == '-': |
1428 raise util.Abort(_('-e is incompatible with import from -')) | 1446 raise util.Abort(_('-e is incompatible with import from -')) |
1429 if not patchname: | 1447 if not patchname: |
1430 patchname = normname(filename) | 1448 patchname = normname(filename) |
1449 self.check_reserved_name(patchname) | |
1431 if not os.path.isfile(self.join(patchname)): | 1450 if not os.path.isfile(self.join(patchname)): |
1432 raise util.Abort(_("patch %s does not exist") % patchname) | 1451 raise util.Abort(_("patch %s does not exist") % patchname) |
1433 else: | 1452 else: |
1434 try: | 1453 try: |
1435 if filename == '-': | 1454 if filename == '-': |
1440 text = file(filename).read() | 1459 text = file(filename).read() |
1441 except IOError: | 1460 except IOError: |
1442 raise util.Abort(_("unable to read %s") % patchname) | 1461 raise util.Abort(_("unable to read %s") % patchname) |
1443 if not patchname: | 1462 if not patchname: |
1444 patchname = normname(os.path.basename(filename)) | 1463 patchname = normname(os.path.basename(filename)) |
1464 self.check_reserved_name(patchname) | |
1445 checkfile(patchname) | 1465 checkfile(patchname) |
1446 patchf = self.opener(patchname, "w") | 1466 patchf = self.opener(patchname, "w") |
1447 patchf.write(text) | 1467 patchf.write(text) |
1448 checkseries(patchname) | 1468 checkseries(patchname) |
1449 index = self.full_series_end() + i | 1469 index = self.full_series_end() + i |
2145 q = self.mq | 2165 q = self.mq |
2146 if not q.applied: | 2166 if not q.applied: |
2147 return tagscache | 2167 return tagscache |
2148 | 2168 |
2149 mqtags = [(revlog.bin(patch.rev), patch.name) for patch in q.applied] | 2169 mqtags = [(revlog.bin(patch.rev), patch.name) for patch in q.applied] |
2170 | |
2171 if mqtags[-1][0] not in self.changelog.nodemap: | |
2172 self.ui.warn('mq status file refers to unknown node %s\n' | |
2173 % revlog.short(mqtags[-1][0])) | |
2174 return tagscache | |
2175 | |
2150 mqtags.append((mqtags[-1][0], 'qtip')) | 2176 mqtags.append((mqtags[-1][0], 'qtip')) |
2151 mqtags.append((mqtags[0][0], 'qbase')) | 2177 mqtags.append((mqtags[0][0], 'qbase')) |
2152 mqtags.append((self.changelog.parents(mqtags[0][0])[0], 'qparent')) | 2178 mqtags.append((self.changelog.parents(mqtags[0][0])[0], 'qparent')) |
2153 for patch in mqtags: | 2179 for patch in mqtags: |
2154 if patch[1] in tagscache: | 2180 if patch[1] in tagscache: |
2161 def _branchtags(self): | 2187 def _branchtags(self): |
2162 q = self.mq | 2188 q = self.mq |
2163 if not q.applied: | 2189 if not q.applied: |
2164 return super(mqrepo, self)._branchtags() | 2190 return super(mqrepo, self)._branchtags() |
2165 | 2191 |
2192 cl = self.changelog | |
2193 qbasenode = revlog.bin(q.applied[0].rev) | |
2194 if qbasenode not in cl.nodemap: | |
2195 self.ui.warn('mq status file refers to unknown node %s\n' | |
2196 % revlog.short(qbasenode)) | |
2197 return super(mqrepo, self)._branchtags() | |
2198 | |
2166 self.branchcache = {} # avoid recursion in changectx | 2199 self.branchcache = {} # avoid recursion in changectx |
2167 cl = self.changelog | |
2168 partial, last, lrev = self._readbranchcache() | 2200 partial, last, lrev = self._readbranchcache() |
2169 | 2201 |
2170 qbase = cl.rev(revlog.bin(q.applied[0].rev)) | 2202 qbase = cl.rev(qbasenode) |
2171 start = lrev + 1 | 2203 start = lrev + 1 |
2172 if start < qbase: | 2204 if start < qbase: |
2173 # update the cache (excluding the patches) and save it | 2205 # update the cache (excluding the patches) and save it |
2174 self._updatebranchcache(partial, lrev+1, qbase) | 2206 self._updatebranchcache(partial, lrev+1, qbase) |
2175 self._writebranchcache(partial, cl.node(qbase-1), qbase-1) | 2207 self._writebranchcache(partial, cl.node(qbase-1), qbase-1) |