File: dump-github-repository.pl

package info (click to toggle)
h2o 2.2.5%2Bdfsg2-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 56,620 kB
  • sloc: ansic: 130,776; cpp: 35,914; ruby: 19,541; sh: 11,844; javascript: 6,720; yacc: 5,964; perl: 3,732; python: 2,658; asm: 2,259; makefile: 526; objc: 385; pascal: 382; php: 13
file content (41 lines) | stat: -rwxr-xr-x 1,177 bytes parent folder | download | duplicates (6)
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
#! /usr/bin/perl

use strict;
use warnings;
use Errno ();
use File::Basename qw(basename);

die "Usage: $0 <https://github.com/user/repo> <commit> <dest-dir> [<path>]\n"
    if @ARGV < 3;

my ($repo, $commit, $dest, $path) = @ARGV;
my $strip_components = 1;
my ($rm_path, $tar_path);

if (defined $path) {
    $path =~ s|/*$||;
    $strip_components += scalar(split "/", $path) - 1;
    $rm_path = "$dest/" . basename $path;
    $tar_path = "*/$path";
} else {
    $path = "";
    $rm_path = "$dest";
    $tar_path = "";
}

run("rm -rf $rm_path");

mkdir("$dest")
    or $! == Errno::EEXIST or die "failed to (re)create directory:$dest:$!";
run("curl --silent --show-error --location $repo/archive/$commit.tar.gz | (cd $dest && tar x --strip-components $strip_components -zf - $tar_path)") == 0
    or die "failed to extract $repo/archive/$commit.tar.gz to $dest";
run("git add -f `find $rm_path -type f`") == 0
    or die "failed to add files under $dest";
run("git commit --allow-empty -m 'extract $repo @ $commit @{[defined $path ? qq{($path)} : '']} at $dest' $dest") == 0
    or die "failed to commit";

sub run {
   my $cmd = shift;
   print "$cmd\n";
   system($cmd);
}