[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Monotone-commits-diffs] net.venge.monotone: 2df669cf5444b56ddafda3f2258
From: |
code |
Subject: |
[Monotone-commits-diffs] net.venge.monotone: 2df669cf5444b56ddafda3f22581c920607a938c |
Date: |
Wed, 27 Jun 2012 00:09:09 +0200 (CEST) |
revision: 2df669cf5444b56ddafda3f22581c920607a938c
comment:
Usage is either one revision ID per line fed into standard input, or
selectors on the command line.
eg.
mtn au select BLAH | mtn-export-revision.pl
or
mtn-export-revision.pl BLAH FOO
or more concretely
mtn-export-revision.pl h:net.venge.monotone
The order you pass the revision IDs/selectors doesn't matter, the
script makes sure everything will be in the correct order ready for
'mtn read'.
date: 2012-06-26T22:07:07
author: Richard Hopkins <address@hidden>
branch: net.venge.monotone
changelog:
Add 'mtn-export-revision.pl' - exports revisions in the correct order in packet
format
I think this worked at least some of the time when I used it last; it
really needs writing by a proper Perl programmer and use the
Monotone::AutomateStdio library. Ideally though this functionality
should be in mtn itself.
manifest:
format_version "1"
new_manifest [9245375a608519df79d4cb9574095d88946be8ac]
old_revision [0b2b933284c39df390c33af1cb322ae545039108]
add_file "contrib/mtn-export-revisions.pl"
content [c5cf12354570aa798414a85883961afd8a8e116e]
set "contrib/mtn-export-revisions.pl"
attr "mtn:execute"
value "true"
============================================================
--- /dev/null
+++ contrib/mtn-export-revisions.pl c5cf12354570aa798414a85883961afd8a8e116e
@@ -0,0 +1,83 @@
+#! /usr/bin/env perl
+use strict;
+use warnings;
+
+# mtn-export-revisions.pl - exports revisions into montone packet format
+#
+# Reads revision IDs from STDIN and exports any fdata, fdelta, rdata,
+# pubkey, and cert packets ready to be fed to "mtn read"; for example on
+# a different machine or database. The revision IDs from STDIN can be in
+# any order as they are automatically toposorted.
+#
+# Alternatively, you can pass selectors on the command line.
+#
+# BUGS:
+# This script was bodged, but it should instead
+# + be written by someone who actually knows Perl
+# + use Tony's excellent Monotone::AutomateStdio Perl library
+#
+use List::MoreUtils 'uniq';
+
+# export_revision($revision_id)
+sub export_revision {
+ my $id = shift;
+ print STDERR "Exporting revision: $id\n";
+ my $revision = `mtn au get_revision $id`;
+ print STDERR $revision;
+
+ print STDERR "Files\n";
+ my @files = $revision =~ /add_file.*?\n content \[([a-f0-9]{40})\]\n/gs;
+ foreach (@files) {
+ print STDERR " file '$_'\n";
+ print `mtn au packet_for_fdata $_`;
+ }
+
+ print STDERR "Patches\n";
+ my %patches = $revision =~
+ /patch.*?\n from \[([a-f0-9]{40})\]\n to \[([a-f0-9]{40})\]/gs;
+ foreach ( keys %patches ) {
+ print STDERR " patch from '$_' to '$patches{$_}'\n";
+ print `mtn au packet_for_fdelta $_ $patches{$_}`;
+ }
+
+ print STDERR "Public keys\n";
+ my $certs_output = `mtn au certs $id`;
+ my @pubkeys = $certs_output =~ / key \[([a-f0-9]{40})\]/;
+ foreach ( uniq(@pubkeys) ) {
+ print STDERR " pubkey '$_'\n";
+ print `mtn au get_public_key $_`;
+ }
+
+ print `mtn au packet_for_rdata $id`;
+ print `mtn au packets_for_certs $id`;
+}
+
+sub get_revisions {
+ my @revisions;
+
+ if ( $#ARGV == -1 ) {
+ while ( my $id = <STDIN> ) {
+ chomp $id;
+ push( @revisions, $id );
+ }
+ }
+ else {
+ foreach my $selector (@ARGV) {
+ my @selected = split( "\n", `mtn au select $selector` );
+ foreach my $id (@selected) {
+ push( @revisions, $id );
+ }
+ }
+ }
+
+ return join( ' ', @revisions );
+}
+
+my $revisions = get_revisions;
+my @toposorted = split( "\n", `mtn au toposort $revisions` );
+
+foreach my $id (@toposorted) {
+ export_revision($id);
+}
+
+exit(0);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Monotone-commits-diffs] net.venge.monotone: 2df669cf5444b56ddafda3f22581c920607a938c,
code <=