gitprep / templates / smart-http / info-refs.html.ep /
Newer Older
89 lines | 2.563kb
cleanup
Yuki Kimoto authored on 2013-10-01
1
<%
2
  use IPC::Open3 ();;
3
  use Symbol ();
cleanup
Yuki Kimoto authored on 2013-10-02
4
  use IO::Select ();
add dump http info/refs test
Yuki Kimoto authored on 2013-10-07
5
  
cleanup
Yuki Kimoto authored on 2013-10-01
6
  my $service = param('service') || '';
7
  my $user = param('user');
8
  my $project = param('project');
revert encoding support
Yuki Kimoto authored on 2013-11-22
9
  my $git = app->git;
cleanup
Yuki Kimoto authored on 2013-10-02
10
  
11
  # Smart HTTP
fixed receive pack bug and a...
Yuki Kimoto authored on 2013-10-03
12
  if ($service eq 'git-upload-pack' || $service eq 'git-receive-pack') {
13
    
14
    my $service_cmd = $service;
15
    substr($service_cmd, 0, 4, '');
cleanup
Yuki Kimoto authored on 2013-10-01
16
    
cleanup
Yuki Kimoto authored on 2016-04-16
17
    my $rep_info = app->rep_info($user, $project);
18
    my $rep_git_dir = $rep_info->{git_dir};
remove cmd_rep
Yuki Kimoto authored on 2016-04-16
19
    my @cmd = $git->cmd(app->rep_info($user, $project), $service_cmd, '--stateless-rpc', '--advertise-refs', $rep_git_dir);
cleanup
Yuki Kimoto authored on 2013-10-01
20
    
21
    my ($cout, $cerr) = (Symbol::gensym, Symbol::gensym);
22
    my $pid = IPC::Open3::open3(my $cin, $cout, $cerr, @cmd );
23
    close $cin;
24
    my ( $refs, $err, $buf ) = ( '', '', '' );
cleanup
Yuki Kimoto authored on 2013-10-02
25
    my $s = IO::Select->new($cout, $cerr);
cleanup
Yuki Kimoto authored on 2013-10-11
26
    my $buffer_size = $ENV{GITPREP_SMART_HTTP_BUFFER_SIZE};
cleanup
Yuki Kimoto authored on 2013-10-01
27
    while (my @ready = $s->can_read) {
28
      for my $handle (@ready) {
cleanup
Yuki Kimoto authored on 2013-10-11
29
        while (sysread($handle, $buf, $buffer_size)) {
cleanup
Yuki Kimoto authored on 2013-10-01
30
          if ($handle == $cerr) {
31
            $err .= $buf;
32
          }
33
          else {
34
            $refs .= $buf;
35
          }
36
        }
37
        $s->remove($handle) if eof($handle);
38
      }
39
    }
40
    close $cout;
41
    close $cerr;
42
    waitpid($pid, 0);
add receive pack test
Yuki Kimoto authored on 2013-10-08
43
    
cleanup
Yuki Kimoto authored on 2013-10-01
44
    if ($err) {
45
      app->log->error($err);
do success xt tests
Yuki Kimoto authored on 2016-03-25
46
      $self->reply->exception($err);
cleanup
Yuki Kimoto authored on 2013-10-01
47
      return;
48
    }
49
    
fixed receive pack bug and a...
Yuki Kimoto authored on 2013-10-03
50
    $self->res->headers->content_type("application/x-$service-advertisement");
cleanup
Yuki Kimoto authored on 2013-10-01
51
    
cleanup
Yuki Kimoto authored on 2013-10-02
52
    # Data start
fixed receive pack bug and a...
Yuki Kimoto authored on 2013-10-03
53
    my $message = "# service=$service\n";
cleanup
Yuki Kimoto authored on 2013-10-02
54
    my $data = sprintf( '%04x', length($message) + 4 ) . $message . '0000' . $refs;
cleanup
Yuki Kimoto authored on 2013-10-01
55
    
56
    $self->render(data => $data);
57
    return;
58
  }
cleanup
Yuki Kimoto authored on 2013-10-02
59
  # Dumb HTTP
cleanup
Yuki Kimoto authored on 2013-10-01
60
  else {
add dump http info/refs test
Yuki Kimoto authored on 2013-10-07
61
    # Update server info
remove cmd_rep
Yuki Kimoto authored on 2016-04-16
62
    my @cmd = $git->cmd(app->rep_info($user, $project), 'update-server-info');
add dump http info/refs test
Yuki Kimoto authored on 2013-10-07
63
    open my $fh, '-|', @cmd
64
      or die "Can't open pipe for @cmd:$!";
65
    close $fh
66
      or die "Can't close pipe for @cmd:$!";
67
    
add test HEAD
Yuki Kimoto authored on 2013-10-08
68
    my $content_type = 'text/plain; charset=UTF-8';
cleanup
Yuki Kimoto authored on 2016-04-16
69
    my $rep_info = app->rep_info($user, $project);
70
    my $rep_git_dir = $rep_info->{git_dir};
71
    my $file = "$rep_git_dir/info/refs";
add test HEAD
Yuki Kimoto authored on 2013-10-08
72
    if (-f $file) {
73
      my $asset = Mojo::Asset::File->new(path => $file);
74
      my $content = $asset->slurp;
75
      $content = '' unless defined $content;
76
      $self->res->headers->content_type($content_type);
add dump http info/refs test
Yuki Kimoto authored on 2013-10-07
77
      $self->res->headers->content_length(length $content);
78
      $self->res->body($content);
79
      $self->res->code(200);
80
      $self->rendered;
81
      return;
82
    }
83
    else {
84
      $self->res->code(404);
85
      $self->rendered;
86
      return;
87
    }
cleanup
Yuki Kimoto authored on 2013-10-01
88
  }
89
%>