forked from pflanze/chj-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcj-git-add-manyfiles
executable file
·119 lines (102 loc) · 2.34 KB
/
cj-git-add-manyfiles
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/perl -w
# Mon Aug 18 13:34:20 CEST 2008
(my $email='XXX%YYY,ch')=~ tr/%,/@./;
use strict;
our $nfiles= 10000; # 30000; hm is already too long "??" why can myxargs use 1e6 then?
$0=~ /(.*?)([^\/]+)\z/s or die "?";
my ($mydir, $myname)=($1,$2);
sub usage {
print STDERR map{"$_\n"} @_ if @_;
print "$myname dir
Add *and commit* many files, and do it in pieces, so every $nfiles a
commit is done and then a git-repack before continuing.
(Christian Jaeger <$email>)
";
exit (@_ ? 1 : 0);
}
use Getopt::Long;
our $verbose=0;
GetOptions("verbose"=> \$verbose,
"help"=> sub{usage},
) or exit 1;
usage unless @ARGV;
# how to deliver items, "with continue", ?
# lazy or....?
# insideout, sigh.
{
package CJGIT::Filestream;
# recursively returns all file system items except directories
# (depth-first)
use Class::Array -fields=>
-publica=>
("fdstack",
"dirstack",
);
use Chj::xopendir;
use Chj::xperlfunc ':all'; # xlstat
sub new {
my $class=shift;
our ($basedir)=@_;
my $s= $class->SUPER::new;
$$s[Fdstack]= [ scalar xopendir $basedir ];
$$s[Dirstack]= [$basedir];
$s
}
sub curfd {
my $s=shift;
$$s[Fdstack][-1]
}
sub next_path {
my $s=shift;
if (defined (my $item= $s->curfd->xnread)) {
my $path= join("/", @{$$s[Dirstack]}, $item);
my $stat= xlstat $path;
if ($stat->is_dir) {
push @{$$s[Dirstack]}, $item;
push @{$$s[Fdstack]}, scalar xopendir $path;
$s->next_path
} else {
$path
}
} else {
pop @{$$s[Dirstack]};
pop @{$$s[Fdstack]};
if (@{$$s[Fdstack]}) {
$s->next_path
} else {
undef
}
}
}
}
#use Chj::ruse;
use Chj::Backtrace; use Chj::repl; #repl;
use Chj::xperlfunc;
sub addmanyfiles ( $ ) {
my ($path)=@_;
our $stream= CJGIT::Filestream->new($path);
while (1) {
# collect files:
my $files=[];
my $is_last_partialcommit;
LP: {
while(defined (my $file= $stream->next_path)) {
push @$files,$file;
if (@$files== $nfiles) {
last LP;
} elsif (@$files > $nfiles) {
die "???"
}
}
$is_last_partialcommit=1;
};
xxsystem "git", "add", "--", @$files;
xxsystem "git", "commit", "-m", "PARTIALCOMMIT\n\n(created by $myname)";
xxsystem "git", "repack", "-d";
last if $is_last_partialcommit;
}
# UNFINISHED HERE.
}
for my $path (@ARGV) {
addmanyfiles $path
}