monotone

monotone Mtn Source Tree

Root/contrib/mtn-export-revisions.pl

  • Property mtn:execute set to true
1#! /usr/bin/env perl
2use strict;
3use warnings;
4
5# mtn-export-revisions.pl - exports revisions into montone packet format
6#
7# Reads revision IDs from STDIN and exports any fdata, fdelta, rdata,
8# pubkey, and cert packets ready to be fed to "mtn read"; for example on
9# a different machine or database. The revision IDs from STDIN can be in
10# any order as they are automatically toposorted.
11#
12# Alternatively, you can pass selectors on the command line.
13#
14# BUGS:
15# This script was bodged, but it should instead
16# + be written by someone who actually knows Perl
17# + use Tony's excellent Monotone::AutomateStdio Perl library
18#
19use List::MoreUtils 'uniq';
20
21# export_revision($revision_id)
22sub export_revision {
23 my $id = shift;
24 print STDERR "Exporting revision: $id\n";
25 my $revision = `mtn au get_revision $id`;
26 print STDERR $revision;
27
28 print STDERR "Files\n";
29 my @files = $revision =~ /add_file.*?\n content \[([a-f0-9]{40})\]\n/gs;
30 foreach (@files) {
31 print STDERR " file '$_'\n";
32 print `mtn au packet_for_fdata $_`;
33 }
34
35 print STDERR "Patches\n";
36 my %patches = $revision =~
37 /patch.*?\n from \[([a-f0-9]{40})\]\n to \[([a-f0-9]{40})\]/gs;
38 foreach ( keys %patches ) {
39 print STDERR " patch from '$_' to '$patches{$_}'\n";
40 print `mtn au packet_for_fdelta $_ $patches{$_}`;
41 }
42
43 print STDERR "Public keys\n";
44 my $certs_output = `mtn au certs $id`;
45 my @pubkeys = $certs_output =~ / key \[([a-f0-9]{40})\]/;
46 foreach ( uniq(@pubkeys) ) {
47 print STDERR " pubkey '$_'\n";
48 print `mtn au get_public_key $_`;
49 }
50
51 print `mtn au packet_for_rdata $id`;
52 print `mtn au packets_for_certs $id`;
53}
54
55sub get_revisions {
56 my @revisions;
57
58 if ( $#ARGV == -1 ) {
59 while ( my $id = <STDIN> ) {
60 chomp $id;
61 push( @revisions, $id );
62 }
63 }
64 else {
65 foreach my $selector (@ARGV) {
66 my @selected = split( "\n", `mtn au select $selector` );
67 foreach my $id (@selected) {
68 push( @revisions, $id );
69 }
70 }
71 }
72
73 return join( ' ', @revisions );
74}
75
76my $revisions = get_revisions;
77my @toposorted = split( "\n", `mtn au toposort $revisions` );
78
79foreach my $id (@toposorted) {
80 export_revision($id);
81}
82
83exit(0);

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status