Mercurial > hg > mercurial-crew-with-dirclash
comparison hgext/mq.py @ 3176:0e6b58c7beea
mq: add --summary to qapplied, qunapplied, qtop, qnext and qprev
This moves most of the queue display code into qseries.
author | Brendan Cully <brendan@kublai.com> |
---|---|
date | Wed, 27 Sep 2006 13:34:20 -0700 |
parents | e21337e06952 |
children | 87b7ae306d54 |
comparison
equal
deleted
inserted
replaced
3175:f6c36cc92d02 | 3176:0e6b58c7beea |
---|---|
1069 if pushable: | 1069 if pushable: |
1070 unapplied.append((i, self.series[i])) | 1070 unapplied.append((i, self.series[i])) |
1071 self.explain_pushable(i) | 1071 self.explain_pushable(i) |
1072 return unapplied | 1072 return unapplied |
1073 | 1073 |
1074 def qseries(self, repo, missing=None, summary=False): | 1074 def qseries(self, repo, missing=None, start=0, length=0, status=None, |
1075 start = self.series_end(all_patches=True) | 1075 summary=False): |
1076 def displayname(patchname): | |
1077 if summary: | |
1078 msg = self.readheaders(patchname)[0] | |
1079 msg = msg and ': ' + msg[0] or ': ' | |
1080 else: | |
1081 msg = '' | |
1082 return '%s%s' % (patchname, msg) | |
1083 | |
1084 def pname(i): | |
1085 if status == 'A': | |
1086 return self.applied[i].name | |
1087 else: | |
1088 return self.series[i] | |
1089 | |
1090 unapplied = self.series_end(all_patches=True) | |
1091 if not length: | |
1092 length = len(self.series) - start | |
1076 if not missing: | 1093 if not missing: |
1077 for i in range(len(self.series)): | 1094 for i in range(start, start+length): |
1078 patch = self.series[i] | 1095 pfx = '' |
1096 patch = pname(i) | |
1079 if self.ui.verbose: | 1097 if self.ui.verbose: |
1080 if i < start: | 1098 if i < unapplied: |
1081 status = 'A' | 1099 status = 'A' |
1082 elif self.pushable(i)[0]: | 1100 elif self.pushable(i)[0]: |
1083 status = 'U' | 1101 status = 'U' |
1084 else: | 1102 else: |
1085 status = 'G' | 1103 status = 'G' |
1086 self.ui.write('%d %s ' % (i, status)) | 1104 pfx = '%d %s ' % (i, status) |
1087 if summary: | 1105 self.ui.write('%s%s\n' % (pfx, displayname(patch))) |
1088 msg = self.readheaders(patch)[0] | |
1089 msg = msg and ': ' + msg[0] or ': ' | |
1090 else: | |
1091 msg = '' | |
1092 self.ui.write('%s%s\n' % (patch, msg)) | |
1093 else: | 1106 else: |
1094 msng_list = [] | 1107 msng_list = [] |
1095 for root, dirs, files in os.walk(self.path): | 1108 for root, dirs, files in os.walk(self.path): |
1096 d = root[len(self.path) + 1:] | 1109 d = root[len(self.path) + 1:] |
1097 for f in files: | 1110 for f in files: |
1100 fl not in (self.status_path, self.series_path) | 1113 fl not in (self.status_path, self.series_path) |
1101 and not fl.startswith('.')): | 1114 and not fl.startswith('.')): |
1102 msng_list.append(fl) | 1115 msng_list.append(fl) |
1103 msng_list.sort() | 1116 msng_list.sort() |
1104 for x in msng_list: | 1117 for x in msng_list: |
1105 if self.ui.verbose: | 1118 pfx = self.ui.verbose and ('D ') or '' |
1106 self.ui.write("D ") | 1119 self.ui.write("%s%s\n" % (pfx, displayname(x))) |
1107 self.ui.write("%s\n" % x) | |
1108 | 1120 |
1109 def issaveline(self, l): | 1121 def issaveline(self, l): |
1110 if l.name == '.hg.patches.save.line': | 1122 if l.name == '.hg.patches.save.line': |
1111 return True | 1123 return True |
1112 | 1124 |
1225 except ValueError: | 1237 except ValueError: |
1226 return 0 | 1238 return 0 |
1227 return next(end + 1) | 1239 return next(end + 1) |
1228 return next(end) | 1240 return next(end) |
1229 | 1241 |
1230 def qapplied(self, repo, patch=None): | |
1231 if patch and patch not in self.series: | |
1232 raise util.Abort(_("patch %s is not in series file") % patch) | |
1233 if not patch: | |
1234 end = len(self.applied) | |
1235 else: | |
1236 end = self.series.index(patch) + 1 | |
1237 for x in xrange(end): | |
1238 p = self.appliedname(x) | |
1239 self.ui.write("%s\n" % p) | |
1240 | |
1241 def appliedname(self, index): | 1242 def appliedname(self, index): |
1242 pname = self.applied[index].name | 1243 pname = self.applied[index].name |
1243 if not self.ui.verbose: | 1244 if not self.ui.verbose: |
1244 p = pname | 1245 p = pname |
1245 else: | 1246 else: |
1246 p = str(self.series.index(pname)) + " " + pname | 1247 p = str(self.series.index(pname)) + " " + pname |
1247 return p | 1248 return p |
1248 | |
1249 def top(self, repo): | |
1250 if len(self.applied): | |
1251 p = self.appliedname(-1) | |
1252 self.ui.write(p + '\n') | |
1253 else: | |
1254 self.ui.write("No patches applied\n") | |
1255 return 1 | |
1256 | |
1257 def next(self, repo): | |
1258 end = self.series_end() | |
1259 if end == len(self.series): | |
1260 self.ui.write("All patches applied\n") | |
1261 return 1 | |
1262 else: | |
1263 p = self.series[end] | |
1264 if self.ui.verbose: | |
1265 self.ui.write("%d " % self.series.index(p)) | |
1266 self.ui.write(p + '\n') | |
1267 | |
1268 def prev(self, repo): | |
1269 if len(self.applied) > 1: | |
1270 p = self.appliedname(-2) | |
1271 self.ui.write(p + '\n') | |
1272 elif len(self.applied) == 1: | |
1273 self.ui.write("Only one patch applied\n") | |
1274 return 1 | |
1275 else: | |
1276 self.ui.write("No patches applied\n") | |
1277 return 1 | |
1278 | 1249 |
1279 def qimport(self, repo, files, patchname=None, rev=None, existing=None, | 1250 def qimport(self, repo, files, patchname=None, rev=None, existing=None, |
1280 force=None): | 1251 force=None): |
1281 def checkseries(patchname): | 1252 def checkseries(patchname): |
1282 if patchname in self.series: | 1253 if patchname in self.series: |
1394 q.save_dirty() | 1365 q.save_dirty() |
1395 return 0 | 1366 return 0 |
1396 | 1367 |
1397 def applied(ui, repo, patch=None, **opts): | 1368 def applied(ui, repo, patch=None, **opts): |
1398 """print the patches already applied""" | 1369 """print the patches already applied""" |
1399 repo.mq.qapplied(repo, patch) | 1370 q = repo.mq |
1400 return 0 | 1371 if patch: |
1372 if patch not in q.series: | |
1373 raise util.Abort(_("patch %s is not in series file") % patch) | |
1374 end = q.series.index(patch) + 1 | |
1375 else: | |
1376 end = len(q.applied) | |
1377 return q.qseries(repo, length=end, status='A', summary=opts.get('summary')) | |
1401 | 1378 |
1402 def unapplied(ui, repo, patch=None, **opts): | 1379 def unapplied(ui, repo, patch=None, **opts): |
1403 """print the patches not yet applied""" | 1380 """print the patches not yet applied""" |
1404 for i, p in repo.mq.unapplied(repo, patch): | 1381 q = repo.mq |
1405 if ui.verbose: | 1382 if patch: |
1406 ui.write("%d " % i) | 1383 if patch not in q.series: |
1407 ui.write("%s\n" % p) | 1384 raise util.Abort(_("patch %s is not in series file") % patch) |
1385 start = q.series.index(patch) + 1 | |
1386 else: | |
1387 start = q.series_end() | |
1388 q.qseries(repo, start=start, summary=opts.get('summary')) | |
1408 | 1389 |
1409 def qimport(ui, repo, *filename, **opts): | 1390 def qimport(ui, repo, *filename, **opts): |
1410 """import a patch | 1391 """import a patch |
1411 | 1392 |
1412 The patch will have the same name as its source file unless you | 1393 The patch will have the same name as its source file unless you |
1501 repo.mq.qseries(repo, missing=opts['missing'], summary=opts['summary']) | 1482 repo.mq.qseries(repo, missing=opts['missing'], summary=opts['summary']) |
1502 return 0 | 1483 return 0 |
1503 | 1484 |
1504 def top(ui, repo, **opts): | 1485 def top(ui, repo, **opts): |
1505 """print the name of the current patch""" | 1486 """print the name of the current patch""" |
1506 return repo.mq.top(repo) | 1487 q = repo.mq |
1488 t = len(q.applied) | |
1489 if t: | |
1490 return q.qseries(repo, start=t-1, length=1, status='A', | |
1491 summary=opts.get('summary')) | |
1492 else: | |
1493 ui.write("No patches applied\n") | |
1494 return 1 | |
1507 | 1495 |
1508 def next(ui, repo, **opts): | 1496 def next(ui, repo, **opts): |
1509 """print the name of the next patch""" | 1497 """print the name of the next patch""" |
1510 return repo.mq.next(repo) | 1498 q = repo.mq |
1499 end = q.series_end() | |
1500 if end == len(q.series): | |
1501 ui.write("All patches applied\n") | |
1502 return 1 | |
1503 return q.qseries(repo, start=end, length=1, summary=opts.get('summary')) | |
1511 | 1504 |
1512 def prev(ui, repo, **opts): | 1505 def prev(ui, repo, **opts): |
1513 """print the name of the previous patch""" | 1506 """print the name of the previous patch""" |
1514 return repo.mq.prev(repo) | 1507 q = repo.mq |
1508 l = len(q.applied) | |
1509 if l == 1: | |
1510 ui.write("Only one patch applied\n") | |
1511 return 1 | |
1512 if not l: | |
1513 ui.write("No patches applied\n") | |
1514 return 1 | |
1515 return q.qseries(repo, start=l-2, length=1, status='A', | |
1516 summary=opts.get('summary')) | |
1515 | 1517 |
1516 def new(ui, repo, patch, **opts): | 1518 def new(ui, repo, patch, **opts): |
1517 """create a new patch | 1519 """create a new patch |
1518 | 1520 |
1519 qnew creates a new patch on top of the currently-applied patch | 1521 qnew creates a new patch on top of the currently-applied patch |
1986 | 1988 |
1987 if repo.local(): | 1989 if repo.local(): |
1988 repo.__class__ = mqrepo | 1990 repo.__class__ = mqrepo |
1989 repo.mq = queue(ui, repo.join("")) | 1991 repo.mq = queue(ui, repo.join("")) |
1990 | 1992 |
1993 seriesopts = [('s', 'summary', None, _('print first line of patch header'))] | |
1994 | |
1991 cmdtable = { | 1995 cmdtable = { |
1992 "qapplied": (applied, [], 'hg qapplied [PATCH]'), | 1996 "qapplied": (applied, [] + seriesopts, 'hg qapplied [-s] [PATCH]'), |
1993 "qclone": (clone, | 1997 "qclone": (clone, |
1994 [('', 'pull', None, _('use pull protocol to copy metadata')), | 1998 [('', 'pull', None, _('use pull protocol to copy metadata')), |
1995 ('U', 'noupdate', None, _('do not update the new working directories')), | 1999 ('U', 'noupdate', None, _('do not update the new working directories')), |
1996 ('', 'uncompressed', None, | 2000 ('', 'uncompressed', None, |
1997 _('use uncompressed transfer (fast over LAN)')), | 2001 _('use uncompressed transfer (fast over LAN)')), |
2041 [('e', 'edit', None, _('edit commit message')), | 2045 [('e', 'edit', None, _('edit commit message')), |
2042 ('m', 'message', '', _('use <text> as commit message')), | 2046 ('m', 'message', '', _('use <text> as commit message')), |
2043 ('l', 'logfile', '', _('read the commit message from <file>')), | 2047 ('l', 'logfile', '', _('read the commit message from <file>')), |
2044 ('f', 'force', None, _('import uncommitted changes into patch'))], | 2048 ('f', 'force', None, _('import uncommitted changes into patch'))], |
2045 'hg qnew [-e] [-m TEXT] [-l FILE] [-f] PATCH'), | 2049 'hg qnew [-e] [-m TEXT] [-l FILE] [-f] PATCH'), |
2046 "qnext": (next, [], 'hg qnext'), | 2050 "qnext": (next, [] + seriesopts, 'hg qnext [-s]'), |
2047 "qprev": (prev, [], 'hg qprev'), | 2051 "qprev": (prev, [] + seriesopts, 'hg qprev [-s]'), |
2048 "^qpop": | 2052 "^qpop": |
2049 (pop, | 2053 (pop, |
2050 [('a', 'all', None, 'pop all patches'), | 2054 [('a', 'all', None, 'pop all patches'), |
2051 ('n', 'name', '', 'queue name to pop'), | 2055 ('n', 'name', '', 'queue name to pop'), |
2052 ('f', 'force', None, 'forget any local changes')], | 2056 ('f', 'force', None, 'forget any local changes')], |
2092 _('pop to before first guarded applied patch')), | 2096 _('pop to before first guarded applied patch')), |
2093 ('', 'reapply', None, _('pop, then reapply patches'))], | 2097 ('', 'reapply', None, _('pop, then reapply patches'))], |
2094 'hg qselect [OPTION...] [GUARD...]'), | 2098 'hg qselect [OPTION...] [GUARD...]'), |
2095 "qseries": | 2099 "qseries": |
2096 (series, | 2100 (series, |
2097 [('m', 'missing', None, 'print patches not in series'), | 2101 [('m', 'missing', None, 'print patches not in series')] + seriesopts, |
2098 ('s', 'summary', None, _('print first line of patch header'))], | |
2099 'hg qseries [-ms]'), | 2102 'hg qseries [-ms]'), |
2100 "^strip": | 2103 "^strip": |
2101 (strip, | 2104 (strip, |
2102 [('f', 'force', None, 'force multi-head removal'), | 2105 [('f', 'force', None, 'force multi-head removal'), |
2103 ('b', 'backup', None, 'bundle unrelated changesets'), | 2106 ('b', 'backup', None, 'bundle unrelated changesets'), |
2104 ('n', 'nobackup', None, 'no backups')], | 2107 ('n', 'nobackup', None, 'no backups')], |
2105 'hg strip [-f] [-b] [-n] REV'), | 2108 'hg strip [-f] [-b] [-n] REV'), |
2106 "qtop": (top, [], 'hg qtop'), | 2109 "qtop": (top, [] + seriesopts, 'hg qtop [-s]'), |
2107 "qunapplied": (unapplied, [], 'hg qunapplied [PATCH]'), | 2110 "qunapplied": (unapplied, [] + seriesopts, 'hg qunapplied [-s] [PATCH]'), |
2108 } | 2111 } |