Esempio n. 1
0
def get_commit_templatedata(repo, obj):
    """Gets the required data to feed into the templates which display a single commit, including the tree changes
    in the commit, author and committer info, time and commit messages, and list of changed files. Returns a dict
    with appropriate key names for the templates to use."""
    tree = list(get_tree_diff(repo, obj))
    td = tree_diff.TreeDiffer(repo)
    
    changed_files = []
    for entry in tree:
        if entry.kind != tree_diff.DiffEntry.UNMODIFIED:
            changed_files.extend(td.commitdiff(entry))
    
    message = ggutils.force_unicode(obj.message)
    short_message = ggutils.short_message(message)
    author = (ggutils.force_unicode(obj.author.name), ggutils.force_unicode(obj.author.email))
    committer = (ggutils.force_unicode(obj.committer.name), ggutils.force_unicode(obj.committer.email))
    author_time = ggutils.format_commit_time(obj.author.time)
    commit_time = ggutils.format_commit_time(obj.committer.time)
    return dict(
        commit=obj,
        message=message,
        title=short_message,
        author=author,
        committer=committer,
        author_time=author_time,
        commit_time=commit_time,
        initial_tree=tree,
        td_encoder=tree_diff.DiffEntryEncoder,
        changed_files=changed_files
    )
Esempio n. 2
0
 def draw_commits(self, walker, existing_branches=[], currentY=0):
     """ This is the main function that draws the commits taken from a walk of the repository
     (the walker object). It can optionally start with a number of existing branches and at a
     given y-position. It returns a tuple with the first member being a dictionary of the nodes,
     edges, and labels to be drawn, and the second member being a list of branches at the bottom
     of the graph (used for continuing the graph later)"""
     column = 0
     self.graph = [] #stores a list of edges which aren't finished being drawn.
     # display_list is a structure holding what should actually be drawn on the screen.
     self.display_list = {'edges':[], 'nodes':[], 'labels':[], 'authors':[], 'dates':[]}
     # branches is an array of strings used to track where branches should go.
     # A SHA hash in some position indicates that commit should be the next one in that position.
     # An empty string indicates the position is blank and can be filled with a new branch if one appears.
     self.branches = []
     for existing_branch in existing_branches:
         if existing_branch:
             # start drawing these existing branches
             self.graph.append(self.new_edge(column, currentY, existing_branch))
         column = column + 1
         # Keep track of existing branches
         self.branches.append(existing_branch)
     for commit in walker:
         pos = self.place_commit(commit, currentY)
         
         # Do any edges need finishing off?
         self.finish_edges(commit.hex, pos, currentY)
         
         #The delete flag determines whether to mark this branch as deleted
         if commit.parents:
             delete = self.process_parents(commit.parents, pos, currentY)
         else:
             del self.branches[pos] #this branch has no parent, delete it
             delete = False
         
         #TODO: make this more elegant?
         textX = len(self.branches)
         for branch in reversed(self.branches):
             if branch == '':
                 textX -= 1
             else:
                 break
         textX = max(textX,1)
         
         if delete:
             #clear out this branch for future use
             self.branches[pos] = ''
         
         # Create a node representing this commit and the message, author and time labels
         self.display_list['nodes'].append(self.new_node(pos, currentY, commit.hex, [x.hex for x in commit.parents]))
         label_text = ggutils.force_unicode(ggutils.short_message(commit.message))
         self.display_list['labels'].append({'x': textX, 'y': currentY, 'content': label_text, 'sha': commit.hex})
         self.display_list['authors'].append({'x': 0, 'y': currentY, 'content': ggutils.force_unicode(commit.author.name), 'sha': commit.hex})
         self.display_list['dates'].append({'x': 0, 'y': currentY, 'content': ggutils.format_commit_time(commit.commit_time), 'sha': commit.hex})
         currentY += 1
     for incomplete in self.graph:
         incomplete['d'].append({'type': 'V', 'y': currentY})
         self.display_list['edges'].append(incomplete)
     self.display_list['edges'].sort(key=itemgetter('order'))
     return (self.display_list, self.branches)