git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
4b3ca0948b29109a23589e469e38fcb42aa6ac70 blob 1987 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
 
#!/usr/bin/perl
#
# Example implementation for the Git read-object protocol version 1
# See Documentation/technical/read-object-protocol.txt
#
# Allows you to test the ability for blobs to be pulled from a host git repo
# "on demand."  Called when git needs a blob it couldn't find locally due to
# a lazy clone that only cloned the commits and trees.
#
# A lazy clone can be simulated via the following commands from the host repo
# you wish to create a lazy clone of:
#
# cd /host_repo
# git rev-parse HEAD
# git init /guest_repo
# git cat-file --batch-check --batch-all-objects | grep -v 'blob' |
#	cut -d' ' -f1 | git pack-objects /e/guest_repo/.git/objects/pack/noblobs
# cd /guest_repo
# git config core.virtualizeobjects true
# git reset --hard <sha from rev-parse call above>
#
# Please note, this sample is a minimal skeleton. No proper error handling 
# was implemented.
#

use 5.008;
use lib (split(/:/, $ENV{GITPERLLIB}));
use strict;
use warnings;
use Git::Packet;

#
# Point $DIR to the folder where your host git repo is located so we can pull
# missing objects from it
#
my $DIR = "../.git/";

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

my %remote_caps = packet_read_and_check_capabilities("get_git_obj");
packet_check_and_write_capabilities(\%remote_caps, "get_git_obj");

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 "get_git_obj" ) {
		my ($sha1) = packet_txt_read() =~ /^sha1=([0-9a-f]{40})$/;
		packet_bin_read();

		my $path = $sha1;
		$path =~ s{..}{$&/};
		$path = $DIR . "/objects/" . $path;

		my $contents = do {
		    local $/;
		    open my $fh, $path or die "Can't open '$path': $!";
		    <$fh>
		};

		packet_bin_write($contents);
		packet_flush();
		packet_txt_write("status=success");
		packet_flush();
	} else {
		die "bad command '$command'";
	}
}
debug log:

solving 4b3ca0948b ...
found 4b3ca0948b in https://public-inbox.org/git/20180319133147.15413-31-chriscool@tuxfamily.org/

applying [1/1] https://public-inbox.org/git/20180319133147.15413-31-chriscool@tuxfamily.org/
diff --git a/t/t0560/read-object-git b/t/t0560/read-object-git
new file mode 100755
index 0000000000..4b3ca0948b

1:28: trailing whitespace.
# Please note, this sample is a minimal skeleton. No proper error handling 
Checking patch t/t0560/read-object-git...
Applied patch t/t0560/read-object-git cleanly.
warning: 1 line adds whitespace errors.

index at:
100755 4b3ca0948b29109a23589e469e38fcb42aa6ac70	t/t0560/read-object-git

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).