gitprep / templates / smart-http / service.html.ep /
Newer Older
74 lines | 1.669kb
implement git-upload-pack
Yuki Kimoto authored on 2013-10-02
1
<%
2
  use IPC::Open3 ();
3
  use Symbol ();
4
  use IO::Select ();
5
  
6
  my $service = param('service');
7
  my $user = param('user');
8
  my $project = param('project');
9
  
revert encoding support
Yuki Kimoto authored on 2013-11-22
10
  my $git = app->git;
implement git-upload-pack
Yuki Kimoto authored on 2013-10-02
11
  
12
  my $rep_dir = $git->rep($user, $project);
13
  my @cmd = $git->cmd($user, $project, $service, '--stateless-rpc', $rep_dir);
14
  
add FAQ large repository can...
Yuki Kimoto authored on 2013-10-07
15
  # Command
implement git-upload-pack
Yuki Kimoto authored on 2013-10-02
16
  my ($cout, $cerr) = (Symbol::gensym, Symbol::gensym);
17
  my $pid = IPC::Open3::open3(my $cin, $cout, $cerr, @cmd);
improve memory usage of smar...
Yuki Kimoto authored on 2013-10-07
18
  my $pos = 0;
add FAQ large repository can...
Yuki Kimoto authored on 2013-10-07
19
  my $content = $self->req->content;
improve memory usage of smar...
Yuki Kimoto authored on 2013-10-07
20
  while (1) {
21
    my $chunk = $content->get_body_chunk($pos);
22
    last unless defined $chunk;
23
    my $length = length $chunk;
24
    last unless $length;
25

            
26
    print $cin $chunk;
27
    $pos += $length;
28
  }
implement git-upload-pack
Yuki Kimoto authored on 2013-10-02
29
  close $cin;
30
  
31
  # Response
32
  $self->res->headers->content_type("application/x-git-$service-result");
33
  $self->render_later;
34
  
35
  # Write
36
  my $s = IO::Select->new($cout, $cerr);
cleanup
Yuki Kimoto authored on 2013-10-11
37
  my $buffer_size = $ENV{GITPREP_SMART_HTTP_BUFFER_SIZE};
fix bug that lerge repositor...
Yuki Kimoto authored on 2014-02-17
38
  my $error;
39
  my $output;
40
  my @ready;
fix defunct process remainin...
Yuki Kimoto authored on 2014-02-19
41
  my $cb;
implement git-upload-pack
Yuki Kimoto authored on 2013-10-02
42
  $cb = sub {
43
    my $c = shift;
fix bug that lerge repositor...
Yuki Kimoto authored on 2014-02-17
44
    if (@ready = $s->can_read) {
45
      $output = '';
implement git-upload-pack
Yuki Kimoto authored on 2013-10-02
46
      for my $handle (@ready) {
fix bug that lerge repositor...
Yuki Kimoto authored on 2014-02-17
47
        
48
        if (sysread($handle, my $buf, $buffer_size)) {
49
          #warn `ps axuww|grep gitprep` if $k % 3000 == 0;
50
          
implement git-upload-pack
Yuki Kimoto authored on 2013-10-02
51
          if ($handle == $cerr) {
52
            $error .= $buf;
53
          }
54
          else {
55
            $output .= $buf;
56
          }
57
        }
fix defunct process remainin...
Yuki Kimoto authored on 2014-02-19
58
        else {
59
          $s->remove($handle);
60
        }
implement git-upload-pack
Yuki Kimoto authored on 2013-10-02
61
      }
62
      $c->write_chunk($output, $cb);
63
    }
64
    else {
fix bug that lerge repositor...
Yuki Kimoto authored on 2014-02-17
65
      $c->finish;
implement git-upload-pack
Yuki Kimoto authored on 2013-10-02
66
      waitpid($pid, 0);
fix smart-http not working b...
Yuki Kimoto authored on 2016-03-25
67

            
68
      $c->app->log->error($c->url_for . ": $error") if defined $error;
implement git-upload-pack
Yuki Kimoto authored on 2013-10-02
69
      undef $cb;
70
      return;
71
    }
72
  };
73
  $self->$cb;
74
%>