cvsserver: Make always-binary mode a config file option
The config option gitcvs.allbinary may be set to force all entries to get the -kb flag. In the future the gitattributes system will probably be a more appropriate way of doing this, but that will easily slot in as the entries lines sent to the CVS client now have their kopts set via the function kopts_from_path(). In the interim it might be better to not just have a all-or-nothing approach, but rather detect based on file extension (or file contents?). That would slot in easily here as well. However, I personally prefer everything to be binary-safe, so I just switch the switch. Signed-off-by: Andy Parkins <andyparkins@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
Andy Parkins committed
Feb 27, 2007 at 13:46 UTC
8538e876b191901b7d37ec34a83287e51df91816
1 file changed
+38
-9
git-cvsserver.perl
+38
-9
@@ -374,7 +374,8 @@ sub req_add
374
375
print "Checked-in $dirpart\n";
376
print "$filename\n";
377
- print "/$filepart/0///\n";
377
+ my $kopts = kopts_from_path($filepart);
378
+ print "/$filepart/0//$kopts/\n";
379
380
$addcount++;
381
}
@@ -455,7 +456,8 @@ sub req_remove
456
457
print "Checked-in $dirpart\n";
458
print "$filename\n";
458
- print "/$filepart/-1.$wrev///\n";
459
+ my $kopts = kopts_from_path($filepart);
460
+ print "/$filepart/-1.$wrev//$kopts/\n";
461
462
$rmcount++;
463
}
@@ -726,7 +728,8 @@ sub req_co
728
print $state->{CVSROOT} . "/$module/" . ( defined ( $git->{dir} ) and $git->{dir} ne "./" ? $git->{dir} . "/" : "" ) . "$git->{name}\n";
729
730
# this is an "entries" line
729
- print "/$git->{name}/1.$git->{revision}///\n";
731
+ my $kopts = kopts_from_path($git->{name});
732
+ print "/$git->{name}/1.$git->{revision}//$kopts/\n";
733
# permissions
734
print "u=$git->{mode},g=$git->{mode},o=$git->{mode}\n";
735
@@ -917,8 +920,9 @@ sub req_update
920
print $state->{CVSROOT} . "/$state->{module}/$filename\n";
921
922
# this is an "entries" line
920
- $log->debug("/$filepart/1.$meta->{revision}///");
921
- print "/$filepart/1.$meta->{revision}///\n";
923
+ my $kopts = kopts_from_path($filepart);
924
+ $log->debug("/$filepart/1.$meta->{revision}//$kopts/");
925
+ print "/$filepart/1.$meta->{revision}//$kopts/\n";
926
927
# permissions
928
$log->debug("SEND : u=$meta->{mode},g=$meta->{mode},o=$meta->{mode}");
@@ -961,8 +965,9 @@ sub req_update
965
print "Update-existing $dirpart\n";
966
$log->debug($state->{CVSROOT} . "/$state->{module}/$filename");
967
print $state->{CVSROOT} . "/$state->{module}/$filename\n";
964
- $log->debug("/$filepart/1.$meta->{revision}///");
965
- print "/$filepart/1.$meta->{revision}///\n";
968
+ my $kopts = kopts_from_path($filepart);
969
+ $log->debug("/$filepart/1.$meta->{revision}//$kopts/");
970
+ print "/$filepart/1.$meta->{revision}//$kopts/\n";
971
}
972
}
973
elsif ( $return == 1 )
@@ -975,7 +980,8 @@ sub req_update
980
{
981
print "Update-existing $dirpart\n";
982
print $state->{CVSROOT} . "/$state->{module}/$filename\n";
978
- print "/$filepart/1.$meta->{revision}/+//\n";
983
+ my $kopts = kopts_from_path($filepart);
984
+ print "/$filepart/1.$meta->{revision}/+/$kopts/\n";
985
}
986
}
987
else
@@ -1206,7 +1212,8 @@ sub req_ci
1212
} else {
1213
print "Checked-in $dirpart\n";
1214
print "$filename\n";
1209
- print "/$filepart/1.$meta->{revision}///\n";
1215
+ my $kopts = kopts_from_path($filepart);
1216
+ print "/$filepart/1.$meta->{revision}//$kopts/\n";
1217
}
1218
}
1219
@@ -1887,6 +1894,28 @@ sub filecleanup
1894
return $filename;
1895
}
1896
1897
+# Given a path, this function returns a string containing the kopts
1898
+# that should go into that path's Entries line. For example, a binary
1899
+# file should get -kb.
1900
+sub kopts_from_path
1901
+{
1902
+ my ($path) = @_;
1903
+
1904
+ # Once it exists, the git attributes system should be used to look up
1905
+ # what attributes apply to this path.
1906
+
1907
+ # Until then, take the setting from the config file
1908
+ unless ( defined ( $cfg->{gitcvs}{allbinary} ) and $cfg->{gitcvs}{allbinary} =~ /^\s*(1|true|yes)\s*$/i )
1909
+ {
1910
+ # Return "" to give no special treatment to any path
1911
+ return "";
1912
+ } else {
1913
+ # Alternatively, to have all files treated as if they are binary (which
1914
+ # is more like git itself), always return the "-kb" option
1915
+ return "-kb";
1916
+ }
1917
+}
1918
+
1919
package GITCVS::log;
1920
1921
####