Return path's Mercurial revision number.
(self, path)
| 1911 | return None |
| 1912 | |
| 1913 | def _get_hg_revision(self, path): |
| 1914 | """Return path's Mercurial revision number. |
| 1915 | """ |
| 1916 | try: |
| 1917 | output = subprocess.check_output( |
| 1918 | ['hg', 'identify', '--num'], cwd=path) |
| 1919 | except (subprocess.CalledProcessError, OSError): |
| 1920 | pass |
| 1921 | else: |
| 1922 | m = re.match(rb'(?P<revision>\d+)', output) |
| 1923 | if m: |
| 1924 | return int(m.group('revision')) |
| 1925 | |
| 1926 | branch_fn = njoin(path, '.hg', 'branch') |
| 1927 | branch_cache_fn = njoin(path, '.hg', 'branch.cache') |
| 1928 | |
| 1929 | if os.path.isfile(branch_fn): |
| 1930 | branch0 = None |
| 1931 | with open(branch_fn) as f: |
| 1932 | revision0 = f.read().strip() |
| 1933 | |
| 1934 | branch_map = {} |
| 1935 | with open(branch_cache_fn) as f: |
| 1936 | for line in f: |
| 1937 | branch1, revision1 = line.split()[:2] |
| 1938 | if revision1==revision0: |
| 1939 | branch0 = branch1 |
| 1940 | try: |
| 1941 | revision1 = int(revision1) |
| 1942 | except ValueError: |
| 1943 | continue |
| 1944 | branch_map[branch1] = revision1 |
| 1945 | |
| 1946 | return branch_map.get(branch0) |
| 1947 | |
| 1948 | return None |
| 1949 | |
| 1950 | |
| 1951 | def get_version(self, version_file=None, version_variable=None): |