gitprep / templates / commit.html.ep /
7233306 10 years ago
1 contributor
149 lines | 5.374kb
<%
  # API
  my $api = gitprep_api;
  
  # Paramters
  my $project = param('project');
  my $diff = param('diff');
  my ($from_rev, $rev) = $diff =~ /(.+)\.\.(.+)/;
  $rev = $diff unless defined $rev;
  
  # Git
  my $git = app->git;
  
  # Commit
  my $commit = $git->get_commit($user, $project, $rev);
  unless ($commit) {
    $self->render_not_found;
    return;
  }
  my $author_date
    = $git->parse_date($commit->{author_epoch}, $commit->{author_tz});
  my $committer_date
    = $git->parse_date($commit->{committer_epoch}, $commit->{committer_tz});
  $commit->{author_date} = $git->timestamp($author_date);
  $commit->{committer_date} = $git->timestamp($committer_date);
  $from_rev = $commit->{parent} unless defined $from_rev;
  my $commit_short_id = substr($commit->{id}, 0, 7, );
  
  # Branches
  my $branch_refs = $git->references($user, $project, 'heads');
  my $branches = $branch_refs->{$commit->{id}} || [];
  
  # Tags
  my $tag_refs = $git->references($user, $project, 'tags');
  my $tags = $tag_refs->{$commit->{id}} || [];
  
  # Global variable for included template
  stash(
    rev => $rev,
    from_rev => $from_rev,
    commit => $commit,
    parents => $commit->{parents}
  );
%>

% layout 'common', title => "$commit->{title_short} \x{30fb} $commit_short_id";

  %= include '/include/header';

  <div class="container">
    %= include '/include/project_header';
    %= include '/include/code_menu', display => 'commits';

    <div class="bk-blue-light border-gray" style="border-bottom:none;padding:10px;border-top-left-radius:5px;border-top-right-radius:5px">
      <div class="row">
       <div class="span10">
          <big>
            % if ($commit->{title_short} eq $commit->{title}) {
              <b><%= $commit->{title_short} %></b>;
            % } else {
              <%
                my $title_short = $commit->{title_short};
                $title_short =~ s/\.\.\.\s*$//;
                my $title_tail = $commit->{title};
                $title_tail =~ s/^\Q$title_short//;
                $title_tail =~ s/^\s+//;
              %>
              <p style="margin-bottom:2px;"><b><%= $title_short %>...</b></p>
              <p style="margin-top:2px;margin-bottom:15px;">...<%= $title_tail %></p>
            % }
          </big>
        </div>
        <div class="text-right">
          <a class="btn btn-primary" href="<%= url_for("/$user/$project/tree/$commit->{id}") %>">
            Browse code
          </a>
        </div>
      </div>
      % if (@{$commit->{comment}} > 1) {
        <div style="padding-left:15px;padding-bottom:5px">
          % for (my $i = 1; $i < @{$commit->{comment}}; $i++) {
            <div>
              <%= $commit->{comment}[$i] %>
            </div>
          % }
        </div>
      % }
      % if (@$branches || @$tags) {
        <hr class="border-gray" style="border-bottom:none;margin-top:5px;margin-bottom:0px">
        <div class="broder-top-gray" style="padding-top:7px">
          % for my $branch (@$branches) {
            <span style="padding-left:5px;">
              <i class="icon-share-alt" style="padding-right:1px"></i><a href="<%= url_for("/$user/$project/tree/$branch") %>"><%= $branch %></a>
            </span>
          % }
          
          % for my $tag (@$tags) {
            <span style="padding-left:5px">
              <i class="icon-tag" style="padding-right:2px"></i><a href="<%= url_for("/$user/$project/tree/$tag") %>"><%= $tag %></a>
            </span>
          % }
        </div>
      % }
    </div>
    <div class="border-gray" style="border-bottom-left-radius:5px;border-bottom-right-radius:5px;margin-bottom:10px;">
      <div class="row">
        <div class="span4" style="padding:5px">
          <span><b><%= $commit->{author_name} %></b></span>
          <span class="muted">authored <span title="<%= $commit->{age_string_datetime} %>"><%= $commit->{age_string} %></span>
        </div>
        <div class="span7 text-right" style="padding:5px;margin-left:75px">
          % my $parents = $commit->{parents};
          
          % if (@$parents == 0) {
            <div>
              0 <span class="muted" style="padding-right:10px">parent</span>
              <span class="muted">commit</span> <%= $commit->{id} %>
            </div>
          % } elsif (@$parents == 1) {
            <div>
              1 <span class="muted">parent</span>
              <a class="font-black" style="padding-right:10px" href="<%= url_for("/$user/$project/commit/$parents->[0]") %>">
                <%= substr($parents->[0], 0, 7) %>
              </a>
              <span class="muted">commit</span> <%= $commit->{id} %>
            </div>
          % } else {
            <div>
              <span class="muted">commit</span> <%= $commit->{id} %>
            </div>
            <div>
              2 <span class="muted">parents</span>:
              
              <a class="font-black" href="<%= url_for("/$user/$project/commit/$parents->[0]") %>">
                <%= substr($parents->[0], 0, 7) %>
              </a>
              +
              <a class="font-black" href="<%= url_for("/$user/$project/commit/$parents->[1]") %>">
                <%= substr($parents->[1], 0, 7) %>
              </a>
            </div>
          % }
        </div>
      </div>
    </div>
  
  %= include '/include/commit_body';
  
  %= include '/include/footer';