git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
f230cbd5eb1b7823cab9b506d0984215e8c39939 blob 2665 bytes (raw)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
 
#!/usr/bin/perl
#

use 5.008;
use lib (split(/:/, $ENV{GITPERLLIB}));
use strict;
use warnings;
use Git::Packet;
use LWP::UserAgent;
use HTTP::Request::Common;

packet_initialize("git-read-object", 1);

my %remote_caps = packet_read_and_check_capabilities("get_raw_obj", "put_raw_obj", "have");
packet_check_and_write_capabilities(\%remote_caps, "get_raw_obj", "put_raw_obj", "have");

my $http_url = $ENV{HTTPD_URL};

while (1) {
	my ($res, $command) = packet_txt_read();

	if ( $res == -1 ) {
		exit 0;
	}

	$command =~ s/^command=//;

	if ( $command eq "init" ) {
		packet_bin_read();

		packet_txt_write("status=success");
		packet_flush();
	} elsif ( $command eq "have" ) {
		# read the flush after the command
		packet_bin_read();

		my $have_url = $http_url . "/list/";

		my $userAgent = LWP::UserAgent->new();
		my $response = $userAgent->get( $have_url );

		if ($response->is_error) {
			packet_bin_write("");
			packet_flush();
			packet_txt_write("status=failure");
		} else {
			packet_bin_write($response->content);
			packet_flush();
			packet_txt_write("status=success");
		}
		packet_flush();
	} elsif ( $command eq "get_raw_obj" ) {
		my ($sha1) = packet_txt_read() =~ /^sha1=([0-9a-f]{40})$/;
		packet_bin_read();

		my $get_url = $http_url . "/list/?sha1=" . $sha1;

		my $userAgent = LWP::UserAgent->new();

		my $response = $userAgent->get( $get_url );

		if ($response->is_error) {
			packet_txt_write("size=0");
			packet_txt_write("kind=none");	    
			packet_txt_write("status=notfound");
		} else {
			packet_txt_write("size=" . length($response->content));
			packet_txt_write("kind=blob");
			packet_bin_write($response->content);
			packet_flush();
			packet_txt_write("status=success");
		}

		packet_flush();
	} elsif ( $command eq "put_raw_obj" ) {
		my ($sha1) = packet_txt_read() =~ /^sha1=([0-9a-f]{40})$/;
		my ($size) = packet_txt_read() =~ /^size=([0-9]+)$/;
		my ($kind) = packet_txt_read() =~ /^kind=(\w+)$/;

		packet_bin_read();

		# We must read the content we are sent and send it to the right url
		my ($res, $buf) = packet_bin_read();
		die "bad packet_bin_read res ($res)" unless ($res eq 0);
		( packet_bin_read() eq ( 1, "" ) ) || die "bad send end";		

		my $upload_url = $http_url . "/upload/?sha1=" . $sha1 . "&size=" . $size . "&type=blob";

		my $userAgent = LWP::UserAgent->new();
		my $request = POST $upload_url, Content_Type => 'multipart/form-data', Content => $buf;

		my $response = $userAgent->request($request);

		if ($response->is_error) {
			packet_txt_write("status=failure");
		} else {
			packet_txt_write("status=success");
		}
		packet_flush();
	} else {
		die "bad command '$command'";
	}
}
debug log:

solving f230cbd5eb ...
found f230cbd5eb in https://public-inbox.org/git/20180319133147.15413-35-chriscool@tuxfamily.org/

applying [1/1] https://public-inbox.org/git/20180319133147.15413-35-chriscool@tuxfamily.org/
diff --git a/t/t0580/read-object-plain-have b/t/t0580/read-object-plain-have
new file mode 100755
index 0000000000..f230cbd5eb

1:70: trailing whitespace.
			packet_txt_write("kind=none");	    
1:91: trailing whitespace.
		( packet_bin_read() eq ( 1, "" ) ) || die "bad send end";		
Checking patch t/t0580/read-object-plain-have...
Applied patch t/t0580/read-object-plain-have cleanly.
warning: 2 lines add whitespace errors.

index at:
100755 f230cbd5eb1b7823cab9b506d0984215e8c39939	t/t0580/read-object-plain-have

Code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).