Show More
@@ -183,6 +183,34 b' import [-p <n> -b <base> -q] <patches>::' | |||||
183 | init:: |
|
183 | init:: | |
184 | Initialize a new repository in the current directory. |
|
184 | Initialize a new repository in the current directory. | |
185 |
|
185 | |||
|
186 | locate [options] [patterns]:: | |||
|
187 | Print all files under Mercurial control whose names or paths match | |||
|
188 | the given patterns. | |||
|
189 | ||||
|
190 | Patterns are shell-style globs. To restrict searches to specific | |||
|
191 | directories, use the "-i <pat>" option. To eliminate particular | |||
|
192 | directories from searching, use the "-x <pat>" option. | |||
|
193 | ||||
|
194 | This command searches the current directory and its | |||
|
195 | subdirectories. To search an entire repository, move to the root | |||
|
196 | of the repository. | |||
|
197 | ||||
|
198 | If no patterns are given to match, this command prints all file | |||
|
199 | names. | |||
|
200 | ||||
|
201 | If you want to feed the output of this command into the "xargs" | |||
|
202 | command, use the "-0" option to both this command and "xargs". | |||
|
203 | This will avoid the problem of "xargs" treating single filenames | |||
|
204 | that contain white space as multiple file names. | |||
|
205 | ||||
|
206 | options: | |||
|
207 | ||||
|
208 | -0, --print0 end filenames with NUL, for use with xargs | |||
|
209 | -f, --fullpath print complete paths from the filesystem root | |||
|
210 | -i, --include <pat> include directories matching the given globs | |||
|
211 | -r, --rev <rev> search the repository as it stood at rev | |||
|
212 | -x, --exclude <pat> exclude directories matching the given globs | |||
|
213 | ||||
186 | log [-r revision ...] [-p] [file]:: |
|
214 | log [-r revision ...] [-p] [file]:: | |
187 | Print the revision history of the specified file or the entire project. |
|
215 | Print the revision history of the specified file or the entire project. | |
188 |
|
216 |
@@ -8,7 +8,7 b'' | |||||
8 | from demandload import * |
|
8 | from demandload import * | |
9 | demandload(globals(), "os re sys signal") |
|
9 | demandload(globals(), "os re sys signal") | |
10 | demandload(globals(), "fancyopts ui hg util") |
|
10 | demandload(globals(), "fancyopts ui hg util") | |
11 | demandload(globals(), "hgweb mdiff random signal time traceback") |
|
11 | demandload(globals(), "fnmatch hgweb mdiff random signal time traceback") | |
12 | demandload(globals(), "errno socket version struct") |
|
12 | demandload(globals(), "errno socket version struct") | |
13 |
|
13 | |||
14 | class UnknownCommand(Exception): pass |
|
14 | class UnknownCommand(Exception): pass | |
@@ -631,6 +631,46 b' def init(ui, source=None):' | |||||
631 | sys.exit(1) |
|
631 | sys.exit(1) | |
632 | repo = hg.repository(ui, ".", create=1) |
|
632 | repo = hg.repository(ui, ".", create=1) | |
633 |
|
633 | |||
|
634 | def locate(ui, repo, *pats, **opts): | |||
|
635 | """locate files matching specific patterns""" | |||
|
636 | if [p for p in pats if os.sep in p]: | |||
|
637 | ui.warn("error: patterns may not contain '%s'\n" % os.sep) | |||
|
638 | ui.warn("use '-i <dir>' instead\n") | |||
|
639 | sys.exit(1) | |||
|
640 | def compile(pats, head = '^', tail = os.sep, on_empty = True): | |||
|
641 | if not pats: | |||
|
642 | class c: | |||
|
643 | def match(self, x): return on_empty | |||
|
644 | return c() | |||
|
645 | regexp = r'%s(?:%s)%s' % ( | |||
|
646 | head, | |||
|
647 | '|'.join([fnmatch.translate(os.path.normpath(os.path.normcase(p)))[:-1] | |||
|
648 | for p in pats]), | |||
|
649 | tail) | |||
|
650 | print regexp | |||
|
651 | return re.compile(regexp) | |||
|
652 | exclude = compile(opts['exclude'], on_empty = False) | |||
|
653 | include = compile(opts['include']) | |||
|
654 | pat = compile([os.path.normcase(p) for p in pats], head = '', tail = '$') | |||
|
655 | end = '\n' | |||
|
656 | if opts['print0']: end = '\0' | |||
|
657 | if opts['rev']: node = repo.manifest.lookup(opts['rev']) | |||
|
658 | else: node = repo.manifest.tip() | |||
|
659 | manifest = repo.manifest.read(node) | |||
|
660 | cwd = repo.getcwd() | |||
|
661 | cwd_plus = cwd and (cwd + os.sep) | |||
|
662 | found = [] | |||
|
663 | for f in manifest: | |||
|
664 | f = os.path.normcase(f) | |||
|
665 | if exclude.match(f) or not(include.match(f) and | |||
|
666 | f.startswith(cwd_plus) and | |||
|
667 | pat.match(os.path.basename(f))): continue | |||
|
668 | if opts['fullpath']: f = os.path.join(repo.root, f) | |||
|
669 | elif cwd: f = f[len(cwd_plus):] | |||
|
670 | found.append(f) | |||
|
671 | found.sort() | |||
|
672 | for f in found: ui.write(f, end) | |||
|
673 | ||||
634 | def log(ui, repo, f=None, **opts): |
|
674 | def log(ui, repo, f=None, **opts): | |
635 | """show the revision history of the repository or a single file""" |
|
675 | """show the revision history of the repository or a single file""" | |
636 | if f: |
|
676 | if f: | |
@@ -1037,6 +1077,13 b' table = {' | |||||
1037 | ('b', 'base', "", 'base path')], |
|
1077 | ('b', 'base', "", 'base path')], | |
1038 | "hg import [options] <patches>"), |
|
1078 | "hg import [options] <patches>"), | |
1039 | "^init": (init, [], 'hg init'), |
|
1079 | "^init": (init, [], 'hg init'), | |
|
1080 | "locate": (locate, | |||
|
1081 | [('0', 'print0', None, 'end records with NUL'), | |||
|
1082 | ('f', 'fullpath', None, 'print complete paths'), | |||
|
1083 | ('i', 'include', [], 'include path in search'), | |||
|
1084 | ('r', 'rev', '', 'revision'), | |||
|
1085 | ('x', 'exclude', [], 'exclude path from search')], | |||
|
1086 | 'hg locate [options] [files]'), | |||
1040 | "^log|history": (log, |
|
1087 | "^log|history": (log, | |
1041 | [('r', 'rev', [], 'revision'), |
|
1088 | [('r', 'rev', [], 'revision'), | |
1042 | ('p', 'patch', None, 'show patch')], |
|
1089 | ('p', 'patch', None, 'show patch')], |
@@ -508,6 +508,11 b' class localrepository:' | |||||
508 | if f[0] == '/': f = f[1:] |
|
508 | if f[0] == '/': f = f[1:] | |
509 | return filelog(self.opener, f) |
|
509 | return filelog(self.opener, f) | |
510 |
|
510 | |||
|
511 | def getcwd(self): | |||
|
512 | cwd = os.getcwd() | |||
|
513 | if cwd == self.root: return '' | |||
|
514 | return cwd[len(self.root) + 1:] | |||
|
515 | ||||
511 | def wfile(self, f, mode='r'): |
|
516 | def wfile(self, f, mode='r'): | |
512 | return self.wopener(f, mode) |
|
517 | return self.wopener(f, mode) | |
513 |
|
518 |
General Comments 0
You need to be logged in to leave comments.
Login now