Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Version control system for the laziest of the lazy

by toolic (Chancellor)
on Apr 05, 2011 at 15:45 UTC ( #897538=CUFP: print w/ replies, xml ) Need Help??

Alternate node title: "You can't really call this version control"

  • Can't afford Perforce?
  • Too busy to set up a CVS pserver?
  • Too lazy to create an RCS directory?
  • No need for branches or tags?
  • No desire to share your files?
  • Don't really care about commenting on your revision?

If you answered "yes" to the above, then have I got the version control system for you!

It's easy to install and easy to use because it has NO features!

Clearly, this is not meant to be a replacement for your favorite fancy software. I use it when I'm in rapid hack experiment mode and I don't want to clutter up my real version control system with versions that should be thrown away.

It only uses Core modules and works on Unix and Windows. The POD says it all:

=head1 NAME B<bak> - Make a backup copy of a file =head1 SYNOPSIS bak file ... =head1 DESCRIPTION A uniquely-named backup copy of a file is created. The file is written to a subdirectory named C<backup>, which will be created if it does not yet exist. The name of the backup copy is the original filename with a date and timestamp appended to it. Multiple files may also be specified. Output: A file to subdirectory named C<backup>. Example1: bak file.txt Example2: bak *.doc =cut use warnings FATAL => 'all'; use strict; use File::Copy; use POSIX qw(strftime); die "Error: No files specified\n" unless @ARGV; mkdir 'backup'; my $date = strftime('%y%m%d_%H%M%S', localtime); for my $file (@ARGV) { copy($file, "backup/${file}_$date") or die "Copy failed: $!"; }

Update: Apr 28, 2011: If you want to preserve file permissions and you have File::Copy version 2.15 or later, change copy to cp.

Comment on Version control system for the laziest of the lazy
Select or Download Code
Re: Version control system for the laziest of the lazy
by Anonymous Monk on Apr 06, 2011 at 07:08 UTC
    I prefer a iso 8601
    $ perl -MDateTime -le"print DateTime->now->strftime( q!%F-%H-%M-%S%z! +);" 2011-04-06-07-04-11+0000 $ perl -MDateTime -le"print DateTime->now( qw[ time_zone local ] )->st +rftime( q!%F-%H-%M-%S%z! );" 2011-04-06-00-04-29-0700
    or double digit suffix
    foo.pl-00 foo.pl-01
    With a iso 8601 timestamp at the top of the file
      Use whatever timestamp or string that suits you. That ISO format string is compatible with POSIX::strftime (so there's no need for the non-Core DateTime).
      With a iso 8601 timestamp at the top of the file
      If you are implying that the contents of each copied file should be modified, that is far beyond the scope of this simple tool.
Re: Version control system for the laziest of the lazy
by goibhniu (Hermit) on Apr 07, 2011 at 15:42 UTC

    ++

    First thing I tried was:

    C:\chas_sandbox\PM>bak.pl *.pl Copy failed: No such file or directory at C:\chas_sandbox\PM\bak.pl li +ne 34.

    How about glob?

    for my $file (@ARGV) { for my $globfile (glob($file)) { copy($globfile, "backup/${globfile}_$date") or die "Copy faile +d: $!"; } }

    now I get:

    C:\chas_sandbox\PM>bak.pl *.pl C:\chas_sandbox\PM>


    #my sig used to say 'I humbly seek wisdom. '. Now it says:
    use strict;
    use warnings;
    I humbly seek wisdom.
      Excellent. This seems to make up for one of the many shortcomings of the MS-DOS shell.

      Let me recommend bsd_glob from File::Glob. It understands and properly treats whitespace in path and filenames, something that plain Perl glob does not (unless you start quoting things).

Re: Version control system for the laziest of the lazy
by Voronich (Hermit) on Apr 07, 2011 at 16:09 UTC
    Exactly what I need MOST of the time.

    Sure, definitive source versions end up in clearcase. But most of the time I'm fiddling around in ~/scrapbin and don't have anything definitive enough to actually check in, but still want to fuddle around and keep iterations.

    What I may do is rip this to teeny pieces and add an "only create a backup if it would be different" feature.

    Then I'd just include it in my "every 5 second" build/test loop

    Me
      only create a backup if it would be different
      I've been wanting a simple "backup every file in my directory if it has changed since the last backup" feature myself, but just haven't gotten to it.
        I was thinking about this over lunch and I realized that to TRULY capture the spirit of this script the right thing would be to de-dupe the backup directory afterwards, perhaps create a second shell script that grabbed MD5s of files in a directory with matching base filenames and removed later ones that matched.
        Me
Re: Version control system for the laziest of the lazy
by educated_foo (Vicar) on Apr 07, 2011 at 17:35 UTC
    Or just
    #!perl -p BEGIN {($^I='.'.localtime)=~s/[^\w\d.]+/_/g}
    But seriously, if you stick to timestamped versions, RCS/CVS/git are all pretty easy to use. They only get complicated when you try to mess with branches, remote repositories, etc.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://897538]
Approved by ww
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (12)
As of 2014-09-22 18:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (198 votes), past polls