Show More
@@ -643,39 +643,10 b' class Backend(object):' | |||
|
643 | 643 | self._fixture.destroy_repo(repo_name) |
|
644 | 644 | |
|
645 | 645 | def _add_commits_to_repo(self, repo, commits): |
|
646 | if not commits: | |
|
646 | commit_ids = _add_commits_to_repo(repo, commits) | |
|
647 | if not commit_ids: | |
|
647 | 648 | return |
|
648 | ||
|
649 | imc = repo.in_memory_commit | |
|
650 | commit = None | |
|
651 | self._commit_ids = {} | |
|
652 | ||
|
653 | for idx, commit in enumerate(commits): | |
|
654 | message = unicode(commit.get('message', 'Commit %s' % idx)) | |
|
655 | ||
|
656 | for node in commit.get('added', []): | |
|
657 | imc.add(FileNode(node.path, content=node.content)) | |
|
658 | for node in commit.get('changed', []): | |
|
659 | imc.change(FileNode(node.path, content=node.content)) | |
|
660 | for node in commit.get('removed', []): | |
|
661 | imc.remove(FileNode(node.path)) | |
|
662 | ||
|
663 | parents = [ | |
|
664 | repo.get_commit(commit_id=self._commit_ids[p]) | |
|
665 | for p in commit.get('parents', [])] | |
|
666 | ||
|
667 | operations = ('added', 'changed', 'removed') | |
|
668 | if not any((commit.get(o) for o in operations)): | |
|
669 | imc.add(FileNode('file_%s' % idx, content=message)) | |
|
670 | ||
|
671 | commit = imc.commit( | |
|
672 | message=message, | |
|
673 | author=unicode(commit.get('author', 'Automatic')), | |
|
674 | date=commit.get('date'), | |
|
675 | branch=commit.get('branch'), | |
|
676 | parents=parents) | |
|
677 | ||
|
678 | self._commit_ids[commit.message] = commit.raw_id | |
|
649 | self._commit_ids = commit_ids | |
|
679 | 650 | |
|
680 | 651 | # Creating refs for Git to allow fetching them from remote repository |
|
681 | 652 | if self.alias == 'git': |
@@ -687,8 +658,6 b' class Backend(object):' | |||
|
687 | 658 | refs[ref_name] = self._commit_ids[message] |
|
688 | 659 | self._create_refs(repo, refs) |
|
689 | 660 | |
|
690 | return commit | |
|
691 | ||
|
692 | 661 | def _create_refs(self, repo, refs): |
|
693 | 662 | for ref_name in refs: |
|
694 | 663 | repo.set_refs(ref_name, refs[ref_name]) |
@@ -783,17 +752,20 b' class VcsBackend(object):' | |||
|
783 | 752 | """ |
|
784 | 753 | return get_backend(self.alias) |
|
785 | 754 | |
|
786 | def create_repo(self, number_of_commits=0, _clone_repo=None): | |
|
755 | def create_repo(self, commits=None, number_of_commits=0, _clone_repo=None): | |
|
787 | 756 | repo_name = self._next_repo_name() |
|
788 | 757 | self._repo_path = get_new_dir(repo_name) |
|
789 |
|
|
|
758 | repo_class = get_backend(self.alias) | |
|
790 | 759 | src_url = None |
|
791 | 760 | if _clone_repo: |
|
792 | 761 | src_url = _clone_repo.path |
|
793 |
repo = |
|
|
762 | repo = repo_class(self._repo_path, create=True, src_url=src_url) | |
|
794 | 763 | self._cleanup_repos.append(repo) |
|
795 | for idx in xrange(number_of_commits): | |
|
796 | self.ensure_file(filename='file_%s' % idx, content=repo.name) | |
|
764 | ||
|
765 | commits = commits or [ | |
|
766 | {'message': 'Commit %s of %s' % (x, repo_name)} | |
|
767 | for x in xrange(number_of_commits)] | |
|
768 | _add_commits_to_repo(repo, commits) | |
|
797 | 769 | return repo |
|
798 | 770 | |
|
799 | 771 | def clone_repo(self, repo): |
@@ -825,6 +797,44 b' class VcsBackend(object):' | |||
|
825 | 797 | self.add_file(self.repo, filename, content) |
|
826 | 798 | |
|
827 | 799 | |
|
800 | def _add_commits_to_repo(vcs_repo, commits): | |
|
801 | commit_ids = {} | |
|
802 | if not commits: | |
|
803 | return commit_ids | |
|
804 | ||
|
805 | imc = vcs_repo.in_memory_commit | |
|
806 | commit = None | |
|
807 | ||
|
808 | for idx, commit in enumerate(commits): | |
|
809 | message = unicode(commit.get('message', 'Commit %s' % idx)) | |
|
810 | ||
|
811 | for node in commit.get('added', []): | |
|
812 | imc.add(FileNode(node.path, content=node.content)) | |
|
813 | for node in commit.get('changed', []): | |
|
814 | imc.change(FileNode(node.path, content=node.content)) | |
|
815 | for node in commit.get('removed', []): | |
|
816 | imc.remove(FileNode(node.path)) | |
|
817 | ||
|
818 | parents = [ | |
|
819 | vcs_repo.get_commit(commit_id=commit_ids[p]) | |
|
820 | for p in commit.get('parents', [])] | |
|
821 | ||
|
822 | operations = ('added', 'changed', 'removed') | |
|
823 | if not any((commit.get(o) for o in operations)): | |
|
824 | imc.add(FileNode('file_%s' % idx, content=message)) | |
|
825 | ||
|
826 | commit = imc.commit( | |
|
827 | message=message, | |
|
828 | author=unicode(commit.get('author', 'Automatic')), | |
|
829 | date=commit.get('date'), | |
|
830 | branch=commit.get('branch'), | |
|
831 | parents=parents) | |
|
832 | ||
|
833 | commit_ids[commit.message] = commit.raw_id | |
|
834 | ||
|
835 | return commit_ids | |
|
836 | ||
|
837 | ||
|
828 | 838 | @pytest.fixture |
|
829 | 839 | def reposerver(request): |
|
830 | 840 | """ |
General Comments 0
You need to be logged in to leave comments.
Login now