Gave ownership of URLs to Gitalist proper.
broquaint [Mon, 26 Oct 2009 11:24:49 +0000 (11:24 +0000)]
To get back to gitweb s{/(\w+)\?}(/?a=$1).
Straightened out the controller somewhat.
Fixed the model's get_object method to return undef when no object is available.
Created the partials _diff, _diff_tree & _tree.
The /diff view while simple, is approaching something useful.

lib/Gitalist/Controller/Root.pm
lib/Gitalist/Model/Git.pm
templates/_diff.tt2 [new file with mode: 0644]
templates/_diff_tree.tt2 [new file with mode: 0644]
templates/_tree.tt2 [new file with mode: 0644]
templates/commitdiff.tt2
templates/index.tt2
templates/tree.tt2

index 4b2dcf2..dc79c49 100644 (file)
@@ -57,6 +57,22 @@ sub run_gitweb {
   }
 }
 
+sub _get_commit {
+  my($self, $c) = @_;
+
+  # Either use the provided h(ash) parameter, the f(ile) parameter or just use HEAD.
+  my $hash = $c->req->param('h')
+          || ($c->req->param('f') ? $c->model('Git')->hash_by_path($c->req->param('f')) : '')
+          || $c->model('Git')->head_hash
+          # XXX This could definitely use more context.
+          || Carp::croak("Couldn't find a hash for the commit object!");
+
+  my $commit = $c->model('Git')->get_object($hash)
+    or Carp::croak("Couldn't find a commit object for '$hash'!");
+
+  return $commit;
+}
+
 =head2 index
 
 Provides the project listing.
