mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-06 09:20:57 +01:00
commit
5d3f0688a0
2 changed files with 7 additions and 22 deletions
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
**Changed:**
|
**Changed:**
|
||||||
|
|
||||||
* ``get_hg_branch`` runs ``hg status`` first to check if we are in a repo
|
* ``get_hg_branch`` runs ``hg root`` to find root dir and check if we're in repo
|
||||||
|
|
||||||
**Deprecated:** None
|
**Deprecated:** None
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
|
||||||
import queue
|
import queue
|
||||||
import builtins
|
import builtins
|
||||||
import warnings
|
import warnings
|
||||||
|
@ -55,36 +54,22 @@ def get_git_branch():
|
||||||
return branch
|
return branch
|
||||||
|
|
||||||
|
|
||||||
def _get_parent_dir_for(path, dir_name, timeout):
|
|
||||||
# walk up the directory tree to see if we are inside an hg repo
|
|
||||||
# the timeout makes sure that we don't thrash the file system
|
|
||||||
previous_path = ''
|
|
||||||
t0 = time.time()
|
|
||||||
while path != previous_path and ((time.time() - t0) < timeout):
|
|
||||||
if os.path.isdir(os.path.join(path, dir_name)):
|
|
||||||
return path
|
|
||||||
previous_path = path
|
|
||||||
path, _ = os.path.split(path)
|
|
||||||
return path == previous_path
|
|
||||||
|
|
||||||
|
|
||||||
def get_hg_branch(root=None):
|
def get_hg_branch(root=None):
|
||||||
"""Try to get the mercurial branch of the current directory,
|
"""Try to get the mercurial branch of the current directory,
|
||||||
return None if not in a repo or subprocess.TimeoutExpired if timed out.
|
return None if not in a repo or subprocess.TimeoutExpired if timed out.
|
||||||
"""
|
"""
|
||||||
env = builtins.__xonsh_env__
|
env = builtins.__xonsh_env__
|
||||||
timeout = env['VC_BRANCH_TIMEOUT']
|
timeout = env['VC_BRANCH_TIMEOUT']
|
||||||
# Bail if we are not in a repo or we timed out
|
|
||||||
try:
|
try:
|
||||||
status = subprocess.call(['hg', 'status'], timeout=timeout,
|
root = subprocess.check_output(['hg', 'root'], timeout=timeout,
|
||||||
stdout=subprocess.DEVNULL,
|
|
||||||
stderr=subprocess.DEVNULL)
|
stderr=subprocess.DEVNULL)
|
||||||
except subprocess.TimeoutExpired:
|
except subprocess.TimeoutExpired:
|
||||||
return subprocess.TimeoutExpired(['hg'], timeout)
|
return subprocess.TimeoutExpired(['hg'], timeout)
|
||||||
else:
|
except subprocess.CalledProcessError:
|
||||||
if status == 255:
|
# not in repo
|
||||||
return None
|
return None
|
||||||
root = _get_parent_dir_for(env['PWD'], '.hg', timeout)
|
else:
|
||||||
|
root = xt.decode_bytes(root)
|
||||||
if env.get('VC_HG_SHOW_BRANCH'):
|
if env.get('VC_HG_SHOW_BRANCH'):
|
||||||
# get branch name
|
# get branch name
|
||||||
branch_path = os.path.sep.join([root, '.hg', 'branch'])
|
branch_path = os.path.sep.join([root, '.hg', 'branch'])
|
||||||
|
|
Loading…
Add table
Reference in a new issue