git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Add git-bundle: move objects and references by archive

From
Johannes Sixt <j.sixt@eudaptics.com>
Date
Feb 22, 2007, 09:31 UTC
Message-ID
<45DD62DF.9324130F@eudaptics.com>
In-Reply-To
<Pine.LNX.4.63.0702220157130.22628@wbgn013.biozentrum.uni-wuerzburg.de>
Johannes Schindelin wrote:
Show 52 quoted lines
> +/* if in && *in >= 0, take that as input file descriptor instead */
> +static int fork_with_pipe(const char **argv, int *in, int *out)
> +{
> +       int needs_in, needs_out;
> +       int fdin[2], fdout[2], pid;
> +
> +       needs_in = in && *in < 0;
> +       if (needs_in) {
> +               if (pipe(fdin) < 0)
> +                       return error("could not setup pipe");
> +               *in = fdin[1];
> +       }
> +
> +       needs_out = out && *out < 0;
> +       if (needs_out) {
> +               if (pipe(fdout) < 0)
> +                       return error("could not setup pipe");
> +               *out = fdout[0];
> +       }
> +
> +       if ((pid = fork()) < 0) {
> +               if (needs_in) {
> +                       close(fdin[0]);
> +                       close(fdin[1]);
> +               }
> +               if (needs_out) {
> +                       close(fdout[0]);
> +                       close(fdout[1]);
> +               }
> +               return error("could not fork");
> +       }
> +       if (!pid) {
> +               if (needs_in) {
> +                       dup2(fdin[0], 0);
> +                       close(fdin[0]);
> +                       close(fdin[1]);
> +               } else if (in)
> +                       dup2(*in, 0);
> +               if (needs_out) {
> +                       dup2(fdout[1], 1);
> +                       close(fdout[0]);
> +                       close(fdout[1]);
> +               } else if (out)
> +                       dup2(*out, 1);
> +               exit(execv_git_cmd(argv));
> +       }
> +       if (needs_in)
> +               close(fdin[0]);
> +       if (needs_out)
> +               close(fdout[1]);
> +       return pid;
> +}

This function looks very similar to spawnvppe, which I use in the MinGW port for a number of fork/exec pairs. Do you see a chance to make this into a helper that can be used in more places (so that it reduces the differences to the MinGW code)?

Show 13 quoted lines
> +       in = out = -1;
> +       pid = fork_with_pipe(argv, &in, &out);
> +       if (pid < 0)
> +               return error("Could not fork rev-list");
> +       if (!fork()) {
> +               for (i = 0; i < p->nr; i++) {
> +                       write(in, sha1_to_hex(p->list[i].sha1), 40);
> +                       write(in, "\n", 1);
> +               }
> +               close(in);
> +               exit(0);
> +       }
> +       close(in);
Oops, fork error check missing?
-- Hannes
Previous: Junio C HamanoNext: Johannes Schindelin
Message 22 of 28 in “Add git-bundle: move objects and references by archive”
  1. Add git-bundle: move objects and references by archiveJohannes Schindelin, Feb 22, 2007
  2. Nicolas PitreFeb 22, 2007
  3. Johannes SchindelinFeb 22, 2007
  4. Simon 'corecode' SchubertFeb 22, 2007
  5. Nicolas PitreFeb 22, 2007
  6. Johannes SchindelinFeb 22, 2007
  7. Simon 'corecode' SchubertFeb 22, 2007
  8. Johannes SchindelinFeb 22, 2007
  9. Nicolas PitreFeb 22, 2007
  10. Johannes SchindelinFeb 22, 2007
  11. Nicolas PitreFeb 22, 2007
  12. Junio C HamanoFeb 22, 2007
  13. Junio C HamanoFeb 22, 2007
  14. Johannes SchindelinFeb 22, 2007
  15. Junio C HamanoFeb 22, 2007
  16. Johannes SchindelinFeb 22, 2007
  17. Junio C HamanoFeb 22, 2007
  18. Johannes SchindelinFeb 22, 2007
  19. Johannes SchindelinFeb 22, 2007
  20. Mark LevedahlFeb 23, 2007
  21. Junio C HamanoFeb 23, 2007
  22. Johannes SixtFeb 22, 2007
  23. git-bundle: assorted fixesJohannes Schindelin, Feb 22, 2007
  24. Mark LevedahlFeb 23, 2007
  25. Johannes SchindelinFeb 23, 2007
  26. Mark LevedahlFeb 23, 2007
  27. Johannes SchindelinFeb 23, 2007
  28. Mark LevedahlFeb 23, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.