Thread (1 message) 1 message, 1 author, 2016-07-19

Re: Looking for help to understand external filter driver code

From: Junio C Hamano <hidden>
Date: 2016-07-19 17:56:09

Lars Schneider [off-list ref] writes:
a long time ago in aa4ed4 Junio introduced the external filter
driver definition. Since that time we fork the Git process and
then we fork again to run the external filter. This is probably a
super stupid question with an obvious answer... but can anyone
help me to understand the code and explain why we fork twice?
In "git show aa4ed4" you find this picture:

       /*
        * Create a pipeline to have the command filter the buffer's
        * contents.
        *
        * (child --> cmd) --> us
        */

where "child" is a fork of the original Git process; it still has
the <src, size> buffered data inherited from the original process,
so it can write_in_full() into the pipe going to the cmd process.
"us" is the original process that has the reading end of the pipe
that connects us to the "(child --> cmd)" processes, so that it can
read the filtered result from them.

The key benefit of this arrangement is the above can be done without
having to do poll() to flip between reading and writing that is
needed to avoid deadlocking, which kept the code simpler.  A later
conversion of the write side into async does not fundamentally
change anything from the original arrangement.





Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help