@matheusbsbs / matheus-bagliano / commits / 7d90095abe
Fork 0

Many fixes for most operations in Eclipse.

* Implemented global -n option * Implemented "Questionable" * Fixed Directory method, I _believe_ it's now correct in both cmdline and Eclipse. * Directory method Now looks for localdir of "." and compares the repo dir, uses THIS as a basis for all directory level calculations. * Added extra parameter to filenamesplit() to force stripping of "prepended" directory name. This ensures commits/updates etc work from any directory in the source tree. * Modified argsfromdir() so it is "always" called. This means that when the client specifies a directory, the method can detect this and behave accordingly (this is currently only implemented for the '.' directory) * Fixed "commit" method to correctly work from in a subdir

Martyn Smith committed Mar 27, 2006 at 15:51 UTC 7d90095abe322f72820f334839afb75c23e009ff
1 file changed +139 -82
git-cvsserver.perl
+139 -82
@@ -214,8 +214,7 @@ sub req_Globaloption
214 {
215 my ( $cmd, $data ) = @_;
216 $log->debug("req_Globaloption : $data");
217 -
218 - # TODO : is this data useful ???
217 + $state->{globaloptions}{$data} = 1;
218 }
219
220 # Valid-responses request-list \n
@@ -267,11 +266,32 @@ sub req_Directory
266
267 $state->{localdir} = $data;
268 $state->{repository} = $repository;
270 - $state->{directory} = $repository;
271 - $state->{directory} =~ s/^$state->{CVSROOT}\///;
272 - $state->{module} = $1 if ($state->{directory} =~ s/^(.*?)(\/|$)//);
269 + $state->{path} = $repository;
270 + $state->{path} =~ s/^$state->{CVSROOT}\///;
271 + $state->{module} = $1 if ($state->{path} =~ s/^(.*?)(\/|$)//);
272 + $state->{path} .= "/" if ( $state->{path} =~ /\S/ );
273 +
274 + $state->{directory} = $state->{localdir};
275 + $state->{directory} = "" if ( $state->{directory} eq "." );
276 $state->{directory} .= "/" if ( $state->{directory} =~ /\S/ );
277
278 + if ( not defined($state->{prependdir}) and $state->{localdir} eq "." and $state->{path} =~ /\S/ )
279 + {
280 + $log->info("Setting prepend to '$state->{path}'");
281 + $state->{prependdir} = $state->{path};
282 + foreach my $entry ( keys %{$state->{entries}} )
283 + {
284 + $state->{entries}{$state->{prependdir} . $entry} = $state->{entries}{$entry};
285 + delete $state->{entries}{$entry};
286 + }
287 + }
288 +
289 + if ( defined ( $state->{prependdir} ) )
290 + {
291 + $log->debug("Prepending '$state->{prependdir}' to state|directory");
292 + $state->{directory} = $state->{prependdir} . $state->{directory}
293 + }
294 +
295 $log->debug("req_Directory : localdir=$data repository=$repository directory=$state->{directory} module=$state->{module}");
296 }
297
@@ -290,7 +310,7 @@ sub req_Entry
310 {
311 my ( $cmd, $data ) = @_;
312
293 - $log->debug("req_Entry : $data");
313 + #$log->debug("req_Entry : $data");
314
315 my @data = split(/\//, $data);
316
@@ -300,6 +320,22 @@ sub req_Entry
320 options => $data[4],
321 tag_or_date => $data[5],
322 };
323 +
324 + $log->info("Received entry line '$data' => '" . $state->{directory} . $data[1] . "'");
325 +}
326 +
327 +# Questionable filename \n
328 +# Response expected: no. Additional data: no. Tell the server to check
329 +# whether filename should be ignored, and if not, next time the server
330 +# sends responses, send (in a M response) `?' followed by the directory and
331 +# filename. filename must not contain `/'; it needs to be a file in the
332 +# directory named by the most recent Directory request.
333 +sub req_Questionable
334 +{
335 + my ( $cmd, $data ) = @_;
336 +
337 + $log->debug("req_Questionable : $data");
338 + $state->{entries}{$state->{directory}.$data}{questionable} = 1;
339 }
340
341 # add \n
@@ -332,8 +368,7 @@ sub req_add
368 next;
369 }
370
335 -
336 - my ( $filepart, $dirpart ) = filenamesplit($filename);
371 + my ( $filepart, $dirpart ) = filenamesplit($filename, 1);
372
373 print "E cvs add: scheduling file `$filename' for addition\n";
374
@@ -414,7 +449,7 @@ sub req_remove
449 }
450
451
417 - my ( $filepart, $dirpart ) = filenamesplit($filename);
452 + my ( $filepart, $dirpart ) = filenamesplit($filename, 1);
453
454 print "E cvs remove: scheduling `$filename' for removal\n";
455
@@ -502,22 +537,6 @@ sub req_Unchanged
537 #$log->debug("req_Unchanged : $data");
538 }
539
505 -# Questionable filename \n
506 -# Response expected: no. Additional data: no.
507 -# Tell the server to check whether filename should be ignored,
508 -# and if not, next time the server sends responses, send (in
509 -# a M response) `?' followed by the directory and filename.
510 -# filename must not contain `/'; it needs to be a file in the
511 -# directory named by the most recent Directory request.
512 -sub req_Questionable
513 -{
514 - my ( $cmd, $data ) = @_;
515 -
516 - $state->{entries}{$state->{directory}.$data}{questionable} = 1;
517 -
518 - #$log->debug("req_Questionable : $data");
519 -}
520 -
540 # Argument text \n
541 # Response expected: no. Save argument for use in a subsequent command.
542 # Arguments accumulate until an argument-using command is given, at which
@@ -757,8 +776,7 @@ sub req_update
776
777 $updater->update();
778
760 - # if no files were specified, we need to work out what files we should be providing status on ...
761 - argsfromdir($updater) if ( scalar ( @{$state->{args}} ) == 0 );
779 + argsfromdir($updater);
780
781 #$log->debug("update state : " . Dumper($state));
782
@@ -767,6 +785,8 @@ sub req_update
785 {
786 $filename = filecleanup($filename);
787
788 + $log->debug("Processing file $filename");
789 +
790 # if we have a -C we should pretend we never saw modified stuff
791 if ( exists ( $state->{opt}{C} ) )
792 {
@@ -821,13 +841,16 @@ sub req_update
841
842 if ( $meta->{filehash} eq "deleted" )
843 {
824 - my ( $filepart, $dirpart ) = filenamesplit($filename);
844 + my ( $filepart, $dirpart ) = filenamesplit($filename,1);
845
846 $log->info("Removing '$filename' from working copy (no longer in the repo)");
847
848 print "E cvs update: `$filename' is no longer in the repository\n";
829 - print "Removed $dirpart\n";
830 - print "$filepart\n";
849 + # Don't want to actually _DO_ the update if -n specified
850 + unless ( $state->{globaloptions}{-n} ) {
851 + print "Removed $dirpart\n";
852 + print "$filepart\n";
853 + }
854 }
855 elsif ( not defined ( $state->{entries}{$filename}{modified_hash} )
856 or $state->{entries}{$filename}{modified_hash} eq $oldmeta->{filehash} )
@@ -840,34 +863,42 @@ sub req_update
863 print "MT newline\n";
864 print "MT -updated\n";
865
843 - my ( $filepart, $dirpart ) = filenamesplit($filename);
844 - $dirpart =~ s/^$state->{directory}//;
845 -
846 - if ( defined ( $wrev ) )
847 - {
848 - # instruct client we're sending a file to put in this path as a replacement
849 - print "Update-existing $dirpart\n";
850 - $log->debug("Updating existing file 'Update-existing $dirpart'");
851 - } else {
852 - # instruct client we're sending a file to put in this path as a new file
853 - print "Created $dirpart\n";
854 - $log->debug("Creating new file 'Created $dirpart'");
855 - }
856 - print $state->{CVSROOT} . "/$state->{module}/$filename\n";
857 -
858 - # this is an "entries" line
859 - $log->debug("/$filepart/1.$meta->{revision}///");
860 - print "/$filepart/1.$meta->{revision}///\n";
861 -
862 - # permissions
863 - $log->debug("SEND : u=$meta->{mode},g=$meta->{mode},o=$meta->{mode}");
864 - print "u=$meta->{mode},g=$meta->{mode},o=$meta->{mode}\n";
865 -
866 - # transmit file
867 - transmitfile($meta->{filehash});
866 + my ( $filepart, $dirpart ) = filenamesplit($filename,1);
867 +
868 + # Don't want to actually _DO_ the update if -n specified
869 + unless ( $state->{globaloptions}{-n} )
870 + {
871 + if ( defined ( $wrev ) )
872 + {
873 + # instruct client we're sending a file to put in this path as a replacement
874 + print "Update-existing $dirpart\n";
875 + $log->debug("Updating existing file 'Update-existing $dirpart'");
876 + } else {
877 + # instruct client we're sending a file to put in this path as a new file
878 + print "Clear-static-directory $dirpart\n";
879 + print $state->{CVSROOT} . "/$state->{module}/$dirpart\n";
880 + print "Clear-sticky $dirpart\n";
881 + print $state->{CVSROOT} . "/$state->{module}/$dirpart\n";
882 +
883 + $log->debug("Creating new file 'Created $dirpart'");
884 + print "Created $dirpart\n";
885 + }
886 + print $state->{CVSROOT} . "/$state->{module}/$filename\n";
887 +
888 + # this is an "entries" line
889 + $log->debug("/$filepart/1.$meta->{revision}///");
890 + print "/$filepart/1.$meta->{revision}///\n";
891 +
892 + # permissions
893 + $log->debug("SEND : u=$meta->{mode},g=$meta->{mode},o=$meta->{mode}");
894 + print "u=$meta->{mode},g=$meta->{mode},o=$meta->{mode}\n";
895 +
896 + # transmit file
897 + transmitfile($meta->{filehash});
898 + }
899 } else {
900 $log->info("Updating '$filename'");
870 - my ( $filepart, $dirpart ) = filenamesplit($meta->{name});
901 + my ( $filepart, $dirpart ) = filenamesplit($meta->{name},1);
902
903 my $dir = tempdir( DIR => $TEMP_DIR, CLEANUP => 1 ) . "/";
904
@@ -892,19 +923,29 @@ sub req_update
923 $log->info("Merged successfully");
924 print "M M $filename\n";
925 $log->debug("Update-existing $dirpart");
895 - print "Update-existing $dirpart\n";
896 - $log->debug($state->{CVSROOT} . "/$state->{module}/$filename");
897 - print $state->{CVSROOT} . "/$state->{module}/$filename\n";
898 - $log->debug("/$filepart/1.$meta->{revision}///");
899 - print "/$filepart/1.$meta->{revision}///\n";
926 +
927 + # Don't want to actually _DO_ the update if -n specified
928 + unless ( $state->{globaloptions}{-n} )
929 + {
930 + print "Update-existing $dirpart\n";
931 + $log->debug($state->{CVSROOT} . "/$state->{module}/$filename");
932 + print $state->{CVSROOT} . "/$state->{module}/$filename\n";
933 + $log->debug("/$filepart/1.$meta->{revision}///");
934 + print "/$filepart/1.$meta->{revision}///\n";
935 + }
936 }
937 elsif ( $return == 1 )
938 {
939 $log->info("Merged with conflicts");
940 print "M C $filename\n";
905 - print "Update-existing $dirpart\n";
906 - print $state->{CVSROOT} . "/$state->{module}/$filename\n";
907 - print "/$filepart/1.$meta->{revision}/+//\n";
941 +
942 + # Don't want to actually _DO_ the update if -n specified
943 + unless ( $state->{globaloptions}{-n} )
944 + {
945 + print "Update-existing $dirpart\n";
946 + print $state->{CVSROOT} . "/$state->{module}/$filename\n";
947 + print "/$filepart/1.$meta->{revision}/+//\n";
948 + }
949 }
950 else
951 {
@@ -912,17 +953,21 @@ sub req_update
953 next;
954 }
955
915 - # permissions
916 - $log->debug("SEND : u=$meta->{mode},g=$meta->{mode},o=$meta->{mode}");
917 - print "u=$meta->{mode},g=$meta->{mode},o=$meta->{mode}\n";
918 -
919 - # transmit file, format is single integer on a line by itself (file
920 - # size) followed by the file contents
921 - # TODO : we should copy files in blocks
922 - my $data = `cat $file_local`;
923 - $log->debug("File size : " . length($data));
924 - print length($data) . "\n";
925 - print $data;
956 + # Don't want to actually _DO_ the update if -n specified
957 + unless ( $state->{globaloptions}{-n} )
958 + {
959 + # permissions
960 + $log->debug("SEND : u=$meta->{mode},g=$meta->{mode},o=$meta->{mode}");
961 + print "u=$meta->{mode},g=$meta->{mode},o=$meta->{mode}\n";
962 +
963 + # transmit file, format is single integer on a line by itself (file
964 + # size) followed by the file contents
965 + # TODO : we should copy files in blocks
966 + my $data = `cat $file_local`;
967 + $log->debug("File size : " . length($data));
968 + print length($data) . "\n";
969 + print $data;
970 + }
971
972 chdir "/";
973 }
@@ -990,6 +1035,7 @@ sub req_ci
1035 # foreach file specified on the commandline ...
1036 foreach my $filename ( @{$state->{args}} )
1037 {
1038 + my $committedfile = $filename;
1039 $filename = filecleanup($filename);
1040
1041 next unless ( exists $state->{entries}{$filename}{modified_filename} or not $state->{entries}{$filename}{unchanged} );
@@ -1024,7 +1070,7 @@ sub req_ci
1070 exit;
1071 }
1072
1027 - push @committedfiles, $filename;
1073 + push @committedfiles, $committedfile;
1074 $log->info("Committing $filename");
1075
1076 system("mkdir","-p",$dirpart) unless ( -d $dirpart );
@@ -1107,7 +1153,7 @@ sub req_ci
1153
1154 my $meta = $updater->getmeta($filename);
1155
1110 - my ( $filepart, $dirpart ) = filenamesplit($filename);
1156 + my ( $filepart, $dirpart ) = filenamesplit($filename, 1);
1157
1158 $log->debug("Checked-in $dirpart : $filename");
1159
@@ -1143,7 +1189,7 @@ sub req_status
1189 $updater->update();
1190
1191 # if no files were specified, we need to work out what files we should be providing status on ...
1146 - argsfromdir($updater) if ( scalar ( @{$state->{args}} ) == 0 );
1192 + argsfromdir($updater);
1193
1194 # foreach file specified on the commandline ...
1195 foreach my $filename ( @{$state->{args}} )
@@ -1244,7 +1290,7 @@ sub req_diff
1290 $updater->update();
1291
1292 # if no files were specified, we need to work out what files we should be providing status on ...
1247 - argsfromdir($updater) if ( scalar ( @{$state->{args}} ) == 0 );
1293 + argsfromdir($updater);
1294
1295 # foreach file specified on the commandline ...
1296 foreach my $filename ( @{$state->{args}} )
@@ -1386,7 +1432,7 @@ sub req_log
1432 $updater->update();
1433
1434 # if no files were specified, we need to work out what files we should be providing status on ...
1389 - argsfromdir($updater) if ( scalar ( @{$state->{args}} ) == 0 );
1435 + argsfromdir($updater);
1436
1437 # foreach file specified on the commandline ...
1438 foreach my $filename ( @{$state->{args}} )
@@ -1462,7 +1508,7 @@ sub req_annotate
1508 $updater->update();
1509
1510 # if no files were specified, we need to work out what files we should be providing annotate on ...
1465 - argsfromdir($updater) if ( scalar ( @{$state->{args}} ) == 0 );
1511 + argsfromdir($updater);
1512
1513 # we'll need a temporary checkout dir
1514 my $tmpdir = tempdir ( DIR => $TEMP_DIR );
@@ -1657,6 +1703,12 @@ sub argsfromdir
1703 {
1704 my $updater = shift;
1705
1706 + $state->{args} = [] if ( scalar(@{$state->{args}}) == 1 and $state->{args}[0] eq "." );
1707 +
1708 + return if ( scalar ( @{$state->{args}} ) > 0 );
1709 +
1710 + $log->info("No args specified, populating file list automatically");
1711 +
1712 $state->{args} = [];
1713
1714 foreach my $file ( @{$updater->gethead} )
@@ -1738,11 +1790,17 @@ sub transmitfile
1790 sub filenamesplit
1791 {
1792 my $filename = shift;
1793 + my $fixforlocaldir = shift;
1794
1795 my ( $filepart, $dirpart ) = ( $filename, "." );
1796 ( $filepart, $dirpart ) = ( $2, $1 ) if ( $filename =~ /(.*)\/(.*)/ );
1797 $dirpart .= "/";
1798
1799 + if ( $fixforlocaldir )
1800 + {
1801 + $dirpart =~ s/^$state->{prependdir}//;
1802 + }
1803 +
1804 return ( $filepart, $dirpart );
1805 }
1806
@@ -1759,7 +1817,6 @@ sub filecleanup
1817
1818 $filename =~ s/^\.\///g;
1819 $filename = $state->{directory} . $filename;
1762 -
1820 return $filename;
1821 }
1822