comparison mercurial/commands.py @ 1586:5c5aaaa9ab6f

Merge with upstream.
author Thomas Arendsen Hein <thomas@intevation.de>
date Thu, 15 Dec 2005 15:39:20 +0100
parents 63799b01985c db10b7114de0
children fce5292866c6
comparison
equal deleted inserted replaced
1585:d7c4b9bfcc94 1586:5c5aaaa9ab6f
64 64
65 We walk a window of revisions in the desired order. Within the 65 We walk a window of revisions in the desired order. Within the
66 window, we first walk forwards to gather data, then in the desired 66 window, we first walk forwards to gather data, then in the desired
67 order (usually backwards) to display it. 67 order (usually backwards) to display it.
68 68
69 This function returns an (iterator, getchange) pair. The 69 This function returns an (iterator, getchange, matchfn) tuple. The
70 getchange function returns the changelog entry for a numeric 70 getchange function returns the changelog entry for a numeric
71 revision. The iterator yields 3-tuples. They will be of one of 71 revision. The iterator yields 3-tuples. They will be of one of
72 the following forms: 72 the following forms:
73 73
74 "window", incrementing, lastrev: stepping through a window, 74 "window", incrementing, lastrev: stepping through a window,
80 possible display 80 possible display
81 81
82 "iter", rev, None: in-order traversal of the revs earlier iterated 82 "iter", rev, None: in-order traversal of the revs earlier iterated
83 over with "add" - use to display data''' 83 over with "add" - use to display data'''
84 84
85 files, matchfn, anypats, cwd = matchpats(repo, pats, opts)
86
85 if repo.changelog.count() == 0: 87 if repo.changelog.count() == 0:
86 return [], False 88 return [], False, matchfn
87 89
88 files, matchfn, anypats, cwd = matchpats(repo, pats, opts)
89 revs = map(int, revrange(ui, repo, opts['rev'] or ['tip:0'])) 90 revs = map(int, revrange(ui, repo, opts['rev'] or ['tip:0']))
90 wanted = {} 91 wanted = {}
91 slowpath = anypats 92 slowpath = anypats
92 window = 300 93 window = 300
93 fncache = {} 94 fncache = {}
151 for rev in srevs: 152 for rev in srevs:
152 fns = fncache.get(rev) or filter(matchfn, getchange(rev)[3]) 153 fns = fncache.get(rev) or filter(matchfn, getchange(rev)[3])
153 yield 'add', rev, fns 154 yield 'add', rev, fns
154 for rev in nrevs: 155 for rev in nrevs:
155 yield 'iter', rev, None 156 yield 'iter', rev, None
156 return iterate(), getchange 157 return iterate(), getchange, matchfn
157 158
158 revrangesep = ':' 159 revrangesep = ':'
159 160
160 def revrange(ui, repo, revs, revlog=None): 161 def revrange(ui, repo, revs, revlog=None):
161 """Yield revision as strings from a list of revision specifications.""" 162 """Yield revision as strings from a list of revision specifications."""
1115 dodiff(sys.stdout, ui, repo, node1, node2, fns, match=matchfn, 1116 dodiff(sys.stdout, ui, repo, node1, node2, fns, match=matchfn,
1116 text=opts['text']) 1117 text=opts['text'])
1117 1118
1118 def doexport(ui, repo, changeset, seqno, total, revwidth, opts): 1119 def doexport(ui, repo, changeset, seqno, total, revwidth, opts):
1119 node = repo.lookup(changeset) 1120 node = repo.lookup(changeset)
1120 prev, other = repo.changelog.parents(node) 1121 parents = [p for p in repo.changelog.parents(node) if p != nullid]
1122 prev = (parents and parents[0]) or nullid
1121 change = repo.changelog.read(node) 1123 change = repo.changelog.read(node)
1122 1124
1125 if opts['switch_parent']:
1126 parents.reverse()
1123 fp = make_file(repo, repo.changelog, opts['output'], 1127 fp = make_file(repo, repo.changelog, opts['output'],
1124 node=node, total=total, seqno=seqno, 1128 node=node, total=total, seqno=seqno,
1125 revwidth=revwidth) 1129 revwidth=revwidth)
1126 if fp != sys.stdout: 1130 if fp != sys.stdout:
1127 ui.note("%s\n" % fp.name) 1131 ui.note("%s\n" % fp.name)
1128 1132
1129 fp.write("# HG changeset patch\n") 1133 fp.write("# HG changeset patch\n")
1130 fp.write("# User %s\n" % change[1]) 1134 fp.write("# User %s\n" % change[1])
1131 fp.write("# Node ID %s\n" % hex(node)) 1135 fp.write("# Node ID %s\n" % hex(node))
1132 fp.write("# Parent %s\n" % hex(prev)) 1136 fp.write("# Parent %s\n" % hex(prev))
1133 if other != nullid: 1137 if len(parents) > 1:
1134 fp.write("# Parent %s\n" % hex(other)) 1138 fp.write("# Parent %s\n" % hex(parents[1]))
1135 fp.write(change[4].rstrip()) 1139 fp.write(change[4].rstrip())
1136 fp.write("\n\n") 1140 fp.write("\n\n")
1137 1141
1138 dodiff(fp, ui, repo, prev, node, text=opts['text']) 1142 dodiff(fp, ui, repo, prev, node, text=opts['text'])
1139 if fp != sys.stdout: 1143 if fp != sys.stdout:
1160 %r zero-padded changeset revision number 1164 %r zero-padded changeset revision number
1161 1165
1162 Without the -a option, export will avoid generating diffs of files 1166 Without the -a option, export will avoid generating diffs of files
1163 it detects as binary. With -a, export will generate a diff anyway, 1167 it detects as binary. With -a, export will generate a diff anyway,
1164 probably with undesirable results. 1168 probably with undesirable results.
1169
1170 With the --switch-parent option, the diff will be against the second
1171 parent. It can be useful to review a merge.
1165 """ 1172 """
1166 if not changesets: 1173 if not changesets:
1167 raise util.Abort(_("export requires at least one changeset")) 1174 raise util.Abort(_("export requires at least one changeset"))
1168 seqno = 0 1175 seqno = 0
1169 revs = list(revrange(ui, repo, changesets)) 1176 revs = list(revrange(ui, repo, changesets))
1279 counts[change] += 1 1286 counts[change] += 1
1280 return counts['+'], counts['-'] 1287 return counts['+'], counts['-']
1281 1288
1282 fstate = {} 1289 fstate = {}
1283 skip = {} 1290 skip = {}
1284 changeiter, getchange = walkchangerevs(ui, repo, pats, opts) 1291 changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts)
1285 count = 0 1292 count = 0
1286 incrementing = False 1293 incrementing = False
1287 for st, rev, fns in changeiter: 1294 for st, rev, fns in changeiter:
1288 if st == 'window': 1295 if st == 'window':
1289 incrementing = rev 1296 incrementing = rev
1542 def debug(self, *args): 1549 def debug(self, *args):
1543 if self.debugflag: 1550 if self.debugflag:
1544 self.write(*args) 1551 self.write(*args)
1545 def __getattr__(self, key): 1552 def __getattr__(self, key):
1546 return getattr(self.ui, key) 1553 return getattr(self.ui, key)
1547 changeiter, getchange = walkchangerevs(ui, repo, pats, opts) 1554 changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts)
1548 for st, rev, fns in changeiter: 1555 for st, rev, fns in changeiter:
1549 if st == 'window': 1556 if st == 'window':
1550 du = dui(ui) 1557 du = dui(ui)
1551 elif st == 'add': 1558 elif st == 'add':
1552 du.bump(rev) 1559 du.bump(rev)
1558 if opts['only_merges'] and len(parents) != 2: 1565 if opts['only_merges'] and len(parents) != 2:
1559 continue 1566 continue
1560 1567
1561 br = None 1568 br = None
1562 if opts['keyword']: 1569 if opts['keyword']:
1563 changes = repo.changelog.read(repo.changelog.node(rev)) 1570 changes = getchange(rev)
1564 miss = 0 1571 miss = 0
1565 for k in [kw.lower() for kw in opts['keyword']]: 1572 for k in [kw.lower() for kw in opts['keyword']]:
1566 if not (k in changes[1].lower() or 1573 if not (k in changes[1].lower() or
1567 k in changes[4].lower() or 1574 k in changes[4].lower() or
1568 k in " ".join(changes[3][:20]).lower()): 1575 k in " ".join(changes[3][:20]).lower()):
1575 br = repo.branchlookup([repo.changelog.node(rev)]) 1582 br = repo.branchlookup([repo.changelog.node(rev)])
1576 1583
1577 show_changeset(du, repo, rev, brinfo=br) 1584 show_changeset(du, repo, rev, brinfo=br)
1578 if opts['patch']: 1585 if opts['patch']:
1579 prev = (parents and parents[0]) or nullid 1586 prev = (parents and parents[0]) or nullid
1580 dodiff(du, du, repo, prev, changenode, fns) 1587 dodiff(du, du, repo, prev, changenode, match=matchfn)
1581 du.write("\n\n") 1588 du.write("\n\n")
1582 elif st == 'iter': 1589 elif st == 'iter':
1583 for args in du.hunk[rev]: 1590 for args in du.hunk[rev]:
1584 ui.write(*args) 1591 ui.write(*args)
1585 1592
2120 a change is visible for pull by other users, undoing it locally is 2127 a change is visible for pull by other users, undoing it locally is
2121 ineffective. 2128 ineffective.
2122 """ 2129 """
2123 repo.undo() 2130 repo.undo()
2124 2131
2125 def update(ui, repo, node=None, merge=False, clean=False, branch=None): 2132 def update(ui, repo, node=None, merge=False, clean=False, force=None,
2133 branch=None):
2126 """update or merge working directory 2134 """update or merge working directory
2127 2135
2128 Update the working directory to the specified revision. 2136 Update the working directory to the specified revision.
2129 2137
2130 If there are no outstanding changes in the working directory and 2138 If there are no outstanding changes in the working directory and
2157 else: 2165 else:
2158 ui.warn(_("branch %s not found\n") % (branch)) 2166 ui.warn(_("branch %s not found\n") % (branch))
2159 return 1 2167 return 1
2160 else: 2168 else:
2161 node = node and repo.lookup(node) or repo.changelog.tip() 2169 node = node and repo.lookup(node) or repo.changelog.tip()
2162 return repo.update(node, allow=merge, force=clean) 2170 return repo.update(node, allow=merge, force=clean, forcemerge=force)
2163 2171
2164 def verify(ui, repo): 2172 def verify(ui, repo):
2165 """verify the integrity of the repository 2173 """verify the integrity of the repository
2166 2174
2167 Verify the integrity of the current repository. 2175 Verify the integrity of the current repository.
2254 ('X', 'exclude', [], _('exclude names matching the given patterns'))], 2262 ('X', 'exclude', [], _('exclude names matching the given patterns'))],
2255 _('hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...')), 2263 _('hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...')),
2256 "^export": 2264 "^export":
2257 (export, 2265 (export,
2258 [('o', 'output', "", _('print output to file with formatted name')), 2266 [('o', 'output', "", _('print output to file with formatted name')),
2259 ('a', 'text', None, _('treat all files as text'))], 2267 ('a', 'text', None, _('treat all files as text')),
2268 ('', 'switch-parent', None, _('diff against the second parent'))],
2260 "hg export [-a] [-o OUTFILE] REV..."), 2269 "hg export [-a] [-o OUTFILE] REV..."),
2261 "forget": 2270 "forget":
2262 (forget, 2271 (forget,
2263 [('I', 'include', [], _('include names matching the given patterns')), 2272 [('I', 'include', [], _('include names matching the given patterns')),
2264 ('X', 'exclude', [], _('exclude names matching the given patterns'))], 2273 ('X', 'exclude', [], _('exclude names matching the given patterns'))],
2402 "undo": (undo, [], _('hg undo')), 2411 "undo": (undo, [], _('hg undo')),
2403 "^update|up|checkout|co": 2412 "^update|up|checkout|co":
2404 (update, 2413 (update,
2405 [('b', 'branch', "", _('checkout the head of a specific branch')), 2414 [('b', 'branch', "", _('checkout the head of a specific branch')),
2406 ('m', 'merge', None, _('allow merging of branches')), 2415 ('m', 'merge', None, _('allow merging of branches')),
2407 ('C', 'clean', None, _('overwrite locally modified files'))], 2416 ('C', 'clean', None, _('overwrite locally modified files')),
2408 _('hg update [-b TAG] [-m] [-C] [REV]')), 2417 ('f', 'force', None, _('force a merge with outstanding changes'))],
2418 _('hg update [-b TAG] [-m] [-C] [-f] [REV]')),
2409 "verify": (verify, [], _('hg verify')), 2419 "verify": (verify, [], _('hg verify')),
2410 "version": (show_version, [], _('hg version')), 2420 "version": (show_version, [], _('hg version')),
2411 } 2421 }
2412 2422
2413 globalopts = [ 2423 globalopts = [