[svk-commit] r3076 - in branches/git-storage: . lib/SVK lib/SVK/Root
nobody at bestpractical.com
nobody at bestpractical.com
Mon Aug 25 05:31:42 EDT 2008
Author: clkao
Date: Mon Aug 25 05:31:41 2008
New Revision: 3076
Added:
branches/git-storage/lib/SVK/Path/Git.pm
branches/git-storage/lib/SVK/Root/Git.pm
Modified:
branches/git-storage/ (props changed)
branches/git-storage/MANIFEST
branches/git-storage/lib/SVK/Accessor.pm
branches/git-storage/lib/SVK/Command.pm
Log:
Publish the experimental git backend support we did back in
april.
r25011 at mtl (orig r8889): jesse | 2008-02-28 00:37:12 +0800
svk-git
r25012 at mtl (orig r8890): jesse | 2008-02-28 00:42:45 +0800
favor for cl
r27730 at mtl (orig r8903): clkao | 2008-02-28 14:29:03 +0800
r4511 at mtl: clkao | 2008-02-17 21:55:22 +0800
- Create branch git
r4512 at mtl: clkao | 2008-02-18 00:03:32 +0800
first cut of experimental git backend support.
svk cat /git/refs/remotes/origin/HEAD/README
now works.
r4513 at mtl: clkao | 2008-02-18 02:26:20 +0800
ls -R now works.
r4514 at mtl: clkao | 2008-02-18 02:43:51 +0800
fix ls -R for deeper paths.
r28417 at mtl (orig r9156): clsung | 2008-03-31 10:53:25 +0800
- typo
r28856 at mtl (orig r9209): clsung | 2008-04-08 14:29:37 +0800
- dummy/pass functions
Modified: branches/git-storage/MANIFEST
==============================================================================
Modified: branches/git-storage/lib/SVK/Accessor.pm
==============================================================================
--- branches/git-storage/lib/SVK/Accessor.pm (original)
+++ branches/git-storage/lib/SVK/Accessor.pm Mon Aug 25 05:31:41 2008
@@ -87,6 +87,7 @@
sub clonable_accessors {
my $self = shift;
+ Carp::cluck unless defined $self->_clonable_accessors;
return (@{$self->_clonable_accessors});
}
Modified: branches/git-storage/lib/SVK/Command.pm
==============================================================================
--- branches/git-storage/lib/SVK/Command.pm (original)
+++ branches/git-storage/lib/SVK/Command.pm Mon Aug 25 05:31:41 2008
@@ -588,6 +588,25 @@
if is_uri($arg);
my $rev = $arg =~ s/\@(\d+)$// ? $1 : undef;
+
+
+ # GIT: new method here for constructing path_object sanely
+
+ if (my ($depotname, $path) = $arg =~ m{^/(.*?)(/.*)}) {
+ if ( my $repospath = $self->{xd}->{depotmap}{$depotname} ) {
+ if ($repospath =~ m{\.git/?$}) {
+ require SVK::Path::Git;
+ my $p = SVK::Path::Git->real_new
+ ({ depot => SVK::Depot->new({ repospath => $repospath, depotname => $depotname }),
+ commit => 'HEAD',
+ path => $path,
+ } );
+ return $p;
+ }
+ }
+
+ }
+
my ($repospath, $path, $copath, $cinfo, $repos) =
$self->{xd}->find_repos_from_co_maybe ($arg, 1);
from_native ($path, 'path', $self->{encoding});
Added: branches/git-storage/lib/SVK/Path/Git.pm
==============================================================================
--- (empty file)
+++ branches/git-storage/lib/SVK/Path/Git.pm Mon Aug 25 05:31:41 2008
@@ -0,0 +1,62 @@
+package SVK::Path::Git;
+use strict;
+use base 'SVK::Accessor';
+
+use base qw{ Class::Accessor::Fast };
+use Git;
+
+# a depot path object with git backend;
+__PACKAGE__->mk_shared_accessors
+ (qw(depot));
+
+*path_anchor = __PACKAGE__->make_accessor('path');
+__PACKAGE__->mk_clonable_accessors();
+push @{__PACKAGE__->_clonable_accessors}, 'path_anchor';
+
+*path = *path_anchor;
+
+#__PACKAGE__->mk_accessors(qw(path));
+
+sub root {
+ my $self = shift;
+ require SVK::Root::Git;
+ SVK::Root::Git->new({ depot => $self->depot, commit => 'HEAD' });
+}
+
+
+sub as_depotpath {
+ return $_[0];
+}
+
+#sub path_anchor { $_[0]->path }
+
+sub descend {
+ my ($self, $entry) = @_;
+ $self->path( $self->path . ( $self->path eq '/' ? $entry : "/$entry" ) );
+ return $self;
+}
+
+sub path_target {
+ return '';
+}
+
+sub seek_to {
+ return $_[0];
+}
+
+sub revision {
+ return 0;
+}
+
+sub repos {
+ return $_[0];
+}
+
+sub fs {
+ return $_[0];
+}
+
+sub youngest_rev {
+ return 1;
+}
+1;
Added: branches/git-storage/lib/SVK/Root/Git.pm
==============================================================================
--- (empty file)
+++ branches/git-storage/lib/SVK/Root/Git.pm Mon Aug 25 05:31:41 2008
@@ -0,0 +1,65 @@
+package SVK::Root::Git;
+use strict;
+use base 'Class::Accessor::Fast';
+__PACKAGE__->mk_accessors(qw(depot commit));
+
+sub _get_path {
+ my ($self, $full_path) = @_;
+ my $refs = [ map { m/.*? (.*)/ } `git --git-dir @{[ $self->depot->repospath ]} show-ref` =~ m/^.*$/mg ];
+ my $re = join('|', @$refs);
+ if (my ($tree, $path) = $full_path =~ m{^/($re)(?:/(.*))?$}) {
+ $path = '' unless defined $path;
+ my ($ref) = `git --git-dir @{[ $self->depot->repospath ]} show-ref $tree` =~ m/^(.*?) /;
+ return ($ref, $path);
+ }
+}
+
+sub file_contents {
+ my ($self, $full_path, $pool) = @_;
+ my ($tree, $path) = $self->_get_path( $full_path );
+
+ # find the node ref:
+ my ($blob) = `git --git-dir @{[ $self->depot->repospath ]} ls-tree $tree $path` =~ m/^.*? blob (.*?)\s/;
+ my $content = `git --git-dir @{[ $self->depot->repospath ]} cat-file blob $blob`;
+ open my $fh, '<', \$content;
+ return $fh;
+# my ($copath, $root) = $self->_get_copath($path, $pool);
+# return SVK::XD::get_fh($root, '<', $path, $copath);
+}
+
+sub check_path {
+
+ my ($self, $full_path, $pool) = @_;
+ my ($tree, $path) = $self->_get_path( $full_path );
+
+ return $SVN::Node::dir unless length $path;
+ # find the node ref:
+ my ($type, $key) = `git --git-dir @{[ $self->depot->repospath ]} ls-tree $tree $path` =~ m/^.*? (.*?) (.*?)\s/;
+
+ return $type ? $type eq 'blob' ? $SVN::Node::file
+ : $SVN::Node::dir
+ : $SVN::Node::unknown;
+}
+
+sub dir_entries {
+ my ($self, $full_path, $pool) = @_;
+ my ($tree, $path) = $self->_get_path( $full_path );
+ # find the node ref:
+ Carp::confess unless defined $path;
+ $path .= '/' if length $path;
+ my $entries = { map { my $x = {}; @$x{qw(mode type key name)} = split /\s/, $_; $x->{name} =~ s{^$path}{};
+ $x->{name} => $x } `git --git-dir @{[ $self->depot->repospath ]} ls-tree $tree $path` =~ m/^.*$/mg };
+
+ # XXX: just a holder
+ require SVK::Root::Checkout;
+ return { map { $_ => SVK::Root::Checkout::Entry->new
+ ({ kind => $entries->{$_}{type} eq 'blob' ? $SVN::Node::file : $SVN::Node::dir })
+ } keys %$entries };
+
+}
+
+sub node_proplist {
+ return {};
+}
+
+1;
More information about the svk-commit
mailing list