Example #1
0
 def get_commit(self, sha):
     if self.object_type(sha) != 'commit':
         return None
     c = self.cat(sha)
     parent = c['parent'][-1] if c[
         'parent'] else None  # Weird, why would we want only the last one?
     author_name = c['author']['name']
     author_email = email_normalizer(author_name, c['author']['email'])
     author = User(name=author_name, email=author_email)
     committer_name = c['committer']['name']
     committer_email = email_normalizer(committer_name,
                                        c['committer']['email'])
     committer = User(name=committer_name, email=committer_email)
     message = (c['message'] + '\n\n' +
                remove_unknown_character(c['body'])).strip()
     author_time = c['author']['date']
     commit_time = c['committer']['date']
     return Commit(self.project_name,
                   sha=sha,
                   tree=c['tree'],
                   parent=parent,
                   author=author,
                   author_time=author_time,
                   committer=committer,
                   commit_time=commit_time,
                   message=message)
Example #2
0
 def parse_diff(self,
                ref='HEAD',
                ignore_space=False,
                rename_detection=False):
     if self.object_type(ref) != 'commit':
         return False
     diff_data = self.cat(ref)
     diffs = {}
     diffs['parents'] = ' '.join(diff_data['parent'])
     diffs['author'] = diff_data['author']['name']
     diffs['email'] = email_normalizer(diffs['author'],
                                       diff_data['author']['email'])
     diffs['time'] = compute_relative_time(diff_data['author']['ts'])
     diffs['message'] = diff_data['message'].replace('\n', ' ')
     diffs['body'] = remove_unknown_character(diff_data['body'])
     parents = diffs['parents'].split(' ')
     if parents and parents[0]:
         diffs['difflist'] = self.get_3dot_diff(
             parents[0],
             ref,
             ignore_space=ignore_space,
             rename_detection=rename_detection)
     else:
         diffs['difflist'] = self._get_diff_for_first_commit(ref, parents)
     return diffs
Example #3
0
 def get_revlist(self,
                 max_count=20,
                 skip=0,
                 rev='HEAD',
                 path='',
                 author=None,
                 query=None):
     commits = []
     cs = self._gyt_repo.rev_list(rev,
                                  max_count=max_count,
                                  skip=skip,
                                  paths=path,
                                  author=author,
                                  query=query)
     for c in cs:
         commit = {}
         commit['parents'] = [p.hex for p in c.parents] if c.parents else ''
         commit['date'] = datetime.fromtimestamp(
             c.committer.time, FixedOffset(c.committer.offset))
         commit['age'] = compute_relative_time(c.author.time)
         commit['author'] = c.author.name
         commit['email'] = email_normalizer(c.author.name, c.author.email)
         message_title = c.message.splitlines()[0] if c.message else ''
         commit['message'] = message_title
         commit['commit'] = c.hex
         commits.append(commit)
     return commits
Example #4
0
    def __init__(self, repo, commit):
        self.repo = repo
        self._commit = commit
        self.type = 'commit'
        self.repo_name = repo.name
        parent = commit['parent'][0] if commit['parent'] else None
        self.parent = parent
        self.parents = commit['parent']
        message = ("%s\n\n%s" % (
            commit['message'],
            remove_unknown_character(commit['body']))
        ).strip()
        self.message = message
        self.message_header = commit['message']
        self.message_body = commit['body']
        self.sha = commit['sha']
        self.tree = commit['tree']

        author_name = commit['author']['name']
        self.author_name = author_name
        author_email = email_normalizer(author_name, commit['author']['email'])
        self.author_email = author_email
        self.email = author_email
        # FIXME: user
        #author = User(name=author_name, email=author_email)
        author = User.get_by_name(author_name)
        self.author = author
        author_date = datetime.fromtimestamp(commit['author']['time'],
                                             FixedOffset(commit['author']['offset']))
        author_timestamp = str(commit['author']['time'])
        self.author_time = author_date
        self.author_timestamp = author_timestamp
        self.time = author_date

        committer_name = commit['committer']['name']
        committer_email = email_normalizer(
            committer_name, commit['committer']['email'])
        # FIXME: user
        #committer = User(name=committer_name, email=committer_email)
        committer = User.get_by_name(committer_name)
        self.committer = committer
        committer_date = datetime.fromtimestamp(commit['committer']['time'],
                                             FixedOffset(commit['committer']['offset']))
        self.committer_time = committer_date
