def _get_hg_revision(self, path):
revision = None<EOL>m = None<EOL>cwd =  os.getcwd()<EOL>try:<EOL><INDENT>os.chdir(path or '<STR_LIT:.>')<EOL>p = subprocess.Popen(['<STR_LIT>'], shell=True,<EOL>stdout=subprocess.PIPE, stderr=None,<EOL>close_fds=True)<EOL>sout = p.stdout<EOL>m = re.match(r'<STR_LIT>', sout.read())<EOL><DEDENT>except:<EOL><INDENT>pass<EOL><DEDENT>os.chdir(cwd)<EOL>if m:<EOL><INDENT>revision = int(m.group('<STR_LIT>'))<EOL>return revision<EOL><DEDENT>branch_fn = njoin(path, '<STR_LIT>', '<STR_LIT>')<EOL>branch_cache_fn = njoin(path, '<STR_LIT>', '<STR_LIT>')<EOL>if os.path.isfile(branch_fn):<EOL><INDENT>branch0 = None<EOL>f = open(branch_fn)<EOL>revision0 = f.read().strip()<EOL>f.close()<EOL>branch_map = {}<EOL>for line in file(branch_cache_fn, '<STR_LIT:r>'):<EOL><INDENT>branch1, revision1  = line.split()[:<NUM_LIT:2>]<EOL>if revision1==revision0:<EOL><INDENT>branch0 = branch1<EOL><DEDENT>try:<EOL><INDENT>revision1 = int(revision1)<EOL><DEDENT>except ValueError:<EOL><INDENT>continue<EOL><DEDENT>branch_map[branch1] = revision1<EOL><DEDENT>revision = branch_map.get(branch0)<EOL><DEDENT>return revision<EOL>
Return path's Mercurial revision number.