Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: OT: Does anyone know of a version control system that doesn't use separate files or a repo?

by isync (Hermit)
on Oct 16, 2011 at 22:12 UTC ( #931812=note: print w/ replies, xml ) Need Help??


in reply to OT: Does anyone know of a version control system that doesn't use separate files or a repo?

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


Comment on Re: OT: Does anyone know of a version control system that doesn't use separate files or a repo?
Download Code
Re^2: OT: Does anyone know of a version control system that doesn't use separate files or a repo?
by GrandFather (Cardinal) on Oct 16, 2011 at 23:02 UTC

    I see that you have a loop to allow multiple files to be processed, but in the implicit commit code if there is no change in a file the script exits without processing any remaining files (if ($diff eq '') {print "No changes. Exiting.\n"; exit;}). Is that intended behaviour? Printing the name of the unchanged file then skipping to the next file is probably more appropriate.

    True laziness is hard work

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://931812]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2014-08-01 08:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (257 votes), past polls