Example #5
0
    def __init__(self, repo, commit):
        self.repo = repo
        self._commit = commit
        self.type = 'commit'
        self.repo_name = repo.name
        parent = commit['parent'][0] if commit['parent'] else None
        self.parent = parent
        self.parents = commit['parent']
        message = ("%s\n\n%s" %
                   (commit['message'], remove_unknown_character(
                       commit['body']))).strip()
        self.message = message
        self.message_header = commit['message']
        self.message_body = commit['body']
        self.sha = commit['sha']
        self.tree = commit['tree']

        author_name = commit['author']['name']
        self.author_name = author_name
        author_email = email_normalizer(author_name, commit['author']['email'])
        self.author_email = author_email
        self.email = author_email
        # FIXME: user
        #author = User(name=author_name, email=author_email)
        author = User.get_by_name(author_name)
        self.author = author
        author_date = datetime.fromtimestamp(
            commit['author']['time'], FixedOffset(commit['author']['offset']))
        author_timestamp = str(commit['author']['time'])
        self.author_time = author_date
        self.author_timestamp = author_timestamp
        self.time = author_date

        committer_name = commit['committer']['name']
        committer_email = email_normalizer(committer_name,
                                           commit['committer']['email'])
        # FIXME: user
        #committer = User(name=committer_name, email=committer_email)
        committer = User.get_by_name(committer_name)
        self.committer = committer
        committer_date = datetime.fromtimestamp(
            commit['committer']['time'],
            FixedOffset(commit['committer']['offset']))
        self.committer_time = committer_date
Example #6
0
 def _blame_src_header(self, ref):
     header_data = self.cat(ref)
     header = {}
     header['message'] = header_data['message']
     header['parents'] = ' '.join(header_data['parent'])
     header['author'] = header_data['author']['name']
     header['email'] = email_normalizer(
         header['author'], header_data['author']['email'])
     header['time'] = compute_relative_time(header_data['author']['ts'])
     return header
Example #7
0
 def _blame_src_header(self, ref):
     header_data = self.cat(ref)
     header = {}
     header['message'] = header_data['message']
     header['parents'] = ' '.join(header_data['parent'])
     header['author'] = header_data['author']['name']
     header['email'] = email_normalizer(header['author'],
                                        header_data['author']['email'])
     header['time'] = compute_relative_time(header_data['author']['ts'])
     return header
Example #8
0
 def get_commit(self, sha):
     if self.object_type(sha) != 'commit':
         return None
     c = self.cat(sha)
     parent = c['parent'][-1] if c[
         'parent'] else None  # Weird, why would we want only the last one?
     author_name = c['author']['name']
     author_email = email_normalizer(author_name, c['author']['email'])
     author = User(name=author_name, email=author_email)
     committer_name = c['committer']['name']
     committer_email = email_normalizer(
         committer_name, c['committer']['email'])
     committer = User(name=committer_name, email=committer_email)
     message = (
         c['message'] + '\n\n' + remove_unknown_character(c['body'])).strip()
     author_time = c['author']['date']
     commit_time = c['committer']['date']
     return Commit(
         self.project_name, sha=sha, tree=c['tree'], parent=parent,
         author=author, author_time=author_time, committer=committer,
         commit_time=commit_time, message=message)
