git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Matthew Ogilvie <mmogilvi_git@miniinfo.net>
To: git@vger.kernel.org
Cc: Matthew Ogilvie <mmogilvi_git@miniinfo.net>
Subject: [PATCH 17/20] cvsserver: Add version awareness to argsfromdir
Date: Sat, 13 Oct 2012 23:42:30 -0600	[thread overview]
Message-ID: <1350193353-19210-18-git-send-email-mmogilvi_git@miniinfo.net> (raw)
In-Reply-To: <1350193353-19210-1-git-send-email-mmogilvi_git@miniinfo.net>

Signed-off-by: Matthew Ogilvie <mmogilvi_git@miniinfo.net>
---
 git-cvsserver.perl | 228 ++++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 198 insertions(+), 30 deletions(-)

diff --git a/git-cvsserver.perl b/git-cvsserver.perl
index 7bb6f83..5e558d1 100755
--- a/git-cvsserver.perl
+++ b/git-cvsserver.perl
@@ -2226,55 +2226,222 @@ sub argsplit
     }
 }
 
-# This method uses $state->{directory} to populate $state->{args} with a list of filenames
-sub argsfromdir
+# Used by argsfromdir
+sub expandArg
 {
-    my $updater = shift;
+    my ($updater,$outNameMap,$outDirMap,$path,$isDir) = @_;
 
-    $state->{args} = [] if ( scalar(@{$state->{args}}) == 1 and $state->{args}[0] eq "." );
+    my $fullPath = filecleanup($path);
 
-    return if ( scalar ( @{$state->{args}} ) > 1 );
+      # Is it a directory?
+    if( defined($state->{dirMap}{$fullPath}) ||
+        defined($state->{dirMap}{"$fullPath/"}) )
+    {
+          # It is a directory in the user's sandbox.
+        $isDir=1;
 
-    my @gethead = @{$updater->gethead};
+        if(defined($state->{entries}{$fullPath}))
+        {
+            $log->fatal("Inconsistent file/dir type");
+            die "Inconsistent file/dir type";
+        }
+    }
+    elsif(defined($state->{entries}{$fullPath}))
+    {
+          # It is a file in the user's sandbox.
+        $isDir=0;
+    }
+    my($revDirMap,$otherRevDirMap);
+    if(!defined($isDir) || $isDir)
+    {
+          # Resolve version tree for sticky tag:
+          # (for now we only want list of files for the version, not
+          # particular versions of those files: assume it is a directory
+          # for the moment; ignore Entry's stick tag)
+
+          # Order of precedence of sticky tags:
+          #    -A       [head]
+          #    -r /tag/
+          #    [file entry sticky tag, but that is only relevant to files]
+          #    [the tag specified in dir req_Sticky]
+          #    [the tag specified in a parent dir req_Sticky]
+          #    [head]
+          # Also, -r may appear twice (for diff).
+          #
+          # FUTURE: When/if -j (merges) are supported, we also
+          #  need to add relevant files from one or two
+          #  versions specified with -j.
+
+        if(exists($state->{opt}{A}))
+        {
+            $revDirMap=$updater->getRevisionDirMap();
+        }
+        elsif( defined($state->{opt}{r}) and
+               ref $state->{opt}{r} eq "ARRAY" )
+        {
+            $revDirMap=$updater->getRevisionDirMap($state->{opt}{r}[0]);
+            $otherRevDirMap=$updater->getRevisionDirMap($state->{opt}{r}[1]);
+        }
+        elsif(defined($state->{opt}{r}))
+        {
+            $revDirMap=$updater->getRevisionDirMap($state->{opt}{r});
+        }
+        else
+        {
+            my($sticky)=getDirStickyInfo($fullPath);
+            $revDirMap=$updater->getRevisionDirMap($sticky->{tag});
+        }
 
-    # push added files
-    foreach my $file (keys %{$state->{entries}}) {
-	if ( exists $state->{entries}{$file}{revision} &&
-		$state->{entries}{$file}{revision} eq '0' )
-	{
-	    push @gethead, { name => $file, filehash => 'added' };
-	}
+          # Is it a directory?
+        if( defined($revDirMap->{$fullPath}) ||
+            defined($otherRevDirMap->{$fullPath}) )
+        {
+            $isDir=1;
+        }
     }
 
-    if ( scalar(@{$state->{args}}) == 1 )
+      # What to do with it?
+    if(!$isDir)
     {
-        my $arg = $state->{args}[0];
-        $arg .= $state->{prependdir} if ( defined ( $state->{prependdir} ) );
-
-        $log->info("Only one arg specified, checking for directory expansion on '$arg'");
+        $outNameMap->{$fullPath}=1;
+    }
+    else
+    {
+        $outDirMap->{$fullPath}=1;
 
-        foreach my $file ( @gethead )
+        if(defined($revDirMap->{$fullPath}))
         {
-            next if ( $file->{filehash} eq "deleted" and not defined ( $state->{entries}{$file->{name}} ) );
-            next unless ( $file->{name} =~ /^$arg\// or $file->{name} eq $arg  );
-            push @{$state->{args}}, $file->{name};
+            addDirMapFiles($updater,$outNameMap,$outDirMap,
+                           $revDirMap->{$fullPath});
         }
+        if( defined($otherRevDirMap) &&
+            defined($otherRevDirMap->{$fullPath}) )
+        {
+            addDirMapFiles($updater,$outNameMap,$outDirMap,
+                           $otherRevDirMap->{$fullPath});
+        }
+    }
+}
 
-        shift @{$state->{args}} if ( scalar(@{$state->{args}}) > 1 );
-    } else {
-        $log->info("Only one arg specified, populating file list automatically");
+# Used by argsfromdir
+# Add entries from dirMap to outNameMap.  Also recurse into entries
+# that are subdirectories.
+sub addDirMapFiles
+{
+    my($updater,$outNameMap,$outDirMap,$dirMap)=@_;
 
-        $state->{args} = [];
+    my($fullName);
+    foreach $fullName (keys(%$dirMap))
+    {
+        my $cleanName=$fullName;
+        if(defined($state->{prependdir}))
+        {
+            if(!($cleanName=~s/^\Q$state->{prependdir}\E//))
+            {
+                $log->fatal("internal error stripping prependdir");
+                die "internal error stripping prependdir";
+            }
+        }
 
-        foreach my $file ( @gethead )
+        if($dirMap->{$fullName} eq "F")
+        {
+            $outNameMap->{$cleanName}=1;
+        }
+        elsif($dirMap->{$fullName} eq "D")
+        {
+            if(!$state->{opt}{l})
+            {
+                expandArg($updater,$outNameMap,$outDirMap,$cleanName,1);
+            }
+        }
+        else
         {
-            next if ( $file->{filehash} eq "deleted" and not defined ( $state->{entries}{$file->{name}} ) );
-            next unless ( $file->{name} =~ s/^$state->{prependdir}// );
-            push @{$state->{args}}, $file->{name};
+            $log->fatal("internal error in addDirMapFiles");
+            die "internal error in addDirMapFiles";
         }
     }
 }
 
+# This method replaces $state->{args} with a directory-expanded
+# list of all relevant filenames (recursively unless -d), based
+# on $state->{entries}, and the "current" list of files in
+# each directory.  "Current" files as determined by
+# either the requested (-r/-A) or "req_Sticky" version of
+# that directory.
+#    Both the input args and the new output args are relative
+# to the cvs-client's CWD, although some of the internal
+# computations are relative to the top of the project.
+sub argsfromdir
+{
+    my $updater = shift;
+
+    # Notes about requirements for specific callers:
+    #   update # "standard" case (entries; a single -r/-A/default; -l)
+    #          # Special case: -d for create missing directories.
+    #   diff # 0 or 1 -r's: "standard" case.
+    #        # 2 -r's: We could ignore entries (just use the two -r's),
+    #        # but it doesn't really matter.
+    #   annotate # "standard" case
+    #   log # Punting: log -r has a more complex non-"standard"
+    #       # meaning, and we don't currently try to support log'ing
+    #       # branches at all (need a lot of work to
+    #       # support CVS-consistent branch relative version
+    #       # numbering).
+#HERE: But we still want to expand directories.  Maybe we should
+#  essentially force "-A".
+    #   status # "standard", except that -r/-A/default are not possible.
+    #          # Mostly only used to expand entries only)
+    #
+    # Don't use argsfromdir at all:
+    #   add # Explicit arguments required.  Directory args imply add
+    #       # the directory itself, not the files in it.
+    #   co  # Obtain list directly.
+    #   remove # HERE: TEST: MAYBE client does the recursion for us,
+    #          # since it only makes sense to remove stuff already in
+    #          # the sandobx?
+    #   ci # HERE: Similar to remove...
+    #      # Don't try to implement the confusing/weird
+    #      # ci -r bug er.."feature".
+
+    if(scalar(@{$state->{args}})==0)
+    {
+        $state->{args} = [ "." ];
+    }
+    my %allArgs;
+    my %allDirs;
+    for my $file (@{$state->{args}})
+    {
+        expandArg($updater,\%allArgs,\%allDirs,$file);
+    }
+
+    # Include any entries from sandbox.  Generally client won't
+    # send entries that shouldn't be used.
+    foreach my $file (keys %{$state->{entries}})
+    {
+        $allArgs{remove_prependdir($file)} = 1;
+    }
+
+    $state->{dirArgs} = \%allDirs;
+    $state->{args} = [
+        sort {
+                # Sort priority: by directory depth, then actual file name:
+            my @piecesA=split('/',$a);
+            my @piecesB=split('/',$b);
+
+            my $count=scalar(@piecesA);
+            my $tmp=scalar(@piecesB);
+            return $count<=>$tmp if($count!=$tmp);
+
+            for($tmp=0;$tmp<$count;$tmp++)
+            {
+                if($piecesA[$tmp] ne $piecesB[$tmp])
+                {
+                    return $piecesA[$tmp] cmp $piecesB[$tmp]
+                }
+            }
+            return 0;
+        } keys(%allArgs) ];
+}
 
 ## look up directory sticky tag, of either fullPath or a parent:
 sub getDirStickyInfo
@@ -2383,6 +2550,7 @@ sub getStickyTagOrDate
 sub statecleanup
 {
     $state->{files} = [];
+    $state->{dirArgs} = {};
     $state->{args} = [];
     $state->{arguments} = [];
     $state->{entries} = {};
-- 
1.7.10.2.484.gcd07cc5

  parent reply	other threads:[~2012-10-14  5:58 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-14  5:42 [PATCH 00/20] git-cvsserver: add support for cvs "-r" refs Matthew Ogilvie
2012-10-14  5:42 ` [PATCH 01/20] cvsserver t9400: add basic 'cvs log' test Matthew Ogilvie
2012-10-14  5:42 ` [PATCH 02/20] cvsserver: removed unused sha1Or-k mode from kopts_from_path Matthew Ogilvie
2012-10-14  5:42 ` [PATCH 03/20] cvsserver: add comments about database schema/usage Matthew Ogilvie
2012-10-14  5:42 ` [PATCH 04/20] cvsserver update: comment about how we shouldn't remove a user-modified file Matthew Ogilvie
2012-10-14  5:42 ` [PATCH 05/20] cvsserver: remove unused functions _headrev and gethistory Matthew Ogilvie
2012-10-14  5:42 ` [PATCH 06/20] cvsserver: clean up client request handler map comments Matthew Ogilvie
2012-10-14  5:42 ` [PATCH 07/20] cvsserver: split up long lines in req_{status,diff,log} Matthew Ogilvie
2012-10-14  5:42 ` [PATCH 08/20] cvsserver: use whole CVS rev number in-process; don't strip "1." prefix Matthew Ogilvie
2012-10-14  5:42 ` [PATCH 09/20] cvsserver: cvs add: do not expand directory arguments Matthew Ogilvie
2012-10-14  5:42 ` [PATCH 10/20] cvsserver status: provide real sticky info Matthew Ogilvie
2012-10-14  5:42 ` [PATCH 11/20] cvsserver: factor out git-log parsing logic Matthew Ogilvie
2012-10-14  5:42 ` [PATCH 12/20] cvsserver: cleanup extra slashes in filename arguments Matthew Ogilvie
2012-10-14  5:42 ` [PATCH 13/20] cvsserver: define a tag name character escape mechanism Matthew Ogilvie
2012-10-14  5:42 ` [PATCH 14/20] cvsserver: add misc commit lookup, file meta data, and file listing functions Matthew Ogilvie
2012-10-14  5:42 ` [PATCH 15/20] cvsserver: implement req_Sticky and related utilities Matthew Ogilvie
2012-10-14  5:42 ` [PATCH 16/20] cvsserver: generalize getmeta() to recognize commit refs Matthew Ogilvie
2012-10-14  5:42 ` Matthew Ogilvie [this message]
2012-10-14  5:42 ` [PATCH 18/20] cvsserver: support -r and sticky tags for most operations Matthew Ogilvie
2012-10-14  5:42 ` [PATCH 19/20] cvsserver: add t9402 to test branch and tag refs Matthew Ogilvie
2012-10-14  5:42 ` [PATCH 20/20] cvsserver Documentation: new cvs ... -r support Matthew Ogilvie
2012-10-16 19:25 ` [PATCH 00/20] git-cvsserver: add support for cvs "-r" refs Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1350193353-19210-18-git-send-email-mmogilvi_git@miniinfo.net \
    --to=mmogilvi_git@miniinfo.net \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).