8 from __future__ import absolute_import |
8 from __future__ import absolute_import |
9 |
9 |
10 from mercurial.i18n import _ |
10 from mercurial.i18n import _ |
11 from mercurial import ( |
11 from mercurial import ( |
12 commands, |
12 commands, |
|
13 error, |
13 extensions, |
14 extensions, |
14 localrepo, |
15 localrepo, |
15 repository, |
16 repository, |
16 ) |
17 ) |
17 |
18 |
18 def clonecommand(orig, ui, repo, *args, **kwargs): |
19 def clonecommand(orig, ui, repo, *args, **kwargs): |
19 if kwargs.get(r'include') or kwargs.get(r'exclude'): |
20 if kwargs.get(r'include') or kwargs.get(r'exclude'): |
20 kwargs[r'narrow'] = True |
21 kwargs[r'narrow'] = True |
|
22 |
|
23 if kwargs.get(r'depth'): |
|
24 try: |
|
25 kwargs[r'depth'] = int(kwargs[r'depth']) |
|
26 except ValueError: |
|
27 raise error.Abort(_('--depth must be an integer')) |
21 |
28 |
22 return orig(ui, repo, *args, **kwargs) |
29 return orig(ui, repo, *args, **kwargs) |
23 |
30 |
24 def featuresetup(ui, features): |
31 def featuresetup(ui, features): |
25 features.add(repository.NARROW_REQUIREMENT) |
32 features.add(repository.NARROW_REQUIREMENT) |
26 |
33 |
27 def extsetup(ui): |
34 def extsetup(ui): |
28 entry = extensions.wrapcommand(commands.table, 'clone', clonecommand) |
35 entry = extensions.wrapcommand(commands.table, 'clone', clonecommand) |
29 |
36 |
30 hasinclude = any(x[1] == 'include' for x in entry[1]) |
37 hasinclude = any(x[1] == 'include' for x in entry[1]) |
|
38 hasdepth = any(x[1] == 'depth' for x in entry[1]) |
31 |
39 |
32 if not hasinclude: |
40 if not hasinclude: |
33 entry[1].append(('', 'include', [], |
41 entry[1].append(('', 'include', [], |
34 _('pattern of file/directory to clone'))) |
42 _('pattern of file/directory to clone'))) |
35 entry[1].append(('', 'exclude', [], |
43 entry[1].append(('', 'exclude', [], |
36 _('pattern of file/directory to not clone'))) |
44 _('pattern of file/directory to not clone'))) |
37 |
45 |
|
46 if not hasdepth: |
|
47 entry[1].append(('', 'depth', '', |
|
48 _('ancestry depth of changesets to fetch'))) |
|
49 |
38 localrepo.featuresetupfuncs.add(featuresetup) |
50 localrepo.featuresetupfuncs.add(featuresetup) |