gitprep / templates / smart-http / service.html.ep /
Newer Older
72 lines | 1.654kb
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
  
cleanup
Yuki Kimoto authored on 2016-04-16
12
  my $rep_info = app->rep_info($user, $project);
13
  my $rep_git_dir = $rep_info->{git_dir};
remove cmd_rep
Yuki Kimoto authored on 2016-04-16
14
  my @cmd = $git->cmd(app->rep_info($user, $project), $service, '--stateless-rpc', $rep_git_dir);
implement git-upload-pack
Yuki Kimoto authored on 2013-10-02
15
  
add FAQ large repository can...
Yuki Kimoto authored on 2013-10-07
16
  # Command
implement git-upload-pack
Yuki Kimoto authored on 2013-10-02
17
  my ($cout, $cerr) = (Symbol::gensym, Symbol::gensym);
18
  my $pid = IPC::Open3::open3(my $cin, $cout, $cerr, @cmd);
improve memory usage of smar...
Yuki Kimoto authored on 2013-10-07
19
  my $pos = 0;
add FAQ large repository can...
Yuki Kimoto authored on 2013-10-07
20
  my $content = $self->req->content;
improve memory usage of smar...
Yuki Kimoto authored on 2013-10-07
21
  while (1) {
22
    my $chunk = $content->get_body_chunk($pos);
23
    last unless defined $chunk;
24
    my $length = length $chunk;
25
    last unless $length;
26

            
27
    print $cin $chunk;
28
    $pos += $length;
29
  }
implement git-upload-pack
Yuki Kimoto authored on 2013-10-02
30
  close $cin;
31
  
32
  # Response
33
  $self->res->headers->content_type("application/x-git-$service-result");
34
  $self->render_later;
35
  
36
  # Write
37
  my $s = IO::Select->new($cout, $cerr);
cleanup
Yuki Kimoto authored on 2013-10-11
38
  my $buffer_size = $ENV{GITPREP_SMART_HTTP_BUFFER_SIZE};
fix bug that lerge repositor...
Yuki Kimoto authored on 2014-02-17
39
  my $error;
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) {
fix smart_http bug
Yuki Kimoto authored on 2016-03-28
45
      my $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)) {
implement git-upload-pack
Yuki Kimoto authored on 2013-10-02
49
          if ($handle == $cerr) {
Revert "fix smart http bug"
Yuki Kimoto authored on 2016-03-28
50
            $error .= $buf;
implement git-upload-pack
Yuki Kimoto authored on 2013-10-02
51
          }
52
          else {
Revert "fix smart http bug"
Yuki Kimoto authored on 2016-03-28
53
            $output .= $buf;
implement git-upload-pack
Yuki Kimoto authored on 2013-10-02
54
          }
55
        }
fix defunct process remainin...
Yuki Kimoto authored on 2014-02-19
56
        else {
57
          $s->remove($handle);
58
        }
implement git-upload-pack
Yuki Kimoto authored on 2013-10-02
59
      }
Revert "fix smart http bug"
Yuki Kimoto authored on 2016-03-28
60
      $c->write_chunk($output, $cb);
implement git-upload-pack
Yuki Kimoto authored on 2013-10-02
61
    }
62
    else {
fix bug that lerge repositor...
Yuki Kimoto authored on 2014-02-17
63
      $c->finish;
implement git-upload-pack
Yuki Kimoto authored on 2013-10-02
64
      waitpid($pid, 0);
fix smart-http not working b...
Yuki Kimoto authored on 2016-03-25
65

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