##// END OF EJS Templates
Switch cat command to use walk code....
Bryan O'Sullivan -
r1254:e6560042 default
parent child Browse files
Show More
@@ -121,10 +121,23 b' bundle <file> <other>::'
121 Unlike import/export, this exactly preserves all changeset
121 Unlike import/export, this exactly preserves all changeset
122 contents including permissions, rename data, and revision history.
122 contents including permissions, rename data, and revision history.
123
123
124 cat <file> [revision]::
124 cat [options] <file ...>::
125 Output to stdout the given revision for the specified file.
125 Print the specified files as they were at the given revision.
126 If no revision is given then the tip is used.
127
128 Output may be to a file, in which case the name of the file is
129 given using a format string. The formatting rules are the same as
130 for the export command, with the following additions:
126
131
127 If no revision is given then the tip is used.
132 %s basename of file being printed
133 %d dirname of file being printed, or '.' if in repo root
134 %p root-relative path name of file being printed
135
136 options:
137 -I, --include <pat> include names matching the given patterns
138 -X, --exclude <pat> exclude names matching the given patterns
139 -o, --output <filespec> print output to file with formatted name
140 -r, --rev <rev> print the given revision
128
141
129 clone [-U] <source> [dest]::
142 clone [-U] <source> [dest]::
130 Create a copy of an existing repository in a new directory.
143 Create a copy of an existing repository in a new directory.
@@ -176,9 +189,11 b' copy <source ...> <dest>::'
176 This command takes effect in the next commit.
189 This command takes effect in the next commit.
177
190
178 Options:
191 Options:
179 -A, --after record a copy that has already occurred
192 -A, --after record a copy that has already occurred
180 -f, --force forcibly copy over an existing managed file
193 -I, --include <pat> include names matching the given patterns
181 -p, --parents append source path to dest
194 -X, --exclude <pat> exclude names matching the given patterns
195 -f, --force forcibly copy over an existing managed file
196 -p, --parents append source path to dest
182
197
183 aliases: cp
198 aliases: cp
184
199
@@ -226,7 +241,7 b' export [-o filespec] [revision] ...::'
226
241
227 options:
242 options:
228 -a, --text treat all files as text
243 -a, --text treat all files as text
229 -o, --output <filespec> print output to file with formatted named
244 -o, --output <filespec> print output to file with formatted name
230
245
231 forget [options] [files]::
246 forget [options] [files]::
232 Undo an 'hg add' scheduled for the next commit.
247 Undo an 'hg add' scheduled for the next commit.
@@ -194,7 +194,7 b' def revrange(ui, repo, revs, revlog=None'
194 yield str(rev)
194 yield str(rev)
195
195
196 def make_filename(repo, r, pat, node=None,
196 def make_filename(repo, r, pat, node=None,
197 total=None, seqno=None, revwidth=None):
197 total=None, seqno=None, revwidth=None, pathname=None):
198 node_expander = {
198 node_expander = {
199 'H': lambda: hex(node),
199 'H': lambda: hex(node),
200 'R': lambda: str(r.rev(node)),
200 'R': lambda: str(r.rev(node)),
@@ -216,6 +216,10 b' def make_filename(repo, r, pat, node=Non'
216 expander['n'] = lambda: str(seqno)
216 expander['n'] = lambda: str(seqno)
217 if total is not None and seqno is not None:
217 if total is not None and seqno is not None:
218 expander['n'] = lambda:str(seqno).zfill(len(str(total)))
218 expander['n'] = lambda:str(seqno).zfill(len(str(total)))
219 if pathname is not None:
220 expander['s'] = lambda: os.path.basename(pathname)
221 expander['d'] = lambda: os.path.dirname(pathname) or '.'
222 expander['p'] = lambda: pathname
219
223
220 newname = []
224 newname = []
221 patlen = len(pat)
225 patlen = len(pat)
@@ -234,14 +238,15 b' def make_filename(repo, r, pat, node=Non'
234 inst.args[0])
238 inst.args[0])
235
239
236 def make_file(repo, r, pat, node=None,
240 def make_file(repo, r, pat, node=None,
237 total=None, seqno=None, revwidth=None, mode='wb'):
241 total=None, seqno=None, revwidth=None, mode='wb', pathname=None):
238 if not pat or pat == '-':
242 if not pat or pat == '-':
239 return 'w' in mode and sys.stdout or sys.stdin
243 return 'w' in mode and sys.stdout or sys.stdin
240 if hasattr(pat, 'write') and 'w' in mode:
244 if hasattr(pat, 'write') and 'w' in mode:
241 return pat
245 return pat
242 if hasattr(pat, 'read') and 'r' in mode:
246 if hasattr(pat, 'read') and 'r' in mode:
243 return pat
247 return pat
244 return open(make_filename(repo, r, pat, node, total, seqno, revwidth),
248 return open(make_filename(repo, r, pat, node, total, seqno, revwidth,
249 pathname),
245 mode)
250 mode)
246
251
247 def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always,
252 def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always,
@@ -569,25 +574,26 b' def bundle(ui, repo, fname, dest="defaul'
569 except:
574 except:
570 os.unlink(fname)
575 os.unlink(fname)
571
576
572 def cat(ui, repo, file1, rev=None, **opts):
577 def cat(ui, repo, file1, *pats, **opts):
573 """output the latest or given revision of a file"""
578 """output the latest or given revisions of files"""
574 r = repo.file(relpath(repo, [file1])[0])
579 mf = {}
575 if rev:
580 if opts['rev']:
576 try:
581 change = repo.changelog.read(repo.lookup(opts['rev']))
577 # assume all revision numbers are for changesets
582 mf = repo.manifest.read(change[0])
578 n = repo.lookup(rev)
583 for src, abs, rel, exact in walk(repo, (file1,) + pats, opts):
579 change = repo.changelog.read(n)
584 r = repo.file(abs)
580 m = repo.manifest.read(change[0])
585 if opts['rev']:
581 n = m[relpath(repo, [file1])[0]]
582 except (hg.RepoError, KeyError):
583 try:
586 try:
584 n = r.lookup(rev)
587 n = mf[abs]
585 except KeyError, inst:
588 except (hg.RepoError, KeyError):
586 raise util.Abort('cannot find file %s in rev %s', file1, rev)
589 try:
587 else:
590 n = r.lookup(rev)
588 n = r.tip()
591 except KeyError, inst:
589 fp = make_file(repo, r, opts['output'], node=n)
592 raise util.Abort('cannot find file %s in rev %s', rel, rev)
590 fp.write(r.read(n))
593 else:
594 n = r.tip()
595 fp = make_file(repo, r, opts['output'], node=n, pathname=abs)
596 fp.write(r.read(n))
591
597
592 def clone(ui, source, dest=None, **opts):
598 def clone(ui, source, dest=None, **opts):
593 """make a copy of an existing repository"""
599 """make a copy of an existing repository"""
@@ -1765,8 +1771,11 b' table = {'
1765 'hg bundle FILE DEST'),
1771 'hg bundle FILE DEST'),
1766 "cat":
1772 "cat":
1767 (cat,
1773 (cat,
1768 [('o', 'output', "", 'output to file')],
1774 [('I', 'include', [], 'include path in search'),
1769 'hg cat [-o OUTFILE] FILE [REV]'),
1775 ('X', 'exclude', [], 'exclude path from search'),
1776 ('o', 'output', "", 'output to file'),
1777 ('r', 'rev', '', 'revision')],
1778 'hg cat [OPTION]... FILE...'),
1770 "^clone":
1779 "^clone":
1771 (clone,
1780 (clone,
1772 [('U', 'noupdate', None, 'skip update after cloning'),
1781 [('U', 'noupdate', None, 'skip update after cloning'),
@@ -40,7 +40,7 b' list of commands (use "hg help -v" to sh'
40 addremove add all new files, delete all missing files
40 addremove add all new files, delete all missing files
41 annotate show changeset information per file line
41 annotate show changeset information per file line
42 bundle create a changegroup file
42 bundle create a changegroup file
43 cat output the latest or given revision of a file
43 cat output the latest or given revisions of files
44 clone make a copy of an existing repository
44 clone make a copy of an existing repository
45 commit commit the specified files or all outstanding changes
45 commit commit the specified files or all outstanding changes
46 copy mark files as copied for the next commit
46 copy mark files as copied for the next commit
@@ -82,7 +82,7 b' list of commands (use "hg help -v" to sh'
82 addremove add all new files, delete all missing files
82 addremove add all new files, delete all missing files
83 annotate show changeset information per file line
83 annotate show changeset information per file line
84 bundle create a changegroup file
84 bundle create a changegroup file
85 cat output the latest or given revision of a file
85 cat output the latest or given revisions of files
86 clone make a copy of an existing repository
86 clone make a copy of an existing repository
87 commit commit the specified files or all outstanding changes
87 commit commit the specified files or all outstanding changes
88 copy mark files as copied for the next commit
88 copy mark files as copied for the next commit
General Comments 0
You need to be logged in to leave comments. Login now