1111from ._run_cmd import CompletedProcess as _CompletedProcess
1212from ._run_cmd import run as _run
1313from .git import GitWorkdir
14+ from .hg import HG_COMMAND
1415from .hg import HgWorkdir
1516
1617log = logging .getLogger (__name__ )
2526class GitWorkdirHgClient (GitWorkdir , HgWorkdir ):
2627 @classmethod
2728 def from_potential_worktree (cls , wd : _t .PathT ) -> GitWorkdirHgClient | None :
28- res = _run (["hg" , "root" ], cwd = wd ).parse_success (parse = Path )
29+ res = _run ([HG_COMMAND , "root" ], cwd = wd ).parse_success (parse = Path )
2930 if res is None :
3031 return None
3132 return cls (res )
3233
3334 def is_dirty (self ) -> bool :
34- res = _run (["hg" , "id" , "-T" , "{dirty}" ], cwd = self .path , check = True )
35+ res = _run ([HG_COMMAND , "id" , "-T" , "{dirty}" ], cwd = self .path , check = True )
3536 return bool (res .stdout )
3637
3738 def get_branch (self ) -> str | None :
38- res = _run (["hg" , "id" , "-T" , "{bookmarks}" ], cwd = self .path )
39+ res = _run ([HG_COMMAND , "id" , "-T" , "{bookmarks}" ], cwd = self .path )
3940 if res .returncode :
4041 log .info ("branch err %s" , res )
4142 return None
4243 return res .stdout
4344
4445 def get_head_date (self ) -> date | None :
45- return _run ('hg log -r . -T "{shortdate(date)}"' , cwd = self . path ). parse_success (
46- parse = date . fromisoformat , error_msg = "head date err"
47- )
46+ return _run (
47+ [ HG_COMMAND , "log" , "-r" , "." , "-T" , "{shortdate( date)}" ], cwd = self . path
48+ ). parse_success ( parse = date . fromisoformat , error_msg = "head date err" )
4849
4950 def is_shallow (self ) -> bool :
5051 return False
@@ -53,7 +54,7 @@ def fetch_shallow(self) -> None:
5354 pass
5455
5556 def get_hg_node (self ) -> str | None :
56- res = _run ('hg log -r . -T "{node}"' , cwd = self .path )
57+ res = _run ([ HG_COMMAND , " log" , "-r" , "." , "-T" , "{node}" ] , cwd = self .path )
5758 if res .returncode :
5859 return None
5960 else :
@@ -77,7 +78,7 @@ def node(self) -> str | None:
7778
7879 if git_node is None :
7980 # trying again after hg -> git
80- _run (["hg" , "gexport" ], cwd = self .path )
81+ _run ([HG_COMMAND , "gexport" ], cwd = self .path )
8182 git_node = self ._hg2git (hg_node )
8283
8384 if git_node is None :
@@ -92,7 +93,7 @@ def node(self) -> str | None:
9293 return git_node [:7 ]
9394
9495 def count_all_nodes (self ) -> int :
95- res = _run (["hg" , "log" , "-r" , "ancestors(.)" , "-T" , "." ], cwd = self .path )
96+ res = _run ([HG_COMMAND , "log" , "-r" , "ancestors(.)" , "-T" , "." ], cwd = self .path )
9697 return len (res .stdout )
9798
9899 def default_describe (self ) -> _CompletedProcess :
@@ -104,7 +105,7 @@ def default_describe(self) -> _CompletedProcess:
104105 """
105106 res = _run (
106107 [
107- "hg" ,
108+ HG_COMMAND ,
108109 "log" ,
109110 "-r" ,
110111 "(reverse(ancestors(.)) and tag(r're:v?[0-9].*'))" ,
@@ -132,7 +133,7 @@ def default_describe(self) -> _CompletedProcess:
132133 logging .warning ("tag not found hg=%s git=%s" , hg_tags , git_tags )
133134 return _FAKE_GIT_DESCRIBE_ERROR
134135
135- res = _run (["hg" , "log" , "-r" , f"'{ tag } '::." , "-T" , "." ], cwd = self .path )
136+ res = _run ([HG_COMMAND , "log" , "-r" , f"'{ tag } '::." , "-T" , "." ], cwd = self .path )
136137 if res .returncode :
137138 return _FAKE_GIT_DESCRIBE_ERROR
138139 distance = len (res .stdout ) - 1
0 commit comments