Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2024-04-23 18:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found