1. 22 1月, 2009 3 次提交
    • J
      chain kill signals for cleanup functions · 4a16d072
      Jeff King 提交于
      If a piece of code wanted to do some cleanup before exiting
      (e.g., cleaning up a lockfile or a tempfile), our usual
      strategy was to install a signal handler that did something
      like this:
      
        do_cleanup(); /* actual work */
        signal(signo, SIG_DFL); /* restore previous behavior */
        raise(signo); /* deliver signal, killing ourselves */
      
      For a single handler, this works fine. However, if we want
      to clean up two _different_ things, we run into a problem.
      The most recently installed handler will run, but when it
      removes itself as a handler, it doesn't put back the first
      handler.
      
      This patch introduces sigchain, a tiny library for handling
      a stack of signal handlers. You sigchain_push each handler,
      and use sigchain_pop to restore whoever was before you in
      the stack.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      4a16d072
    • J
      diff: refactor tempfile cleanup handling · 479b0ae8
      Jeff King 提交于
      There are two pieces of code that create tempfiles for diff:
      run_external_diff and run_textconv. The former cleans up its
      tempfiles in the face of premature death (i.e., by die() or
      by signal), but the latter does not. After this patch, they
      will both use the same cleanup routines.
      
      To make clear what the change is, let me first explain what
      happens now:
      
        - run_external_diff uses a static global array of 2
          diff_tempfile structs (since it knows it will always
          need exactly 2 tempfiles). It calls prepare_temp_file
          (which doesn't know anything about the global array) on
          each of the structs, creating the tempfiles that need to
          be cleaned up. It then registers atexit and signal
          handlers to look through the global array and remove the
          tempfiles. If it succeeds, it calls the handler manually
          (which marks the tempfile structs as unused).
      
        - textconv has its own tempfile struct, which it allocates
          using prepare_temp_file and cleans up manually. No
          signal or atexit handlers.
      
      The new code moves the installation of cleanup handlers into
      the prepare_temp_file function. Which means that that
      function now has to understand that there is static tempfile
      storage. So what happens now is:
      
        - run_external_diff calls prepare_temp_file
        - prepare_temp_file calls claim_diff_tempfile, which
          allocates an unused slot from our global array
        - prepare_temp_file installs (if they have not already
          been installed) atexit and signal handlers for cleanup
        - prepare_temp_file sets up the tempfile as usual
        - prepare_temp_file returns a pointer to the allocated
          tempfile
      
      The advantage being that run_external_diff no longer has to
      care about setting up cleanup handlers. Now by virtue of
      calling prepare_temp_file, run_textconv gets the same
      benefit, as will any future users of prepare_temp_file.
      
      There are also a few side benefits to the specific
      implementation:
      
        - we now install cleanup handlers _before_ allocating the
          tempfile, closing a race which could leave temp cruft
      
        - when allocating a slot in the global array, we will now
          detect a situation where the old slots were not properly
          vacated (i.e., somebody forgot to call remove upon
          leaving the function). In the old code, such a situation
          would silently overwrite the tempfile names, meaning we
          would forget to clean them up. The new code dies with a
          bug warning.
      
        - we make sure only to install the signal handler once.
          This isn't a big deal, since we are just overwriting the
          old handler, but will become an issue when a later patch
          converts the code to use sigchain
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      479b0ae8
    • J
      Windows: Fix signal numbers · d2825065
      Johannes Sixt 提交于
      We had defined some SIG_FOO macros that appear in the code, but that are
      not supported on Windows, in order to make the code compile.  But a
      subsequent change will assert that a signal number is non-zero.  We now
      use the signal numbers that are commonly used on POSIX systems.
      Signed-off-by: NJohannes Sixt <j6t@kdbg.org>
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      d2825065
  2. 12 1月, 2009 1 次提交
  3. 11 1月, 2009 4 次提交
  4. 07 1月, 2009 14 次提交
  5. 06 1月, 2009 7 次提交
  6. 04 1月, 2009 4 次提交
  7. 03 1月, 2009 2 次提交
    • J
      builtin-apply: prevent non-explicit permission changes · 1f7903a3
      Junio C Hamano 提交于
      A git patch that does not change the executable bit records the mode bits
      on its "index" line.  "git apply" used to interpret this mode exactly the
      same way as it interprets the mode recorded on "new mode" line, as the
      wish by the patch submitter to set the mode to the one recorded on the
      line.
      
      The reason the mode does not agree between the submitter and the receiver
      in the first place is because there is _another_ commit that only appears
      on one side but not the other since their histories diverged, and that
      commit changes the mode.  The patch has "index" line but not "new mode"
      line because its change is about updating the contents without affecting
      the mode.  The application of such a patch is an explicit wish by the
      submitter to only cherry-pick the commit that updates the contents without
      cherry-picking the commit that modifies the mode.  Viewed this way, the
      current behaviour is problematic, even though the command does warn when
      the mode of the path being patched does not match this mode, and a careful
      user could detect this inconsistencies between the patch submitter and the
      patch receiver.
      
      This changes the semantics of the mode recorded on the "index" line;
      instead of interpreting it as the submitter's wish to set the mode to the
      recorded value, it merely informs what the mode submitter happened to
      have, and the presense of the "index" line is taken as submitter's wish to
      keep whatever the mode is on the receiving end.
      
      This is based on the patch originally done by Alexander Potashev with a
      minor fix; the tests are mine.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      1f7903a3
    • J
      git wrapper: Make while loop more reader-friendly · cca17048
      Johannes Schindelin 提交于
      It is not a good practice to prefer performance over readability in
      something as performance uncritical as finding the trailing slash
      of argv[0].
      
      So avoid head-scratching by making the loop user-readable, and not
      hyper-performance-optimized.
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      cca17048
  8. 01 1月, 2009 3 次提交
  9. 29 12月, 2008 2 次提交
    • J
      Merge branch 'lt/reset-merge' · c32f76f4
      Junio C Hamano 提交于
      * lt/reset-merge:
        Document "git-reset --merge"
        Add 'merge' mode to 'git reset'
      c32f76f4
    • J
      Merge branch 'np/auto-thread' · 78d4096d
      Junio C Hamano 提交于
      * np/auto-thread:
        Force t5302 to use a single thread
        pack-objects: don't use too many threads with few objects
        autodetect number of CPUs by default when using threads
      78d4096d