Example #9
0
    def __init__(self, repo, commit):
        self.repo = repo
        self._commit = commit
        self.type = 'commit'
        self.repo_name = repo.name
        parent = commit['parent'][0] if commit['parent'] else None
        self.parent = parent
        self.parents = commit['parent']
        message = ("%s\n\n%s" % (
            commit['message'],
            remove_unknown_character(commit['body']))
        ).strip()
        self.message = message
        self.message_header = commit['message']
        self.message_body = commit['body']
        self.sha = commit['sha']
        self.tree = commit['tree']
        self.has_author_link = True

        # author
        author_name = commit['author']['name']
        self.author_name = author_name
        author_email = commit['author']['email']
        self.author_email = author_email
        self.email = author_email
        code_author_name = get_author_by_email(author_email, None)
        if code_author_name is None:
            self.has_author_link = False
            author = User(name=author_name, email=author_email)
        else:
            author = User(name=code_author_name, email=author_email)
        self.author = author
        author_date = datetime.fromtimestamp(
            commit['author']['time'],
            FixedOffset(commit['author']['offset']))
        self.author_time = author_date
        author_timestamp = str(commit['author']['time'])
        self.author_timestamp = author_timestamp
        self.time = author_date

        # committer
        committer_name = commit['committer']['name']
        committer_email = email_normalizer(committer_name,
                                           commit['committer']['email'])
        committer = User(name=committer_name, email=committer_email)
        self.committer = committer
        committer_date = datetime.fromtimestamp(
            commit['committer']['time'],
            FixedOffset(commit['committer']['offset']))
        self.committer_time = committer_date
        self.commit_time = committer_date  # FIXME: remove this!
Example #10
0
    def __init__(self, repo, commit):
        self.repo = repo
        self._commit = commit
        self.type = 'commit'
        self.repo_name = repo.name
        parent = commit['parent'][0] if commit['parent'] else None
        self.parent = parent
        self.parents = commit['parent']
        message = ("%s\n\n%s" %
                   (commit['message'], remove_unknown_character(
                       commit['body']))).strip()
        self.message = message
        self.message_header = commit['message']
        self.message_body = commit['body']
        self.sha = commit['sha']
        self.tree = commit['tree']
        self.has_author_link = True

        # author
        author_name = commit['author']['name']
        self.author_name = author_name
        author_email = commit['author']['email']
        self.author_email = author_email
        self.email = author_email
        code_author_name = get_author_by_email(author_email, None)
        if code_author_name is None:
            self.has_author_link = False
            author = User(name=author_name, email=author_email)
        else:
            author = User(name=code_author_name, email=author_email)
        self.author = author
        author_date = datetime.fromtimestamp(
            commit['author']['time'], FixedOffset(commit['author']['offset']))
        self.author_time = author_date
        author_timestamp = str(commit['author']['time'])
        self.author_timestamp = author_timestamp
        self.time = author_date

        # committer
        committer_name = commit['committer']['name']
        committer_email = email_normalizer(committer_name,
                                           commit['committer']['email'])
        committer = User(name=committer_name, email=committer_email)
        self.committer = committer
        committer_date = datetime.fromtimestamp(
            commit['committer']['time'],
            FixedOffset(commit['committer']['offset']))
        self.committer_time = committer_date
        self.commit_time = committer_date  # FIXME: remove this!
Example #11
0
 def get_revisions(self, begin='HEAD~5', end='HEAD'):
     if self.is_empty():
         return []
     res = self.get_rev_list(begin, end, _raise=False)
     revisions = []
     if not res:
         return []
     for commit_sha in res:
         commit = self.cat(commit_sha)
         d = {}
         d['name'] = commit['author']['name']
         d['id'] = commit_sha
         d['date'] = commit['committer']['date'].strftime(
             '%Y-%m-%dT%H:%M:%S') + commit['committer']['tz']
         d['message'] = commit['message']
         if commit['body']:
             # TODO check if really needed
             d['message'] = '\n    '.join(
                 [d['message']] + [''] +
                 remove_unknown_character(commit['body']).splitlines())
         d['email'] = email_normalizer(d['name'], commit['author']['email'])
         # TODO check if merge is really needed
         if len(commit['parent']) > 1:
             d['merge'] = ' '.join(sha[:7] for sha in commit['parent'])
         d['files'] = []
         cmt_obj = self.get_commit(commit_sha)
         if cmt_obj.parent:
             repo = self.pygit2_repo
             cmt = repo.revparse_single(commit_sha)
             parent = cmt.parents[0]
             diffs = parent.tree.diff(cmt.tree)
             for patch in diffs:
                 filepath = patch.new_file_path if patch.status != 'D' \
                     else patch.old_file_path
                 d['files'].append({
                     'type': PATCH_TYPE.get(patch.status),
                     'filepath': filepath
                 })
         else:
             diffs = self.parse_diff(commit_sha)
             for diff in diffs['difflist']:
                 d['files'].append({
                     'type': diff.type,
                     'filepath': diff.filepath
                 })
         revisions.append(d)
     return revisions
