So I had to roll my own... Comments welcome!
#!/usr/bin/perl
# hgl
use warnings;
use strict;
use File::Slurp;
use File::Spec;
use JSON::XS;
use Data::Dumper;
our $VERSION = '0.01';
my $mode;
if($ARGV[0] =~ /^tip$|^diff$/){
$mode= shift @ARGV;
}else{
$mode='commit';
}
die "hg-lite (hgl) simple text-file version control.\n\nCommands:\n ti
+p\tShow tip revision information.\n\nUsage: hgl [tip] <filenames>\n"
+unless @ARGV;
for my $path (@ARGV) {
my $raw = read_file( $path );
if($mode eq 'tip'){
if($raw =~ /__HGLITE__/){
my ($file,$json) = split(/\n\n__HGLITE__\n/, $raw);
my $data = JSON::XS->new->decode($json);
my $tip = $#$data;
print "\nRev:\t$tip (tip)\nFile:\t$path\t[Modified: ".loca
+ltime(${ $$data[-1]->{stat} }[9] )."]\n";
}else{
print "File is not versioned by hg-lite. Skipping.\n"; nex
+t;
}
}elsif($mode eq 'diff'){
if($raw =~ /__HGLITE__/){
my ($file,$json) = split(/\n\n__HGLITE__\n/, $raw);
my $data = JSON::XS->new->decode($json);
my $tip = $#$data;
write_file("hglite.rev$tip.tmp", $$data[-1]->{raw});
write_file('hglite.curr.tmp', $file);
my $diff = `diff -u hglite.rev$tip.tmp hglite.curr.tmp`;
unlink("hglite.rev$tip.tmp");
unlink('hglite.curr.tmp');
if($diff eq ''){
print "No changes in $path. Skipping.\n"; next;
}else{
print "$diff\n";
}
}else{
print "File is not versioned by hg-lite. Skipping.\n"; nex
+t;
}
}else{
if($raw =~ /__HGLITE__/){ ## implicit commit
my ($file,$json) = split(/\n\n__HGLITE__\n/, $raw);
my $data = JSON::XS->new->decode($json);
my $tip = $#$data;
## diff curr against prev version
write_file("hglite.rev$tip.tmp", $$data[-1]->{raw});
write_file('hglite.curr.tmp', $file);
my $diff = `diff hglite.rev$tip.tmp hglite.curr.tmp`;
if($diff eq ''){ print "No changes in $path. Skipping.\n";
+ next; }
unlink("hglite.rev$tip.tmp");
unlink('hglite.curr.tmp');
## write our custom weave
my @stat = stat($path);
$stat[7] = length($file);
delete($$data[-1]->{raw});
my @path = File::Spec->splitpath( $path );
push(@$data,{ filename => $path[-1], stat => \@stat, diff
+=> $diff, raw => $file });
$json = JSON::XS->new->pretty->encode($data);
write_file($path, $file."\n\n__HGLITE__\n".$json);
}else{ ## implicit init
print "Versioning init.\n";
## diff against null
write_file('hglite.null.tmp', '');
write_file('hglite.rev0.tmp', $raw);
my $diff = `diff hglite.null.tmp hglite.rev0.tmp`;
unlink('hglite.null.tmp');
unlink('hglite.rev0.tmp');
## write our custom weave
my $data = [];
my @stat = stat($path);
my @path = File::Spec->splitpath( $path );
push(@$data,{ filename => $path[-1], stat => \@stat, diff
+=> $diff, raw => $raw });
my $json = JSON::XS->new->pretty->encode($data);
write_file($path, $raw."\n\n__HGLITE__\n".$json);
}
}
}
P.S. I use hg regularly. And like it. (No offense, git.) That's why it's called lazy-hg.
2011-10-16T22:00:00: @GrandFather: Changed it. Thanks!
2011-10-17T18:00:00: code once again updated
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Outside of code tags, you may need to use entities for some characters:
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|