[Bps-public-commit] Config-GitLike branch, master, updated. 1.00-40-g1d92437

Alex Vandiver alexmv at bestpractical.com
Sat Apr 3 00:58:24 EDT 2010


The branch, master has been updated
       via  1d924370ca6fd0e7345d033cff07f8581adaffc5 (commit)
       via  b05fd210133645818fc1d8d2347d716dfe65150c (commit)
       via  4549275332660e7d4df921732981202b33351e60 (commit)
       via  722f01c7f6c92425d33b8efc50facf1800272a95 (commit)
       via  5696f0e007bbd739a40ae9adc4ce08cfa1c97dd2 (commit)
      from  2d0df23d90b41c9ce6eca4c14a93a26776f11150 (commit)

Summary of changes:
 lib/Config/GitLike.pm          |   26 +++++++++++++----
 lib/Config/GitLike/Cascaded.pm |   41 +++++---------------------
 lib/Config/GitLike/Git.pm      |   61 +++++++++++++++++++++++++++------------
 3 files changed, 70 insertions(+), 58 deletions(-)

- Log -----------------------------------------------------------------
commit 5696f0e007bbd739a40ae9adc4ce08cfa1c97dd2
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Sat Apr 3 00:50:30 2010 -0400

    Note that config_filenames is in the order they were loaded

diff --git a/lib/Config/GitLike.pm b/lib/Config/GitLike.pm
index 850ac0a..e8f55ae 100644
--- a/lib/Config/GitLike.pm
+++ b/lib/Config/GitLike.pm
@@ -1299,7 +1299,7 @@ scalar context.
 =head2 config_filenames
 
 An array reference containing the absolute filenames of all config files
-that are currently loaded.
+that are currently loaded, in the order they were loaded.
 
 =head2 get
 

commit 722f01c7f6c92425d33b8efc50facf1800272a95
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Sat Apr 3 00:51:36 2010 -0400

    Bump copyright to 2010

diff --git a/lib/Config/GitLike.pm b/lib/Config/GitLike.pm
index e8f55ae..b765c4a 100644
--- a/lib/Config/GitLike.pm
+++ b/lib/Config/GitLike.pm
@@ -1683,7 +1683,7 @@ under the same terms as Perl itself.
 
 =head1 COPYRIGHT
 
-Copyright 2009 Best Practical Solutions, LLC
+Copyright 2010 Best Practical Solutions, LLC
 
 =head1 AUTHORS
 
diff --git a/lib/Config/GitLike/Cascaded.pm b/lib/Config/GitLike/Cascaded.pm
index 007ed80..7ad7c86 100644
--- a/lib/Config/GitLike/Cascaded.pm
+++ b/lib/Config/GitLike/Cascaded.pm
@@ -66,7 +66,7 @@ as Perl 5.8.8.
 
 =head1 COPYRIGHT
 
-Copyright 2009 Best Practical Solutions, LLC
+Copyright 2010 Best Practical Solutions, LLC
 
 =head1 AUTHORS
 
diff --git a/lib/Config/GitLike/Git.pm b/lib/Config/GitLike/Git.pm
index 853224f..d17b31e 100644
--- a/lib/Config/GitLike/Git.pm
+++ b/lib/Config/GitLike/Git.pm
@@ -81,7 +81,7 @@ as Perl 5.8.8.
 
 =head1 COPYRIGHT
 
-Copyright 2009 Best Practical Solutions, LLC
+Copyright 2010 Best Practical Solutions, LLC
 
 =head1 AUTHORS
 

commit 4549275332660e7d4df921732981202b33351e60
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Sat Apr 3 00:56:05 2010 -0400

    Merge Config::GitLike::Cascaded into being just a config option
    
    Flatten the inheritance tree, and remove code duplication, by simply
    moving the cascading functionality into Config::GitLike's load_dirs
    method.

diff --git a/lib/Config/GitLike.pm b/lib/Config/GitLike.pm
index b765c4a..e0af52f 100644
--- a/lib/Config/GitLike.pm
+++ b/lib/Config/GitLike.pm
@@ -52,6 +52,12 @@ has 'compatible' => (
     default => 0,
 );
 
