{"thread":{"id":"10142","subject":"[PATCH] cvsserver: Fix req_update to handle packed refs","startedAt":"2007-10-04T19:21:20Z","lastAt":"2007-10-04T20:58:32Z","messageCount":3,"participants":["Frank Lichtenheld","Martin Langhoff"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"54866","messageId":"1191525680-10481-1-git-send-email-frank@lichtenheld.de","threadId":"10142","inReplyTo":null,"subject":"[PATCH] cvsserver: Fix req_update to handle packed refs","fromName":"Frank Lichtenheld","fromEmail":"frank@lichtenheld.de","sentAt":"2007-10-04T19:21:20Z","receivedAt":"2007-10-04T19:21:20Z","isPatch":true,"sender":{"key":"frank@lichtenheld.de","avatar":"https://gravatar.com/avatar/b9f1d4b120e138f157c9e480d0818197c474628923786adb98f30017cdb99c3c?d=mp&s=160"},"body":"cvsserver returns a list of existing modules on command\n'update' without a module specified (apparently this is\nused by some clients to get a list of available modules,\nthe CVS cli client doesn't support it).\n\nFix this code to work correctly in presence of packed refs.\n(Use git-branch instead of reading refs/heads/)\n\nSigned-off-by: Frank Lichtenheld <frank@lichtenheld.de>\n---\n git-cvsserver.perl              |   20 +++++++++-----------\n t/t9400-git-cvsserver-server.sh |   26 ++++++++++++++++++++++++++\n 2 files changed, 35 insertions(+), 11 deletions(-)\n\n Found while testing Johannes' patch. Is that a sane use of git-branch?\n\ndiff --git a/git-cvsserver.perl b/git-cvsserver.perl\nindex 7fff18b..acf2e5f 100755\n--- a/git-cvsserver.perl\n+++ b/git-cvsserver.perl\n@@ -914,19 +914,17 @@ sub req_update\n     # projects (heads in this case) to checkout.\n     #\n     if ($state->{module} eq '') {\n-\tmy $heads_dir = $state->{CVSROOT} . '/refs/heads';\n-\tif (!opendir HEADS, $heads_dir) {\n-\t    print \"E [server aborted]: Failed to open directory, \"\n-\t      . \"$heads_dir: $!\\nerror\\n\";\n-\t    return 0;\n+\tmy @branches = `git branch`;\n+\tif ($?) {\n+\t    print \"E [server aborted]: git branch failed\\nerror\\n\";\n+\t    return;\n \t}\n-        print \"E cvs update: Updating .\\n\";\n-\twhile (my $head = readdir(HEADS)) {\n-\t    if (-f $state->{CVSROOT} . '/refs/heads/' . $head) {\n-\t        print \"E cvs update: New directory `$head'\\n\";\n-\t    }\n+\tforeach (@branches) {\n+\t    chomp;\n+\t    s/^\\*//;\n+\t    s/^\\s+//;\n+\t    print \"E cvs update: New directory `$_'\\n\";\n \t}\n-\tclosedir HEADS;\n \tprint \"ok\\n\";\n \treturn 1;\n     }\ndiff --git a/t/t9400-git-cvsserver-server.sh b/t/t9400-git-cvsserver-server.sh\nindex 11def84..106a696 100755\n--- a/t/t9400-git-cvsserver-server.sh\n+++ b/t/t9400-git-cvsserver-server.sh\n@@ -447,4 +447,30 @@ test_expect_success 'cvs update (merge no-op)' \\\n     GIT_CONFIG=\"$git_config\" cvs -Q update &&\n     diff -q merge ../merge'\n \n+cd \"$WORKDIR\"\n+cat <<EOF >list-modules-cmd\n+Root $SERVERDIR\n+Valid-responses ok error Valid-requests Force-gzip Referrer Redirect Checked-in New-entry Checksum Copy-file Updated Created Update-existing Merged Patched Rcs-diff Mode Mod-time Removed Remove-entry Set-static-directory Clear-static-directory Set-sticky Clear-sticky Edit-file Template Clear-template Notified Module-expansion Wrapper-rcsOption M Mbinary E F MT\n+Global_option -q\n+Directory .\n+$WORKDIR\n+update\n+EOF\n+\n+echo \\`master\\' >modules-list.exp\n+\n+# can't do these with the CVS cli client, but others clients\n+# use that feature\n+test_expect_success 'cvs update (no arg)' \\\n+   'cat list-modules-cmd | git-cvsserver |\n+    sed -n \"s/^E cvs update: New directory //p\" >modules-list &&\n+    diff -q modules-list modules-list.exp'\n+\n+test_expect_success 'cvs update (no arg/packed refs)' \\\n+   'GIT_DIR=\"$SERVERDIR\" git gc &&\n+    test ! -f \"$SERVERDIR/refs/heads/master\" &&\n+    cat list-modules-cmd | git-cvsserver |\n+    sed -n \"s/^E cvs update: New directory //p\" >modules-list &&\n+    diff -q modules-list modules-list.exp'\n+    \n test_done\n-- \n1.5.3.3\n"},{"id":"295486","messageId":"46a038f90710041343g5b6a5a30gcd0c9f18d265fa28@mail.gmail.com","threadId":"10142","inReplyTo":"1191525680-10481-1-git-send-email-frank@lichtenheld.de","subject":"Re: [PATCH] cvsserver: Fix req_update to handle packed refs","fromName":"Martin Langhoff","fromEmail":"martin.langhoff@gmail.com","sentAt":"2007-10-04T20:43:55Z","receivedAt":"2007-10-04T20:43:55Z","isPatch":true,"sender":{"key":"martin.langhoff@gmail.com","avatar":"https://gravatar.com/avatar/1e3f311b6c4c15836501901ca58f8c0b0667246488084ba524d8bc9867e22fd9?d=mp&s=160"},"body":"On 10/5/07, Frank Lichtenheld <frank@lichtenheld.de> wrote:\n> cvsserver returns a list of existing modules on command\n> 'update' without a module specified (apparently this is\n> used by some clients to get a list of available modules,\n> the CVS cli client doesn't support it).\n>\n> Fix this code to work correctly in presence of packed refs.\n> (Use git-branch instead of reading refs/heads/)\n\nACK - good stuff - thanks!\n\nThere is one minor issue around this I suspect - refs with slashes in\nthem. Without this patch, only refs that literally sit in refs/heads\nwill be returned. With git branches, you could see oldbranches/foo\nbeing returned to the client.\n\nIIRC - the behaviour cvsserver supports here is completely\nunspecified, and clients will probably error out in weird and wacky\nways. I'd perhaps filter out any headref with a slash.\n\ncheers,\n\n\nmartin\n\n\n\n"},{"id":"54870","messageId":"20071004205832.GF31659@planck.djpig.de","threadId":"10142","inReplyTo":"46a038f90710041343g5b6a5a30gcd0c9f18d265fa28@mail.gmail.com","subject":"Re: [PATCH] cvsserver: Fix req_update to handle packed refs","fromName":"Frank Lichtenheld","fromEmail":"frank@lichtenheld.de","sentAt":"2007-10-04T20:58:32Z","receivedAt":"2007-10-04T20:58:32Z","isPatch":true,"sender":{"key":"frank@lichtenheld.de","avatar":"https://gravatar.com/avatar/b9f1d4b120e138f157c9e480d0818197c474628923786adb98f30017cdb99c3c?d=mp&s=160"},"body":"On Fri, Oct 05, 2007 at 09:43:55AM +1300, Martin Langhoff wrote:\n> On 10/5/07, Frank Lichtenheld <frank@lichtenheld.de> wrote:\n> > cvsserver returns a list of existing modules on command\n> > 'update' without a module specified (apparently this is\n> > used by some clients to get a list of available modules,\n> > the CVS cli client doesn't support it).\n> >\n> > Fix this code to work correctly in presence of packed refs.\n> > (Use git-branch instead of reading refs/heads/)\n> \n> ACK - good stuff - thanks!\n> \n> There is one minor issue around this I suspect - refs with slashes in\n> them. Without this patch, only refs that literally sit in refs/heads\n> will be returned. With git branches, you could see oldbranches/foo\n> being returned to the client.\n> \n> IIRC - the behaviour cvsserver supports here is completely\n> unspecified, and clients will probably error out in weird and wacky\n> ways. I'd perhaps filter out any headref with a slash.\n\ncvsserver also horribly breaks for module names with slashs in them.\nSomething that might be good to be fixed, too.\n\nGruesse,\n-- \nFrank Lichtenheld <frank@lichtenheld.de>\nwww: http://www.djpig.de/\n"}]}