On Fri, 12 Jun 2020 20:53:20 +0200, Elmar Bartel wrote:
> > [...]
> >   ui0.pushbuffer()
> >   ui1 = ui0.copy(share_buffer=True)
> >   ...
> >   ui0.popbuffer()
> >   # ui1 may outlive and its buffer would be popped implicitly, which might
> >   # not always be what we want, but that's unavoidable.
> What could be done about this: 
> We record in ui._bufferstates[] (as fourth element) the ui which did
> the push and allow/do the pop only when it is done by the same ui.
> But this also would not fix all possible calling-sequence-scenrios
> and then its debatable whether this effort is worth it.

Another option is to create a shallow-copy of the buffers stack, so the
underlying buffer is shared, but the buffers stack itself isn't.

  newui._buffers = oldui._buffers[:]
  ...

Both oldui and newui can/should popbuffer() and will get the data between
oldui.pushbuffer() and self.popbuffer(). newui will remain buffered even
after oldui do popbuffer().

This behavior might be expected if oldui/newui aren't parent/child and should
work as if the underlying fout were replaced with the buffer. But that
wouldn't be always true. So I don't thinks there's the single best way to
implement buffer sharing.
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to