You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Julian Foad <ju...@wandisco.com> on 2010/04/15 13:18:22 UTC

Mark/seek/reset problems in svn_subst_stream_translated()

I noticed some oddities/problems with the stream mark/seek/reset
functionality in svn_subst_stream_translated().

1.
svn_subst_stream_translated() doesn't handle mark/seek properly.
translated_stream_mark() saves and translated_stream_seek() restores
only the source stream's position, and not the internal state of
translation which it resets to "not in a translation".  This will work
properly only if the marked position is not inside a keyword or EOL.  It
needs to store (into the mark structure) the current state of
translation as well.

(An alternative could be to attach conditions to the use of mark/seek:
"this only works if you do XXX" - but I think that would be a Bad Thing.
The concept of streams works well precisely because we can layer
arbitrary streams on top of each other and expect them to work without
having to worry about such conditions.)

2.
translated_stream_seek() first flushes the output buffer, but
translated_stream_reset() doesn't.  I think that's a bug in _reset.

- Julian


Re: Mark/seek/reset problems in svn_subst_stream_translated()

Posted by Julian Foad <ju...@wandisco.com>.
Stefan Sperling wrote:
> On Thu, Apr 15, 2010 at 02:18:22PM +0100, Julian Foad wrote:
> > I noticed some oddities/problems with the stream mark/seek/reset
> > functionality in svn_subst_stream_translated().
> > 
> > 1.
> > svn_subst_stream_translated() doesn't handle mark/seek properly.
> > translated_stream_mark() saves and translated_stream_seek() restores
> > only the source stream's position, and not the internal state of
> > translation which it resets to "not in a translation".  This will work
> > properly only if the marked position is not inside a keyword or EOL.  It
> > needs to store (into the mark structure) the current state of
> > translation as well.
> > 
> > (An alternative could be to attach conditions to the use of mark/seek:
> > "this only works if you do XXX" - but I think that would be a Bad Thing.
> > The concept of streams works well precisely because we can layer
> > arbitrary streams on top of each other and expect them to work without
> > having to worry about such conditions.)
> > 
> > 2.
> > translated_stream_seek() first flushes the output buffer, but
> > translated_stream_reset() doesn't.  I think that's a bug in _reset.
> 
> I think I added this support and have probably made these mistakes.
> Can you file an issue to track these problems?

Filed as issues #3616
<http://subversion.tigris.org/issues/show_bug.cgi?id=3616>, #3617
<http://subversion.tigris.org/issues/show_bug.cgi?id=3617>.

- Julian


Re: Mark/seek/reset problems in svn_subst_stream_translated()

Posted by Stefan Sperling <st...@elego.de>.
On Thu, Apr 15, 2010 at 02:18:22PM +0100, Julian Foad wrote:
> I noticed some oddities/problems with the stream mark/seek/reset
> functionality in svn_subst_stream_translated().
> 
> 1.
> svn_subst_stream_translated() doesn't handle mark/seek properly.
> translated_stream_mark() saves and translated_stream_seek() restores
> only the source stream's position, and not the internal state of
> translation which it resets to "not in a translation".  This will work
> properly only if the marked position is not inside a keyword or EOL.  It
> needs to store (into the mark structure) the current state of
> translation as well.
> 
> (An alternative could be to attach conditions to the use of mark/seek:
> "this only works if you do XXX" - but I think that would be a Bad Thing.
> The concept of streams works well precisely because we can layer
> arbitrary streams on top of each other and expect them to work without
> having to worry about such conditions.)
> 
> 2.
> translated_stream_seek() first flushes the output buffer, but
> translated_stream_reset() doesn't.  I think that's a bug in _reset.

I think I added this support and have probably made these mistakes.
Can you file an issue to track these problems?

Thanks,
Stefan

-- 
Sent from my Nokia 1100

Re: Mark/seek/reset problems in svn_subst_stream_translated()

