comparison hgext/mq.py @ 2938:5b7a118f5b6c

allow qrefresh to take a list of files; closes #96.
author Brendan Cully <brendan@kublai.com>
date Wed, 16 Aug 2006 19:52:21 -0700
parents 9dc568f5e03d
children abd0be815c9c
comparison
equal deleted inserted replaced
2937:9dc568f5e03d 2938:5b7a118f5b6c
910 self.ui.write("No patches applied\n") 910 self.ui.write("No patches applied\n")
911 return 911 return
912 qp = self.qparents(repo, top) 912 qp = self.qparents(repo, top)
913 self.printdiff(repo, qp, files=pats, opts=opts) 913 self.printdiff(repo, qp, files=pats, opts=opts)
914 914
915 def refresh(self, repo, msg='', short=False): 915 def refresh(self, repo, pats=None, **opts):
916 if len(self.applied) == 0: 916 if len(self.applied) == 0:
917 self.ui.write("No patches applied\n") 917 self.ui.write("No patches applied\n")
918 return 918 return
919 wlock = repo.wlock() 919 wlock = repo.wlock()
920 self.check_toppatch(repo) 920 self.check_toppatch(repo)
923 cparents = repo.changelog.parents(top) 923 cparents = repo.changelog.parents(top)
924 patchparent = self.qparents(repo, top) 924 patchparent = self.qparents(repo, top)
925 message, comments, user, date, patchfound = self.readheaders(patch) 925 message, comments, user, date, patchfound = self.readheaders(patch)
926 926
927 patchf = self.opener(patch, "w") 927 patchf = self.opener(patch, "w")
928 msg = msg.rstrip() 928 msg = opts.get('msg', '').rstrip()
929 if msg: 929 if msg:
930 if comments: 930 if comments:
931 # Remove existing message. 931 # Remove existing message.
932 ci = 0 932 ci = 0
933 for mi in range(len(message)): 933 for mi in range(len(message)):
937 comments.append(msg) 937 comments.append(msg)
938 if comments: 938 if comments:
939 comments = "\n".join(comments) + '\n\n' 939 comments = "\n".join(comments) + '\n\n'
940 patchf.write(comments) 940 patchf.write(comments)
941 941
942 fns, matchfn, anypats = cmdutil.matchpats(repo, pats, opts)
942 tip = repo.changelog.tip() 943 tip = repo.changelog.tip()
943 if top == tip: 944 if top == tip:
944 # if the top of our patch queue is also the tip, there is an 945 # if the top of our patch queue is also the tip, there is an
945 # optimization here. We update the dirstate in place and strip 946 # optimization here. We update the dirstate in place and strip
946 # off the tip commit. Then just commit the current directory 947 # off the tip commit. Then just commit the current directory
954 # mm, dd, aa, aa2, uu = repo.status(tip, patchparent)[:5] 955 # mm, dd, aa, aa2, uu = repo.status(tip, patchparent)[:5]
955 # but we do it backwards to take advantage of manifest/chlog 956 # but we do it backwards to take advantage of manifest/chlog
956 # caching against the next repo.status call 957 # caching against the next repo.status call
957 # 958 #
958 mm, aa, dd, aa2, uu = repo.status(patchparent, tip)[:5] 959 mm, aa, dd, aa2, uu = repo.status(patchparent, tip)[:5]
959 if short: 960 if opts.get('short'):
960 filelist = mm + aa + dd 961 filelist = mm + aa + dd
961 else: 962 else:
962 filelist = None 963 filelist = None
963 m, a, r, d, u = repo.status(files=filelist)[:5] 964 m, a, r, d, u = repo.status(files=filelist)[:5]
964 965
990 dd.append(x) 991 dd.append(x)
991 992
992 m = list(util.unique(mm)) 993 m = list(util.unique(mm))
993 r = list(util.unique(dd)) 994 r = list(util.unique(dd))
994 a = list(util.unique(aa)) 995 a = list(util.unique(aa))
995 filelist = list(util.unique(m + r + a)) 996 filelist = filter(matchfn, util.unique(m + r + a))
996 self.printdiff(repo, patchparent, files=filelist, 997 self.printdiff(repo, patchparent, files=filelist,
997 changes=(m, a, r, [], u), fp=patchf) 998 changes=(m, a, r, [], u), fp=patchf)
998 patchf.close() 999 patchf.close()
999 1000
1000 changes = repo.changelog.read(tip) 1001 changes = repo.changelog.read(tip)
1002 copies = [(f, repo.dirstate.copied(f)) for f in a] 1003 copies = [(f, repo.dirstate.copied(f)) for f in a]
1003 repo.dirstate.update(a, 'a') 1004 repo.dirstate.update(a, 'a')
1004 for dst, src in copies: 1005 for dst, src in copies:
1005 repo.dirstate.copy(src, dst) 1006 repo.dirstate.copy(src, dst)
1006 repo.dirstate.update(r, 'r') 1007 repo.dirstate.update(r, 'r')
1008 # if the patch excludes a modified file, mark that file with mtime=0
1009 # so status can see it.
1010 mm = []
1011 for i in range(len(m)-1, -1, -1):
1012 if not matchfn(m[i]):
1013 mm.append(m[i])
1014 del m[i]
1007 repo.dirstate.update(m, 'n') 1015 repo.dirstate.update(m, 'n')
1016 repo.dirstate.update(mm, 'n', st_mtime=0)
1008 repo.dirstate.forget(forget) 1017 repo.dirstate.forget(forget)
1009 1018
1010 if not msg: 1019 if not msg:
1011 if not message: 1020 if not message:
1012 message = "patch queue: %s\n" % patch 1021 message = "patch queue: %s\n" % patch
1421 message = commands.logmessage(opts) 1430 message = commands.logmessage(opts)
1422 q.new(repo, patch, msg=message, force=opts['force']) 1431 q.new(repo, patch, msg=message, force=opts['force'])
1423 q.save_dirty() 1432 q.save_dirty()
1424 return 0 1433 return 0
1425 1434
1426 def refresh(ui, repo, **opts): 1435 def refresh(ui, repo, *pats, **opts):
1427 """update the current patch""" 1436 """update the current patch"""
1428 q = repo.mq 1437 q = repo.mq
1429 message = commands.logmessage(opts) 1438 message = commands.logmessage(opts)
1430 if opts['edit']: 1439 if opts['edit']:
1431 if message: 1440 if message:
1432 raise util.Abort(_('option "-e" incompatible with "-m" or "-l"')) 1441 raise util.Abort(_('option "-e" incompatible with "-m" or "-l"'))
1433 patch = q.applied[-1].name 1442 patch = q.applied[-1].name
1434 (message, comment, user, date, hasdiff) = q.readheaders(patch) 1443 (message, comment, user, date, hasdiff) = q.readheaders(patch)
1435 message = ui.edit('\n'.join(message), user or ui.username()) 1444 message = ui.edit('\n'.join(message), user or ui.username())
1436 q.refresh(repo, msg=message, short=opts['short']) 1445 q.refresh(repo, pats, msg=message, **opts)
1437 q.save_dirty() 1446 q.save_dirty()
1438 return 0 1447 return 0
1439 1448
1440 def diff(ui, repo, *pats, **opts): 1449 def diff(ui, repo, *pats, **opts):
1441 """diff of the current patch""" 1450 """diff of the current patch"""
1940 "^qrefresh": 1949 "^qrefresh":
1941 (refresh, 1950 (refresh,
1942 [('e', 'edit', None, _('edit commit message')), 1951 [('e', 'edit', None, _('edit commit message')),
1943 ('m', 'message', '', _('change commit message with <text>')), 1952 ('m', 'message', '', _('change commit message with <text>')),
1944 ('l', 'logfile', '', _('change commit message with <file> content')), 1953 ('l', 'logfile', '', _('change commit message with <file> content')),
1945 ('s', 'short', None, 'short refresh')], 1954 ('s', 'short', None, 'short refresh'),
1946 'hg qrefresh [-e] [-m TEXT] [-l FILE] [-s]'), 1955 ('I', 'include', [], _('include names matching the given patterns')),
1956 ('X', 'exclude', [], _('exclude names matching the given patterns'))],
1957 'hg qrefresh [-I] [-X] [-e] [-m TEXT] [-l FILE] [-s] FILES...'),
1947 'qrename|qmv': 1958 'qrename|qmv':
1948 (rename, [], 'hg qrename PATCH1 [PATCH2]'), 1959 (rename, [], 'hg qrename PATCH1 [PATCH2]'),
1949 "qrestore": 1960 "qrestore":
1950 (restore, 1961 (restore,
1951 [('d', 'delete', None, 'delete save entry'), 1962 [('d', 'delete', None, 'delete save entry'),