@@ -91,7 +107,7 @@ A summary of what's happening in the repo.
 sub summary : Local {
   my ( $self, $c ) = @_;
 
-  my $commit = $c->model('Git')->get_object($c->model('Git')->head_hash);
+  my $commit = $self->_get_commit($c);
   $c->stash(
     commit    => $commit,
     info      => $c->model('Git')->project_info($c->model('Git')->project),
@@ -111,7 +127,7 @@ sub heads : Local {
   my ( $self, $c ) = @_;
 
   $c->stash(
-    commit => $c->model('Git')->get_object($c->model('Git')->head_hash),
+    commit => $self->_get_commit($c),
     heads  => [$c->model('Git')->heads],
     action => 'heads',
   );
@@ -143,25 +159,6 @@ sub blob : Local {
   $c->forward('View::SyntaxHighlight');
 }
 
-=head2 reflog
-
-Expose the local reflog. This may go away.
-
-=cut
-
-sub reflog : Local {
-  my ( $self, $c ) = @_;
-
-  my @log = $c->model('Git')->reflog(
-      '--since=yesterday'
-  );
-
-  $c->stash(
-      log    => \@log,
-      action => 'reflog',
-  );
-}
-
 =head2 commit
 
 Exposes a given commit.
@@ -171,7 +168,7 @@ Exposes a given commit.
 sub commit : Local {
   my ( $self, $c ) = @_;
 
-  my $commit = $c->model('Git')->get_object($c->req->param('h'));
+  my $commit = $self->_get_commit($c);
   $c->stash(
       commit      => $commit,
       diff_tree   => [$c->model('Git')->diff_tree($commit)],
@@ -189,7 +186,7 @@ Exposes a given diff of a commit.
 sub commitdiff : Local {
   my ( $self, $c ) = @_;
 
-  my $commit = $c->model('Git')->get_object($c->req->param('h'));
+  my $commit = $self->_get_commit($c);
   $c->stash(
       commit      => $commit,
       diff_tree   => [$c->model('Git')->diff_tree($commit)],
@@ -207,7 +204,7 @@ Expose an abbreviated log of a given sha1.
 sub shortlog : Local {
   my ( $self, $c ) = @_;
 
-  my $commit = $c->model('Git')->get_object($c->req->param('h'));
+  my $commit = $self->_get_commit($c);
   # XXX Needs paging.
   $c->stash(
       commit    => $commit,
@@ -235,16 +232,35 @@ The tree of a given commit.
 sub tree : Local {
   my ( $self, $c ) = @_;
 
-  my $commit = $c->model('Git')->get_object($c->req->param('h'));
+  my $commit = $self->_get_commit($c);
   $c->stash(
       # XXX Useful defaults needed ...
       commit    => $commit,
       tree      => $c->model('Git')->get_object($c->req->param('hb')),
-      list_tree => [$c->model('Git')->list_tree($commit->sha1)],
+      tree_list => [$c->model('Git')->list_tree($commit->sha1)],
       action    => 'tree',
   );
 }
 
+=head2 reflog
+
+Expose the local reflog. This may go away.
+
+=cut
+
+sub reflog : Local {
+  my ( $self, $c ) = @_;
+
+  my @log = $c->model('Git')->reflog(
+      '--since=yesterday'
+  );
+
+  $c->stash(
+      log    => \@log,
+      action => 'reflog',
+  );
+}
+
 =head2 auto
 
 Populate the header and footer. Perhaps not the best location.
index e147f9b..953cfcb 100644 (file)
@@ -85,7 +85,8 @@ A wrapper for the equivalent L<Git::PurePerl> method.
 =cut
 
 sub get_object {
-  $_[0]->gpp->get_object($_[1]);
+  # We either want an object or undef, *not* an empty list.
+  return $_[0]->gpp->get_object($_[1]) || undef;
 }
 
 =head2 is_git_repo
@@ -420,7 +421,7 @@ sub raw_diff {
     || scalar @revs > 2
     || any { !$self->valid_rev($_) } @revs;
 
-  return $self->command(diff => @revs);
+  return $self->command(diff => '--full-index', @revs);
 }
 
 =begin
@@ -459,11 +460,11 @@ sub diff {
   my @diff = $self->raw_diff(@revs);
 
   my @ret;
-  for my $line (@diff) {
+  for (@diff) {
        # This regex is a little pathological.
-       if($line =~ m{^diff --git (a/(.*?)) (b/\2)}) {
+       if(m{^diff --git (a/(.*?)) (b/\2)}) {
       push @ret, {
-       head => $line,
+       head => $_,
        a    => $1,
        b    => $3,
                file => $2,
@@ -472,7 +473,7 @@ sub diff {
          next;
        }
 
-       if($line =~ /^index (\w+)\.\.(\w+) (\d+)$/) {
+       if(/^index (\w+)\.\.(\w+) (\d+)$/) {
          @{$ret[-1]}{qw(index src dst mode)} = ($_, $1, $2, $3);
          next
     }
@@ -481,7 +482,7 @@ sub diff {
          unless @ret;
 
        # XXX Somewhat hacky. Ahem.
-       $ret[-1]{diff} .= "$line\n";
+       $ret[-1]{diff} .= "$_\n";
   }
 
   return @ret;
diff --git a/templates/_diff.tt2 b/templates/_diff.tt2
new file mode 100644 (file)
index 0000000..5ae8d91
--- /dev/null
@@ -0,0 +1,13 @@
+[% FOREACH item IN diff %]
+<div class='diff-head'>
+ diff --git
+ <a href='/blob?p=[% project %];f=[% item.file %];h=[% item.src %]'>[% item.a %]</a>
+ <a href='/blob?p=[% project %];f=[% item.file %];h=[% item.dst %]'>[% item.b %]</a>
+</div>
+<div class='diff-index'>
+ [% item.index %]
+</div>
+<div class='diff-patch'>
+ <pre>[% item.diff | html %]</pre>
+</div>
+[% END %]
diff --git a/templates/_diff_tree.tt2 b/templates/_diff_tree.tt2
new file mode 100644 (file)
index 0000000..d8e5219
--- /dev/null
@@ -0,0 +1,26 @@
+<table class='diff-tree'>
+ <thead>
+  <tr>
+   <td>file</td>
+   <td>actions</td>
+  </tr>
+ </thead>
+ <tbody>
+  [% FOREACH line IN diff_tree %]
+  <tr>
+   <td class='filename'>[% line.src %]</td>
+   <td class='action-list'>
+     [% IF !line.is_new %]<a href="/blobdiff?p=[% project %];f=[% line.file %];h=[% line.sha1dst %];hp=[% sha1src %]">diff</a>[% END %]
+     <a href="/blob?p=[% project %];f=[% line.file %];h=[% line.sha1 %];hb=[% commit.sha1 %]">blob</a>
+     [% IF !line.is_new %]<a href="/log?p=[% project %];f=[% line.file %];hb=[% commit.sha1 %]">history</a>[% END %]
+   </td>
+  </tr>
+  [% END %]
+ </tbody>
+ <tfoot>
+  <tr>
+   <td>file</td>
+   <td>actions</td>
+  </tr>
+ </tfoot>
+</table>
diff --git a/templates/_tree.tt2 b/templates/_tree.tt2
new file mode 100644 (file)
index 0000000..e39b1a5
--- /dev/null
@@ -0,0 +1,35 @@
+<table>
+ <thead>
+  <tr>
+   <td>mode</td>
+   <td>file</td>
+   <td>actions</td>
+  </tr>
+ </thead>
+
+ <tbody>
+  [% FOREACH item IN tree_list %]
+  <tr>
+   <td>[% item.modestr %]</td>
+   [% theact = item.type == 'tree' ? 'tree' : 'blob' -%]
+   <td class='filename'>
+    <a href="/[% theact %]?h=[% item.object %];hb=[% commit.sha1 %];f=[% item.file %]">[% item.file %]</a>
+   </td>
+   <td class='action-list'>
+     <a href="/[% theact %]?p=[% project %];h=[% item.object %];hb=[% commit.sha1 %];f=[% item.file %]">[% theact %]</a>
+     <a href="/history?p=[% project %];h=[% item.object %]">history</a>
+     <a href="/raw?p=[% project %];h=[% item.object %]">raw</a>
+   </td>
+  </tr>
+  [% END %]
+ </tbody>
+
+ <tfoot>
+  <tr>
+   <td>mode</td>
+   <td>file</td>
+   <td>actions</td>
+  </tr>
+ </tfoot>
+</table>
+
index b31cd5b..acb61c4 100644 (file)
@@ -10,9 +10,4 @@
 
 [% INCLUDE '_diff_tree.tt2' %]
 
-<div class='diff'>
-[% USE dumper;
-FOREACH file IN diff %]
-<pre>[% dumper.dump(file) | html %]</pre>
-[% END %]
-</div>
+[% INCLUDE '_diff.tt2' %]
index 8134ae1..adf7e87 100644 (file)
     USE Cycle('dark', 'light');
     FOR p IN projects %]
     <tr class="[% Cycle.next %]">
-        <td><a class="list" href="/?p=[% p.name %];a=summary">[% p.name %]</a></td>
-        <td><a class="list" title="[% p.description %]" href="/?p=[% p.name %];a=summary">[% p.description.substr(0, 20) %]</a></td>
+        <td><a class="list" href="/summary?p=[% p.name %]">[% p.name %]</a></td>
+        <td><a class="list" title="[% p.description %]" href="/summary?p=[% p.name %]">[% p.description.substr(0, 20) %]</a></td>
         <td>[% p.owner %]</td>
         <td class="age2">[% p.last_change %]</td>
-        <td class="link"><a href="/?p=[% p.name %];a=summary">summary</a>
-            | <a href="/?p=[% p.name %];a=shortlog">shortlog</a>
-            | <a href="/?p=[% p.name %];a=log">log</a>
-            | <a href="/?p=[% p.name %];a=tree">tree</a></td>
+        <td class="link"><a href="/summary?p=[% p.name %]">summary</a>
+            | <a href="/shortlog?p=[% p.name %]">shortlog</a>
+            | <a href="/log?p=[% p.name %]">log</a>
+            | <a href="/tree?p=[% p.name %]">tree</a></td>
     </tr>
   [% END %]
 </tbody>
index 00435fd..8583cae 100644 (file)
@@ -4,37 +4,4 @@
 [% commit.comment.substr(0, 85) %] ...
 </div>
 
-<table>
- <thead>
-  <tr>
-   <td>mode</td>
-   <td>file</td>
-   <td>actions</td>
-  </tr>
- </thead>
-
- <tbody>
-  [% FOREACH item IN list_tree %]
-  <tr>
-   <td>[% item.modestr %]</td>
-   [% theact = item.type == 'tree' ? 'tree' : 'blob' -%]
-   <td class='filename'>
-    <a href="/[% theact %]?h=[% item.object %];hb=[% commit.sha1 %];f=[% item.file %]">[% item.file %]</a>
-   </td>
-   <td class='action-list'>
-     <a href="/[% theact %]?p=[% project %];h=[% item.object %];hb=[% commit.sha1 %];f=[% item.file %]">[% theact %]</a>
-     <a href="/history?p=[% project %];h=[% item.object %]">history</a>
-     <a href="/raw?p=[% project %];h=[% item.object %]">raw</a>
-   </td>
-  </tr>
-  [% END %]
- </tbody>
-
- <tfoot>
-  <tr>
-   <td>mode</td>
-   <td>file</td>
-   <td>actions</td>
-  </tr>
- </tfoot>
-</table>
+[% INCLUDE '_tree.tt2' %]