|
|
641 |
class MercurialClient(SCMClient): |
|
|
642 |
""" |
|
|
643 |
A wrapper around the hg Mercurial tool that fetches repository |
|
|
644 |
information and generates compatible diffs. |
|
|
645 |
""" |
|
|
646 |
def get_repository_info(self): |
|
|
647 |
data = execute('hg root') |
|
|
648 |
if data.startswith('abort:'): |
|
|
649 |
# hg aborted => no mercurial repository here. |
|
|
650 |
return None |
|
|
651 |
|
|
|
652 |
# Elsewhere, hg root output give us the repository path. |
|
|
653 |
|
|
|
654 |
# We save data here to use it as a fallback. See below |
|
|
655 |
local_data = data.strip() |
|
|
656 |
|
|
|
657 |
# We are going to search .hg/hgrc for the default path. |
|
|
658 |
file_name = os.path.join(local_data,'.hg', 'hgrc') |
|
|
659 |
if not os.path.exists(file_name): |
|
|
660 |
return RepositoryInfo(path=local_data, base_path='/') |
|
|
661 |
|
|
|
662 |
f = open(file_name) |
|
|
663 |
data = f.read() |
|
|
664 |
f.close() |
|
|
665 |
|
|
|
666 |
m = re.search(r'^default\s+=\s+(.+)$', data, re.M) |
|
|
667 |
if not m: |
|
|
668 |
# Return the local path, if no default value is found. |
|
|
669 |
return RepositoryInfo(path=local_data, base_path='/') |
|
|
670 |
|
|
|
671 |
path = m.group(1).strip() |
|
|
672 |
|
|
|
673 |
return RepositoryInfo(path=path, base_path='') |
|
|
674 |
|
|
|
675 |
def diff(self, changenum, files): |
|
|
676 |
""" |
|
|
677 |
Performs a diff across all modified files in a Mercurial repository. |
|
|
678 |
""" |
|
|
679 |
return execute('hg diff %s' % ' '.join(files)) |
|
|
680 |
|
|
|
681 |
def diff_between_revisions(self, revision_range): |
|
|
682 |
""" |
|
|
683 |
Performs a diff between 2 revisions of a Mercurial repository. |
|
|
684 |
""" |
|
|
685 |
r1, r2 = revision_range.split(':') |
|
|
686 |
return execute('hg diff -r %s -r %s' % (r1, r2)) |
|
|
687 |
|
| 869 |
class MercurialClient(SCMClient): |
|
|
| 870 |
""" |
|
|
| 871 |
A wrapper around the hg Mercurial tool that fetches repository |
|
|
| 872 |
information and generates compatible diffs. |
|
|
| 873 |
""" |
|
|
| 874 |
def get_repository_info(self): |
|
|
| 875 |
data = execute('hg root') |
|
|
| 876 |
if data.startswith('abort:'): |
|
|
| 877 |
# hg aborted => no mercurial repository here. |
|
|
| 878 |
return None |
|
|
| 879 |
|
|
|
| 880 |
# Elsewhere, hg root output give us the repository path. |
|
|
| 881 |
|
|
|
| 882 |
# We save data here to use it as a fallback. See below |
|
|
| 883 |
local_data = data.strip() |
|
|
| 884 |
|
|
|
| 885 |
# We are going to search .hg/hgrc for the default path. |
|
|
| 886 |
file_name = os.path.join(local_data,'.hg', 'hgrc') |
|
|
| 887 |
if not os.path.exists(file_name): |
|
|
| 888 |
return RepositoryInfo(path=local_data, base_path='/') |
|
|
| 889 |
|
|
|
| 890 |
f = open(file_name) |
|
|
| 891 |
data = f.read() |
|
|
| 892 |
f.close() |
|
|
| 893 |
|
|
|
| 894 |
m = re.search(r'^default\s+=\s+(.+)$', data, re.M) |
|
|
| 895 |
if not m: |
|
|
| 896 |
# Return the local path, if no default value is found. |
|
|
| 897 |
return RepositoryInfo(path=local_data, base_path='/') |
|
|
| 898 |
|
|
|
| 899 |
path = m.group(1).strip() |
|
|
| 900 |
|
|
|
| 901 |
return RepositoryInfo(path=path, base_path='') |
|
|
| 902 |
|
|
|
| 903 |
def diff(self, changenum, files): |
|
|
| 904 |
""" |
|
|
| 905 |
Performs a diff across all modified files in a Mercurial repository. |
|
|
| 906 |
""" |
|
|
| 907 |
return execute('hg diff %s' % ' '.join(files)) |
|
|
| 908 |
|
|
|
| 909 |
def diff_between_revisions(self, revision_range): |
|
|
| 910 |
""" |
|
|
| 911 |
Performs a diff between 2 revisions of a Mercurial repository. |
|
|
| 912 |
""" |
|
|
| 913 |
r1, r2 = revision_range.split(':') |
|
|
| 914 |
return execute('hg diff -r %s -r %s' % (r1, r2)) |
|
|
| 915 |
|
|
|
| 916 |
|
|
|
Other reviews