Posted by Stefan Sperling <st...@elego.de>.
On Thu, Apr 15, 2010 at 05:36:36PM +0100, Julian Foad wrote:
> I (Julian Foad) wrote:
> > The "line filter" and "line transformer": I don't think these fit the
> > stream abstraction at all well.  Streams don't have "lines" as a primary
> > concept.  Without going into the details, I think it can't play nicely
> > with plain reads and writes, and I doubt it's properly integrated with
> > mark/seek.
> 
> (That could be construed as a very rude thing to say, but I just meant
> that's something I think will be quite difficult to get right and it's
> still a doubt in my mind because I haven't studied it yet.)

I agree that the current way line filtering is done is suboptimal.

Maybe we should move all of that into functions wrapping
svn_stream_readline() within the diff parsing and patch code?

Stefan

-- 
Sent from my Nokia 1100

Re: Mark/seek/reset problems in svn_subst_stream_translated()

Posted by Julian Foad <ju...@wandisco.com>.
I (Julian Foad) wrote:
> The "line filter" and "line transformer": I don't think these fit the
> stream abstraction at all well.  Streams don't have "lines" as a primary
> concept.  Without going into the details, I think it can't play nicely
> with plain reads and writes, and I doubt it's properly integrated with
> mark/seek.

(That could be construed as a very rude thing to say, but I just meant
that's something I think will be quite difficult to get right and it's
still a doubt in my mind because I haven't studied it yet.)

- Julian


>   I think line filtering should be implemented as a wrapper
> stream instead.
> 
> - Julian


Re: Mark/seek/reset problems in svn_subst_stream_translated()

Posted by Julian Foad <ju...@wandisco.com>.
On Thu, 2010-04-15 at 17:59 +0200, Stefan Sperling wrote:
> On Thu, Apr 15, 2010 at 11:28:13AM -0400, Greg Stein wrote:
> > I'd suggest that we simply remove mark/seek/reset from the translated stream.
> 
> We could not handle keywords or newlines during patching if we did that.

Or, more accurately, we'd have to handle them a different way and that
would require substantial changes.  But I think mark and seek
functionality is a natural thing for streams to have, and the idea of
seekable and non-seekable streams already has common precedent in other
systems.

(Reset can be seen as a special case of seek.  I think it would be
better to just have a special mark value to pass to "seek" rather than
have a separate API, because that would help to emphasize and ensure
that it really does behave the same as seek, but that's not a big deal.)

> > (I was never comfortable with that extension to our streams in the
> > first place, and I don't see a reason that all streams must implement
> > them)
> 
> What is the alternative?
> 
> I used streams because the general trend was to go away from passing
> around naked APR file handles. I had to add some features to streams
> to use them for what I wanted to use them. So streams are used for
> more and more things and the original abstraction is being bent.
> 
> I don't really mind which way it's done, but we need some way of
> supporting the features we want to support.
> For patch, that means either using streams that support reading
> ranges from a file, support transformation on lines read from
> the stream, and have mark/seek/reset, or using naked APR
> files and passing around file handles and range information.
> 
> Realistically speaking, at this stage in the development cycle
> I'd much rather fix the mark/seek/reset support for translated
> streams than rewrite a lot of svn patch.

+1 to fixing and keeping mark/seek.

As for the other bits...

Reading a range from an APR file seems too specialized for a public API;
can we make it private for now?

The "line filter" and "line transformer": I don't think these fit the
stream abstraction at all well.  Streams don't have "lines" as a primary
concept.  Without going into the details, I think it can't play nicely
with plain reads and writes, and I doubt it's properly integrated with
mark/seek.  I think line filtering should be implemented as a wrapper
stream instead.

- Julian


> And I guess some people won't be happy if we make patch use raw
> files instead of streams (e.g. Bert suggested the public patch API
> should accept a stream to read the patch from, rather than accept
> an APR file as it does now).
> 
> Stefan


Re: Mark/seek/reset problems in svn_subst_stream_translated()

Posted by Stefan Sperling <st...@elego.de>.
On Thu, Apr 15, 2010 at 11:28:13AM -0400, Greg Stein wrote:
> I'd suggest that we simply remove mark/seek/reset from the translated stream.

We could not handle keywords or newlines during patching if we did that.

> (I was never comfortable with that extension to our streams in the
> first place, and I don't see a reason that all streams must implement
> them)

What is the alternative?

I used streams because the general trend was to go away from passing
around naked APR file handles. I had to add some features to streams
to use them for what I wanted to use them. So streams are used for
more and more things and the original abstraction is being bent.

I don't really mind which way it's done, but we need some way of
supporting the features we want to support.
For patch, that means either using streams that support reading
ranges from a file, support transformation on lines read from
the stream, and have mark/seek/reset, or using naked APR
files and passing around file handles and range information.

Realistically speaking, at this stage in the development cycle
I'd much rather fix the mark/seek/reset support for translated
streams than rewrite a lot of svn patch.

And I guess some people won't be happy if we make patch use raw
files instead of streams (e.g. Bert suggested the public patch API
should accept a stream to read the patch from, rather than accept
an APR file as it does now).

Stefan

Re: Mark/seek/reset problems in svn_subst_stream_translated()

Posted by Greg Stein <gs...@gmail.com>.
I'd suggest that we simply remove mark/seek/reset from the translated stream.

(I was never comfortable with that extension to our streams in the
first place, and I don't see a reason that all streams must implement
them)

Cheers,
-g

On Thu, Apr 15, 2010 at 09:18, Julian Foad <ju...@wandisco.com> wrote:
> I noticed some oddities/problems with the stream mark/seek/reset
> functionality in svn_subst_stream_translated().
>
> 1.
> svn_subst_stream_translated() doesn't handle mark/seek properly.
> translated_stream_mark() saves and translated_stream_seek() restores
> only the source stream's position, and not the internal state of
> translation which it resets to "not in a translation".  This will work
> properly only if the marked position is not inside a keyword or EOL.  It
> needs to store (into the mark structure) the current state of
> translation as well.
>
> (An alternative could be to attach conditions to the use of mark/seek:
> "this only works if you do XXX" - but I think that would be a Bad Thing.
> The concept of streams works well precisely because we can layer
> arbitrary streams on top of each other and expect them to work without
> having to worry about such conditions.)
>
> 2.
> translated_stream_seek() first flushes the output buffer, but
> translated_stream_reset() doesn't.  I think that's a bug in _reset.
>
> - Julian
>
>
>