comparison mercurial/commands.py @ 1737:2c9872a4f3fd

Merge with crew
author Matt Mackall <mpm@selenic.com>
date Fri, 17 Feb 2006 17:39:05 -0600
parents 50de0887bbcd
children 57de7e1a81d2 f95654385065
comparison
equal deleted inserted replaced
1716:ef8cd889a78b 1737:2c9872a4f3fd
259 return open(make_filename(repo, r, pat, node, total, seqno, revwidth, 259 return open(make_filename(repo, r, pat, node, total, seqno, revwidth,
260 pathname), 260 pathname),
261 mode) 261 mode)
262 262
263 def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always, 263 def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always,
264 changes=None, text=False): 264 changes=None, text=False, opts={}):
265 if not changes: 265 if not changes:
266 changes = repo.changes(node1, node2, files, match=match) 266 changes = repo.changes(node1, node2, files, match=match)
267 modified, added, removed, deleted, unknown = changes 267 modified, added, removed, deleted, unknown = changes
268 if files: 268 if files:
269 modified, added, removed = map(lambda x: filterfiles(files, x), 269 modified, added, removed = map(lambda x: filterfiles(files, x),
294 change = repo.changelog.read(node1) 294 change = repo.changelog.read(node1)
295 mmap = repo.manifest.read(change[0]) 295 mmap = repo.manifest.read(change[0])
296 date1 = util.datestr(change[2]) 296 date1 = util.datestr(change[2])
297 297
298 diffopts = ui.diffopts() 298 diffopts = ui.diffopts()
299 showfunc = diffopts['showfunc'] 299 showfunc = opts.get('show_function') or diffopts['showfunc']
300 ignorews = diffopts['ignorews'] 300 ignorews = opts.get('ignore_all_space') or diffopts['ignorews']
301 for f in modified: 301 for f in modified:
302 to = None 302 to = None
303 if f in mmap: 303 if f in mmap:
304 to = repo.file(f).read(mmap[f]) 304 to = repo.file(f).read(mmap[f])
305 tn = read(f) 305 tn = read(f)
620 """ 620 """
621 f = open(fname, "wb") 621 f = open(fname, "wb")
622 dest = ui.expandpath(dest, repo.root) 622 dest = ui.expandpath(dest, repo.root)
623 other = hg.repository(ui, dest) 623 other = hg.repository(ui, dest)
624 o = repo.findoutgoing(other) 624 o = repo.findoutgoing(other)
625 cg = repo.changegroup(o) 625 cg = repo.changegroup(o, 'bundle')
626 626
627 try: 627 try:
628 f.write("HG10") 628 f.write("HG10")
629 z = bz2.BZ2Compressor(9) 629 z = bz2.BZ2Compressor(9)
630 while 1: 630 while 1:
1138 raise util.Abort(_("too many revisions to diff")) 1138 raise util.Abort(_("too many revisions to diff"))
1139 1139
1140 fns, matchfn, anypats = matchpats(repo, pats, opts) 1140 fns, matchfn, anypats = matchpats(repo, pats, opts)
1141 1141
1142 dodiff(sys.stdout, ui, repo, node1, node2, fns, match=matchfn, 1142 dodiff(sys.stdout, ui, repo, node1, node2, fns, match=matchfn,
1143 text=opts['text']) 1143 text=opts['text'], opts=opts)
1144 1144
1145 def doexport(ui, repo, changeset, seqno, total, revwidth, opts): 1145 def doexport(ui, repo, changeset, seqno, total, revwidth, opts):
1146 node = repo.lookup(changeset) 1146 node = repo.lookup(changeset)
1147 parents = [p for p in repo.changelog.parents(node) if p != nullid] 1147 parents = [p for p in repo.changelog.parents(node) if p != nullid]
1148 if opts['switch_parent']: 1148 if opts['switch_parent']:
1679 if opts['patch']: 1679 if opts['patch']:
1680 prev = (parents and parents[0]) or nullid 1680 prev = (parents and parents[0]) or nullid
1681 dodiff(ui, ui, repo, prev, n) 1681 dodiff(ui, ui, repo, prev, n)
1682 ui.write("\n") 1682 ui.write("\n")
1683 1683
1684 def parents(ui, repo, rev=None): 1684 def parents(ui, repo, rev=None, branch=None):
1685 """show the parents of the working dir or revision 1685 """show the parents of the working dir or revision
1686 1686
1687 Print the working directory's parent revisions. 1687 Print the working directory's parent revisions.
1688 """ 1688 """
1689 if rev: 1689 if rev:
1690 p = repo.changelog.parents(repo.lookup(rev)) 1690 p = repo.changelog.parents(repo.lookup(rev))
1691 else: 1691 else:
1692 p = repo.dirstate.parents() 1692 p = repo.dirstate.parents()
1693 1693
1694 br = None
1695 if branch is not None:
1696 br = repo.branchlookup(p)
1694 for n in p: 1697 for n in p:
1695 if n != nullid: 1698 if n != nullid:
1696 show_changeset(ui, repo, changenode=n) 1699 show_changeset(ui, repo, changenode=n, brinfo=br)
1697 1700
1698 def paths(ui, search=None): 1701 def paths(ui, search=None):
1699 """show definition of symbolic path names 1702 """show definition of symbolic path names
1700 1703
1701 Show definition of symbolic path name NAME. If no name is given, show 1704 Show definition of symbolic path name NAME. If no name is given, show
1994 elif cmd == "changegroup": 1997 elif cmd == "changegroup":
1995 nodes = [] 1998 nodes = []
1996 arg, roots = getarg() 1999 arg, roots = getarg()
1997 nodes = map(bin, roots.split(" ")) 2000 nodes = map(bin, roots.split(" "))
1998 2001
1999 cg = repo.changegroup(nodes) 2002 cg = repo.changegroup(nodes, 'serve')
2000 while 1: 2003 while 1:
2001 d = cg.read(4096) 2004 d = cg.read(4096)
2002 if not d: 2005 if not d:
2003 break 2006 break
2004 fout.write(d) 2007 fout.write(d)
2111 disallowed = (revrangesep, '\r', '\n') 2114 disallowed = (revrangesep, '\r', '\n')
2112 for c in disallowed: 2115 for c in disallowed:
2113 if name.find(c) >= 0: 2116 if name.find(c) >= 0:
2114 raise util.Abort(_("%s cannot be used in a tag name") % repr(c)) 2117 raise util.Abort(_("%s cannot be used in a tag name") % repr(c))
2115 2118
2119 repo.hook('pretag', throw=True, node=r, tag=name,
2120 local=int(not not opts['local']))
2121
2116 if opts['local']: 2122 if opts['local']:
2117 repo.opener("localtags", "a").write("%s %s\n" % (r, name)) 2123 repo.opener("localtags", "a").write("%s %s\n" % (r, name))
2124 repo.hook('tag', node=r, tag=name, local=1)
2118 return 2125 return
2119 2126
2120 for x in repo.changes(): 2127 for x in repo.changes():
2121 if ".hgtags" in x: 2128 if ".hgtags" in x:
2122 raise util.Abort(_("working copy of .hgtags is changed " 2129 raise util.Abort(_("working copy of .hgtags is changed "
2128 2135
2129 message = (opts['message'] or 2136 message = (opts['message'] or
2130 _("Added tag %s for changeset %s") % (name, r)) 2137 _("Added tag %s for changeset %s") % (name, r))
2131 try: 2138 try:
2132 repo.commit([".hgtags"], message, opts['user'], opts['date']) 2139 repo.commit([".hgtags"], message, opts['user'], opts['date'])
2140 repo.hook('tag', node=r, tag=name, local=0)
2133 except ValueError, inst: 2141 except ValueError, inst:
2134 raise util.Abort(str(inst)) 2142 raise util.Abort(str(inst))
2135 2143
2136 def tags(ui, repo): 2144 def tags(ui, repo):
2137 """list repository tags 2145 """list repository tags
2148 r = "%5d:%s" % (repo.changelog.rev(n), hex(n)) 2156 r = "%5d:%s" % (repo.changelog.rev(n), hex(n))
2149 except KeyError: 2157 except KeyError:
2150 r = " ?:?" 2158 r = " ?:?"
2151 ui.write("%-30s %s\n" % (t, r)) 2159 ui.write("%-30s %s\n" % (t, r))
2152 2160
2153 def tip(ui, repo): 2161 def tip(ui, repo, **opts):
2154 """show the tip revision 2162 """show the tip revision
2155 2163
2156 Show the tip revision. 2164 Show the tip revision.
2157 """ 2165 """
2158 n = repo.changelog.tip() 2166 n = repo.changelog.tip()
2159 show_changeset(ui, repo, changenode=n) 2167 show_changeset(ui, repo, changenode=n)
2168 if opts['patch']:
2169 dodiff(ui, ui, repo, repo.changelog.parents(n)[0], n)
2160 2170
2161 def unbundle(ui, repo, fname, **opts): 2171 def unbundle(ui, repo, fname, **opts):
2162 """apply a changegroup file 2172 """apply a changegroup file
2163 2173
2164 Apply a compressed changegroup file generated by the bundle 2174 Apply a compressed changegroup file generated by the bundle
2330 "^diff": 2340 "^diff":
2331 (diff, 2341 (diff,
2332 [('r', 'rev', [], _('revision')), 2342 [('r', 'rev', [], _('revision')),
2333 ('a', 'text', None, _('treat all files as text')), 2343 ('a', 'text', None, _('treat all files as text')),
2334 ('I', 'include', [], _('include names matching the given patterns')), 2344 ('I', 'include', [], _('include names matching the given patterns')),
2335 ('X', 'exclude', [], _('exclude names matching the given patterns'))], 2345 ('p', 'show-function', None,
2346 _('show which function each change is in')),
2347 ('w', 'ignore-all-space', None,
2348 _('ignore white space when comparing lines')),
2349 ('X', 'exclude', [],
2350 _('exclude names matching the given patterns'))],
2336 _('hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...')), 2351 _('hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...')),
2337 "^export": 2352 "^export":
2338 (export, 2353 (export,
2339 [('o', 'output', '', _('print output to file with formatted name')), 2354 [('o', 'output', '', _('print output to file with formatted name')),
2340 ('a', 'text', None, _('treat all files as text')), 2355 ('a', 'text', None, _('treat all files as text')),
2405 "outgoing|out": (outgoing, 2420 "outgoing|out": (outgoing,
2406 [('M', 'no-merges', None, _('do not show merges')), 2421 [('M', 'no-merges', None, _('do not show merges')),
2407 ('p', 'patch', None, _('show patch')), 2422 ('p', 'patch', None, _('show patch')),
2408 ('n', 'newest-first', None, _('show newest record first'))], 2423 ('n', 'newest-first', None, _('show newest record first'))],
2409 _('hg outgoing [-p] [-n] [-M] [DEST]')), 2424 _('hg outgoing [-p] [-n] [-M] [DEST]')),
2410 "^parents": (parents, [], _('hg parents [REV]')), 2425 "^parents":
2426 (parents,
2427 [('b', 'branch', None, _('show branches'))],
2428 _('hg parents [-b] [REV]')),
2411 "paths": (paths, [], _('hg paths [NAME]')), 2429 "paths": (paths, [], _('hg paths [NAME]')),
2412 "^pull": 2430 "^pull":
2413 (pull, 2431 (pull,
2414 [('u', 'update', None, 2432 [('u', 'update', None,
2415 _('update the working directory to tip after pull')), 2433 _('update the working directory to tip after pull')),
2488 ('d', 'date', '', _('record datecode as commit date')), 2506 ('d', 'date', '', _('record datecode as commit date')),
2489 ('u', 'user', '', _('record user as commiter')), 2507 ('u', 'user', '', _('record user as commiter')),
2490 ('r', 'rev', '', _('revision to tag'))], 2508 ('r', 'rev', '', _('revision to tag'))],
2491 _('hg tag [-r REV] [OPTION]... NAME')), 2509 _('hg tag [-r REV] [OPTION]... NAME')),
2492 "tags": (tags, [], _('hg tags')), 2510 "tags": (tags, [], _('hg tags')),
2493 "tip": (tip, [], _('hg tip')), 2511 "tip": (tip, [('p', 'patch', None, _('show patch'))], _('hg tip')),
2494 "unbundle": 2512 "unbundle":
2495 (unbundle, 2513 (unbundle,
2496 [('u', 'update', None, 2514 [('u', 'update', None,
2497 _('update the working directory to tip after unbundle'))], 2515 _('update the working directory to tip after unbundle'))],
2498 _('hg unbundle [-u] FILE')), 2516 _('hg unbundle [-u] FILE')),