Example #12
0
 def get_revisions(self, begin='HEAD~5', end='HEAD'):
     if self.is_empty():
         return []
     res = self.get_rev_list(begin, end, _raise=False)
     revisions = []
     if not res:
         return []
     for commit_sha in res:
         commit = self.cat(commit_sha)
         d = {}
         d['name'] = commit['author']['name']
         d['id'] = commit_sha
         d['date'] = commit['committer']['date'].strftime(
             '%Y-%m-%dT%H:%M:%S') + commit['committer']['tz']
         d['message'] = commit['message']
         if commit['body']:
             # TODO check if really needed
             d['message'] = '\n    '.join(
                 [d['message']] + [''] + remove_unknown_character(
                     commit['body']).splitlines())
         d['email'] = email_normalizer(d['name'], commit['author']['email'])
         # TODO check if merge is really needed
         if len(commit['parent']) > 1:
             d['merge'] = ' '.join(sha[:7] for sha in commit['parent'])
         d['files'] = []
         cmt_obj = self.get_commit(commit_sha)
         if cmt_obj.parent:
             repo = self.pygit2_repo
             cmt = repo.revparse_single(commit_sha)
             parent = cmt.parents[0]
             diffs = parent.tree.diff(cmt.tree)
             for patch in diffs:
                 filepath = patch.new_file_path if patch.status != 'D' \
                     else patch.old_file_path
                 d['files'].append({'type': PATCH_TYPE.get(patch.status),
                                    'filepath': filepath})
         else:
             diffs = self.parse_diff(commit_sha)
             for diff in diffs['difflist']:
                 d['files'].append({
                     'type': diff.type, 'filepath': diff.filepath})
         revisions.append(d)
     return revisions
Example #13
0
 def get_revlist(self, max_count=20, skip=0, rev='HEAD', path='',
                 author=None, query=None):
     commits = []
     cs = self._gyt_repo.rev_list(rev, max_count=max_count, skip=skip,
                                  paths=path, author=author, query=query)
     for c in cs:
         commit = {}
         commit['parents'] = [p.hex for p in c.parents] if c.parents else ''
         commit['date'] = datetime.fromtimestamp(
             c.committer.time,
             FixedOffset(c.committer.offset))
         commit['age'] = compute_relative_time(c.author.time)
         commit['author'] = c.author.name
         commit['email'] = email_normalizer(c.author.name,
                                            c.author.email)
         message_title = c.message.splitlines()[0] if c.message else ''
         commit['message'] = message_title
         commit['commit'] = c.hex
         commits.append(commit)
     return commits
Example #14
0
 def parse_diff(self, ref='HEAD', ignore_space=False,
                rename_detection=False):
     if self.object_type(ref) != 'commit':
         return False
     diff_data = self.cat(ref)
     diffs = {}
     diffs['parents'] = ' '.join(diff_data['parent'])
     diffs['author'] = diff_data['author']['name']
     diffs['email'] = email_normalizer(
         diffs['author'], diff_data['author']['email'])
     diffs['time'] = compute_relative_time(diff_data['author']['ts'])
     diffs['message'] = diff_data['message'].replace('\n', ' ')
     diffs['body'] = remove_unknown_character(diff_data['body'])
     parents = diffs['parents'].split(' ')
     if parents and parents[0]:
         diffs['difflist'] = self.get_3dot_diff(
             parents[0], ref, ignore_space=ignore_space,
             rename_detection=rename_detection)
     else:
         diffs['difflist'] = self._get_diff_for_first_commit(ref, parents)
     return diffs