예제 #1
0
 def _scm_clone(repo_url, dst_path):
     try:
         GitCmd.git_clone_repo(repo_url, dst_path)
         return REPO_TYPE_GIT
     except:
         git_exc_info = sys.exc_info()
         try:
             hglib.clone(repo_url, dst_path)
             return REPO_TYPE_MERCURIAL
         except:
             raise ValueError("Failed to clone repo '%s' to '%s':\nGIT:\n%s\nMercurial:\n%s\n",
                              repo_url, dst_path, str(git_exc_info), str(sys.exc_info()))
예제 #2
0
    def scm_log(self, repo_url, max_depth=None, since_date=None, branch=None):
        '''
        Get SCM log of a repo
        @param repo_url: Git repo URL
        @param max_depth: log depth
        @param since_date: since date
        @param branch: repo branch
        @return: list of scm commits (abbreviated hash, author, author email, author time, subject)
        '''
        ret = ServiceResult()

        if branch is not None and branch != "master":
            raise NotImplementedError("Handling different branch than master is not implement")

        dirname = self._get_clone_dir_name(repo_url)
        dst_path = self.dircache.get_location(dirname)

        with self.get_lock(dirname):
            if self.dircache.is_available(dirname):
                repo_type = self._scm_pull(dst_path)
                self.dircache.mark_used(dirname)
            else:
                repo_type = self._scm_clone(repo_url, dst_path)
                self.dircache.register(dirname)

            if repo_type == REPO_TYPE_GIT:
                ret.result = GitCmd.git_log_repo(dst_path, max_depth, since_date)
            elif repo_type == REPO_TYPE_MERCURIAL:
                ret.result = self._hg_log(dst_path, max_depth, since_date)
            else:
                raise ValueError("Internal Error: Unhandled repo type")

        return ret
예제 #3
0
 def _scm_pull(repo_dir, branch="master"):
     try:
         repo = GitCmd(repo_dir)
         repo.git_checkout(branch)
         repo.git_pull()
         return REPO_TYPE_GIT
     except:
         git_exc_info = sys.exc_info()
         try:
             repo = hglib.open(repo_dir)
             repo.pull(update=True, branch="default" if branch != "master" else branch)
             return REPO_TYPE_MERCURIAL
         except:
             raise ValueError("Failed to pull repo:\nGIT:\n%s\nMercurial:\n%s\n",
                              str(git_exc_info), str(sys.exc_info()))
예제 #4
0
    def scm_store(self, repo_url, commit=None, branch=None):
        '''
        Store a SCM repo
        @param repo_url: repo URL
        @param commit: commit hash; if None, the latest is used
        @param branch: branch; if None, "master" is used
        @return:
        '''

        ret = ServiceResult()

        if not branch:
            branch = "master"

        if commit:
            commit = commit[:7]

        dirname = self._get_dirname(repo_url, commit, branch)
        filename = self._get_filename(dirname)
        dst_path = self.dircache.get_location(dirname)

        with self.get_lock(dirname):
            if not self.dircache.is_available(filename):
                repo = GitCmd.git_clone_repo(repo_url, dst_path)
                repo.git_checkout(branch)
                if commit:
                    repo.git_checkout(commit)
                else:
                    commit = repo.git_rev_parse_head(dst_path)[:7]

                # if user did not supplied commit, we have to check it explicitly
                filename_old = filename
                filename = self._get_filename(
                    self._get_dirname(repo_url, commit, branch))
                # we have to move it so it will be available with specified commit and branch
                if filename_old != filename:
                    shutil.move(filename_old, filename)

                if not self.dircache.is_available(filename):
                    # if user did not supplied commit, we have to pack the repo
                    self._pack_repo(dirname, filename)
                shutil.rmtree(dst_path)

                if not self.dircache.is_available(filename):
                    self.dircache.register(filename)

        ret.result = FileId.construct(self,
                                      self.dircache.get_file_path(filename))
        ret.meta = {'origin': repo_url}
        return ret
예제 #5
0
파일: service.py 프로젝트: fridex/gofed-ng
    def scm_store(self, repo_url, commit=None, branch=None):
        '''
        Store a SCM repo
        @param repo_url: repo URL
        @param commit: commit hash; if None, the latest is used
        @param branch: branch; if None, "master" is used
        @return:
        '''

        ret = ServiceResult()

        if not branch:
            branch = "master"

        if commit:
            commit = commit[:7]

        dirname = self._get_dirname(repo_url, commit, branch)
        filename = self._get_filename(dirname)
        dst_path = self.dircache.get_location(dirname)

        with self.get_lock(dirname):
            if not self.dircache.is_available(filename):
                repo = GitCmd.git_clone_repo(repo_url, dst_path)
                repo.git_checkout(branch)
                if commit:
                    repo.git_checkout(commit)
                else:
                    commit = repo.git_rev_parse_head(dst_path)[:7]

                # if user did not supplied commit, we have to check it explicitly
                filename_old = filename
                filename = self._get_filename(self._get_dirname(repo_url, commit, branch))
                # we have to move it so it will be available with specified commit and branch
                if filename_old != filename:
                    shutil.move(filename_old, filename)

                if not self.dircache.is_available(filename):
                    # if user did not supplied commit, we have to pack the repo
                    self._pack_repo(dirname, filename)
                shutil.rmtree(dst_path)

                if not self.dircache.is_available(filename):
                    self.dircache.register(filename)

        ret.result = FileId.construct(self, self.dircache.get_file_path(filename))
        ret.meta = {'origin': repo_url}
        return ret