Showing 6 changed files with 65 additions and 34 deletions
+36
lib/Gitprep/Git.pm
... ...
@@ -322,6 +322,42 @@ sub id_by_path {
322 322
   return $id;
323 323
 }
324 324
 
325
+sub root_ns {
326
+  my ($self, $root) = @_;
327
+
328
+  $root =~ s/^\///;
329
+  
330
+  return $root;
331
+}
332
+
333
+sub parse_object {
334
+  my ($self, $project, $id_path) = @_;
335
+  
336
+  # Parse id and path
337
+  my $refs = $self->references($project);
338
+  my $id;
339
+  my $path;
340
+  for my $rs (values %$refs) {
341
+    for my $ref (@$rs) {
342
+      $ref =~ s#^heads/##;
343
+      $ref =~ s#^tags/##;
344
+      if ($id_path =~ s#^\Q$ref(/|$)##) {
345
+        $id = $ref;
346
+        $path = $id_path;
347
+        last;
348
+      }      
349
+    }
350
+  }
351
+  unless (defined $id) {
352
+    if ($id_path =~ s#(^[^/]+)(/|$)##) {
353
+      $id = $1;
354
+      $path = $id_path;
355
+    }
356
+  }
357
+  
358
+  return ($id, $path);
359
+}
360
+
325 361
 sub path_by_id {
326 362
   my $self = shift;
327 363
   my $project = shift;
+1 -2
templates/include/difftree.html.ep
... ...
@@ -53,8 +53,7 @@
53 53
             </td>
54 54
           % } else {
55 55
             <td>
56
-              <a class="list ubar" href="<%= url_for('blob', project => $project_ns,
57
-                  id_file => "$id/$file") %>">
56
+              <a class="list ubar" href="<%= url_for("/$user/$project/blob/$id/$file") %>">
58 57
                 <%= $file %>
59 58
               </a>
60 59
             </td>
+4 -4
templates/main/blob.html.ep
... ...
@@ -10,12 +10,12 @@
10 10
   my $rep = "/$rep_ns";
11 11
   my $object = param('object');
12 12
 
13
-  # Revision and blob
14
-  my ($rev, $blob) = $api->parse_id_path($rep, $object);
15
-
16 13
   # Git
17 14
   my $git = $self->app->git;
18 15
   
16
+  # Revision and blob
17
+  my ($rev, $blob) = $git->parse_object($rep, $object);
18
+
19 19
   # Commit log
20 20
   my $commit_log = $git->latest_commit_log($rep, $rev, $blob);
21 21
 
... ...
@@ -185,7 +185,7 @@
185 185
             % if (defined $blob) {
186 186
               alt="<%= $blob %>" title="<%= $blob %>"
187 187
             % }
188
-            src="<%= url_for('blob_plain', project => $rep_ns, id_file => "$rev/$blob") %>"
188
+            src="<%= url_for("/$user/$project/raw/$rev/$blob") %>"
189 189
           />
190 190
         % } else {
191 191
           % my $nr = 1;
+6 -6
templates/main/project.html.ep
... ...
@@ -1,5 +1,8 @@
1 1
 <%
2 2
   use Gitprep::API;
3
+
4
+  # API
5
+  my $api = Gitprep::API->new($self);
3 6
   
4 7
   # Default revision
5 8
   my $rev = 'master';
... ...
@@ -8,9 +11,6 @@
8 11
   my $user = param('user');
9 12
   my $project = param('project');
10 13
   my $object ||= param('object') || 'master/';
11
-
12
-  # API
13
-  my $api = Gitprep::API->new($self);
14 14
   
15 15
   # Parameters
16 16
   my $root_ns = $api->root_ns(config->{root});
... ...
@@ -20,11 +20,11 @@
20 20
   my $home_ns = $api->dirname($rep_ns);
21 21
   my $home = "/$home_ns";
22 22
 
23
-  # Id and directory
24
-  my ($id, $dir) = $api->parse_id_path($rep, $object);
25
-
26 23
   # Git
27 24
   my $git = app->git;
25
+
26
+  # Id and directory
27
+  my ($id, $dir) = $git->parse_object($rep, $object);
28 28
   
29 29
   # Tree id
30 30
   my $tid;
+4 -4
templates/main/raw.html.ep
... ...
@@ -11,14 +11,14 @@
11 11
   my $rep = "/$rep_ns";
12 12
   my $home_ns = $api->dirname($rep_ns);
13 13
   my $home = "/$home_ns";
14
-  my $id_file = param('id_file');
15
-
16
-  # Id and file
17
-  my ($id, $file) = $api->parse_id_path($rep, $id_file);
14
+  my $object = param('object');
18 15
 
19 16
   # Git
20 17
   my $git = $self->app->git;
21 18
   
19
+  # Id and file
20
+  my ($id, $file) = $git->parse_object($rep, $object);
21
+
22 22
   # Commit
23 23
   my $commit_log = $git->latest_commit_log($rep, $id, $file);
24 24
   
+14 -18
templates/main/tree.html.ep
... ...
@@ -12,48 +12,44 @@
12 12
   my $rep_ns = "$root_ns/$user/$project.git";
13 13
   my $rep = "/$rep_ns";
14 14
 
15
-  # Id and directory
16
-  my ($id, $dir) = $api->parse_id_path($rep, $object);
17
-
18 15
   # Git
19 16
   my $git = app->git;
17
+
18
+  # Id and directory
19
+  my ($rev, $dir) = $git->parse_object($rep, $object);
20 20
   
21 21
   # Tree id
22
+  my $commit = $git->parse_commit($rep, $rev);
22 23
   my $tid;
23
-  my $commit = $git->parse_commit($rep, $id);
24
-  unless (defined $tid) {
25
-    if (defined $dir && $dir ne '') {
26
-      $tid = $git->id_by_path($rep, $id, $dir, 'tree');
27
-    }
28
-    else { $tid = $commit->{tree} }
24
+  if (defined $dir && $dir ne '') {
25
+    $tid = $git->id_by_path($rep, $rev, $dir, 'tree');
29 26
   }
27
+  else { $tid = $commit->{tree} }
30 28
   $self->render_not_found unless defined $tid;
31 29
   
32 30
   # Commit log
33
-  my $latest_commit_log = $git->latest_commit_log($rep, $id);
31
+  my $latest_commit_log = $git->latest_commit_log($rep, $rev);
34 32
   
35 33
   # Tree
36
-  my $trees = $api->trees($rep, $tid, $id, $dir);
34
+  my $trees = $api->trees($rep, $tid, $rev, $dir);
37 35
   
38 36
   # Repository description
39 37
   my $desc = $git->project_description($rep);
40 38
   
41 39
   # Commits number
42
-  my $commits_number = $git->commits_number($rep, $id);
40
+  my $commits_number = $git->commits_number($rep, $rev);
43 41
   
44 42
   # README
45
-  my $readme = $git->blob_plain($rep, $id, 'README');
43
+  my $readme = $git->blob_plain($rep, $rev, 'README');
46 44
   
47
-  # Global variable
45
+  # Variable for included templates
48 46
   stash(
49
-    user => $user,
50
-    id => $id,
51
-    rev => $id,
47
+    rev => $rev,
52 48
     commit => $commit,
53 49
     latest_commit_log => $latest_commit_log,
54 50
     trees => $trees,
55 51
     dir => $dir,
56
-    title => "$project/$dir at $id - $user/$project"
52
+    title => "$project/$dir at $rev - $user/$project"
57 53
   );
58 54
 %>
59 55