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