]>
Git — Sourcephile - git-remote-gpg.git/blob - git-remote-gpg
2 our $VERSION = '2014.01.28';
5 use warnings FATAL
=> qw(all);
10 use File
::Spec
::Functions
qw(:ALL);
14 # NOTE: to debug: IPCRUNDEBUG=basic|data|details|gory
17 use POSIX
qw(WNOHANG);
24 foreach my $msg (@_) {
30 my $call = (caller(1))[3];
34 , "\e[30m\e[1m.", join('.', $call."\e[m")
38 : Data
::Dumper
::Dumper
($_)
45 my $call = (caller(1))[3];
48 , "\e[30m\e[1m.", join('.', $call."\e[m")
49 , " ", (ref $_ eq 'CODE'?(join("\n ", $_->()), "\n"):(@_, "\n"))
53 local $Carp::CarpLevel
= 1;
54 carp
("\e[33mWARNING\e[m ", @_, "\n\t");
57 local $Carp::CarpLevel
= 1;
58 croak
("\e[31mERROR\e[m ", @_, "\n\t");
64 debug
(sub{"file="},$file);
70 my ($ctx, $size) = @_;
72 IPC
::Run
::run
([@{$ctx->{config
}->{gpg
}}
73 , '--armor', '--gen-rand', '1', $size]
75 or error
("failed to get random bits");
80 my ($ctx, $algo, $run) = @_;
81 $run = sub {return @_} unless defined $run;
83 IPC
::Run
::run
($run->([@{$ctx->{config
}->{gpg
}}
84 , '--with-colons', '--print-md', $algo]
86 or error
("failed to hash data");
87 return ((split(':', $hash))[2]);
89 sub gpg_fingerprint
($$$) {
90 my ($ctx, $id, $caps_needed) = @_;
93 if (IPC
::Run
::run
([@{$ctx->{config
}->{gpg
}}
94 , '--fixed-list-mode', '--with-colons', '--with-fingerprint', '--list-keys', $id]
96 my @lines = split(/\n/,$output);
97 while (my $line = shift @lines) {
98 if (my ($longkeyid, $caps) = $line =~ m/^pub:[^:]*:[^:]*:[^:]*:([^:]*):[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:([^:]+):.*$/) {
100 foreach my $cap (@$caps_needed) {
101 if (not ($caps =~ m/$cap/)) {
102 warning
("skipping key 0x$longkeyid which has not usable capability: $cap, but matches: `$id'");
109 while ((not defined $fpr or not defined $uid)
110 and $line = shift @lines) {
111 (not defined $fpr and (($fpr) = $line =~ m/^fpr:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:([0-9A-F]+):.*$/)) or
112 (not defined $uid and (($uid) = $line =~ m/^uid:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:([^:]+):.*$/)) or
115 error
("unable to extract fingerprint and user ID")
123 error
("unable to find any OpenPGP key with usable capability: ".join('', @$caps_needed)." for: `$id'")
124 unless scalar(%h) gt 0;
125 debug
(sub{"$id -> "}, \
%h);
128 sub grg_encrypt_symmetric
($$$;$) {
129 my ($ctx, $clear, $key, $run) = @_;
130 $run = sub {return @_} unless defined $run;
131 IPC
::Run
::run
($run->([@{$ctx->{config
}->{gpg
}}
133 , '--compress-algo', 'none'
135 , '--passphrase-fd', '3'
137 , '--trust-model', 'always'
139 , '<', \
$clear, '3<', \
$key))
140 or error
("failed to encrypt symmetrically data");
142 sub grg_decrypt_symmetric
($$$;$) {
143 my ($ctx, $key, $run) = @_;
144 $run = sub {return @_} unless defined $run;
145 IPC
::Run
::run
($run->([@{$ctx->{config
}->{gpg
}}
146 , '--batch', '--no-default-keyring', '--keyring', '/dev/null', '--secret-keyring', '/dev/null'
147 , '--passphrase-fd', '3', '--quiet', '--decrypt']
149 or error
("failed to decrypt symmetrically data");
151 sub grg_encrypt_asymmetric
($$;$) {
152 my ($ctx, $clear, $run) = @_;
153 $run = sub {return @_} unless defined $run;
155 ( (map { ('--recipient', '0x'.$_) } (keys %{$ctx->{config
}->{keys}}))
156 , (map { ('--hidden-recipient', '0x'.$_) } (keys %{$ctx->{config
}->{'hidden-keys'}})) );
157 @recipients = ('--default-recipient-self')
159 IPC
::Run
::run
($run->([@{$ctx->{config
}->{gpg
}}
161 , '--compress-algo', 'none'
162 , '--trust-model', 'always'
163 , '--sign', '--encrypt'
164 , ($ctx->{config
}->{signingkey
}->{fpr
} ? ('--local-user', $ctx->{config
}->{signingkey
}->{fpr
}) : ())
167 or error
("failed to encrypt asymmetrically data");
169 sub grg_decrypt_asymmetric
($$;$) {
170 my ($ctx, $run) = @_;
171 my ($clear, $status);
172 $run = sub {return @_} unless defined $run;
173 IPC
::Run
::run
($run->([@{$ctx->{config
}->{gpg
}}
174 , '--batch', '--no-default-keyring',
175 , '--status-fd', '3', '--quiet', '--decrypt']
176 , '>', \
$clear, '3>', \
$status))
177 or error
("failed to decrypt asymmetrically data");
178 debug
(sub{"status=\n$status"});
179 my @lines = split(/\n/,$status);
180 my ($enc_to, $goodsig, $validsig, $validpub, $goodmdc);
181 foreach my $line (@lines) {
182 (not defined $enc_to and (($enc_to) = $line =~ m/^\[GNUPG:\] ENC_TO ([0-9A-F]+).*$/)) or
183 (not defined $goodsig and (($goodsig) = $line =~ m/^\[GNUPG:\] GOODSIG ([0-9A-F]+).*$/)) or
184 (not defined $goodmdc and (($goodmdc) = $line =~ m/^\[GNUPG:\] (GOODMDC)$/)) or
185 (not defined $validsig and not defined $validpub and (($validsig, $validpub)
186 = $line =~ m/^\[GNUPG:\] VALIDSIG ([0-9A-F]+) [^ ]+ [^ ]+ [^ ]+ [^ ]+ [^ ]+ [^ ]+ [^ ]+ [^ ]+ ([0-9A-F]+).*$/)) or
189 error
("data expected to be encrypted")
191 debug
(sub{"enc_to=$enc_to\n"});
192 error
("data expected to be signed")
194 debug
(sub{"goodsig=$goodsig\n"});
195 error
("modification detection code incorrect")
197 debug
(sub{"good_mdc=$goodmdc\n"});
198 error
("data signature invalid")
199 unless $validsig and $validpub;
200 debug
(sub{"validsig=$validsig\n"});
201 debug
(sub{"validpub=$validpub\n"});
202 error
("data signature refused")
203 unless exists $ctx->{config
}->{keys}->{$validpub}
204 or exists $ctx->{config
}->{'hidden-keys'}->{$validpub};
205 debug
(sub{"accepted:$validpub\n"});
209 sub grg_remote_fetch_file
($$$) {
210 my ($ctx, $files, $fetch_files) = @_;
211 # NOTE: avoid File::Copy::copy().
212 @$fetch_files = map { File
::Spec-
>catfile($ctx->{remote
}->{uri
}->file, $_) } @$files;
213 foreach my $file (@$fetch_files) {
214 -r
$file or return ();
218 sub grg_remote_fetch_rsync
($$$) {
219 my ($ctx, $files, $fetch_files) = @_;
220 my $uri = $ctx->{remote
}->{uri
}->clone;
222 $uri->fragment(undef);
224 $uri = $uri->as_string;
225 IPC
::Run
::run
([@{$ctx->{config
}->{rsync
}}
226 , '--verbose', '--ignore-times', '--inplace', '--progress'
227 , (map { File
::Spec-
>catfile($uri, $_) } @$files)
228 , $ctx->{'dir-cache'}.'/']
231 sub grg_remote_fetch_sftp
($$$) {
232 my ($ctx, $files, $fetch_files) = @_;
233 IPC
::Run
::run
([@{$ctx->{config
}->{curl
}}
235 , '--output', File
::Spec-
>catfile($ctx->{'dir-cache'}, '#1')
236 , File
::Spec-
>catfile($ctx->{remote
}->{uri
}, '{'.join(',',@$files).'}') ])
238 sub grg_remote_fetch
($$) {
239 my ($ctx, $files) = @_;
240 debug
(sub{'files='}, $files);
241 my $scheme = $ctx->{remote
}->{uri
}->scheme;
242 my $fetch_files = [map { File
::Spec-
>catfile($ctx->{'dir-cache'}, $_) } @$files];
244 { file
=> \
&grg_remote_fetch_file
245 , rsync
=> \
&grg_remote_fetch_rsync
246 , sftp
=> \
&grg_remote_fetch_sftp
248 error
("URL scheme not supported: `$scheme'")
250 $fct->($ctx, $files, $fetch_files)
252 return @$fetch_files;
254 sub grg_remote_init_file
($) {
256 my $dst = $ctx->{remote
}->{uri
}->file;
257 debug
(sub{"File::Path::make_path('$dst')\n"});
258 defined File
::Path
::make_path
($dst, {verbose
=> 1})
260 sub grg_remote_init_rsync
($) {
262 my $tmp = File
::Temp-
>tempdir(CLEANUP
=> 1);
263 my $path = $ctx->{remote
}->{uri
}->path;
264 my $uri = $ctx->{remote
}->{uri
}->clone;
265 $uri->fragment(undef);
268 File
::Path
::make_path
(File
::Spec-
>catdir($tmp, $path), {verbose
=> 0}) and
269 IPC
::Run
::run
([@{$ctx->{config
}->{rsync
}}
270 , '--verbose', '--recursive', '--relative'
272 , File
::Spec-
>catfile($uri->as_string)]
273 , init
=> sub { chdir $tmp or die $!; })
275 sub grg_remote_init_sftp
($) {
277 my $path = $ctx->{remote
}->{uri
}->path;
278 my $uri = $ctx->{remote
}->{uri
}->clone;
279 $uri->fragment(undef);
282 IPC
::Run
::run
([@{$ctx->{config
}->{curl
}}
283 , '--show-error', '--ftp-create-dirs'
284 , '-Q', "+mkdir ".$path
287 sub grg_remote_init
($) {
289 my $scheme = $ctx->{remote
}->{uri
}->scheme;
291 { file
=> \
&grg_remote_init_file
292 , rsync
=> \
&grg_remote_init_rsync
293 , sftp
=> \
&grg_remote_init_sftp
295 error
("URL scheme not supported: `$scheme'")
298 or error
("remote init failed");
301 sub grg_remote_push_file
($$) {
302 my ($ctx, $files) = @_;
303 foreach my $file (@$files) {
304 my $src = File
::Spec-
>catfile($ctx->{'dir-cache'}, $file);
305 my $dst = File
::Spec-
>catfile($ctx->{remote
}->{uri
}->file, $file);
306 debug
(sub{"File::Copy::move('$src', '$dst')\n"});
307 File
::Copy
::move
($src, $dst);
311 sub grg_remote_push_rsync
($$) {
312 my ($ctx, $files) = @_;
313 my $uri = $ctx->{remote
}->{uri
}->clone;
316 IPC
::Run
::run
([@{$ctx->{config
}->{rsync
}}
317 , '--verbose', '--relative'
321 sub grg_remote_push_sftp
($$) {
322 my ($ctx, $files) = @_;
323 my $uri = $ctx->{remote
}->{uri
}->clone;
326 IPC
::Run
::run
([@{$ctx->{config
}->{curl
}}
327 , '--show-error', '--ftp-create-dirs', '--upload-file'
328 , '{'.join(',', @$files).'}'
329 , $uri->as_string.'/'])
331 sub grg_remote_push
($) {
333 my $scheme = $ctx->{remote
}->{uri
}->scheme;
334 grg_remote_init
($ctx)
335 unless $ctx->{remote
}->{checked
};
337 if @{$ctx->{remote
}->{push}} == 0;
339 { file
=> \
&grg_remote_push_file
340 , rsync
=> \
&grg_remote_push_rsync
341 , sftp
=> \
&grg_remote_push_sftp
343 error
("URL scheme not supported: `$scheme'")
345 $fct->($ctx, $ctx->{remote
}->{push})
346 or error
("remote push failed");
349 sub grg_remote_remove
($) {
351 #my $scheme = $ctx->{remote}->{uri}->scheme;
354 # File::Copy::remove_tree
355 # ( map { File::Spec->catfile($ctx->{remote}->{uri}->path, $_) } @$files
359 # IPC::Run::run([@{$ctx->{config}->{rsync}}
360 # , '--verbose', '--ignore-times', '--recursive', '--delete'
362 # , $ctx->{remote}->{uri}])
365 # IPC::Run::run([@{$ctx->{config}->{curl}}
367 # , map { ('-Q', 'rm '.$_) } @$files
368 # , $ctx->{remote}->{uri}])
371 #error("URL scheme not supported: `$scheme'")
373 #$fct->($ctx, $ctx->{remote}->{remove})
374 # or error("remote remove failed");
378 sub grg_pack_fetch
($$) {
379 my ($ctx, $fetch_objects) = @_;
382 my %remote_objects = ();
383 while (my ($pack_id, $pack) = each %{$ctx->{manifest
}->{packs
}}) {
384 foreach my $obj (@{$pack->{objects
}}) {
385 $remote_objects{$obj} = $pack_id;
389 my %packs_to_fetch = ();
390 foreach my $obj (@$fetch_objects) {
391 my @packs = ($remote_objects{$obj});
392 while (my $pack_id = shift @packs) {
393 if (not exists $packs_to_fetch{$pack_id}) {
394 $packs_to_fetch{$pack_id} = 1;
395 my $manifest_pack = $ctx->{manifest
}->{packs
}->{$pack_id};
396 error
("manifest is missing a dependency pack: $pack_id")
397 unless defined $manifest_pack;
398 @packs = (@packs, @{$manifest_pack->{deps
}});
402 my @packs_to_fetch = keys %packs_to_fetch;
403 grg_remote_fetch
($ctx, [@packs_to_fetch]);
404 foreach my $pack_id (@packs_to_fetch) {
405 my $pack_file = File
::Spec-
>catfile($ctx->{'dir-cache'}, $pack_id);
406 my $manifest_pack = $ctx->{manifest
}->{packs
}->{$pack_id};
407 my $pack_key = $manifest_pack->{key
};
409 grg_decrypt_symmetric
($ctx, $pack_key, sub {
410 push @{$_[0]}, ($pack_file);
411 return (@_, '>', \
$pack_data);
413 my $pack_hash_algo = $manifest_pack->{hash_algo
};
414 my $pack_hash = grg_hash
($ctx
416 , sub { return (@_, '<', \
$pack_data); });
417 error
("pack data hash differs from pack manifest hash")
418 unless $pack_hash eq $manifest_pack->{hash
};
420 IPC
::Run
::run
(['git', 'index-pack', '-v', '--stdin']
425 sub grg_pack_push
($$) {
426 my ($ctx, $push_objects) = @_;
428 debug
(sub{"push_objects=\n"}, $push_objects);
430 my %remote_objects = ();
431 while (my ($pack_id, $pack) = each %{$ctx->{manifest
}->{packs
}}) {
432 foreach my $obj (@{$pack->{objects
}}) {
433 $remote_objects{$obj} = $pack_id;
437 IPC
::Run
::run
(['git', 'cat-file', '--batch-check']
438 , '<', \
join("\n", keys %remote_objects)
440 or error
("failed to query local git objects");
443 if ($_ =~ m/ missing$/) { () }
446 # @pack_objects, @pack_deps_objects
447 IPC
::Run
::run
(['git', 'rev-list', '--objects-edge', '--stdin', '--']
448 , '<', \
join("\n", ((map {'^'.$_} @common_objects), @$push_objects))
450 or error
("failed to query objects to pack");
451 my @pack_objects_edge = split(/\n/, $_);
452 foreach (@pack_objects_edge) {s/ .*//}
453 my @pack_objects = grep {m/^[^-]/} @pack_objects_edge;
454 my @pack_deps_objects = grep {s/^-//} @pack_objects_edge;
457 foreach my $obj (@pack_deps_objects) {
458 my $pack = $remote_objects{$obj};
459 error
("manifest is missing object dependencies")
460 unless defined $pack;
461 $pack_deps{$pack} = 1;
463 if (@pack_objects > 0) {
467 while (not defined $pack_id
468 or exists $ctx->{manifest
}->{packs
}->{$pack_id}) {
469 $pack_id = grg_rand
($ctx, $ctx->{config
}->{'pack-filename-size'});
470 $pack_id =~ s{/}{-}g;
471 error
("failed to pick an unused random pack filename after 512 tries; retry or increase grg.pack-filename-size")
472 if $pack_id_try++ >= 512;
474 my $pack_key = grg_rand
($ctx, $ctx->{config
}->{'pack-key-size'});
476 IPC
::Run
::run
(['git', 'pack-objects', '--stdout']
477 , '<', \
join("\n", @pack_objects)
479 or error
("failed to pack objects to push");
480 my $pack_hash = grg_hash
($ctx
481 , $ctx->{config
}->{'pack-hash-algo'}
482 , sub { return (@_, '<', \
$pack_data); });
483 grg_encrypt_symmetric
($ctx, $pack_data, $pack_key, sub {
484 push @{$_[0]}, ('--output', File
::Spec-
>catfile($ctx->{'dir-cache'}, $pack_id));
487 push @{$ctx->{remote
}->{push}}, $pack_id;
488 $ctx->{manifest
}->{packs
}->{$pack_id} =
489 { deps
=> [keys %pack_deps]
491 , hash_algo
=> $ctx->{config
}->{'pack-hash-algo'}
493 , objects
=> \
@pack_objects
498 sub grg_manifest_fetch
($) {
501 { 'hidden-keys' => {}
507 my ($crypt) = grg_remote_fetch
($ctx, [$ctx->{'manifest-file'}]);
508 if (defined $crypt) {
509 $ctx->{remote
}->{checked
} = 1;
511 grg_decrypt_asymmetric
($ctx, sub {
512 push @{$_[0]}, $crypt;
513 return (@_, '>', \
$json); });
514 # TODO: remove cached manifest?
516 ($manifest = JSON
::decode_json
($json) and ref $manifest eq 'HASH')
517 or error
("failed to decode JSON manifest");
518 $ctx->{manifest
} = {%{$ctx->{manifest
}}, %$manifest};
519 foreach my $slot (qw(keys hidden-keys)) {
520 while (my ($fpr, $uid) = each %{$ctx->{manifest
}->{$slot}}) {
521 my %keys = gpg_fingerprint
($ctx, '0x'.$fpr, ['E']);
522 my ($fpr, $uid) = each %keys;
523 $ctx->{config
}->{$slot}->{$fpr} = $uid;
528 debug
(sub{'ctx='}, $ctx);
529 if ($ctx->{command
} eq 'push') {
530 $ctx->{remote
}->{checked
} = 0;
532 elsif ($ctx->{remote
}->{checking
}) {
536 error
("remote checking failed");
540 sub grg_manifest_push
($) {
542 foreach my $slot (qw(keys hidden-keys)) {
543 $ctx->{manifest
}->{$slot} = {};
544 while (my ($fpr, $uid) = each %{$ctx->{config
}->{$slot}}) {
545 $ctx->{manifest
}->{$slot}->{$fpr} = $uid;
548 my $json = JSON
::encode_json
($ctx->{manifest
})
549 or error
("failed to encode JSON manifest");
550 grg_encrypt_asymmetric
($ctx, $json, sub {
552 , ('--output', File
::Spec-
>catfile($ctx->{'dir-cache'}, $ctx->{'manifest-file'}));
554 push @{$ctx->{remote
}->{push}}, $ctx->{'manifest-file'};
557 sub grg_config_read
($) {
559 my $cfg = $ctx->{config
};
562 foreach my $name (qw(gpg signingkey keys)
563 , grep { !m/^(gpg|signingkey|keys)$/ } (keys %$cfg)) {
565 IPC
::Run
::run
(['git', 'config', '--get', 'remote.'.$ctx->{remote
}->{name
}.'.'.$name, '.+'], '>', \
$value) or
566 IPC
::Run
::run
(['git', 'config', '--get', 'grg.'.$name, '.+'], '>', \
$value) or 1;
567 if ($name eq 'signingkey') {
568 IPC
::Run
::run
(['git', 'config', '--get', 'user.'.$name, '.+'], '>', \
$value)
571 my %keys = gpg_fingerprint
($ctx, $value, ['S']);
572 warning
("signing key ID is not matching a unique key: taking only one")
573 unless scalar(keys %keys) == 1;
574 my ($fpr, $uid) = each %keys;
575 $cfg->{$name} = {fpr
=> $fpr, uid
=> $uid};
577 elsif ($name eq 'keys' or $name eq 'hidden-keys') {
578 IPC
::Run
::run
(['git', 'config', '--get', 'user.'.$name, '.+'], '>', \
$value)
581 my @ids = split(/,/, $value);
583 foreach my $key (@ids) {
584 my %keys = gpg_fingerprint
($ctx, $key, ['E']);
585 while (my ($fpr, $uid) = each %keys) {
586 $cfg->{$name}->{$fpr} = $uid;
591 elsif (grep(/^$name$/, qw(curl gpg rsync))) {
592 IPC
::Run
::run
(['git', 'config', '--get', $name.'.program', '.+'], '>', \
$value)
594 $cfg->{$name} = [split(' ', $value)]
599 $cfg->{$name} = $value
603 error
("no signingkey configured; to do so you may use one of following commands:\n"
604 , "\t\$ git config remote.'$ctx->{remote}->{name}'.signingkey \$your_openpgp_id\n"
605 , "\t\$ git config grg.signingkey \$your_openpgp_id\n"
606 , "\t\$ git config user.signingkey \$your_openpgp_id"
607 ) unless defined $cfg->{signingkey
};
608 if ( (scalar (keys %{$cfg->{keys}}) == 0)
609 and (scalar (keys %{$cfg->{'hidden-keys'}}) == 0) ) {
610 $cfg->{keys} = { $cfg->{signingkey
}->{fpr
} => $cfg->{signingkey
}->{uid
} };
613 debug
(sub{'config='},$cfg);
616 sub grg_connect
($) {
618 grg_config_read
($ctx);
619 grg_manifest_fetch
($ctx);
621 sub grg_disconnect
($) {
623 grg_remote_push
($ctx);
626 sub gpg_command_answer
($) {
628 debug
(sub{join('', @cmd)."\n"});
629 print STDOUT
(@cmd, "\n");
631 sub grg_command_capabilities
($) {
633 $ctx->{command
} = 'capabilities';
634 gpg_command_answer
("fetch");
635 gpg_command_answer
("push");
636 gpg_command_answer
("");
639 sub grg_command_fetch
($$) {
640 my ($ctx, $fetch_refs) = @_;
641 $ctx->{command
} = 'fetch';
642 debug
(sub{"fetch_refs="}, $fetch_refs);
645 my @fetch_objects= ();
646 foreach my $ref (@$fetch_refs) {
647 push @fetch_objects, $ref->{sha1
};
649 grg_pack_fetch
($ctx, \
@fetch_objects);
651 sub grg_command_list
($) {
653 $ctx->{command
} = 'list';
655 while (my ($ref, $obj) = each %{$ctx->{manifest
}->{refs
}}) {
656 gpg_command_answer
("$obj $ref");
658 gpg_command_answer
("");
660 sub grg_command_push
($$) {
661 my ($ctx, $push_refs) = @_;
663 $ctx->{command
} = 'push';
664 debug
(sub{"push_refs="}, $push_refs);
667 my @push_objects= ();
668 foreach my $ref (@$push_refs) {
669 IPC
::Run
::run
(['git', 'rev-list', '--ignore-missing', '--max-count=1', $ref->{src
}, '--']
671 or error
("failed to dereference ref to push: ".$ref->{src
});
673 $ref->{src_obj
} = $_;
674 push @push_objects, $_;
676 grg_pack_push
($ctx, \
@push_objects);
677 my $manifest_refs = $ctx->{manifest
}->{refs
};
678 foreach my $ref (@$push_refs) {
679 $manifest_refs->{$ref->{dst
}} = $ref->{src_obj
};
681 $manifest_refs->{HEAD
}
682 = $push_refs->[-1]->{src_obj
}
683 unless exists $manifest_refs->{HEAD
}
685 grg_manifest_push
($ctx);
686 grg_disconnect
($ctx);
688 sub grg_commands
(@) {
692 #STDOUT->autoflush(1);
693 while (defined $line or (not eof(*STDIN
) and
694 (defined($line = readline(*STDIN
)))
696 : error
("readline failed: $!")
698 debug
(sub{"line=\"",$line,"\"\n"});
699 $ctx->{command
} = undef;
700 if ($line eq 'capabilities') {
701 grg_command_capabilities
($ctx);
704 elsif ($line =~ m/^fetch .*$/) {
707 while ((defined $line or (not eof(*STDIN
) and
708 ((defined($line = readline(*STDIN
)))
710 : error
("readline failed: $!")))) and
711 (($sha1, $name) = ($line =~ m/^fetch ([0-9a-f]{40}) (.+)$/))
713 debug
(sub{"fetch line=\"",$line,"\"\n"});
714 push @refs, {sha1
=>$sha1, name
=>$name};
717 error
("failed to parse command: $line")
719 grg_command_fetch
($ctx, \
@refs);
721 elsif ($line eq 'list' or $line eq 'list for-push') {
722 grg_command_list
($ctx);
725 elsif ($line =~ m/^push .*$/) {
727 my ($force, $src, $dst);
728 while ((defined $line or (not eof(*STDIN
) and
729 ((defined($line = readline(*STDIN
)))
731 : error
("readline failed: $!")))) and
732 (($force, $src, $dst) = ($line =~ m/^push (\+)?([^:]+):(.+)$/))
734 debug
(sub{"push line=\"",$line,"\"\n"});
735 push @refs, {force
=>(defined $force), src
=>$src, dst
=>$dst};
738 error
("failed to parse command: $line")
740 grg_command_push
($ctx, \
@refs);
742 elsif ($line =~ m/^$/) {
744 gpg_command_answer
("");
748 warning
("unsupported command supplied: `$line'");
754 $ENV{GIT_DIR
} = $ENV{GIT_DIR
} || '.git';
755 $ENV{GITCEPTION
} = ($ENV{GITCEPTION
} || '') . '+';
762 , 'hidden-keys' => {}
763 , 'manifest-hash-algo' => 'SHA224' # NOTE: SHA512, SHA384, SHA256, SHA224 supported.
764 , 'pack-filename-size' => 42
765 , 'pack-hash-algo' => 'SHA224' # NOTE: SHA512, SHA384, SHA256, SHA224 supported.
766 , 'pack-key-size' => 64
767 , signingkey
=> undef
770 , 'dir-cache' => undef
772 , 'manifest-file' => undef
781 Getopt
::Long
::Configure
786 Getopt
::Long
::GetOptions
787 ( help
=> sub { Pod
::Usage
::pod2usage
789 , -sections
=> ['SYNOPSIS', 'OPTIONS', 'REMOTES', 'CONFIG']
790 , -verbose
=> 99 ); }
791 , man
=> sub { Pod
::Usage
::pod2usage
(-verbose
=> 2); }
793 $ctx->{remote
}->{checking
} = 1;
796 if (not $ctx->{remote
}->{checking
}) {
797 my $name = shift @ARGV;
798 Pod
::Usage
::pod2usage
(-verbose
=> 1)
799 unless defined $name;
800 ($ctx->{remote
}->{name
}) = ($name =~ m/^((\w|-)+)$/);
801 error
("valid name of remote Git required, got: `$name'")
802 unless $ctx->{remote
}->{name
};
804 my $uri = shift @ARGV;
805 Pod
::Usage
::pod2usage
(-verbose
=> 1)
807 $ctx->{remote
}->{uri
} = URI-
>new($uri);
808 error
("valid URL of remote Git required, got: `$uri'")
809 unless $ctx->{remote
}->{uri
};
810 my $fragment = $ctx->{remote
}->{uri
}->fragment;
812 unless defined $fragment;
813 $ctx->{'manifest-file'} = grg_hash
($ctx
814 , $ctx->{config
}->{'manifest-hash-algo'}
815 , sub { return (@_, '<', \
$fragment); });
816 if (-d
$ENV{GIT_DIR
}) {
817 $ctx->{'dir-cache'} = File
::Spec-
>catdir
818 ( $ENV{GIT_DIR
}, 'cache', 'remotes'
819 , $ctx->{remote
}->{name
}, 'gpg');
820 File
::Path
::make_path
($ctx->{'dir-cache'}, {verbose
=> 1});
823 $ctx->{'dir-cache'} = File
::Temp-
>tempdir(CLEANUP
=> 1);
825 debug
(sub{"ctx="},$ctx);
836 git-remote-gpg - git-remote-helpers(1) to encrypt remote repository through gpg(1)
840 =item git-remote-gpg $gpg_remote $gpg_url
842 =item git-remote-gpg --check $gpg_url
848 =item B<-h>, B<--help>
858 =item git remote add $remote gpg::rsync://${user:+$user@}$host/$path
862 =item git remote add $remote gpg::sftp://${user:+$user@}$host/$path
864 =head2 Via File::Copy(3pm)
866 =item git remote add $remote gpg::file://$path
880 =item B<grg.hidden-keys>
882 =item B<grg.manifest-hash-algo>
884 =item B<grg.pack-filename-size>
886 =item B<grg.pack-hash-algo>
888 =item B<grg.pack-key-size>
890 =item B<grg.signingkey>