Mercurial > hg > mercurial-crew-with-dirclash
comparison hgext/mq.py @ 2724:9c41ae1908c7
mq: replace module-wide repo hash with a repo attribute
author | Brendan Cully <brendan@kublai.com> |
---|---|
date | Fri, 28 Jul 2006 13:08:25 -0700 |
parents | 04d9b31faeca |
children | 9ffee4f07323 |
comparison
equal
deleted
inserted
replaced
2723:04d9b31faeca | 2724:9c41ae1908c7 |
---|---|
33 demandload(globals(), "os sys re struct traceback errno bz2") | 33 demandload(globals(), "os sys re struct traceback errno bz2") |
34 from mercurial.i18n import gettext as _ | 34 from mercurial.i18n import gettext as _ |
35 from mercurial import ui, hg, revlog, commands, util | 35 from mercurial import ui, hg, revlog, commands, util |
36 | 36 |
37 versionstr = "0.45" | 37 versionstr = "0.45" |
38 | |
39 repomap = {} | |
40 | 38 |
41 commands.norepo += " qclone qversion" | 39 commands.norepo += " qclone qversion" |
42 | 40 |
43 class queue: | 41 class queue: |
44 def __init__(self, ui, path, patchdir=None): | 42 def __init__(self, ui, path, patchdir=None): |
1139 if qrepo: | 1137 if qrepo: |
1140 qrepo.add(added) | 1138 qrepo.add(added) |
1141 | 1139 |
1142 def delete(ui, repo, patch, **opts): | 1140 def delete(ui, repo, patch, **opts): |
1143 """remove a patch from the series file""" | 1141 """remove a patch from the series file""" |
1144 q = repomap[repo] | 1142 q = repo.mq |
1145 q.delete(repo, patch) | 1143 q.delete(repo, patch) |
1146 q.save_dirty() | 1144 q.save_dirty() |
1147 return 0 | 1145 return 0 |
1148 | 1146 |
1149 def applied(ui, repo, patch=None, **opts): | 1147 def applied(ui, repo, patch=None, **opts): |
1150 """print the patches already applied""" | 1148 """print the patches already applied""" |
1151 repomap[repo].qapplied(repo, patch) | 1149 repo.mq.qapplied(repo, patch) |
1152 return 0 | 1150 return 0 |
1153 | 1151 |
1154 def unapplied(ui, repo, patch=None, **opts): | 1152 def unapplied(ui, repo, patch=None, **opts): |
1155 """print the patches not yet applied""" | 1153 """print the patches not yet applied""" |
1156 repomap[repo].unapplied(repo, patch) | 1154 repo.mq.unapplied(repo, patch) |
1157 return 0 | 1155 return 0 |
1158 | 1156 |
1159 def qimport(ui, repo, *filename, **opts): | 1157 def qimport(ui, repo, *filename, **opts): |
1160 """import a patch""" | 1158 """import a patch""" |
1161 q = repomap[repo] | 1159 q = repo.mq |
1162 q.qimport(repo, filename, patch=opts['name'], | 1160 q.qimport(repo, filename, patch=opts['name'], |
1163 existing=opts['existing'], force=opts['force']) | 1161 existing=opts['existing'], force=opts['force']) |
1164 q.save_dirty() | 1162 q.save_dirty() |
1165 return 0 | 1163 return 0 |
1166 | 1164 |
1167 def init(ui, repo, **opts): | 1165 def init(ui, repo, **opts): |
1168 """init a new queue repository""" | 1166 """init a new queue repository""" |
1169 q = repomap[repo] | 1167 q = repo.mq |
1170 r = q.init(repo, create=opts['create_repo']) | 1168 r = q.init(repo, create=opts['create_repo']) |
1171 q.save_dirty() | 1169 q.save_dirty() |
1172 if r: | 1170 if r: |
1173 fp = r.wopener('.hgignore', 'w') | 1171 fp = r.wopener('.hgignore', 'w') |
1174 print >> fp, 'syntax: glob' | 1172 print >> fp, 'syntax: glob' |
1224 ui.note(_('updating destination repo\n')) | 1222 ui.note(_('updating destination repo\n')) |
1225 dr.update(dr.changelog.tip()) | 1223 dr.update(dr.changelog.tip()) |
1226 | 1224 |
1227 def commit(ui, repo, *pats, **opts): | 1225 def commit(ui, repo, *pats, **opts): |
1228 """commit changes in the queue repository""" | 1226 """commit changes in the queue repository""" |
1229 q = repomap[repo] | 1227 q = repo.mq |
1230 r = q.qrepo() | 1228 r = q.qrepo() |
1231 if not r: raise util.Abort('no queue repository') | 1229 if not r: raise util.Abort('no queue repository') |
1232 commands.commit(r.ui, r, *pats, **opts) | 1230 commands.commit(r.ui, r, *pats, **opts) |
1233 | 1231 |
1234 def series(ui, repo, **opts): | 1232 def series(ui, repo, **opts): |
1235 """print the entire series file""" | 1233 """print the entire series file""" |
1236 repomap[repo].qseries(repo, missing=opts['missing']) | 1234 repo.mq.qseries(repo, missing=opts['missing']) |
1237 return 0 | 1235 return 0 |
1238 | 1236 |
1239 def top(ui, repo, **opts): | 1237 def top(ui, repo, **opts): |
1240 """print the name of the current patch""" | 1238 """print the name of the current patch""" |
1241 repomap[repo].top(repo) | 1239 repo.mq.top(repo) |
1242 return 0 | 1240 return 0 |
1243 | 1241 |
1244 def next(ui, repo, **opts): | 1242 def next(ui, repo, **opts): |
1245 """print the name of the next patch""" | 1243 """print the name of the next patch""" |
1246 repomap[repo].next(repo) | 1244 repo.mq.next(repo) |
1247 return 0 | 1245 return 0 |
1248 | 1246 |
1249 def prev(ui, repo, **opts): | 1247 def prev(ui, repo, **opts): |
1250 """print the name of the previous patch""" | 1248 """print the name of the previous patch""" |
1251 repomap[repo].prev(repo) | 1249 repo.mq.prev(repo) |
1252 return 0 | 1250 return 0 |
1253 | 1251 |
1254 def new(ui, repo, patch, **opts): | 1252 def new(ui, repo, patch, **opts): |
1255 """create a new patch""" | 1253 """create a new patch""" |
1256 q = repomap[repo] | 1254 q = repo.mq |
1257 message=commands.logmessage(**opts) | 1255 message=commands.logmessage(**opts) |
1258 q.new(repo, patch, msg=message, force=opts['force']) | 1256 q.new(repo, patch, msg=message, force=opts['force']) |
1259 q.save_dirty() | 1257 q.save_dirty() |
1260 return 0 | 1258 return 0 |
1261 | 1259 |
1262 def refresh(ui, repo, **opts): | 1260 def refresh(ui, repo, **opts): |
1263 """update the current patch""" | 1261 """update the current patch""" |
1264 q = repomap[repo] | 1262 q = repo.mq |
1265 message=commands.logmessage(**opts) | 1263 message=commands.logmessage(**opts) |
1266 q.refresh(repo, msg=message, short=opts['short']) | 1264 q.refresh(repo, msg=message, short=opts['short']) |
1267 q.save_dirty() | 1265 q.save_dirty() |
1268 return 0 | 1266 return 0 |
1269 | 1267 |
1270 def diff(ui, repo, *files, **opts): | 1268 def diff(ui, repo, *files, **opts): |
1271 """diff of the current patch""" | 1269 """diff of the current patch""" |
1272 # deep in the dirstate code, the walkhelper method wants a list, not a tuple | 1270 # deep in the dirstate code, the walkhelper method wants a list, not a tuple |
1273 repomap[repo].diff(repo, list(files)) | 1271 repo.mq.diff(repo, list(files)) |
1274 return 0 | 1272 return 0 |
1275 | 1273 |
1276 def lastsavename(path): | 1274 def lastsavename(path): |
1277 (dir, base) = os.path.split(path) | 1275 (dir, base) = os.path.split(path) |
1278 names = os.listdir(dir) | 1276 names = os.listdir(dir) |
1297 newpath = path + ".%d" % (index + 1) | 1295 newpath = path + ".%d" % (index + 1) |
1298 return newpath | 1296 return newpath |
1299 | 1297 |
1300 def push(ui, repo, patch=None, **opts): | 1298 def push(ui, repo, patch=None, **opts): |
1301 """push the next patch onto the stack""" | 1299 """push the next patch onto the stack""" |
1302 q = repomap[repo] | 1300 q = repo.mq |
1303 mergeq = None | 1301 mergeq = None |
1304 | 1302 |
1305 if opts['all']: | 1303 if opts['all']: |
1306 patch = q.series[-1] | 1304 patch = q.series[-1] |
1307 if opts['merge']: | 1305 if opts['merge']: |
1325 if opts['name']: | 1323 if opts['name']: |
1326 q = queue(ui, repo.join(""), repo.join(opts['name'])) | 1324 q = queue(ui, repo.join(""), repo.join(opts['name'])) |
1327 ui.warn('using patch queue: %s\n' % q.path) | 1325 ui.warn('using patch queue: %s\n' % q.path) |
1328 localupdate = False | 1326 localupdate = False |
1329 else: | 1327 else: |
1330 q = repomap[repo] | 1328 q = repo.mq |
1331 q.pop(repo, patch, force=opts['force'], update=localupdate, all=opts['all']) | 1329 q.pop(repo, patch, force=opts['force'], update=localupdate, all=opts['all']) |
1332 q.save_dirty() | 1330 q.save_dirty() |
1333 return 0 | 1331 return 0 |
1334 | 1332 |
1335 def restore(ui, repo, rev, **opts): | 1333 def restore(ui, repo, rev, **opts): |
1336 """restore the queue state saved by a rev""" | 1334 """restore the queue state saved by a rev""" |
1337 rev = repo.lookup(rev) | 1335 rev = repo.lookup(rev) |
1338 q = repomap[repo] | 1336 q = repo.mq |
1339 q.restore(repo, rev, delete=opts['delete'], | 1337 q.restore(repo, rev, delete=opts['delete'], |
1340 qupdate=opts['update']) | 1338 qupdate=opts['update']) |
1341 q.save_dirty() | 1339 q.save_dirty() |
1342 return 0 | 1340 return 0 |
1343 | 1341 |
1344 def save(ui, repo, **opts): | 1342 def save(ui, repo, **opts): |
1345 """save current queue state""" | 1343 """save current queue state""" |
1346 q = repomap[repo] | 1344 q = repo.mq |
1347 message=commands.logmessage(**opts) | 1345 message=commands.logmessage(**opts) |
1348 ret = q.save(repo, msg=message) | 1346 ret = q.save(repo, msg=message) |
1349 if ret: | 1347 if ret: |
1350 return ret | 1348 return ret |
1351 q.save_dirty() | 1349 q.save_dirty() |
1377 backup = 'all' | 1375 backup = 'all' |
1378 if opts['backup']: | 1376 if opts['backup']: |
1379 backup = 'strip' | 1377 backup = 'strip' |
1380 elif opts['nobackup']: | 1378 elif opts['nobackup']: |
1381 backup = 'none' | 1379 backup = 'none' |
1382 repomap[repo].strip(repo, rev, backup=backup) | 1380 repo.mq.strip(repo, rev, backup=backup) |
1383 return 0 | 1381 return 0 |
1384 | 1382 |
1385 def version(ui, q=None): | 1383 def version(ui, q=None): |
1386 """print the version number""" | 1384 """print the version number""" |
1387 ui.write("mq version %s\n" % versionstr) | 1385 ui.write("mq version %s\n" % versionstr) |
1393 if self.tagscache: | 1391 if self.tagscache: |
1394 return self.tagscache | 1392 return self.tagscache |
1395 | 1393 |
1396 tagscache = super(self.__class__, self).tags() | 1394 tagscache = super(self.__class__, self).tags() |
1397 | 1395 |
1398 q = repomap[repo] | 1396 q = self.mq |
1399 if not q.applied: | 1397 if not q.applied: |
1400 return tagscache | 1398 return tagscache |
1401 | 1399 |
1402 mqtags = [patch.split(':') for patch in q.applied] | 1400 mqtags = [patch.split(':') for patch in q.applied] |
1403 mqtags.append((mqtags[-1][0], 'qtip')) | 1401 mqtags.append((mqtags[-1][0], 'qtip')) |
1409 tagscache[patch[1]] = revlog.bin(patch[0]) | 1407 tagscache[patch[1]] = revlog.bin(patch[0]) |
1410 | 1408 |
1411 return tagscache | 1409 return tagscache |
1412 | 1410 |
1413 repo.__class__ = MqRepo | 1411 repo.__class__ = MqRepo |
1414 repomap[repo] = queue(ui, repo.join("")) | 1412 repo.mq = queue(ui, repo.join("")) |
1415 | 1413 |
1416 cmdtable = { | 1414 cmdtable = { |
1417 "qapplied": (applied, [], 'hg qapplied [PATCH]'), | 1415 "qapplied": (applied, [], 'hg qapplied [PATCH]'), |
1418 "qclone": (clone, | 1416 "qclone": (clone, |
1419 [('', 'pull', None, _('use pull protocol to copy metadata')), | 1417 [('', 'pull', None, _('use pull protocol to copy metadata')), |