+has 'cascade' => (
+    is => 'rw',
+    isa => 'Bool',
+    default => 0,
+);
+
 sub set_multiple {
     my $self = shift;
     my ($name, $mult) = (@_, 1);
@@ -87,16 +93,18 @@ sub load_dirs {
     my $path = shift;
     my($vol, $dirs, undef) = File::Spec->splitpath( $path, 1 );
     my @dirs = File::Spec->splitdir( $dirs );
+    my @found;
     while (@dirs) {
         my $path = File::Spec->catpath(
             $vol, File::Spec->catdir(@dirs), $self->dir_file
         );
         if (-f $path) {
-            $self->load_file( $path );
-            last;
+            push @found, $path;
+            last unless $self->cascade;
         }
         pop @dirs;
     }
+    $self->load_file( $_ ) for reverse @found;
 }
 
 sub global_file {
@@ -1439,6 +1447,12 @@ Parameters:
 Just a convenience wrapper around L<"rename_section"> for readability's sake.
 Removes the given section (which you can do by renaming to nothing as well).
 
+=head2 cascade( $bool )
+
+Gets or sets if only the B<deepest> configuration file in a directory
+tree is loaded, or if all of them are loaded, shallowest to deepest.
+Alternately, C<cascade =E<gt> 1> can be passed to C<new>.
+
 =head1 METHODS YOU MAY WISH TO OVERRIDE
 
 If your application's configuration layout is different from the default, e.g.
@@ -1673,8 +1687,8 @@ configuration files or code snippets.
 =head1 SEE ALSO
 
 L<http://www.kernel.org/pub/software/scm/git/docs/git-config.html#_configuration_file>,
-L<Config::GitLike::Cascaded|Config::GitLike::Cascaded>, L<http://syncwith.us/>
-(C<Config::GitLike> is used in Prophet/SD and provides a working example)
+L<Config::GitLike::Git>, L<http://syncwith.us/> (C<Config::GitLike> is
+used in Prophet/SD and provides a working example)
 
 =head1 LICENSE
 
diff --git a/lib/Config/GitLike/Cascaded.pm b/lib/Config/GitLike/Cascaded.pm
index 7ad7c86..c2da4b1 100644
--- a/lib/Config/GitLike/Cascaded.pm
+++ b/lib/Config/GitLike/Cascaded.pm
@@ -5,16 +5,9 @@ use File::Spec;
 
 extends 'Config::GitLike';
 
-sub load_dirs {
-    my $self = shift;
-    my $path = shift;
-    my($vol, $dirs, undef) = File::Spec->splitpath( $path, 1 );
-    my @dirs = File::Spec->splitdir( $dirs );
-    for my $i ( 1 .. $#dirs ) {
-        my $path = File::Spec->catpath( $vol, File::Spec->catdir(@dirs[0..$i]), $self->dir_file );
-        $self->load_file( $path ) if -e $path;
-    }
-}
+has 'cascade' => (
+    default => 1,
+);
 
 __PACKAGE__->meta->make_immutable;
 no Any::Moose;
@@ -29,31 +22,13 @@ Config::GitLike::Cascaded - git-like config file parsing with cascaded inheritan
 
 =head1 SYNOPSIS
 
-B<Stop!> Do not pass go! Go directly to L<Config::GitLike|Config::GitLike> and read that
-instead. This is a minor variation on that which changes how the configuration
-loading works. Everything else is exactly the same. Just swap in
-C<Config::GitLike::Cascaded> where it reads C<Config::GitLike>.
+This module exists purely for backwards compatability; its use is
+deprecated, and will be removed in a future release.
 
 =head1 DESCRIPTION
 
-The only difference between this module and C<Config::GitLike> as that
-when it's loading the configuration file in the current directory, it
-keeps walking the directory tree even if it finds a config file,
-whereas C<Config::GitLike> will stop after finding the first.
-
-This allows us to have interesting cascading configuration inheritance.
-
-=head1 METHODS
-
-This module overrides this method from C<Config::GitLike>:
-
-=head2 load_dirs
-
-Load the configuration files in the directory tree, starting with the root
-directory and walking up to the current working directory. (No error is thrown
-if no config files are found.)
-
-Returns nothing of note.
+This module simply defaults L<Config::GitLike/cascaded> to a true
+value.
 
 =head1 SEE ALSO
 

commit b05fd210133645818fc1d8d2347d716dfe65150c
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri Dec 4 20:04:59 2009 -0500

    Detect correct git directory using the same algorithm as git

diff --git a/lib/Config/GitLike/Git.pm b/lib/Config/GitLike/Git.pm
index d17b31e..b853917 100644
--- a/lib/Config/GitLike/Git.pm
+++ b/lib/Config/GitLike/Git.pm
@@ -1,30 +1,50 @@
 package Config::GitLike::Git;
 use Any::Moose;
+use strict;
+use warnings;
 
 extends 'Config::GitLike';
 
 has 'confname' => (
-    default => 'git',
+    default => 'gitconfig',
 );
 
 has 'compatible' => (
     default => 1,
 );
 
-sub dir_file {
+sub is_git_dir {
     my $self = shift;
-    return ".git/config";
+    my $path = File::Spec->rel2abs( shift );
+    $path =~ s{/+$}{};
+
+    ($path) = grep {-d} map {"$path$_"} (".git/.git", "/.git", ".git", "");
+    return unless $path;
+
+    # Has to have objects/ and refs/ directories
+    return unless -d "$path/objects" and -d "$path/refs";
+
+    # Has to have a HEAD file
+    return unless -f "$path/HEAD";
+
+    if (-l "$path/HEAD" ) {
+        # Symbolic link into refs/
+        return unless readlink("$path/HEAD") =~ m{^refs/};
+    } else {
+        open(HEAD, "$path/HEAD") or return;
+        my ($line) = <HEAD>;
+        close HEAD;
+        # Is either 'ref: refs/whatever' or a sha1
+        return unless $line =~ m{^(ref:\s*refs/|[0-9a-fA-F]{20})};
+    }
+    return $path;
 }
 
-sub user_file {
+sub load_dirs {
     my $self = shift;
-    return
-        File::Spec->catfile( $ENV{'HOME'}, ".gitconfig" );
-}
-
-sub global_file {
-    my $self = shift;
-    return "/etc/gitconfig";
+    my $path = shift;
+    my $dir = $self->is_git_dir($path) or return;
+    $self->load_file( File::Spec->catfile( $dir, "config" ) );
 }
 
 __PACKAGE__->meta->make_immutable;

commit 1d924370ca6fd0e7345d033cff07f8581adaffc5
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri Apr 2 21:39:40 2010 -0400

    Update documentation to reflect new gitdir detection

diff --git a/lib/Config/GitLike/Git.pm b/lib/Config/GitLike/Git.pm
index b853917..f2dd546 100644
--- a/lib/Config/GitLike/Git.pm
+++ b/lib/Config/GitLike/Git.pm
@@ -62,17 +62,20 @@ Config::GitLike::Git - load Git configuration files
 
     use Config::GitLike::Git;
     my $config = Config::GitLike::Git->new;
+    $config->load("/path/to/repo");
 
 =head1 DESCRIPTION
 
-This is a modification of L<Config::GitLike|Config::GitLike> to look at the
-same locations that Git writes to. Unlike with
-L<Config::GitLike|Config::GitLike>, you do not need to pass a confname to its
-constructor. This module also enables the L<Config::GitLike|Config::GitLike>
-option to maintain git compatibility when reading and writing variables.
+This is a modification of L<Config::GitLike> to look at the same
+locations that Git writes to. Unlike with L<Config::GitLike>, you do
+not need to pass a confname to its constructor. This module also
+enables the L<Config::GitLike> option to maintain git compatibility
+when reading and writing variables.
 
-Notethat it only checks the current directory for being the root of a
-git repository; it also does not work on bare repositories.
+L<Config::GitLike/load> should be passed path to the top level of a
+git repository -- this defaults to the current directory.  It will
+append C<.git> as necessary.  It supports both bare and non-bare
+repositories.
 
 =head1 METHODS
 

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list