Showing 6 changed files with 24 additions and 57 deletions
+16 -49
lib/Gitprep/Git.pm
... ...
@@ -41,7 +41,7 @@ sub branch {
41 41
   $branch_name =~ s/\s*$//;
42 42
   my $branch = {};
43 43
   $branch->{name} = $branch_name;
44
-  my $commit = $self->get_commit_new($rep_info, $branch_name);
44
+  my $commit = $self->get_commit($rep_info, $branch_name);
45 45
   $branch->{commit} = $commit;
46 46
 
47 47
   return $branch;
... ...
@@ -716,7 +716,7 @@ sub forward_commits {
716 716
   while (my $line = <$fh>) {
717 717
     if ($line =~ /^>(.+)\s/) {
718 718
       my $rev = $1;
719
-      my $commit = $self->get_commit_new($rep_info, $rev);
719
+      my $commit = $self->get_commit($rep_info, $rev);
720 720
       push @$commits, $commit;
721 721
     }
722 722
   }
... ...
@@ -993,7 +993,7 @@ sub tags {
993 993
       $tag{comment_short} = $self->_chop_str($tag{subject}, 30, 5)
994 994
         if $tag{subject};
995 995
 
996
-      $tag{commit} = $self->get_commit_new($rep_info, $name);
996
+      $tag{commit} = $self->get_commit($rep_info, $name);
997 997
 
998 998
       push @tags, \%tag;
999 999
     }
... ...
@@ -1032,7 +1032,7 @@ sub last_change_commit {
1032 1032
   my $commit;
1033 1033
   if ($commit_log_text =~ /^([0-9a-zA-Z]+)/) {
1034 1034
     my $rev = $1;
1035
-    $commit = $self->get_commit_new($rep_info, $rev);
1035
+    $commit = $self->get_commit($rep_info, $rev);
1036 1036
   }
1037 1037
   
1038 1038
   return $commit;
... ...
@@ -1119,42 +1119,11 @@ sub parse_blob_diff_lines {
1119 1119
 }
1120 1120
 
1121 1121
 sub get_commit {
1122
-  my ($self, $user, $project, $id) = @_;
1123
-  
1124
-  # Git rev-list
1125
-  my @cmd = $self->cmd_rep(
1126
-    $user,
1127
-    $project,
1128
-    'rev-list',
1129
-    '--parents',
1130
-    '--header',
1131
-    '--max-count=1',
1132
-    $id,
1133
-    '--'
1134
-  );
1135
-  open my $fh, '-|', @cmd
1136
-    or croak 'Open git-rev-list failed';
1137
-  
1138
-  # Parse commit
1139
-  local $/ = "\0";
1140
-  my $content = <$fh>;
1141
-  $content = $self->_dec($content);
1142
-  return unless defined $content;
1143
-  my $commit = $self->parse_commit_text($content, 1);
1144
-  close $fh;
1145
-
1146
-  return $commit;
1147
-}
1148
-
1149
-sub get_commit_new {
1150
-  my ($self, $rep, $id) = @_;
1151
-  
1152
-  my $git_dir = $rep->{git_dir};
1153
-  my $work_tree = $rep->{work_tree};
1122
+  my ($self, $rep_info, $id) = @_;
1154 1123
   
1155 1124
   # Git rev-list
1156 1125
   my @cmd = $self->cmd(
1157
-    $rep,
1126
+    $rep_info,
1158 1127
     'rev-list',
1159 1128
     '--parents',
1160 1129
     '--header',
... ...
@@ -1461,12 +1430,11 @@ sub search_bin {
1461 1430
 }
1462 1431
 
1463 1432
 sub separated_commit {
1464
-  my ($self, $user, $project, $rev1, $rev2) = @_;
1433
+  my ($self, $rep_info, $rev1, $rev2) = @_;
1465 1434
   
1466 1435
   # Command "git diff-tree"
1467
-  my @cmd = $self->cmd_rep(
1468
-    $user,
1469
-    $project,
1436
+  my @cmd = $self->cmd(
1437
+    $rep_info,
1470 1438
     'show-branch',
1471 1439
     $rev1,
1472 1440
     $rev2
... ...
@@ -1481,7 +1449,7 @@ sub separated_commit {
1481 1449
   my $commit;
1482 1450
   if (defined $last_line) {
1483 1451
       my ($id) = $last_line =~ /^.*?\[(.+)?\]/;
1484
-      $commit = $self->get_commit($user, $project, $id);
1452
+      $commit = $self->get_commit($rep_info, $id);
1485 1453
   }
1486 1454
 
1487 1455
   return $commit;
... ...
@@ -1535,23 +1503,22 @@ sub timestamp {
1535 1503
 }
1536 1504
 
1537 1505
 sub trees {
1538
-  my ($self, $user, $project, $rev, $dir) = @_;
1506
+  my ($self, $rep_info, $rev, $dir) = @_;
1539 1507
   $dir = '' unless defined $dir;
1540 1508
   
1541 1509
   # Get tree
1542 1510
   my $tid;
1543 1511
   if (defined $dir && $dir ne '') {
1544
-    $tid = $self->path_to_hash($self->app->rep_info($user, $project), $rev, $dir, 'tree');
1512
+    $tid = $self->path_to_hash($rep_info, $rev, $dir, 'tree');
1545 1513
   }
1546 1514
   else {
1547
-    my $commit = $self->get_commit($user, $project, $rev);
1515
+    my $commit = $self->get_commit($rep_info, $rev);
1548 1516
     $tid = $commit->{tree};
1549 1517
   }
1550 1518
   my @entries = ();
1551 1519
   my $show_sizes = 0;
1552
-  my @cmd = $self->cmd_rep(
1553
-    $user,
1554
-    $project,
1520
+  my @cmd = $self->cmd(
1521
+    $rep_info,
1555 1522
     'ls-tree',
1556 1523
     '-z',
1557 1524
     ($show_sizes ? '-l' : ()),
... ...
@@ -1575,7 +1542,7 @@ sub trees {
1575 1542
     
1576 1543
     # Commit log
1577 1544
     my $path = defined $dir && $dir ne '' ? "$dir/$tree->{name}" : $tree->{name};
1578
-    my $commit = $self->last_change_commit($self->app->rep_info($user, $project), $rev, $path);
1545
+    my $commit = $self->last_change_commit($rep_info, $rev, $path);
1579 1546
     $tree->{commit} = $commit;
1580 1547
     
1581 1548
     push @$trees, $tree;
+1 -1
templates/auto/_search.html.ep
... ...
@@ -116,7 +116,7 @@
116 116
                   my $branches = app->git->branches($self->app->rep_info($user, $project));
117 117
                   my $commit;
118 118
                   if (@$branches) {
119
-                    $commit = app->git->get_commit($user, $project, $rev);
119
+                    $commit = app->git->get_commit(app->rep_info($user, $project), $rev);
120 120
                   }
121 121
                 %>
122 122
                 
+1 -1
templates/commit.html.ep
... ...
@@ -12,7 +12,7 @@
12 12
   my $git = app->git;
13 13
   
14 14
   # Commit
15
-  my $commit = $git->get_commit($user, $project, $rev);
15
+  my $commit = $git->get_commit(app->rep_info($user, $project), $rev);
16 16
   
17 17
   unless ($commit) {
18 18
     $self->reply->not_found;
+1 -1
templates/commits.html.ep
... ...
@@ -16,7 +16,7 @@
16 16
   my $page = param('page') || 0;
17 17
   
18 18
   # Commit
19
-  my $commit = $git->get_commit($user, $project, $rev);
19
+  my $commit = $git->get_commit(app->rep_info($user, $project), $rev);
20 20
 
21 21
   # Not found
22 22
   unless ($commit) {
+2 -2
templates/compare.html.ep
... ...
@@ -31,10 +31,10 @@
31 31
   my $authors_count = keys %$authors;
32 32
 
33 33
   # Start commit
34
-  my $start_commit = $git->separated_commit($user, $project, $from_rev, $rev);
34
+  my $start_commit = $git->separated_commit(app->rep_info($user, $project), $from_rev, $rev);
35 35
 
36 36
   # End commit
37
-  my $end_commit = $git->get_commit($user, $project, $rev);
37
+  my $end_commit = $git->get_commit(app->rep_info($user, $project), $rev);
38 38
   
39 39
   if (!$start_commit || !$end_commit) {
40 40
     $self->reply->not_found;
+3 -3
templates/tree.html.ep
... ...
@@ -35,15 +35,15 @@
35 35
   my $commits_number;
36 36
   if ($git->exists_branch(app->rep_info($user, $project))) {
37 37
     # Commit
38
-    my $commit = $git->get_commit($user, $project, $rev);
38
+    my $commit = $git->get_commit(app->rep_info($user, $project), $rev);
39 39
     
40 40
     # Tree
41 41
     my $trees;
42 42
     if (defined $dir && length $dir) {
43
-      $trees = $git->trees($user, $project, $rev, $dir);
43
+      $trees = $git->trees(app->rep_info($user, $project), $rev, $dir);
44 44
     }
45 45
     else {
46
-      $trees = $git->trees($user, $project, $rev);
46
+      $trees = $git->trees(app->rep_info($user, $project), $rev);
47 47
     }
48 48
     # Commits number
49 49
     $commits_number = $git->commits_number(app->rep_info($user, $project), $rev);