#!/usr/bin/perl -w
use strict;
our $VERSION = $SVK::VERSION;
require SVN::Core;
require SVN::Repos;
require SVN::Fs;
use SVK::XD;
use SVK::I18N;
use SVK::Util qw(get_anchor);
use Getopt::Long qw(:config no_ignore_case bundling);
use Cwd;
use File::Spec;
use Data::Hierarchy;
use SVK::Command;

=head1 NAME

svk - A Distributed Version Control System

=head1 SYNOPSIS

B<svk> I<commands> S<[I<options>]> [I<args>]

=head1 DESCRIPTION

B<svk> is a decentralized version control system written in Perl.
It uses the subversion filesystem but provides additional features:

=over 4

=item * Offline operations like C<checkin>, C<log>, C<merge>.

=item * Distributed branches.

=item * Lightweight checkout copy management (no F<.svn> directories).

=item * Advanced merge algorithms, like I<star-merge> and I<cherry picking>.

=back

For more information about the Subversion project, visit
L<http://svk.elixus.org/>.

Run C<svk help> to access the built-in tool documentation.

By default svk stores its state in the F<.svk> directory in your home
directory. You can change this default by setting the SVKROOT environment
variable to your preferred svk depot path.

=cut

my $cmd = shift;
{
    my $show_version;
    local *ARGV = [$cmd];
    die unless GetOptions ('version' => \$show_version);

    if ($show_version) {
	print loc("This is svk, version %1.\n", $VERSION);
	exit 0;
    }
}

unless ($cmd) {
    print loc("Type 'svk help' for usage.\n");
    exit 0;
}

if ($cmd eq 'help') {
    SVK::Command->invoke (undef, $cmd, undef, @ARGV);
    exit 0;
}

my $svkpath = $ENV{SVKROOT} || "$ENV{HOME}/.svk";
{
    my $xd = SVK::XD->new ( giantlock => "$svkpath/lock",
			    statefile => "$svkpath/config",
			    svkpath => $svkpath,
			  );
    $xd->load();
    $SIG{INT} = sub {
	die loc("Interrupted.\n");
    };
    my $msg = SVK::Command->invoke ($xd, $cmd, undef, @ARGV);
    print $msg if $msg;
    $xd->store ();
}

1;

=head1 AUTHORS

Chia-liang Kao E<lt>clkao@clkao.orgE<gt>

=head1 COPYRIGHT

Copyright 2003-2004 by Chia-liang Kao E<lt>clkao@clkao.orgE<gt>.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

See L<http://www.perl.com/perl/misc/Artistic.html>

=cut
