Showing 5 changed files with 51 additions and 71 deletions
+42 -41
lib/Gitprep/Git.pm
... ...
@@ -39,7 +39,7 @@ sub branch_status {
39 39
   
40 40
   # Branch status
41 41
   my $status = {ahead => 0, behind => 0};
42
-  my @cmd = $self->cmd(
42
+  my @cmd = $self->cmd_rep(
43 43
     $user,
44 44
     $project,
45 45
     'rev-list',
... ...
@@ -64,7 +64,7 @@ sub no_merged_branch_h {
64 64
   {
65 65
     my $rep = $self->app->rep_path($user, $project);
66 66
     
67
-    my @cmd = $self->cmd($user, $project, 'branch', '--no-merged');
67
+    my @cmd = $self->cmd_rep($user, $project, 'branch', '--no-merged');
68 68
     open my $fh, '-|', @cmd or return;
69 69
     my @lines = <$fh>;
70 70
     for my $branch_name (@lines) {
... ...
@@ -83,7 +83,7 @@ sub branches {
83 83
   my ($self, $user, $project) = @_;
84 84
   
85 85
   # Branches
86
-  my @cmd = $self->cmd($user, $project, 'branch');
86
+  my @cmd = $self->cmd_rep($user, $project, 'branch');
87 87
   open my $fh, '-|', @cmd or return;
88 88
   my $branches = [];
89 89
   my $start;
... ...
@@ -113,7 +113,7 @@ sub branches_count {
113 113
   my ($self, $user, $project) = @_;
114 114
   
115 115
   # Branches count
116
-  my @cmd = $self->cmd($user, $project, 'branch');
116
+  my @cmd = $self->cmd_rep($user, $project, 'branch');
117 117
   open my $fh, '-|', @cmd or return;
118 118
   my @branches = <$fh>;
119 119
   my $branches_count = @branches;
... ...
@@ -128,11 +128,12 @@ sub cmd_clone {
128 128
   my $rep = $self->app->rep_path($user, $project);
129 129
   
130 130
   # Working directory
131
-  my $working_dir = $self->app->home->rel_file("/data/work/$user/$project");
131
+  my $rep_work = $self->app->rep_work_path($user, $project);
132 132
   
133
-  return ($self->bin, 'clone', $rep, $working_dir)
133
+  return ($self->bin, 'clone', $rep, $rep_work)
134 134
 }
135
-sub cmd {
135
+
136
+sub cmd_rep {
136 137
   my ($self, $user, $project, @cmd) = @_;
137 138
   
138 139
   # Git command
... ...
@@ -147,16 +148,16 @@ sub cmd_dir {
147 148
   return ($self->bin, "--git-dir=$dir", @cmd);
148 149
 }
149 150
 
150
-sub cmd_working {
151
+sub cmd_rep_work {
151 152
   my ($self, $user, $project, @cmd) = @_;
152 153
   
153
-  # Git command
154
-  my $working_dir = $self->home->rel_file("/data/work/$user/$project");
154
+  # Working directory
155
+  my $rep_work = $self->app->rep_work_path($user, $project);
155 156
   
156
-  return $self->cmd_working_dir($working_dir, @cmd);
157
+  return $self->cmd_work_dir($rep_work, @cmd);
157 158
 }
158 159
 
159
-sub cmd_working_dir {
160
+sub cmd_work_dir {
160 161
   my ($self, $dir, @cmd) = @_;
161 162
   
162 163
   return ($self->bin, "--git-dir=$dir", "--work-tree=$dir",  @cmd);
... ...
@@ -166,7 +167,7 @@ sub authors {
166 167
   my ($self, $user, $project, $rev, $file) = @_;
167 168
   
168 169
   # Authors
169
-  my @cmd = $self->cmd(
170
+  my @cmd = $self->cmd_rep(
170 171
     $user,
171 172
     $project,
172 173
     'log',
... ...
@@ -196,7 +197,7 @@ sub blame {
196 197
     or croak 'Cannot find file';
197 198
   
198 199
   # Git blame
199
-  my @cmd = $self->cmd(
200
+  my @cmd = $self->cmd_rep(
200 201
     $user,
201 202
     $project,
202 203
     'blame',
... ...
@@ -295,7 +296,7 @@ sub blob {
295 296
   # Blob
296 297
   my $hash = $self->path_to_hash($user, $project, $rev, $file, 'blob')
297 298
     or croak 'Cannot find file';
298
-  my @cmd = $self->cmd(
299
+  my @cmd = $self->cmd_rep(
299 300
     $user,
300 301
     $project,
301 302
     'cat-file',
... ...
@@ -327,7 +328,7 @@ sub blob_diffs {
327 328
   return unless defined $rev1 && defined $rev2;
328 329
   
329 330
   # Diff tree
330
-  my @cmd = $self->cmd(
331
+  my @cmd = $self->cmd_rep(
331 332
     $user,
332 333
     $project,
333 334
     'diff-tree',
... ...
@@ -365,7 +366,7 @@ sub blob_diffs {
365 366
     my $file = $diffinfo->{to_file};
366 367
     
367 368
     # Blob diff
368
-    my @cmd = $self->cmd(
369
+    my @cmd = $self->cmd_rep(
369 370
       $user,
370 371
       $project,
371 372
       'diff-tree',
... ...
@@ -428,7 +429,7 @@ sub blob_mime_type {
428 429
   # Blob
429 430
   my $hash = $self->path_to_hash($user, $project, $rev, $file, 'blob')
430 431
     or croak 'Cannot find file';
431
-  my @cmd = $self->cmd(
432
+  my @cmd = $self->cmd_rep(
432 433
     $user,
433 434
     $project,
434 435
     'cat-file',
... ...
@@ -473,7 +474,7 @@ sub blob_mode {
473 474
   
474 475
   # Blob mode
475 476
   $file =~ s#/+$##;
476
-  my @cmd = $self->cmd(
477
+  my @cmd = $self->cmd_rep(
477 478
     $user,
478 479
     $project,
479 480
     'ls-tree',
... ...
@@ -495,7 +496,7 @@ sub blob_raw {
495 496
   my ($self, $user, $project, $rev, $path) = @_;
496 497
   
497 498
   # Blob raw
498
-  my @cmd = $self->cmd($user, $project, 'cat-file', 'blob', "$rev:$path");
499
+  my @cmd = $self->cmd_rep($user, $project, 'cat-file', 'blob', "$rev:$path");
499 500
   open my $fh, "-|", @cmd
500 501
     or croak 500, "Open git-cat-file failed";
501 502
   local $/;
... ...
@@ -510,7 +511,7 @@ sub blob_size {
510 511
   my ($self, $user, $project, $rev, $file) = @_;
511 512
   
512 513
   # Blob size(KB)
513
-  my @cmd = $self->cmd(
514
+  my @cmd = $self->cmd_rep(
514 515
     $user,
515 516
     $project,
516 517
     'cat-file',
... ...
@@ -544,7 +545,7 @@ sub commits_number {
544 545
   my ($self, $user, $project, $ref) = @_;
545 546
   
546 547
   # Command "git diff-tree"
547
-  my @cmd = $self->cmd($user, $project, 'shortlog', '-s', $ref);
548
+  my @cmd = $self->cmd_rep($user, $project, 'shortlog', '-s', $ref);
548 549
   open my $fh, "-|", @cmd
549 550
     or croak 500, "Open git-shortlog failed";
550 551
   my @commits_infos = <$fh>;
... ...
@@ -565,7 +566,7 @@ sub exists_branch {
565 566
   my ($self, $user, $project) = @_;
566 567
   
567 568
   # Exists branch
568
-  my @cmd = $self->cmd($user, $project, 'branch');
569
+  my @cmd = $self->cmd_rep($user, $project, 'branch');
569 570
   open my $fh, "-|", @cmd
570 571
     or croak 'git branch failed';
571 572
   local $/;
... ...
@@ -587,7 +588,7 @@ sub delete_branch {
587 588
   }
588 589
   
589 590
   if ($exists) {
590
-    my @cmd = $self->cmd($user, $project, 'branch', '-D', $branch);
591
+    my @cmd = $self->cmd_rep($user, $project, 'branch', '-D', $branch);
591 592
     Gitprep::Util::run_command(@cmd)
592 593
       or croak "Branch deleting failed. Can't delete branch $branch";
593 594
   }
... ...
@@ -629,7 +630,7 @@ sub diff_tree {
629 630
   $parent = '--root' unless defined $parent;
630 631
 
631 632
   # Get diff tree
632
-  my @cmd = $self->cmd(
633
+  my @cmd = $self->cmd_rep(
633 634
     $user,
634 635
     $project,
635 636
     "diff-tree",
... ...
@@ -720,7 +721,7 @@ sub forward_commits {
720 721
   my ($self, $user, $project, $rev1, $rev2) = @_;
721 722
   
722 723
   # Forwarding commits
723
-  my @cmd = $self->cmd(
724
+  my @cmd = $self->cmd_rep(
724 725
     $user,
725 726
     $project,
726 727
     'rev-list',
... ...
@@ -746,7 +747,7 @@ sub path_to_hash {
746 747
   
747 748
   # Get blob id or tree id (command "git ls-tree")
748 749
   $path =~ s#/+$##;
749
-  my @cmd = $self->cmd(
750
+  my @cmd = $self->cmd_rep(
750 751
     $user,
751 752
     $project,
752 753
     'ls-tree',
... ...
@@ -771,7 +772,7 @@ sub last_activity {
771 772
   my ($self, $user, $project) = @_;
772 773
   
773 774
   # Command "git for-each-ref"
774
-  my @cmd = $self->cmd(
775
+  my @cmd = $self->cmd_rep(
775 776
     $user,
776 777
     $project,
777 778
     'for-each-ref',
... ...
@@ -798,7 +799,7 @@ sub last_activity {
798 799
 sub no_merged_branches_count {
799 800
   my ($self, $user, $project) = @_;
800 801
   
801
-  my @cmd = $self->cmd($user, $project, 'branch', '--no-merged');
802
+  my @cmd = $self->cmd_rep($user, $project, 'branch', '--no-merged');
802 803
   open my $fh, '-|', @cmd or return;
803 804
   my @branches = <$fh>;
804 805
   my $branches_count = @branches;
... ...
@@ -813,7 +814,7 @@ sub path_by_id {
813 814
   return unless $hash;
814 815
   
815 816
   # Command "git ls-tree"
816
-  my @cmd = $self->cmd($user, $project, 'ls-tree', '-r', '-t', '-z', $base);
817
+  my @cmd = $self->cmd_rep($user, $project, 'ls-tree', '-r', '-t', '-z', $base);
817 818
   open my $fh, '-|', @cmd or return;
818 819
 
819 820
   # Get path
... ...
@@ -837,7 +838,7 @@ sub parse_rev_path {
837 838
   my ($self, $user, $project, $rev_path) = @_;
838 839
   
839 840
   # References
840
-  my @cmd = $self->cmd(
841
+  my @cmd = $self->cmd_rep(
841 842
     $user,
842 843
     $project,
843 844
     'show-ref',
... ...
@@ -887,7 +888,7 @@ sub object_type {
887 888
   my ($self, $user, $project, $rev) = @_;
888 889
   
889 890
   # Get object type
890
-  my @cmd = $self->cmd(
891
+  my @cmd = $self->cmd_rep(
891 892
     $user,
892 893
     $project,
893 894
     'cat-file',
... ...
@@ -952,7 +953,7 @@ sub references {
952 953
   $type ||= '';
953 954
   
954 955
   # Branches or tags
955
-  my @cmd = $self->cmd(
956
+  my @cmd = $self->cmd_rep(
956 957
     $user,
957 958
     $project,
958 959
     'show-ref',
... ...
@@ -1012,7 +1013,7 @@ sub tags_count {
1012 1013
   my $limit = 1000;
1013 1014
   
1014 1015
   # Get tags
1015
-  my @cmd = $self->cmd(
1016
+  my @cmd = $self->cmd_rep(
1016 1017
     $user,
1017 1018
     $project,
1018 1019
     'for-each-ref',
... ...
@@ -1035,7 +1036,7 @@ sub tags {
1035 1036
   $offset ||= 0;
1036 1037
   
1037 1038
   # Get tags
1038
-  my @cmd = $self->cmd(
1039
+  my @cmd = $self->cmd_rep(
1039 1040
     $user,
1040 1041
     $project,
1041 1042
     'for-each-ref',
... ...
@@ -1124,7 +1125,7 @@ sub last_change_commit {
1124 1125
   my $commit_log = {};
1125 1126
   $file = '' unless defined $file;
1126 1127
   
1127
-  my @cmd = $self->cmd(
1128
+  my @cmd = $self->cmd_rep(
1128 1129
     $user,
1129 1130
     $project,
1130 1131
     '--no-pager',
... ...
@@ -1236,7 +1237,7 @@ sub get_commit {
1236 1237
   my ($self, $user, $project, $id) = @_;
1237 1238
   
1238 1239
   # Git rev-list
1239
-  my @cmd = $self->cmd(
1240
+  my @cmd = $self->cmd_rep(
1240 1241
     $user,
1241 1242
     $project,
1242 1243
     'rev-list',
... ...
@@ -1371,7 +1372,7 @@ sub get_commits {
1371 1372
   # Get Commits
1372 1373
   $maxcount ||= 1;
1373 1374
   $skip ||= 0;
1374
-  my @cmd = $self->cmd(
1375
+  my @cmd = $self->cmd_rep(
1375 1376
     $user,
1376 1377
     $project,
1377 1378
     'rev-list',
... ...
@@ -1508,7 +1509,7 @@ sub import_branch {
1508 1509
   
1509 1510
   # Git pull
1510 1511
   my $remote_rep = $self->app->rep_path($remote_user, $remote_project);
1511
-  my @cmd = $self->cmd(
1512
+  my @cmd = $self->cmd_rep(
1512 1513
     $user,
1513 1514
     $project,
1514 1515
     'fetch',
... ...
@@ -1548,7 +1549,7 @@ sub separated_commit {
1548 1549
   my ($self, $user, $project, $rev1, $rev2) = @_;
1549 1550
   
1550 1551
   # Command "git diff-tree"
1551
-  my @cmd = $self->cmd(
1552
+  my @cmd = $self->cmd_rep(
1552 1553
     $user,
1553 1554
     $project,
1554 1555
     'show-branch',
... ...
@@ -1633,7 +1634,7 @@ sub trees {
1633 1634
   }
1634 1635
   my @entries = ();
1635 1636
   my $show_sizes = 0;
1636
-  my @cmd = $self->cmd(
1637
+  my @cmd = $self->cmd_rep(
1637 1638
     $user,
1638 1639
     $project,
1639 1640
     'ls-tree',
+5 -26
lib/Gitprep/Manager.pm
... ...
@@ -15,27 +15,6 @@ use Gitprep::Util;
15 15
 has 'app';
16 16
 has 'authorized_keys_file';
17 17
 
18
-sub working_home {
19
-  my ($self, $user, $project) = @_;
20
-  
21
-  my $working_home = $self->app->home->rel_file("data/work/$user/$project");
22
-  
23
-  return $working_home;
24
-}
25
-
26
-sub create_working_repository {
27
-  my ($self, $user, $project) = @_;
28
-  
29
-  my $working_home = $self->working_home($user, $project);
30
-  
31
-  mkpath $working_home;
32
-  
33
-  chdir $working_home
34
-    or croak "Can't change working directory $working_home: $!";
35
-  
36
-  
37
-}
38
-
39 18
 sub admin_user {
40 19
   my $self = shift;
41 20
   
... ...
@@ -722,7 +701,7 @@ sub _create_rep {
722 701
       print $readme_fh "\n" . encode('UTF-8', $description) . "\n";
723 702
       close $readme_fh;
724 703
       
725
-      my @git_add_cmd = $git->cmd_working_dir(
704
+      my @git_add_cmd = $git->cmd_work_dir(
726 705
         $temp_work,
727 706
         'add',
728 707
         'README.md'
... ...
@@ -731,7 +710,7 @@ sub _create_rep {
731 710
         or croak "Can't execute git add: @git_add_cmd";
732 711
       
733 712
       # Set user name
734
-      my @git_config_user_name = $git->cmd_working_dir(
713
+      my @git_config_user_name = $git->cmd_work_dir(
735 714
         $temp_work,
736 715
         'config',
737 716
         'user.name',
... ...
@@ -742,7 +721,7 @@ sub _create_rep {
742 721
       
743 722
       # Set user mail
744 723
       my $user_mail = $self->app->dbi->model('user')->select('mail', where => {id => $user})->value;
745
-      my @git_config_user_mail = $git->cmd_working_dir(
724
+      my @git_config_user_mail = $git->cmd_work_dir(
746 725
         $temp_work,
747 726
         'config',
748 727
         'user.email',
... ...
@@ -752,7 +731,7 @@ sub _create_rep {
752 731
         or croak "Can't execute git config: @git_config_user_mail";
753 732
       
754 733
       # Commit
755
-      my @git_commit_cmd = $git->cmd_working_dir(
734
+      my @git_commit_cmd = $git->cmd_work_dir(
756 735
         $temp_work,
757 736
         'commit',
758 737
         '-q',
... ...
@@ -764,7 +743,7 @@ sub _create_rep {
764 743
       
765 744
       # Push
766 745
       {
767
-        my @git_push_cmd = $git->cmd_working_dir(
746
+        my @git_push_cmd = $git->cmd_work_dir(
768 747
           $temp_work,
769 748
           'push',
770 749
           '-q',
+1 -1
templates/archive.html.ep
... ...
@@ -40,7 +40,7 @@
40 40
     );
41 41
   };
42 42
   my $cmd = $quote->(
43
-    $git->cmd(
43
+    $git->cmd_rep(
44 44
       $user,
45 45
       $project,
46 46
       'archive',
+2 -2
templates/smart-http/info-refs.html.ep
... ...
@@ -15,7 +15,7 @@
15 15
     substr($service_cmd, 0, 4, '');
16 16
     
17 17
     my $rep = app->rep_path($user, $project);
18
-    my @cmd = $git->cmd($user, $project, $service_cmd, '--stateless-rpc', '--advertise-refs', $rep);
18
+    my @cmd = $git->cmd_rep($user, $project, $service_cmd, '--stateless-rpc', '--advertise-refs', $rep);
19 19
     
20 20
     my ($cout, $cerr) = (Symbol::gensym, Symbol::gensym);
21 21
     my $pid = IPC::Open3::open3(my $cin, $cout, $cerr, @cmd );
... ...
@@ -58,7 +58,7 @@
58 58
   # Dumb HTTP
59 59
   else {
60 60
     # Update server info
61
-    my @cmd = $git->cmd($user, $project, 'update-server-info');
61
+    my @cmd = $git->cmd_rep($user, $project, 'update-server-info');
62 62
     open my $fh, '-|', @cmd
63 63
       or die "Can't open pipe for @cmd:$!";
64 64
     close $fh
+1 -1
templates/smart-http/service.html.ep
... ...
@@ -10,7 +10,7 @@
10 10
   my $git = app->git;
11 11
   
12 12
   my $rep_dir = app->rep_path($user, $project);
13
-  my @cmd = $git->cmd($user, $project, $service, '--stateless-rpc', $rep_dir);
13
+  my @cmd = $git->cmd_rep($user, $project, $service, '--stateless-rpc', $rep_dir);
14 14
   
15 15
   # Command
16 16
   my ($cout, $cerr) = (Symbol::gensym, Symbol::gensym);