Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

RFC: proposed new module VCS::Lite

by rinceWind (Monsignor)
on Dec 18, 2002 at 15:41 UTC ( [id://220863]=perlmeditation: print w/replies, xml ) Need Help??

I am contemplating writing a module, and I would like to invite comments. At the moment I just have some pod, but I am interested in some feedback before I settle on design decisions and start coding.

I plan on releasing to CPAN when I have something usable.

package VCS::Lite; use strict; use warnings; our $VERSION = '0.01'; =head1 NAME VCS::Lite - Minimal version control system =head1 SYNOPSIS use VCS::Lite; # diff my $lit = VCS::Lite->new($fh1); my $lit2 = VCS::Lite->new($fh2); my $difftxt = $lit->diff($lit2); print OUTFILE $difftxt; # patch my $lit3 = $lit->patch($fh3); $lit3->save('~me/patched_file'); # merge my $lit4 = $lit->merge($lit2,$lit3); $lit4->save('~me/merged_file'); =head1 DESCRIPTION This module provides the functions normally associated with a version control system, but without needing or implementing a version control system. Applications include wikis, document management systems and configuration management. It makes use of the module Algorithm::Diff. It provides the facility for basic diffing, patching and merging. =head2 new The underlying object of VCS::Lite is an array. The members of the array can be anything that a scalar can represent (including reference +s to structures and objects). The default is for the object to hold an array of scalars as strings corresponding to lines of text. If you want other underlying types, it is normal to subclass VCS::Lite for reasons which will become apparent, There are several forms of the parameter list that B<new> can take. my $lite = VCS::Lite->new( \@foo); #Array ref my $lite = VCS::Lite->new( '/users/me/prog.pl'); #File name my $lite = VCS::Lite->new( $fh1); #File handle my $lite = VCS::Lite->new( \&next, $p1, $p2...); #Callback In the Perl spirit of DWIM, new assumes that given an arrayref, you have already done all the work of making your list of whatevers. Given a string (filename) or a file handle, the file is slurped, reading each line of text into a member of the array. Given a callback, the routine is called successively with arguments $p1, $p2, etc. and is expected to return a scalar which is added (pushed on) to the array. =head2 save $lit3->save('~me/patched_file'); Save is the reverse operation to new, given a file name or file handle. The file is written out calling the object's serialize method for successive members. If you are subclassing, you can supply your own serializer. =head2 diff my $difftxt = $lit->diff($lit2); Perform the difference between two VCS::Lite objects. Output is in ordinary diff format, e.g.: 827c828 < my ($id, $name) = @_; --- > my ($id, $name, $prefix) = @_; =head2 patch my $lit3 = $lit->patch($fh3); Applies a patch to a VCS::Lite object. Accepts a file handle or file name string. Reads the file in diff format, and applies it. =head2 merge my $lit4 = $lit->merge($lit2,$lit3,\&confl); Performs the "parallelogram of merging". This takes three VCS::Lite objects - the base object and two change streams. Returns a VCS::Lite object with both sets of changes merged. The third parameter to the method is a sub which is called whenever a merge conflict occurs. This needs to either resolve the conflict or insert the necessary text to highlight the conflict. =head1 AUTHOR I. P. Williams, E<lt>Ivor dot williams (at) tiscali dot co dot United +KingdomE<gt> =head1 SEE ALSO L<Algorithm::Diff>. 1;

Replies are listed 'Best First'.
Re: RFC: proposed new module VCS::Lite
by perrin (Chancellor) on Dec 18, 2002 at 16:38 UTC
    This module provides the functions normally associated with a version control system, but without needing or implementing a version control system.

    It looks to me like this module implements a version control system.

    Using an array as your base object seems really bizarre to me. VC systems normally work on versioning a single "thing." That thing could be represented as an array, but there's no reason for a user to know that.

      It looks to me like this module implements a version control system.
      I suppose you could take that view, much as DBD::SQLLite implements an RDBMS. Anyway, there are many things that a VC system does that I have no intention of implementing for VCS::Lite. These include an audit trail, change history, development streams, access control, check-out locking and unlocking, labels (aggregation of specific revisions of multiple objects). I can see the potential for another module in the VCS:: namespace which does implement a full VCS, or perhaps a software layer sitting above CVS, P4, PVCS, etc.
      Using an array as your base object seems really bizarre to me.
      There is a reason for this. A source file is a list of lines of text. Diff, patch and merge operate at the level of lines. Thinking about this polymorphically, the concept is really an array, and if you take a look at Algorithm::Diff, you will see that this module works on arrays.

      The naive user of the module who is working with text files, does not need to realise that the underlying object is an array. Thanks, Perrin for the feedback. I need to restructure the pod to make this clear - go through a simple worked example with text files; only afterwards deal with other types of array.

      This approach overcomes the difficulty that traditional VC systems have with binary files. If the programmer can supply a representation of a binary file as an array, it should be possible to do merges on binary files, given the rules for combining changes.

        I don't tend to think of files as lists of lines. The line separator is totally arbitrary and I always slurp files into scalars. I think you should work with scalars and just split them into arrays when you need to feed them to Algorithm::Diff.

        I also don't think that working with arrays will make a difference to binary files. Binary diff utilities do exist, and I believe they just treat the file as a stream of bytes and use offsets.

Re: RFC: proposed new module VCS::Lite
by vagnerr (Prior) on Dec 18, 2002 at 17:11 UTC
    I take it you are aware of the VCS package already on CPAN. A nice system that integrates with cvs, rcs and hms. Its only a read-only interface right now and there development is a little slow. However they do have a sourceforge entry and a Mailing List.

    As for your plans to build a self contained VCS system. Will it not suffer from the fact that its storage will be proprietory or are you planning to interface to a more widely used system as a backend?

    _______________________________________________________
    Remember that amateurs built Noah's Ark. Professionals built the Titanic.
      The aim is not to provide a full blown VCS, but a toolkit for doing certain functions: diff, patch, merge, in memory.

      It grew out of a requirement I have for a cross-platform patch and merge utility, coupled with an idea for building an OO wrapper for Algorithm::Diff.

      I was not aware of the VCS project on Sourceforge - I will check this out (pun intended) as I have an interest in VCS systems in general.

Re: RFC: proposed new module VCS::Lite
by John M. Dlugosz (Monsignor) on Dec 18, 2002 at 21:55 UTC
    I'd like to see a abstract front-end that can work with any version control system, including a stub like that.

    Someone pointed you to that existing thing already; I looked at it, and it's read-only and pretty specific for looking at history rather than manipulating the files (check in and out). I'm interested in checking out files when a script modifies one that's under control. I just redid a script from Continuus to SourceSafe, and have also used PVCS here, and ClearCase is in the wind.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://220863]
Approved by Tanalis
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (7)
As of 2024-04-16 06:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found