[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to admin deep hierachy directories
From: |
Mark D. Baushke |
Subject: |
Re: How to admin deep hierachy directories |
Date: |
Tue, 11 Feb 2003 00:50:36 -0800 |
Charles Sun <address@hidden> writes:
> I have a tool that generates many new files and folders in my working area.
> These files shall be CVS controlled.
>
> For example, my working area looks like:
>
> Project_folder --- folderA --- subfolderA1 --- fileA1.1
> -- folderB --- subfolderB1 --- fileB1.1
>
> After running my tool, it becomes:
>
> Project_folder --- folderA --- subfolderA1 --- fileA1.1(updated)
> -- subfolderA2 --- fileA2.1
> -- folderB --- subfolderB1 --- fileB1.1
> -- fileB1.2
> -- folderC --- fileC.1
>
> I don't want to find and add each new files and folders one by one. What is
> the easiest way to maintain my working area?
I believe the easiest way is to write a script to do the job for you.
It could be as simple as
findcvs.perl -f -d | xargs cvs add
cvs commit -m 'Control working area files.'
given the findcvs.perl script (provided after my .signature).
> I want to add a symbolic link in my working area. Can CVS keep this and
> distribute it to other co-developers?
No, cvs does not version control symbolic links or directories.
Enjoy!
-- Mark
--------------- findcvs.perl ---------------
: # use perl
eval 'exec perl -S "$0" ${1+"$@"}'
if 0;
# findcvs.perl - find selected [non-]cvs controlled files in the current tree.
#
# Copyright (c) 2000-2003, Mark D. Baushke <address@hidden>
# All rights reserved.
#
# You may distribute this script under the terms of the GNU General
# Public License as specified in the README file that comes with the CVS
# source distribution.
#
# Basic algorithm:
# Find all CVS directories. The parent directory is cvs controlled.
# Read the CVS/Entries file. All entries are cvs controlled.
# All entities in the tree that are not controlled are marked.
#
# Determine which filenames to print and how they are to be sorted,
# based on the command-line options.
#
use strict;
use Getopt::Std;
use File::Find;
use vars qw(%iscvs $entries $controlled
$opt_a $opt_c $opt_d $opt_f $opt_h $opt_n $opt_r);
$entries = 'CVS/Entries'; # A CVS control file for this sandbox
&getopts('acdfhnr'); # process the command-line options
# Make sure that mixed command flags are identified.
# Provide help if needed.
if ($opt_h || ($opt_n && $opt_c)) {
print(STDERR
join("\n",
"Usage: $0 [-c|-n] [-a|-d|-f] [-h]",
"-c\tPrint out cvs controlled files.",
"-n\tPrint out non-cvs controlled files (default).",
"-a\tPrint all names (default unless -f or -d flags are used).",
"-d\tPrint directory names.",
"-f\tPrint file names.",
"-f\tSort in reverse order.",
"-h\tPrint out this usage message.",
''));
exit 1;
}
# Print out cvs controlled files by default and non-cvs controlled
# entities by request.
$controlled = ($opt_c) ? 1 : 0;
# If neither -d nor -f are on the command-line, assume -a for the
# default.
$opt_a = 1 if (! ($opt_f ||$opt_d));
# Search the current tree for cvs controlled files and directories
File::Find::find(\&wanted, '.');
# Apply the sorting desired by the user.
my @list;
if ($opt_r) {
@list = sort { $b cmp $a } keys %iscvs;
} else {
@list = sort { $a cmp $b } keys %iscvs;
}
# Go thru the list and print out those entities that were desired.
foreach my $key (@list) {
if ($iscvs{$key} == $controlled) {
if ($opt_a || ($opt_f && -f $key) || ($opt_d && -d $key)) {
print $key,"\n";
}
}
}
# Walk thru the tree and find the filesystem entities desired
sub wanted {
my($name) = $File::Find::name;
my($dir) = $File::Find::dir;
if ($_ eq 'CVS') {
$File::Find::prune = 1; # ignore stuff in CVS directories
$iscvs{$dir} = 1; # this directory is cvs controlled
proc_cvs_entries($dir) if ( -f $entries );
} else {
# set entries that are not CVS controlled entities
if (!$iscvs{$name}) {
$iscvs{$name} = 0; # this entity is not cvs controlled
}
}
}
# Process a CVS/Entries file
sub proc_cvs_entries {
my($pdir) = @_;
my($entry, $file);
# A typica CVS/Entries file looks like this:
# D
#or
# D/<directory-name>////
#or
# <optionaltag>/file/...
if (open(ENTRIES, $entries)) {
while($entry=<ENTRIES>) {
chomp($entry);
# Just 'D' on a line by itself indicates that all
# subdirectories have been enumerated in the Entries file
# already.
next if ($entry eq 'D');
# We don't care about anything but the name of the file
$file = (split(/\//, $entry, 3))[1];
$iscvs{$pdir.'/'.$file} = 1; # mark as processed
}
close(ENTRIES);
} else {
warn "Unable to read $entries: $!";
}
}
__END__
--------------- end of findcvs.perl ---------------