Review Board

beta

Move MercurialClient class to be next to other SCMClient subclasses

Updated 9 months, 2 weeks ago

Marc Hedlund Reviewers
reviewboard
chipx86
None Review Board SVN
Move MercurialClient class to be in the same part of the post-review source as the other SCMClient subclasses.  It took me a moment to find the Mercurial class since it is currently distant from its peers and I'd like to save other people from spending that moment.  :)
I don't use Mercurial, so I don't have a good way to test that class, but I confirmed that the post-review script still runs after this change.

Diff revision 1 (Latest)

  1. http://reviewboard.googlecode.com/svn/trunk/reviewboard/contrib/tools/post-review: 2 changes [ 1 2 ]
http://reviewboard.googlecode.com/svn/trunk/reviewboard/contrib/tools/post-review
Revision 1226 New Change
636
        last_line = where_output[-1]
636
        last_line = where_output[-1]
637
637
638
        # XXX: This breaks on filenames with spaces.
638
        # XXX: This breaks on filenames with spaces.
639
        return last_line.split(' ')[2]
639
        return last_line.split(' ')[2]
640
640
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
641
def debug(s):
688
def debug(s):
642
    """
689
    """
643
    Prints debugging information if post-review was run with --debug
690
    Prints debugging information if post-review was run with --debug
644
    """
691
    """
645
    if options.debug:
692
    if options.debug:
864
    (globals()["options"], args) = parser.parse_args(args)
911
    (globals()["options"], args) = parser.parse_args(args)
865
912
866
    return args
913
    return args
867
914
868
915
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
917
def main(args):
916
def main(args):
918
    # Load the config file
917
    # Load the config file
919
    globals()['user_config'] = \
918
    globals()['user_config'] = \
920
        load_config_file(os.path.join(homepath, ".reviewboardrc"))
919
        load_config_file(os.path.join(homepath, ".reviewboardrc"))
921
920
  1. http://reviewboard.googlecode.com/svn/trunk/reviewboard/contrib/tools/post-review: 2 changes [ 1 2 ]