build_vcs_cache.pl 943 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#!/usr/bin/perl -w

## Quick utility - initialise a VCS cache, then save it to disk for
## others to share in the goodness

## Copyright (C) 2018  Steve McIntyre <93sam@debian.org>
##
## This program is free software; you can redistribute it and/or modify it
## under the terms of version 2 of the GNU General Public License as published
## by the Free Software Foundation.

use strict;

# These modules reside under webwml/Perl
use lib ($0 =~ m|(.*)/|, $1 or ".") ."/Perl";
use Local::VCS;
17
use Fcntl qw/:flock/;
18 19

my $VCS = Local::VCS->new();
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
my $topdir = $VCS->get_topdir();
chdir ($topdir);

my $cache_lock = ".git-revs-cache.lock";
open (my $lock, "+> $cache_lock") or die "Can't create lock file $cache_lock: $!\n";

flock ($lock, LOCK_EX);
if (!$VCS->db_cache_valid()) {
    print "Initialising VCS cache for performance\n";

    $VCS->cache_repo();
    $VCS->save_cache_to_database();
    print " ... done\n";
}
flock ($lock, LOCK_UN);
35