git-svn: convert 'set-tree' command to use Git::SVN
Signed-off-by: Eric Wong <normalperson@yhbt.net>
Eric Wong committed
Jan 14, 2007 at 23:21 UTC
1ce255dc168cc1fcf849a7c82bdf45753b0dfe09
1 file changed
+17
-495
git-svn.perl
+17
-495
@@ -24,16 +24,6 @@ $ENV{TZ} = 'UTC';
24
$ENV{LC_ALL} = 'C';
25
$| = 1; # unbuffer STDOUT
26
27
-# properties that we do not log:
28
-my %SKIP = ( 'svn:wc:ra_dav:version-url' => 1,
29
- 'svn:special' => 1,
30
- 'svn:executable' => 1,
31
- 'svn:entry:committed-rev' => 1,
32
- 'svn:entry:last-author' => 1,
33
- 'svn:entry:uuid' => 1,
34
- 'svn:entry:committed-date' => 1,
35
-);
36
-
27
sub fatal (@) { print STDERR @_; exit 1 }
28
require SVN::Core; # use()-ing this causes segfaults for me... *shrug*
29
require SVN::Ra;
@@ -113,8 +103,9 @@ my %cmd = (
103
'strategy|s=s' => \$_strategy,
104
'dry-run|n' => \$_dry_run,
105
%cmt_opts, %fc_opts } ],
116
- 'set-tree' => [ \&commit, "Set an SVN repository to a git tree-ish",
117
- { 'stdin|' => \$_stdin, %cmt_opts, %fc_opts, } ],
106
+ 'set-tree' => [ \&cmd_set_tree,
107
+ "Set an SVN repository to a git tree-ish",
108
+ { 'stdin|' => \$_stdin, %cmt_opts, %fc_opts, } ],
109
'show-ignore' => [ \&cmd_show_ignore, "Show svn:ignore listings",
110
{ 'revision|r=i' => \$_revision } ],
111
rebuild => [ \&cmd_rebuild, "Rebuild git-svn metadata (after git clone)",
@@ -301,94 +292,8 @@ sub cmd_fetch {
292
}
293
}
294
304
-sub fetch {
305
- check_upgrade_needed();
306
- $SVN_URL ||= file_to_s("$GIT_SVN_DIR/info/url");
307
- my $ret = fetch_lib(@_);
308
- if ($ret->{commit} && !verify_ref('refs/heads/master^0')) {
309
- command_noisy(qw(update-ref refs/heads/master),$ret->{commit});
310
- }
311
- return $ret;
312
-}
313
-
314
-sub fetch_lib {
315
- my (@parents) = @_;
316
- $SVN_URL ||= file_to_s("$GIT_SVN_DIR/info/url");
317
- $SVN ||= Git::SVN::Ra->new($SVN_URL);
318
- my ($last_rev, $last_commit) = svn_grab_base_rev();
319
- my ($base, $head) = libsvn_parse_revision($last_rev);
320
- if ($base > $head) {
321
- return { revision => $last_rev, commit => $last_commit }
322
- }
323
- my $index = set_index($GIT_SVN_INDEX);
324
-
325
- # limit ourselves and also fork() since get_log won't release memory
326
- # after processing a revision and SVN stuff seems to leak
327
- my $inc = 1000;
328
- my ($min, $max) = ($base, $head < $base+$inc ? $head : $base+$inc);
329
- if (defined $last_commit) {
330
- unless (-e $GIT_SVN_INDEX) {
331
- command_noisy('read-tree', $last_commit);
332
- }
333
- my $x = command_oneline('write-tree');
334
- my ($y) = (command(qw/cat-file commit/, $last_commit)
335
- =~ /^tree ($sha1)/m);
336
- if ($y ne $x) {
337
- unlink $GIT_SVN_INDEX or croak $!;
338
- command_noisy('read-tree', $last_commit);
339
- }
340
- $x = command_oneline('write-tree');
341
- if ($y ne $x) {
342
- print STDERR "trees ($last_commit) $y != $x\n",
343
- "Something is seriously wrong...\n";
344
- }
345
- }
346
- while (1) {
347
- # fork, because using SVN::Pool with get_log() still doesn't
348
- # seem to help enough to keep memory usage down.
349
- defined(my $pid = fork) or croak $!;
350
- if (!$pid) {
351
- $SVN::Error::handler = \&libsvn_skip_unknown_revs;
352
-
353
- # Yes I'm perfectly aware that the fourth argument
354
- # below is the limit revisions number. Unfortunately
355
- # performance sucks with it enabled, so it's much
356
- # faster to fetch revision ranges instead of relying
357
- # on the limiter.
358
- $SVN->dup->get_log([''], $min, $max, 0, 1, 1,
359
- sub {
360
- my $log_entry;
361
- if ($last_commit) {
362
- $log_entry = libsvn_fetch(
363
- $last_commit, @_);
364
- $last_commit = git_commit(
365
- $log_entry,
366
- $last_commit,
367
- @parents);
368
- } else {
369
- $log_entry = libsvn_new_tree(@_);
370
- $last_commit = git_commit(
371
- $log_entry, @parents);
372
- }
373
- });
374
- exit 0;
375
- }
376
- waitpid $pid, 0;
377
- croak $? if $?;
378
- ($last_rev, $last_commit) = svn_grab_base_rev();
379
- last if ($max >= $head);
380
- $min = $max + 1;
381
- $max += $inc;
382
- $max = $head if ($max > $head);
383
- $SVN = Git::SVN::Ra->new($SVN_URL);
384
- }
385
- restore_index($index);
386
- return { revision => $last_rev, commit => $last_commit };
387
-}
388
-
389
-sub commit {
295
+sub cmd_set_tree {
296
my (@commits) = @_;
391
- check_upgrade_needed();
297
if ($_stdin || !@commits) {
298
print "Reading from stdin...\n";
299
@commits = ();
@@ -406,81 +311,20 @@ sub commit {
311
} elsif (scalar @tmp > 1) {
312
push @revs, reverse(command('rev-list',@tmp));
313
} else {
409
- die "Failed to rev-parse $c\n";
314
+ fatal "Failed to rev-parse $c\n";
315
}
316
}
412
- commit_lib(@revs);
413
- print "Done committing ",scalar @revs," revisions to SVN\n";
414
-}
415
-
416
-sub commit_lib {
417
- my (@revs) = @_;
418
- my ($r_last, $cmt_last) = svn_grab_base_rev();
419
- defined $r_last or die "Must have an existing revision to commit\n";
420
- my $fetched = fetch();
421
- if ($r_last != $fetched->{revision}) {
422
- print STDERR "There are new revisions that were fetched ",
423
- "and need to be merged (or acknowledged) ",
424
- "before committing.\n",
425
- "last rev: $r_last\n",
426
- " current: $fetched->{revision}\n";
427
- exit 1;
428
- }
429
- my $commit_msg = "$GIT_SVN_DIR/.svn-commit.tmp.$$";
430
-
431
- my $repo;
432
- set_svn_commit_env();
433
- foreach my $c (@revs) {
434
- my $log_entry = get_commit_entry($c, $commit_msg);
435
-
436
- # fork for each commit because there's a memory leak I
437
- # can't track down... (it's probably in the SVN code)
438
- defined(my $pid = open my $fh, '-|') or croak $!;
439
- if (!$pid) {
440
- my $pool = SVN::Pool->new;
441
- my $ed = SVN::Git::Editor->new(
442
- { r => $r_last,
443
- ra => $SVN->dup,
444
- svn_path => $SVN->{svn_path},
445
- },
446
- $SVN->get_commit_editor(
447
- $log_entry->{log},
448
- sub {
449
- libsvn_commit_cb(
450
- @_, $c,
451
- $log_entry->{log},
452
- $r_last,
453
- $cmt_last)
454
- }, $pool)
455
- );
456
- my $mods = $ed->apply_diff($cmt_last, $c);
457
- if (@$mods == 0) {
458
- print "No changes\nr$r_last = $cmt_last\n";
459
- }
460
- $pool->clear;
461
- exit 0;
462
- }
463
- my ($r_new, $cmt_new, $no);
464
- while (<$fh>) {
465
- print $_;
466
- chomp;
467
- if (/^r(\d+) = ($sha1)$/o) {
468
- ($r_new, $cmt_new) = ($1, $2);
469
- } elsif ($_ eq 'No changes') {
470
- $no = 1;
471
- }
472
- }
473
- close $fh or exit 1;
474
- if (! defined $r_new && ! defined $cmt_new) {
475
- unless ($no) {
476
- die "Failed to parse revision information\n";
477
- }
478
- } else {
479
- ($r_last, $cmt_last) = ($r_new, $cmt_new);
480
- }
317
+ my $gs = Git::SVN->new;
318
+ my ($r_last, $cmt_last) = $gs->last_rev_commit;
319
+ $gs->fetch;
320
+ if ($r_last != $gs->{last_rev}) {
321
+ fatal "There are new revisions that were fetched ",
322
+ "and need to be merged (or acknowledged) ",
323
+ "before committing.\nlast rev: $r_last\n",
324
+ " current: $gs->{last_rev}\n";
325
}
482
- $ENV{LC_ALL} = 'C';
483
- unlink $commit_msg;
326
+ $gs->set_tree($_) foreach @revs;
327
+ print "Done committing ",scalar @revs," revisions to SVN\n";
328
}
329
330
sub cmd_dcommit {
@@ -1055,14 +899,6 @@ sub get_commit_entry {
899
\%log_entry;
900
}
901
1058
-sub set_svn_commit_env {
1059
- if (defined $LC_ALL) {
1060
- $ENV{LC_ALL} = $LC_ALL;
1061
- } else {
1062
- delete $ENV{LC_ALL};
1063
- }
1064
-}
1065
-
902
sub rev_list_raw {
903
my ($fh, $c) = command_output_pipe(qw/rev-list --pretty=raw/, @_);
904
return { fh => $fh, ctx => $c, t => { } };
@@ -1109,124 +945,6 @@ sub file_to_s {
945
return $ret;
946
}
947
1112
-sub assert_revision_unknown {
1113
- my $r = shift;
1114
- if (my $c = revdb_get($REVDB, $r)) {
1115
- croak "$r = $c already exists! Why are we refetching it?";
1116
- }
1117
-}
1118
-
1119
-sub git_commit {
1120
- my ($log_entry, @parents) = @_;
1121
- assert_revision_unknown($log_entry->{revision});
1122
- map_tree_joins() if (@_branch_from && !%tree_map);
1123
-
1124
- my (@tmp_parents, @exec_parents, %seen_parent);
1125
- if (my $lparents = $log_entry->{parents}) {
1126
- @tmp_parents = @$lparents
1127
- }
1128
- # commit parents can be conditionally bound to a particular
1129
- # svn revision via: "svn_revno=commit_sha1", filter them out here:
1130
- foreach my $p (@parents) {
1131
- next unless defined $p;
1132
- if ($p =~ /^(\d+)=($sha1_short)$/o) {
1133
- if ($1 == $log_entry->{revision}) {
1134
- push @tmp_parents, $2;
1135
- }
1136
- } else {
1137
- push @tmp_parents, $p if $p =~ /$sha1_short/o;
1138
- }
1139
- }
1140
- my $tree = $log_entry->{tree};
1141
- if (!defined $tree) {
1142
- my $index = set_index($GIT_SVN_INDEX);
1143
- $tree = command_oneline('write-tree');
1144
- croak $? if $?;
1145
- restore_index($index);
1146
- }
1147
- # just in case we clobber the existing ref, we still want that ref
1148
- # as our parent:
1149
- if (my $cur = verify_ref("refs/remotes/$GIT_SVN^0")) {
1150
- chomp $cur;
1151
- push @tmp_parents, $cur;
1152
- }
1153
-
1154
- if (exists $tree_map{$tree}) {
1155
- foreach my $p (@{$tree_map{$tree}}) {
1156
- my $skip;
1157
- foreach (@tmp_parents) {
1158
- # see if a common parent is found
1159
- my $mb = eval { command('merge-base', $_, $p) };
1160
- next if ($@ || $?);
1161
- $skip = 1;
1162
- last;
1163
- }
1164
- next if $skip;
1165
- my ($url_p, $r_p, $uuid_p) = cmt_metadata($p);
1166
- next if (($SVN->uuid eq $uuid_p) &&
1167
- ($log_entry->{revision} > $r_p));
1168
- next if (defined $url_p && defined $SVN_URL &&
1169
- ($SVN->uuid eq $uuid_p) &&
1170
- ($url_p eq $SVN_URL));
1171
- push @tmp_parents, $p;
1172
- }
1173
- }
1174
- foreach (@tmp_parents) {
1175
- next if $seen_parent{$_};
1176
- $seen_parent{$_} = 1;
1177
- push @exec_parents, $_;
1178
- # MAXPARENT is defined to 16 in commit-tree.c:
1179
- last if @exec_parents > 16;
1180
- }
1181
-
1182
- set_commit_env($log_entry);
1183
- my @exec = ('git-commit-tree', $tree);
1184
- push @exec, '-p', $_ foreach @exec_parents;
1185
- defined(my $pid = open3(my $msg_fh, my $out_fh, '>&STDERR', @exec))
1186
- or croak $!;
1187
- print $msg_fh $log_entry->{log} or croak $!;
1188
- unless ($_no_metadata) {
1189
- print $msg_fh "\ngit-svn-id: $SVN_URL\@$log_entry->{revision} ",
1190
- $SVN->uuid,"\n" or croak $!;
1191
- }
1192
- $msg_fh->flush == 0 or croak $!;
1193
- close $msg_fh or croak $!;
1194
- chomp(my $commit = do { local $/; <$out_fh> });
1195
- close $out_fh or croak $!;
1196
- waitpid $pid, 0;
1197
- croak $? if $?;
1198
- if ($commit !~ /^$sha1$/o) {
1199
- die "Failed to commit, invalid sha1: $commit\n";
1200
- }
1201
- command_noisy('update-ref',"refs/remotes/$GIT_SVN",$commit);
1202
- revdb_set($REVDB, $log_entry->{revision}, $commit);
1203
-
1204
- # this output is read via pipe, do not change:
1205
- print "r$log_entry->{revision} = $commit\n";
1206
- return $commit;
1207
-}
1208
-
1209
-sub check_repack {
1210
- if ($_repack && (--$_repack_nr == 0)) {
1211
- $_repack_nr = $_repack;
1212
- # repack doesn't use any arguments with spaces in them, does it?
1213
- command_noisy('repack', split(/\s+/, $_repack_flags));
1214
- }
1215
-}
1216
-
1217
-sub set_commit_env {
1218
- my ($log_entry) = @_;
1219
- my $author = $log_entry->{author};
1220
- if (!defined $author || length $author == 0) {
1221
- $author = '(no author)';
1222
- }
1223
- my ($name,$email) = defined $users{$author} ? @{$users{$author}}
1224
- : ($author,$author . '@' . $SVN->uuid);
1225
- $ENV{GIT_AUTHOR_NAME} = $ENV{GIT_COMMITTER_NAME} = $name;
1226
- $ENV{GIT_AUTHOR_EMAIL} = $ENV{GIT_COMMITTER_EMAIL} = $email;
1227
- $ENV{GIT_AUTHOR_DATE} = $ENV{GIT_COMMITTER_DATE} = $log_entry->{date};
1228
-}
1229
-
948
sub check_upgrade_needed {
949
if (!-r $REVDB) {
950
-d $GIT_SVN_DIR or mkpath([$GIT_SVN_DIR]);
@@ -1859,7 +1577,7 @@ sub write_untracked {
1577
foreach my $path (sort keys %$h) {
1578
my $ppath = $path eq '' ? '.' : $path;
1579
foreach my $prop (sort keys %{$h->{$path}}) {
1862
- next if $SKIP{$prop};
1580
+ next if $SKIP_PROP{$prop};
1581
my $v = $h->{$path}->{$prop};
1582
if (defined $v) {
1583
print $fh " +$t: ",
@@ -1975,7 +1693,7 @@ sub set_tree_cb {
1693
1694
sub set_tree {
1695
my ($self, $tree) = (shift, shift);
1978
- my $log_entry = get_commit_entry($tree);
1696
+ my $log_entry = ::get_commit_entry($tree);
1697
unless ($self->{last_rev}) {
1698
fatal("Must have an existing revision to commit\n");
1699
}
@@ -2218,118 +1936,6 @@ sub uri_decode {
1936
$f
1937
}
1938
2221
-sub libsvn_log_entry {
2222
- my ($rev, $author, $date, $log, $parents, $untracked) = @_;
2223
- my ($Y,$m,$d,$H,$M,$S) = ($date =~ /^(\d{4})\-(\d\d)\-(\d\d)T
2224
- (\d\d)\:(\d\d)\:(\d\d).\d+Z$/x)
2225
- or die "Unable to parse date: $date\n";
2226
- if (defined $author && length $author > 0 &&
2227
- defined $_authors && ! defined $users{$author}) {
2228
- die "Author: $author not defined in $_authors file\n";
2229
- }
2230
- $log = '' if ($rev == 0 && !defined $log);
2231
-
2232
- open my $un, '>>', "$GIT_SVN_DIR/unhandled.log" or croak $!;
2233
- my $h;
2234
- print $un "r$rev\n" or croak $!;
2235
- $h = $untracked->{empty};
2236
- foreach (sort keys %$h) {
2237
- my $act = $h->{$_} ? '+empty_dir' : '-empty_dir';
2238
- print $un " $act: ", uri_encode($_), "\n" or croak $!;
2239
- warn "W: $act: $_\n";
2240
- }
2241
- foreach my $t (qw/dir_prop file_prop/) {
2242
- $h = $untracked->{$t} or next;
2243
- foreach my $path (sort keys %$h) {
2244
- my $ppath = $path eq '' ? '.' : $path;
2245
- foreach my $prop (sort keys %{$h->{$path}}) {
2246
- next if $SKIP{$prop};
2247
- my $v = $h->{$path}->{$prop};
2248
- if (defined $v) {
2249
- print $un " +$t: ",
2250
- uri_encode($ppath), ' ',
2251
- uri_encode($prop), ' ',
2252
- uri_encode($v), "\n"
2253
- or croak $!;
2254
- } else {
2255
- print $un " -$t: ",
2256
- uri_encode($ppath), ' ',
2257
- uri_encode($prop), "\n"
2258
- or croak $!;
2259
- }
2260
- }
2261
- }
2262
- }
2263
- foreach my $t (qw/absent_file absent_directory/) {
2264
- $h = $untracked->{$t} or next;
2265
- foreach my $parent (sort keys %$h) {
2266
- foreach my $path (sort @{$h->{$parent}}) {
2267
- print $un " $t: ",
2268
- uri_encode("$parent/$path"), "\n"
2269
- or croak $!;
2270
- warn "W: $t: $parent/$path ",
2271
- "Insufficient permissions?\n";
2272
- }
2273
- }
2274
- }
2275
-
2276
- # revprops (make this optional? it's an extra network trip...)
2277
- my $rp = $SVN->rev_proplist($rev);
2278
- foreach (sort keys %$rp) {
2279
- next if /^svn:(?:author|date|log)$/;
2280
- print $un " rev_prop: ", uri_encode($_), ' ',
2281
- uri_encode($rp->{$_}), "\n";
2282
- }
2283
- close $un or croak $!;
2284
-
2285
- { revision => $rev, date => "+0000 $Y-$m-$d $H:$M:$S",
2286
- author => $author, log => $log."\n", parents => $parents || [],
2287
- revprops => $rp }
2288
-}
2289
-
2290
-sub libsvn_fetch {
2291
- my ($last_commit, $paths, $rev, $author, $date, $log) = @_;
2292
- my $ed = SVN::Git::Fetcher->new({ c => $last_commit, q => $_q });
2293
- my (undef, $last_rev, undef) = cmt_metadata($last_commit);
2294
- unless ($SVN->gs_do_update($last_rev, $rev, '', 1, $ed)) {
2295
- die "SVN connection failed somewhere...\n";
2296
- }
2297
- libsvn_log_entry($rev, $author, $date, $log, [$last_commit], $ed);
2298
-}
2299
-
2300
-sub svn_grab_base_rev {
2301
- my $c = eval { command_oneline([qw/rev-parse --verify/,
2302
- "refs/remotes/$GIT_SVN^0"],
2303
- { STDERR => 0 }) };
2304
- if (defined $c && length $c) {
2305
- my ($url, $rev, $uuid) = cmt_metadata($c);
2306
- return ($rev, $c) if defined $rev;
2307
- }
2308
- if ($_no_metadata) {
2309
- my $offset = -41; # from tail
2310
- my $rl;
2311
- open my $fh, '<', $REVDB or
2312
- die "--no-metadata specified and $REVDB not readable\n";
2313
- seek $fh, $offset, 2;
2314
- $rl = readline $fh;
2315
- defined $rl or return (undef, undef);
2316
- chomp $rl;
2317
- while ($c ne $rl && tell $fh != 0) {
2318
- $offset -= 41;
2319
- seek $fh, $offset, 2;
2320
- $rl = readline $fh;
2321
- defined $rl or return (undef, undef);
2322
- chomp $rl;
2323
- }
2324
- my $rev = tell $fh;
2325
- croak $! if ($rev < -1);
2326
- $rev = ($rev - 41) / 41;
2327
- close $fh or croak $!;
2328
- return ($rev, $c);
2329
- }
2330
- return (undef, undef);
2331
-}
2332
-
1939
sub libsvn_parse_revision {
1940
my $base = shift;
1941
my $head = $SVN->get_latest_revnum();
@@ -2450,14 +2056,6 @@ sub libsvn_find_parent_branch {
2056
return undef;
2057
}
2058
2453
-sub libsvn_new_tree {
2454
- if (my $log_entry = libsvn_find_parent_branch(@_)) {
2455
- return $log_entry;
2456
- }
2457
- my ($paths, $rev, $author, $date, $log) = @_; # $pool is last
2458
- _libsvn_new_tree($paths, $rev, $author, $date, $log, []);
2459
-}
2460
-
2059
sub _libsvn_new_tree {
2060
my ($paths, $rev, $author, $date, $log, $parents) = @_;
2061
my $ed = SVN::Git::Fetcher->new({q => $_q});
@@ -2513,82 +2111,6 @@ sub libsvn_graft_file_copies {
2111
}
2112
}
2113
2516
-sub set_index {
2517
- my $old = $ENV{GIT_INDEX_FILE};
2518
- $ENV{GIT_INDEX_FILE} = shift;
2519
- return $old;
2520
-}
2521
-
2522
-sub restore_index {
2523
- my ($old) = @_;
2524
- if (defined $old) {
2525
- $ENV{GIT_INDEX_FILE} = $old;
2526
- } else {
2527
- delete $ENV{GIT_INDEX_FILE};
2528
- }
2529
-}
2530
-
2531
-sub libsvn_commit_cb {
2532
- my ($rev, $date, $committer, $c, $log, $r_last, $cmt_last) = @_;
2533
- if ($_optimize_commits && $rev == ($r_last + 1)) {
2534
- my $log = libsvn_log_entry($rev,$committer,$date,$log);
2535
- $log->{tree} = get_tree_from_treeish($c);
2536
- my $cmt = git_commit($log, $cmt_last, $c);
2537
- my @diff = command('diff-tree', $cmt, $c);
2538
- if (@diff) {
2539
- print STDERR "Trees differ: $cmt $c\n",
2540
- join('',@diff),"\n";
2541
- exit 1;
2542
- }
2543
- } else {
2544
- fetch("$rev=$c");
2545
- }
2546
-}
2547
-
2548
-sub libsvn_skip_unknown_revs {
2549
- my $err = shift;
2550
- my $errno = $err->apr_err();
2551
- # Maybe the branch we're tracking didn't
2552
- # exist when the repo started, so it's
2553
- # not an error if it doesn't, just continue
2554
- #
2555
- # Wonderfully consistent library, eh?
2556
- # 160013 - svn:// and file://
2557
- # 175002 - http(s)://
2558
- # 175007 - http(s):// (this repo required authorization, too...)
2559
- # More codes may be discovered later...
2560
- if ($errno == 175007 || $errno == 175002 || $errno == 160013) {
2561
- return;
2562
- }
2563
- croak "Error from SVN, ($errno): ", $err->expanded_message,"\n";
2564
-};
2565
-
2566
-# Tie::File seems to be prone to offset errors if revisions get sparse,
2567
-# it's not that fast, either. Tie::File is also not in Perl 5.6. So
2568
-# one of my favorite modules is out :< Next up would be one of the DBM
2569
-# modules, but I'm not sure which is most portable... So I'll just
2570
-# go with something that's plain-text, but still capable of
2571
-# being randomly accessed. So here's my ultra-simple fixed-width
2572
-# database. All records are 40 characters + "\n", so it's easy to seek
2573
-# to a revision: (41 * rev) is the byte offset.
2574
-# A record of 40 0s denotes an empty revision.
2575
-# And yes, it's still pretty fast (faster than Tie::File).
2576
-sub revdb_set {
2577
- my ($file, $rev, $commit) = @_;
2578
- length $commit == 40 or croak "arg3 must be a full SHA1 hexsum\n";
2579
- open my $fh, '+<', $file or croak $!;
2580
- my $offset = $rev * 41;
2581
- # assume that append is the common case:
2582
- seek $fh, 0, 2 or croak $!;
2583
- my $pos = tell $fh;
2584
- if ($pos < $offset) {
2585
- print $fh (('0' x 40),"\n") x (($offset - $pos) / 41);
2586
- }
2587
- seek $fh, $offset, 0 or croak $!;
2588
- print $fh $commit,"\n";
2589
- close $fh or croak $!;
2590
-}
2591
-
2114
sub revdb_get {
2115
my ($file, $rev) = @_;
2116
my $ret;