Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/scmutil.py @ 34462:c67db5dc131d
extdata: use subprocess so we don't have to chdir() manually
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 01 Oct 2017 12:12:56 +0100 |
parents | 910adadf08e8 |
children | 153e4e05e9b3 |
comparison
equal
deleted
inserted
replaced
34461:910adadf08e8 | 34462:c67db5dc131d |
---|---|
11 import glob | 11 import glob |
12 import hashlib | 12 import hashlib |
13 import os | 13 import os |
14 import re | 14 import re |
15 import socket | 15 import socket |
16 import subprocess | |
16 import weakref | 17 import weakref |
17 | 18 |
18 from .i18n import _ | 19 from .i18n import _ |
19 from .node import ( | 20 from .node import ( |
20 hex, | 21 hex, |
1036 spec = repo.ui.config("extdata", source) | 1037 spec = repo.ui.config("extdata", source) |
1037 if not spec: | 1038 if not spec: |
1038 raise error.Abort(_("unknown extdata source '%s'") % source) | 1039 raise error.Abort(_("unknown extdata source '%s'") % source) |
1039 | 1040 |
1040 data = {} | 1041 data = {} |
1041 if spec.startswith("shell:"): | 1042 src = proc = None |
1042 # external commands should be run relative to the repo root | |
1043 cmd = spec[6:] | |
1044 cwd = os.getcwd() | |
1045 os.chdir(repo.root) | |
1046 try: | |
1047 src = util.popen(cmd) | |
1048 finally: | |
1049 os.chdir(cwd) | |
1050 else: | |
1051 # treat as a URL or file | |
1052 src = url.open(repo.ui, spec) | |
1053 | |
1054 try: | 1043 try: |
1044 if spec.startswith("shell:"): | |
1045 # external commands should be run relative to the repo root | |
1046 cmd = spec[6:] | |
1047 proc = subprocess.Popen(cmd, shell=True, bufsize=-1, | |
1048 close_fds=util.closefds, | |
1049 stdout=subprocess.PIPE, cwd=repo.root) | |
1050 src = proc.stdout | |
1051 else: | |
1052 # treat as a URL or file | |
1053 src = url.open(repo.ui, spec) | |
1055 for l in src: | 1054 for l in src: |
1056 if " " in l: | 1055 if " " in l: |
1057 k, v = l.strip().split(" ", 1) | 1056 k, v = l.strip().split(" ", 1) |
1058 else: | 1057 else: |
1059 k, v = l.strip(), "" | 1058 k, v = l.strip(), "" |
1062 try: | 1061 try: |
1063 data[repo[k].rev()] = encoding.tolocal(v) | 1062 data[repo[k].rev()] = encoding.tolocal(v) |
1064 except (error.LookupError, error.RepoLookupError): | 1063 except (error.LookupError, error.RepoLookupError): |
1065 pass # we ignore data for nodes that don't exist locally | 1064 pass # we ignore data for nodes that don't exist locally |
1066 finally: | 1065 finally: |
1067 src.close() | 1066 if proc: |
1067 proc.communicate() | |
1068 if src: | |
1069 src.close() | |
1068 | 1070 |
1069 return data | 1071 return data |
1070 | 1072 |
1071 def _locksub(repo, lock, envvar, cmd, environ=None, *args, **kwargs): | 1073 def _locksub(repo, lock, envvar, cmd, environ=None, *args, **kwargs): |
1072 if lock is None: | 1074 if lock is None: |