Show More
@@ -6,7 +6,6 b'' | |||||
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | from i18n import _ |
|
8 | from i18n import _ | |
9 | import osutil |
|
|||
10 | import os, sys, errno, stat, getpass, pwd, grp, tempfile |
|
9 | import os, sys, errno, stat, getpass, pwd, grp, tempfile | |
11 |
|
10 | |||
12 | posixfile = open |
|
11 | posixfile = open | |
@@ -29,29 +28,6 b' def nlinks(name):' | |||||
29 | '''return number of hardlinks for the given file''' |
|
28 | '''return number of hardlinks for the given file''' | |
30 | return os.lstat(name).st_nlink |
|
29 | return os.lstat(name).st_nlink | |
31 |
|
30 | |||
32 | def rcfiles(path): |
|
|||
33 | rcs = [os.path.join(path, 'hgrc')] |
|
|||
34 | rcdir = os.path.join(path, 'hgrc.d') |
|
|||
35 | try: |
|
|||
36 | rcs.extend([os.path.join(rcdir, f) |
|
|||
37 | for f, kind in osutil.listdir(rcdir) |
|
|||
38 | if f.endswith(".rc")]) |
|
|||
39 | except OSError: |
|
|||
40 | pass |
|
|||
41 | return rcs |
|
|||
42 |
|
||||
43 | def system_rcpath(): |
|
|||
44 | path = [] |
|
|||
45 | # old mod_python does not set sys.argv |
|
|||
46 | if len(getattr(sys, 'argv', [])) > 0: |
|
|||
47 | path.extend(rcfiles(os.path.dirname(sys.argv[0]) + |
|
|||
48 | '/../etc/mercurial')) |
|
|||
49 | path.extend(rcfiles('/etc/mercurial')) |
|
|||
50 | return path |
|
|||
51 |
|
||||
52 | def user_rcpath(): |
|
|||
53 | return [os.path.expanduser('~/.hgrc')] |
|
|||
54 |
|
||||
55 | def parse_patch_output(output_line): |
|
31 | def parse_patch_output(output_line): | |
56 | """parses the output produced by patch and returns the filename""" |
|
32 | """parses the output produced by patch and returns the filename""" | |
57 | pf = output_line[14:] |
|
33 | pf = output_line[14:] |
@@ -7,7 +7,7 b'' | |||||
7 |
|
7 | |||
8 | from i18n import _ |
|
8 | from i18n import _ | |
9 | import util, error, osutil |
|
9 | import util, error, osutil | |
10 | import os, errno, stat |
|
10 | import os, errno, stat, sys | |
11 |
|
11 | |||
12 | def checkfilename(f): |
|
12 | def checkfilename(f): | |
13 | '''Check that the filename f is an acceptable filename for a tracked file''' |
|
13 | '''Check that the filename f is an acceptable filename for a tracked file''' | |
@@ -298,8 +298,8 b' def walkrepos(path, followsym=False, see' | |||||
298 |
|
298 | |||
299 | def os_rcpath(): |
|
299 | def os_rcpath(): | |
300 | '''return default os-specific hgrc search path''' |
|
300 | '''return default os-specific hgrc search path''' | |
301 |
path = |
|
301 | path = system_rcpath() | |
302 |
path.extend( |
|
302 | path.extend(user_rcpath()) | |
303 | path = [os.path.normpath(f) for f in path] |
|
303 | path = [os.path.normpath(f) for f in path] | |
304 | return path |
|
304 | return path | |
305 |
|
305 | |||
@@ -328,3 +328,74 b' def rcpath():' | |||||
328 | else: |
|
328 | else: | |
329 | _rcpath = os_rcpath() |
|
329 | _rcpath = os_rcpath() | |
330 | return _rcpath |
|
330 | return _rcpath | |
|
331 | ||||
|
332 | if os.name != 'nt': | |||
|
333 | ||||
|
334 | def rcfiles(path): | |||
|
335 | rcs = [os.path.join(path, 'hgrc')] | |||
|
336 | rcdir = os.path.join(path, 'hgrc.d') | |||
|
337 | try: | |||
|
338 | rcs.extend([os.path.join(rcdir, f) | |||
|
339 | for f, kind in osutil.listdir(rcdir) | |||
|
340 | if f.endswith(".rc")]) | |||
|
341 | except OSError: | |||
|
342 | pass | |||
|
343 | return rcs | |||
|
344 | ||||
|
345 | def system_rcpath(): | |||
|
346 | path = [] | |||
|
347 | # old mod_python does not set sys.argv | |||
|
348 | if len(getattr(sys, 'argv', [])) > 0: | |||
|
349 | path.extend(rcfiles(os.path.dirname(sys.argv[0]) + | |||
|
350 | '/../etc/mercurial')) | |||
|
351 | path.extend(rcfiles('/etc/mercurial')) | |||
|
352 | return path | |||
|
353 | ||||
|
354 | def user_rcpath(): | |||
|
355 | return [os.path.expanduser('~/.hgrc')] | |||
|
356 | ||||
|
357 | else: | |||
|
358 | ||||
|
359 | _HKEY_LOCAL_MACHINE = 0x80000002L | |||
|
360 | ||||
|
361 | def system_rcpath(): | |||
|
362 | '''return default os-specific hgrc search path''' | |||
|
363 | rcpath = [] | |||
|
364 | filename = util.executable_path() | |||
|
365 | # Use mercurial.ini found in directory with hg.exe | |||
|
366 | progrc = os.path.join(os.path.dirname(filename), 'mercurial.ini') | |||
|
367 | if os.path.isfile(progrc): | |||
|
368 | rcpath.append(progrc) | |||
|
369 | return rcpath | |||
|
370 | # Use hgrc.d found in directory with hg.exe | |||
|
371 | progrcd = os.path.join(os.path.dirname(filename), 'hgrc.d') | |||
|
372 | if os.path.isdir(progrcd): | |||
|
373 | for f, kind in osutil.listdir(progrcd): | |||
|
374 | if f.endswith('.rc'): | |||
|
375 | rcpath.append(os.path.join(progrcd, f)) | |||
|
376 | return rcpath | |||
|
377 | # else look for a system rcpath in the registry | |||
|
378 | value = util.lookup_reg('SOFTWARE\\Mercurial', None, | |||
|
379 | _HKEY_LOCAL_MACHINE) | |||
|
380 | if not isinstance(value, str) or not value: | |||
|
381 | return rcpath | |||
|
382 | value = value.replace('/', os.sep) | |||
|
383 | for p in value.split(os.pathsep): | |||
|
384 | if p.lower().endswith('mercurial.ini'): | |||
|
385 | rcpath.append(p) | |||
|
386 | elif os.path.isdir(p): | |||
|
387 | for f, kind in osutil.listdir(p): | |||
|
388 | if f.endswith('.rc'): | |||
|
389 | rcpath.append(os.path.join(p, f)) | |||
|
390 | return rcpath | |||
|
391 | ||||
|
392 | def user_rcpath(): | |||
|
393 | '''return os-specific hgrc search path to the user dir''' | |||
|
394 | home = os.path.expanduser('~') | |||
|
395 | path = [os.path.join(home, 'mercurial.ini'), | |||
|
396 | os.path.join(home, '.hgrc')] | |||
|
397 | userprofile = os.environ.get('USERPROFILE') | |||
|
398 | if userprofile: | |||
|
399 | path.append(os.path.join(userprofile, 'mercurial.ini')) | |||
|
400 | path.append(os.path.join(userprofile, '.hgrc')) | |||
|
401 | return path |
@@ -73,49 +73,6 b' def _is_win_9x():' | |||||
73 | def openhardlinks(): |
|
73 | def openhardlinks(): | |
74 | return not _is_win_9x() |
|
74 | return not _is_win_9x() | |
75 |
|
75 | |||
76 | _HKEY_LOCAL_MACHINE = 0x80000002L |
|
|||
77 |
|
||||
78 | def system_rcpath(): |
|
|||
79 | '''return default os-specific hgrc search path''' |
|
|||
80 | rcpath = [] |
|
|||
81 | filename = executable_path() |
|
|||
82 | # Use mercurial.ini found in directory with hg.exe |
|
|||
83 | progrc = os.path.join(os.path.dirname(filename), 'mercurial.ini') |
|
|||
84 | if os.path.isfile(progrc): |
|
|||
85 | rcpath.append(progrc) |
|
|||
86 | return rcpath |
|
|||
87 | # Use hgrc.d found in directory with hg.exe |
|
|||
88 | progrcd = os.path.join(os.path.dirname(filename), 'hgrc.d') |
|
|||
89 | if os.path.isdir(progrcd): |
|
|||
90 | for f, kind in osutil.listdir(progrcd): |
|
|||
91 | if f.endswith('.rc'): |
|
|||
92 | rcpath.append(os.path.join(progrcd, f)) |
|
|||
93 | return rcpath |
|
|||
94 | # else look for a system rcpath in the registry |
|
|||
95 | value = lookup_reg('SOFTWARE\\Mercurial', None, _HKEY_LOCAL_MACHINE) |
|
|||
96 | if not isinstance(value, str) or not value: |
|
|||
97 | return rcpath |
|
|||
98 | value = value.replace('/', os.sep) |
|
|||
99 | for p in value.split(os.pathsep): |
|
|||
100 | if p.lower().endswith('mercurial.ini'): |
|
|||
101 | rcpath.append(p) |
|
|||
102 | elif os.path.isdir(p): |
|
|||
103 | for f, kind in osutil.listdir(p): |
|
|||
104 | if f.endswith('.rc'): |
|
|||
105 | rcpath.append(os.path.join(p, f)) |
|
|||
106 | return rcpath |
|
|||
107 |
|
||||
108 | def user_rcpath(): |
|
|||
109 | '''return os-specific hgrc search path to the user dir''' |
|
|||
110 | home = os.path.expanduser('~') |
|
|||
111 | path = [os.path.join(home, 'mercurial.ini'), |
|
|||
112 | os.path.join(home, '.hgrc')] |
|
|||
113 | userprofile = os.environ.get('USERPROFILE') |
|
|||
114 | if userprofile: |
|
|||
115 | path.append(os.path.join(userprofile, 'mercurial.ini')) |
|
|||
116 | path.append(os.path.join(userprofile, '.hgrc')) |
|
|||
117 | return path |
|
|||
118 |
|
||||
119 | def parse_patch_output(output_line): |
|
76 | def parse_patch_output(output_line): | |
120 | """parses the output produced by patch and returns the filename""" |
|
77 | """parses the output produced by patch and returns the filename""" | |
121 | pf = output_line[14:] |
|
78 | pf = output_line[14:] |
General Comments 0
You need to be logged in to leave comments.
Login now