Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
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

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (11)
    As of 2014-07-30 20:40 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (240 votes), past polls