コード例 #1
0
    def _save_changes(self, data):
        # Figure out the files to add
        git_files = [ x for x in self.handlers_new2old ]

        # Save
        RWDatabase._save_changes(self, data)

        # Add
        fs = self.fs
        git_files = [ x for x in git_files if fs.exists(x) ]
        if git_files:
            send_subprocess(['git', 'add'] + git_files)

        # Commit
        command = ['git', 'commit', '-aq']
        if data is None:
            command.extend(['-m', 'no comment'])
        else:
            git_author, git_message = data
            command.extend(['--author=%s' % git_author, '-m', git_message])
        try:
            send_subprocess(command)
        except CalledProcessError, excp:
            # Avoid an exception for the 'nothing to commit' case
            # FIXME Not reliable, we may catch other cases
            if excp.returncode != 1:
                raise
コード例 #2
0
    def get_stats(self, from_, to=None, paths=[]):
        if to is None:
            cmd = ['git', 'show', '--pretty=format:', '--stat', from_]
        else:
            cmd = ['git', 'diff', '--stat', from_, to]

        if paths:
            cmd.append('--')
            cmd.extend(paths)
        return send_subprocess(cmd)
コード例 #3
0
    def get_diff_between(self, from_, to='HEAD', paths=[]):
        """Get the diff of the given path from the given commit revision to
        HEAD.

        If "stat" is True, get a diff stat only.
        """
        cmd = ['git', 'diff', from_, to]
        if paths:
            cmd.append('--')
            cmd.extend(paths)
        return send_subprocess(cmd)
コード例 #4
0
    def get_diff(self, revision):
        cmd = ['git', 'show', revision, '--pretty=format:%an%n%at%n%s']
        data = send_subprocess(cmd)
        lines = data.splitlines()

        ts = int(lines[1])
        return {
            'author_name': lines[0],
            'author_date': datetime.fromtimestamp(ts),
            'subject': lines[2],
            'diff': '\n'.join(lines[2:])}
コード例 #5
0
 def get_files_affected(self, revisions):
     """Get the unordered set of files affected by a  list of revisions.
     """
     cmd = ['git', 'show', '--numstat', '--pretty=format:'] + revisions
     data = send_subprocess(cmd)
     lines = data.splitlines()
     files = set()
     for line in lines:
         if not line:
             continue
         before, after, filename = line.split('\t')
         files.add(filename)
     return freeze(files)
コード例 #6
0
 def _rollback(self):
     send_subprocess(['git', 'checkout', '-f'])
     send_subprocess(['git', 'clean', '-fxdq'])
コード例 #7
0
 def get_blob(self, revision, path):
     """Get the file contents located at the given path after the given
     commit revision has been commited.
     """
     cmd = ['git', 'show', '%s:%s' % (revision, path)]
     return send_subprocess(cmd)