Show More
@@ -0,0 +1,32 b'' | |||||
|
1 | import sys, os | |||
|
2 | import osutil | |||
|
3 | ||||
|
4 | def _rcfiles(path): | |||
|
5 | rcs = [os.path.join(path, 'hgrc')] | |||
|
6 | rcdir = os.path.join(path, 'hgrc.d') | |||
|
7 | try: | |||
|
8 | rcs.extend([os.path.join(rcdir, f) | |||
|
9 | for f, kind in osutil.listdir(rcdir) | |||
|
10 | if f.endswith(".rc")]) | |||
|
11 | except OSError: | |||
|
12 | pass | |||
|
13 | return rcs | |||
|
14 | ||||
|
15 | def systemrcpath(): | |||
|
16 | path = [] | |||
|
17 | if sys.platform == 'plan9': | |||
|
18 | root = 'lib/mercurial' | |||
|
19 | else: | |||
|
20 | root = 'etc/mercurial' | |||
|
21 | # old mod_python does not set sys.argv | |||
|
22 | if len(getattr(sys, 'argv', [])) > 0: | |||
|
23 | p = os.path.dirname(os.path.dirname(sys.argv[0])) | |||
|
24 | path.extend(_rcfiles(os.path.join(p, root))) | |||
|
25 | path.extend(_rcfiles('/' + root)) | |||
|
26 | return path | |||
|
27 | ||||
|
28 | def userrcpath(): | |||
|
29 | if sys.platform == 'plan9': | |||
|
30 | return [os.environ['home'] + '/lib/hgrc'] | |||
|
31 | else: | |||
|
32 | return [os.path.expanduser('~/.hgrc')] |
@@ -0,0 +1,45 b'' | |||||
|
1 | import os | |||
|
2 | import osutil | |||
|
3 | import _winreg | |||
|
4 | ||||
|
5 | def systemrcpath(): | |||
|
6 | '''return default os-specific hgrc search path''' | |||
|
7 | rcpath = [] | |||
|
8 | filename = util.executablepath() | |||
|
9 | # Use mercurial.ini found in directory with hg.exe | |||
|
10 | progrc = os.path.join(os.path.dirname(filename), 'mercurial.ini') | |||
|
11 | if os.path.isfile(progrc): | |||
|
12 | rcpath.append(progrc) | |||
|
13 | return rcpath | |||
|
14 | # Use hgrc.d found in directory with hg.exe | |||
|
15 | progrcd = os.path.join(os.path.dirname(filename), 'hgrc.d') | |||
|
16 | if os.path.isdir(progrcd): | |||
|
17 | for f, kind in osutil.listdir(progrcd): | |||
|
18 | if f.endswith('.rc'): | |||
|
19 | rcpath.append(os.path.join(progrcd, f)) | |||
|
20 | return rcpath | |||
|
21 | # else look for a system rcpath in the registry | |||
|
22 | value = util.lookupreg('SOFTWARE\\Mercurial', None, | |||
|
23 | _winreg.HKEY_LOCAL_MACHINE) | |||
|
24 | if not isinstance(value, str) or not value: | |||
|
25 | return rcpath | |||
|
26 | value = util.localpath(value) | |||
|
27 | for p in value.split(os.pathsep): | |||
|
28 | if p.lower().endswith('mercurial.ini'): | |||
|
29 | rcpath.append(p) | |||
|
30 | elif os.path.isdir(p): | |||
|
31 | for f, kind in osutil.listdir(p): | |||
|
32 | if f.endswith('.rc'): | |||
|
33 | rcpath.append(os.path.join(p, f)) | |||
|
34 | return rcpath | |||
|
35 | ||||
|
36 | def userrcpath(): | |||
|
37 | '''return os-specific hgrc search path to the user dir''' | |||
|
38 | home = os.path.expanduser('~') | |||
|
39 | path = [os.path.join(home, 'mercurial.ini'), | |||
|
40 | os.path.join(home, '.hgrc')] | |||
|
41 | userprofile = os.environ.get('USERPROFILE') | |||
|
42 | if userprofile: | |||
|
43 | path.append(os.path.join(userprofile, 'mercurial.ini')) | |||
|
44 | path.append(os.path.join(userprofile, '.hgrc')) | |||
|
45 | return path |
@@ -9,7 +9,15 b' from i18n import _' | |||||
9 | from mercurial.node import nullrev |
|
9 | from mercurial.node import nullrev | |
10 | import util, error, osutil, revset, similar, encoding, phases |
|
10 | import util, error, osutil, revset, similar, encoding, phases | |
11 | import match as matchmod |
|
11 | import match as matchmod | |
12 |
import os, errno, re, stat, |
|
12 | import os, errno, re, stat, glob | |
|
13 | ||||
|
14 | if os.name == 'nt': | |||
|
15 | import scmwindows as scmplatform | |||
|
16 | else: | |||
|
17 | import scmposix as scmplatform | |||
|
18 | ||||
|
19 | systemrcpath = scmplatform.systemrcpath | |||
|
20 | userrcpath = scmplatform.userrcpath | |||
13 |
|
21 | |||
14 | def nochangesfound(ui, repo, excluded=None): |
|
22 | def nochangesfound(ui, repo, excluded=None): | |
15 | '''Report no changes for push/pull, excluded is None or a list of |
|
23 | '''Report no changes for push/pull, excluded is None or a list of | |
@@ -531,84 +539,6 b' def rcpath():' | |||||
531 | _rcpath = osrcpath() |
|
539 | _rcpath = osrcpath() | |
532 | return _rcpath |
|
540 | return _rcpath | |
533 |
|
541 | |||
534 | if os.name != 'nt': |
|
|||
535 |
|
||||
536 | def rcfiles(path): |
|
|||
537 | rcs = [os.path.join(path, 'hgrc')] |
|
|||
538 | rcdir = os.path.join(path, 'hgrc.d') |
|
|||
539 | try: |
|
|||
540 | rcs.extend([os.path.join(rcdir, f) |
|
|||
541 | for f, kind in osutil.listdir(rcdir) |
|
|||
542 | if f.endswith(".rc")]) |
|
|||
543 | except OSError: |
|
|||
544 | pass |
|
|||
545 | return rcs |
|
|||
546 |
|
||||
547 | def systemrcpath(): |
|
|||
548 | path = [] |
|
|||
549 | if sys.platform == 'plan9': |
|
|||
550 | root = 'lib/mercurial' |
|
|||
551 | else: |
|
|||
552 | root = 'etc/mercurial' |
|
|||
553 | # old mod_python does not set sys.argv |
|
|||
554 | if len(getattr(sys, 'argv', [])) > 0: |
|
|||
555 | p = os.path.dirname(os.path.dirname(sys.argv[0])) |
|
|||
556 | path.extend(rcfiles(os.path.join(p, root))) |
|
|||
557 | path.extend(rcfiles('/' + root)) |
|
|||
558 | return path |
|
|||
559 |
|
||||
560 | def userrcpath(): |
|
|||
561 | if sys.platform == 'plan9': |
|
|||
562 | return [os.environ['home'] + '/lib/hgrc'] |
|
|||
563 | else: |
|
|||
564 | return [os.path.expanduser('~/.hgrc')] |
|
|||
565 |
|
||||
566 | else: |
|
|||
567 |
|
||||
568 | import _winreg |
|
|||
569 |
|
||||
570 | def systemrcpath(): |
|
|||
571 | '''return default os-specific hgrc search path''' |
|
|||
572 | rcpath = [] |
|
|||
573 | filename = util.executablepath() |
|
|||
574 | # Use mercurial.ini found in directory with hg.exe |
|
|||
575 | progrc = os.path.join(os.path.dirname(filename), 'mercurial.ini') |
|
|||
576 | if os.path.isfile(progrc): |
|
|||
577 | rcpath.append(progrc) |
|
|||
578 | return rcpath |
|
|||
579 | # Use hgrc.d found in directory with hg.exe |
|
|||
580 | progrcd = os.path.join(os.path.dirname(filename), 'hgrc.d') |
|
|||
581 | if os.path.isdir(progrcd): |
|
|||
582 | for f, kind in osutil.listdir(progrcd): |
|
|||
583 | if f.endswith('.rc'): |
|
|||
584 | rcpath.append(os.path.join(progrcd, f)) |
|
|||
585 | return rcpath |
|
|||
586 | # else look for a system rcpath in the registry |
|
|||
587 | value = util.lookupreg('SOFTWARE\\Mercurial', None, |
|
|||
588 | _winreg.HKEY_LOCAL_MACHINE) |
|
|||
589 | if not isinstance(value, str) or not value: |
|
|||
590 | return rcpath |
|
|||
591 | value = util.localpath(value) |
|
|||
592 | for p in value.split(os.pathsep): |
|
|||
593 | if p.lower().endswith('mercurial.ini'): |
|
|||
594 | rcpath.append(p) |
|
|||
595 | elif os.path.isdir(p): |
|
|||
596 | for f, kind in osutil.listdir(p): |
|
|||
597 | if f.endswith('.rc'): |
|
|||
598 | rcpath.append(os.path.join(p, f)) |
|
|||
599 | return rcpath |
|
|||
600 |
|
||||
601 | def userrcpath(): |
|
|||
602 | '''return os-specific hgrc search path to the user dir''' |
|
|||
603 | home = os.path.expanduser('~') |
|
|||
604 | path = [os.path.join(home, 'mercurial.ini'), |
|
|||
605 | os.path.join(home, '.hgrc')] |
|
|||
606 | userprofile = os.environ.get('USERPROFILE') |
|
|||
607 | if userprofile: |
|
|||
608 | path.append(os.path.join(userprofile, 'mercurial.ini')) |
|
|||
609 | path.append(os.path.join(userprofile, '.hgrc')) |
|
|||
610 | return path |
|
|||
611 |
|
||||
612 | def revsingle(repo, revspec, default='.'): |
|
542 | def revsingle(repo, revspec, default='.'): | |
613 | if not revspec: |
|
543 | if not revspec: | |
614 | return repo[default] |
|
544 | return repo[default] |
General Comments 0
You need to be logged in to leave comments.
Login now