You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Peter Ericson <ar...@gmail.com> on 2006/01/01 22:10:24 UTC

[PATCH] tools/examples/svnshell.py

* tools/examples/svnshell.py
  (do_cat): Fix endless loop that occurs when cat-ing files larger
  than core.SVN_STREAM_CHUNK_SIZE.

Re: [PATCH] tools/examples/svnshell.py

Posted by Max Bowsher <ma...@ukf.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Peter Ericson wrote:
> Good point; I had tested my fix by calling write method on a file
> object instead of print.  I didn't test the patch because trunk
> svnlook.py was incompatible with my installed bindings!
> 
> Thanks,
> 
> Peter
> 
> On 03/01/06, Max Bowsher <ma...@ukf.net> wrote:
> 
> Peter Ericson wrote:
> 
>>* tools/examples/svnshell.py
>>  (do_cat): Fix endless loop that occurs when cat-ing files larger
>>  than core.SVN_STREAM_CHUNK_SIZE.
>>@@ -78,6 +78,7 @@
>>     stream = fs.file_contents(self.root, catpath)
>>     while filelen > core.SVN_STREAM_CHUNK_SIZE:
>>       print core.svn_stream_read(stream, int(core.SVN_STREAM_CHUNK_SIZE))
>>+      filelen -= core.SVN_STREAM_CHUNK_SIZE
>>     print core.svn_stream_read(stream, int(filelen))
> 
> Thanks for the heads-up - actually, now you have drawn attention to that
> code, I see that it is even more buggy than you have noticed:
> 
> It is using 'print', which will cause an extra newline to be inserted
> every SVN_STREAM_CHUNK_SIZE bytes, and at the end of the file. Also, it
> is unnecessarily using svn_fs_file_length, since it can just keep
> reading the stream until it gets a short read to indicate EOF.
> 
> And, using int(core.SVN_STREAM_CHUNK_SIZE) is rather strange too -
> actually, does anyone know a reason for that? Was it working around some
> old Python bindings bug?
> 
> 
> Index: svnshell.py
> ===================================================================
> --- svnshell.py (revision 17951)
> +++ svnshell.py (working copy)
> @@ -74,11 +74,12 @@
>        print "Path '%s' is not a file." % catpath
>        return
>      ### be nice to get some paging in here.
> -    filelen = fs.file_length(self.root, catpath)
>      stream = fs.file_contents(self.root, catpath)
> -    while filelen > core.SVN_STREAM_CHUNK_SIZE:
> -      print core.svn_stream_read(stream, int(core.SVN_STREAM_CHUNK_SIZE))
> -    print core.svn_stream_read(stream, int(filelen))
> +    while 1:
> +      data = core.svn_stream_read(stream, core.SVN_STREAM_CHUNK_SIZE)
> +      sys.stdout.write(data)
> +      if len(data) < core.SVN_STREAM_CHUNK_SIZE:
> +        break
> 
>    def do_cd(self, arg):
>      """change directory"""
> 


Committed r17989.

Max.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Cygwin)

iD8DBQFDvRE4fFNSmcDyxYARAkleAJ9xu5TarrMAzUD+mACVLorgZfja8ACeKVtD
7C34kcdKMhJ/40mXFzydI7s=
=FakQ
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] tools/examples/svnshell.py

Posted by Peter Ericson <ar...@gmail.com>.
Good point; I had tested my fix by calling write method on a file
object instead of print.  I didn't test the patch because trunk
svnlook.py was incompatible with my installed bindings!

Thanks,

Peter

On 03/01/06, Max Bowsher <ma...@ukf.net> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> NotDashEscaped: You need GnuPG to verify this message
>
> Peter Ericson wrote:
> > * tools/examples/svnshell.py
> >   (do_cat): Fix endless loop that occurs when cat-ing files larger
> >   than core.SVN_STREAM_CHUNK_SIZE.
> > @@ -78,6 +78,7 @@
> >      stream = fs.file_contents(self.root, catpath)
> >      while filelen > core.SVN_STREAM_CHUNK_SIZE:
> >        print core.svn_stream_read(stream, int(core.SVN_STREAM_CHUNK_SIZE))
> > +      filelen -= core.SVN_STREAM_CHUNK_SIZE
> >      print core.svn_stream_read(stream, int(filelen))
>
> Thanks for the heads-up - actually, now you have drawn attention to that
> code, I see that it is even more buggy than you have noticed:
>
> It is using 'print', which will cause an extra newline to be inserted
> every SVN_STREAM_CHUNK_SIZE bytes, and at the end of the file. Also, it
> is unnecessarily using svn_fs_file_length, since it can just keep
> reading the stream until it gets a short read to indicate EOF.
>
> And, using int(core.SVN_STREAM_CHUNK_SIZE) is rather strange too -
> actually, does anyone know a reason for that? Was it working around some
> old Python bindings bug?
>
>
> Index: svnshell.py
> ===================================================================
> --- svnshell.py (revision 17951)
> +++ svnshell.py (working copy)
> @@ -74,11 +74,12 @@
>        print "Path '%s' is not a file." % catpath
>        return
>      ### be nice to get some paging in here.
> -    filelen = fs.file_length(self.root, catpath)
>      stream = fs.file_contents(self.root, catpath)
> -    while filelen > core.SVN_STREAM_CHUNK_SIZE:
> -      print core.svn_stream_read(stream, int(core.SVN_STREAM_CHUNK_SIZE))
> -    print core.svn_stream_read(stream, int(filelen))
> +    while 1:
> +      data = core.svn_stream_read(stream, core.SVN_STREAM_CHUNK_SIZE)
> +      sys.stdout.write(data)
> +      if len(data) < core.SVN_STREAM_CHUNK_SIZE:
> +        break
>
>    def do_cd(self, arg):
>      """change directory"""
>
> Max.
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.1 (Cygwin)
>
> iD8DBQFDuV9ZfFNSmcDyxYARAhhNAJwL7BGUvClyJXbyZVWqo2g+jj3j5QCeIKeP
> Oy9rzIouPW31etUhKauP6LQ=
> =aXph
> -----END PGP SIGNATURE-----
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org


Re: [PATCH] tools/examples/svnshell.py

Posted by Max Bowsher <ma...@ukf.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
NotDashEscaped: You need GnuPG to verify this message

Peter Ericson wrote:
> * tools/examples/svnshell.py
>   (do_cat): Fix endless loop that occurs when cat-ing files larger
>   than core.SVN_STREAM_CHUNK_SIZE.
> @@ -78,6 +78,7 @@
>      stream = fs.file_contents(self.root, catpath)
>      while filelen > core.SVN_STREAM_CHUNK_SIZE:
>        print core.svn_stream_read(stream, int(core.SVN_STREAM_CHUNK_SIZE))
> +      filelen -= core.SVN_STREAM_CHUNK_SIZE
>      print core.svn_stream_read(stream, int(filelen))

Thanks for the heads-up - actually, now you have drawn attention to that
code, I see that it is even more buggy than you have noticed:

It is using 'print', which will cause an extra newline to be inserted
every SVN_STREAM_CHUNK_SIZE bytes, and at the end of the file. Also, it
is unnecessarily using svn_fs_file_length, since it can just keep
reading the stream until it gets a short read to indicate EOF.

And, using int(core.SVN_STREAM_CHUNK_SIZE) is rather strange too -
actually, does anyone know a reason for that? Was it working around some
old Python bindings bug?


Index: svnshell.py
===================================================================
--- svnshell.py (revision 17951)
+++ svnshell.py (working copy)
@@ -74,11 +74,12 @@
       print "Path '%s' is not a file." % catpath
       return
     ### be nice to get some paging in here.
-    filelen = fs.file_length(self.root, catpath)
     stream = fs.file_contents(self.root, catpath)
-    while filelen > core.SVN_STREAM_CHUNK_SIZE:
-      print core.svn_stream_read(stream, int(core.SVN_STREAM_CHUNK_SIZE))
-    print core.svn_stream_read(stream, int(filelen))
+    while 1:
+      data = core.svn_stream_read(stream, core.SVN_STREAM_CHUNK_SIZE)
+      sys.stdout.write(data)
+      if len(data) < core.SVN_STREAM_CHUNK_SIZE:
+        break

   def do_cd(self, arg):
     """change directory"""

Max.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Cygwin)

iD8DBQFDuV9ZfFNSmcDyxYARAhhNAJwL7BGUvClyJXbyZVWqo2g+jj3j5QCeIKeP
Oy9rzIouPW31etUhKauP6LQ=
=aXph
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org