Skip to content
Commits on Mar 1, 2016
  1. @moy @gitster

    lockfile: improve error message when lockfile exists

    moy committed with gitster Mar 1, 2016
    A common mistake leading a user to see this message is to launch "git
    commit", let the editor open (and forget about it), and try again to
    commit.
    
    The previous message was going too quickly to "a git process crashed"
    and to the advice "remove the file manually".
    
    This patch modifies the message in two ways: first, it considers that
    "another process is running" is the norm, not the exception, and it
    explicitly hints the user to look at text editors.
    
    The message is 2 lines longer, but this is not a problem since
    experienced users do not see the message often.
    
    Helped-by: Moritz Neeb <lists@moritzneeb.de>
    Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
  2. @moy @gitster

    lockfile: mark strings for translation

    moy committed with gitster Mar 1, 2016
    Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Aug 28, 2015
  1. @ralfth @gitster

    lockfile: remove function "hold_lock_file_for_append"

    ralfth committed with gitster Aug 28, 2015
    With 77b9b1d (add_to_alternates_file: don't add duplicate entries,
    2015-08-10) the last caller of function "hold_lock_file_for_append"
    has been removed, so we can remove the function as well.
    
    Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com>
    Acked-by: Jeff King <peff@peff.net>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Aug 25, 2015
  1. @gitster

    Merge branch 'mh/tempfile'

    gitster committed Aug 25, 2015
    The "lockfile" API has been rebuilt on top of a new "tempfile" API.
    
    * mh/tempfile:
      credential-cache--daemon: use tempfile module
      credential-cache--daemon: delete socket from main()
      gc: use tempfile module to handle gc.pid file
      lock_repo_for_gc(): compute the path to "gc.pid" only once
      diff: use tempfile module
      setup_temporary_shallow(): use tempfile module
      write_shared_index(): use tempfile module
      register_tempfile(): new function to handle an existing temporary file
      tempfile: add several functions for creating temporary files
      prepare_tempfile_object(): new function, extracted from create_tempfile()
      tempfile: a new module for handling temporary files
      commit_lock_file(): use get_locked_file_path()
      lockfile: add accessor get_lock_file_path()
      lockfile: add accessors get_lock_file_fd() and get_lock_file_fp()
      create_bundle(): duplicate file descriptor to avoid closing it twice
      lockfile: move documentation to lockfile.h and lockfile.c
Commits on Aug 10, 2015
  1. @mhagger @gitster

    tempfile: a new module for handling temporary files

    mhagger committed with gitster Aug 10, 2015
    A lot of work went into defining the state diagram for lockfiles and
    ensuring correct, race-resistant cleanup in all circumstances.
    
    Most of that infrastructure can be applied directly to *any* temporary
    file. So extract a new "tempfile" module from the "lockfile" module.
    Reimplement lockfile on top of tempfile.
    
    Subsequent commits will add more users of the new module.
    
    Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
  2. @mhagger @gitster

    commit_lock_file(): use get_locked_file_path()

    mhagger committed with gitster Aug 10, 2015
    First beef up the sanity checking in get_locked_file_path() to match
    that in commit_lock_file(). Then rewrite commit_lock_file() to use
    get_locked_file_path() for its pathname computation.
    
    Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
  3. @mhagger @gitster

    lockfile: add accessor get_lock_file_path()

    mhagger committed with gitster Aug 10, 2015
    Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
  4. @mhagger @gitster

    lockfile: add accessors get_lock_file_fd() and get_lock_file_fp()

    mhagger committed with gitster Aug 10, 2015
    We are about to move those members, so change client code to read them
    through accessor functions.
    
    Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
  5. @mhagger @gitster

    lockfile: move documentation to lockfile.h and lockfile.c

    mhagger committed with gitster Aug 10, 2015
    Rearrange/rewrite it somewhat to fit its new environment.
    
    Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Jun 24, 2015
  1. @gitster

    Merge branch 'js/sleep-without-select'

    gitster committed Jun 24, 2015
    Portability fix.
    
    * js/sleep-without-select:
      lockfile: wait using sleep_millisec() instead of select()
      lockfile: convert retry timeout computations to millisecond
      help.c: wrap wait-only poll() invocation in sleep_millisec()
      lockfile: replace random() by rand()
Commits on Jun 5, 2015
  1. @j6t @gitster

    lockfile: wait using sleep_millisec() instead of select()

    j6t committed with gitster Jun 5, 2015
    Use the new function sleep_millisec() to delay execution for a short
    time. This avoids the invocation of select() with just a timeout, but
    no file descriptors. Such a use of select() is quit with EINVAL on
    Windows, leading to no delay at all.
    
    Signed-off-by: Johannes Sixt <j6t@kdbg.org>
    Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
  2. @j6t @gitster

    lockfile: convert retry timeout computations to millisecond

    j6t committed with gitster Jun 5, 2015
    When the goal is to wait for some random amount of time up to one
    second, it is not necessary to compute with microsecond precision.
    This is a preparation to re-use sleep_millisec().
    
    Signed-off-by: Johannes Sixt <j6t@kdbg.org>
    Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
  3. @j6t @gitster

    lockfile: replace random() by rand()

    j6t committed with gitster Jun 5, 2015
    On Windows, we do not have functions srandom() and random(). Use srand()
    and rand(). These functions produce random numbers of lesser quality,
    but for the purpose (a retry time-out) they are still good enough.
    
    Signed-off-by: Johannes Sixt <j6t@kdbg.org>
    Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on May 22, 2015
  1. @gitster

    Merge branch 'jc/ignore-epipe-in-filter'

    gitster committed May 22, 2015
    Filter scripts were run with SIGPIPE disabled on the Git side,
    expecting that they may not read what Git feeds them to filter.
    We however treated a filter that does not read its input fully
    before exiting as an error.
    
    This changes semantics, but arguably in a good way.  If a filter
    can produce its output without consuming its input using whatever
    magic, we now let it do so, instead of diagnosing it as a
    programming error.
    
    * jc/ignore-epipe-in-filter:
      filter_buffer_or_fd(): ignore EPIPE
      copy.c: make copy_fd() report its status silently
Commits on May 19, 2015
  1. @gitster

    copy.c: make copy_fd() report its status silently

    gitster committed May 19, 2015
    When copy_fd() function encounters errors, it emits error messages
    itself, which makes it impossible for callers to take responsibility
    for reporting errors, especially when they want to ignore certain
    errors.
    
    Move the error reporting to its callers in preparation.
    
     - copy_file() and copy_file_with_time() by indirection get their
       own calls to error().
    
     - hold_lock_file_for_append(), when told to die on error, used to
       exit(128) relying on the error message from copy_fd(), but now it
       does its own die() instead.  Note that the callers that do not
       pass LOCK_DIE_ON_ERROR need to be adjusted for this change, but
       fortunately there is none ;-)
    
     - filter_buffer_or_fd() has its own error() already, in addition to
       the message from copy_fd(), so this will change the output but
       arguably in a better way.
    
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on May 14, 2015
  1. @mhagger @gitster

    lockfile: allow file locking to be retried with a timeout

    mhagger committed with gitster May 11, 2015
    Currently, there is only one attempt to lock a file. If it fails, the
    whole operation fails.
    
    But it might sometimes be advantageous to try acquiring a file lock a
    few times before giving up. So add a new function,
    hold_lock_file_for_update_timeout(), that allows a timeout to be
    specified. Make hold_lock_file_for_update() a thin wrapper around the
    new function.
    
    If timeout_ms is positive, then retry for at least that many
    milliseconds to acquire the lock. On each failed attempt, use select()
    to wait for a backoff time that increases quadratically (capped at 1
    second) and has a random component to prevent two processes from
    getting synchronized. If timeout_ms is negative, retry indefinitely.
    
    In a moment we will switch to using the new function when locking
    packed-refs.
    
    Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Nov 3, 2014
  1. @pclouds @gitster

    lockfile.c: store absolute path

    pclouds committed with gitster Nov 2, 2014
    Locked paths can be saved in a linked list so that if something wrong
    happens, *.lock are removed. For relative paths, this works fine if we
    keep cwd the same, which is true 99% of time except:
    
    - update-index and read-tree hold the lock on $GIT_DIR/index really
      early, then later on may call setup_work_tree() to move cwd.
    
    - Suppose a lock is being held (e.g. by "git add") then somewhere
      down the line, somebody calls real_path (e.g. "link_alt_odb_entry"),
      which temporarily moves cwd away and back.
    
    During that time when cwd is moved (either permanently or temporarily)
    and we decide to die(), attempts to remove relative *.lock will fail,
    and the next operation will complain that some files are still locked.
    
    Avoid this case by turning relative paths to absolute before storing
    the path in "filename" field.
    
    Reported-by: Yue Lin Ho <yuelinho777@gmail.com>
    Helped-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
    Helped-by: Johannes Sixt <j6t@kdbg.org>
    Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
    Adapted-by: Michael Haggerty <mhagger@alum.mit.edu>
    Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Oct 15, 2014
  1. @jrn @gitster

    lockfile: remove unable_to_lock_error

    jrn committed with gitster Aug 28, 2014
    The former caller uses unable_to_lock_message now.
    
    Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
    Reviewed-by: Ronnie Sahlberg <sahlberg@google.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Commits on Oct 14, 2014
  1. @gitster

    Merge branch 'mh/lockfile-stdio'

    gitster committed Oct 14, 2014
    * mh/lockfile-stdio:
      commit_packed_refs(): reimplement using fdopen_lock_file()
      dump_marks(): reimplement using fdopen_lock_file()
      fdopen_lock_file(): access a lockfile using stdio
  2. @gitster

    Merge branch 'mh/lockfile'

    gitster committed Oct 14, 2014
    The lockfile API and its users have been cleaned up.
    
    * mh/lockfile: (38 commits)
      lockfile.h: extract new header file for the functions in lockfile.c
      hold_locked_index(): move from lockfile.c to read-cache.c
      hold_lock_file_for_append(): restore errno before returning
      get_locked_file_path(): new function
      lockfile.c: rename static functions
      lockfile: rename LOCK_NODEREF to LOCK_NO_DEREF
      commit_lock_file_to(): refactor a helper out of commit_lock_file()
      trim_last_path_component(): replace last_path_elm()
      resolve_symlink(): take a strbuf parameter
      resolve_symlink(): use a strbuf for internal scratch space
      lockfile: change lock_file::filename into a strbuf
      commit_lock_file(): use a strbuf to manage temporary space
      try_merge_strategy(): use a statically-allocated lock_file object
      try_merge_strategy(): remove redundant lock_file allocation
      struct lock_file: declare some fields volatile
      lockfile: avoid transitory invalid states
      git_config_set_multivar_in_file(): avoid call to rollback_lock_file()
      dump_marks(): remove a redundant call to rollback_lock_file()
      api-lockfile: document edge cases
      commit_lock_file(): rollback lock file on failure to rename
      ...
Commits on Oct 8, 2014
  1. @gitster

    Merge branch 'sp/stream-clean-filter'

    gitster committed Oct 8, 2014
    When running a required clean filter, we do not have to mmap the
    original before feeding the filter.  Instead, stream the file
    contents directly to the filter and process its output.
    
    * sp/stream-clean-filter:
      sha1_file: don't convert off_t to size_t too early to avoid potential die()
      convert: stream from fd to required clean filter to reduce used address space
      copy_fd(): do not close the input file descriptor
      mmap_limit: introduce GIT_MMAP_LIMIT to allow testing expected mmap size
      memory_limit: use git_env_ulong() to parse GIT_ALLOC_LIMIT
      config.c: add git_env_ulong() to parse environment variable
      convert: drop arguments other than 'path' from would_convert_to_git()
Commits on Oct 1, 2014
  1. @mhagger @gitster

    fdopen_lock_file(): access a lockfile using stdio

    mhagger committed with gitster Oct 1, 2014
    Add a new function, fdopen_lock_file(), which returns a FILE pointer
    open to the lockfile. If a stream is open on a lock_file object, it is
    closed using fclose() on commit, rollback, or close_lock_file().
    
    This change will allow callers to use stdio to write to a lockfile
    without having to muck around in the internal representation of the
    lock_file object (callers will be rewritten in upcoming commits).
    
    Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
  2. @mhagger @gitster

    lockfile.h: extract new header file for the functions in lockfile.c

    mhagger committed with gitster Oct 1, 2014
    Move the interface declaration for the functions in lockfile.c from
    cache.h to a new file, lockfile.h. Add #includes where necessary (and
    remove some redundant includes of cache.h by files that already
    include builtin.h).
    
    Move the documentation of the lock_file state diagram from lockfile.c
    to the new header file.
    
    Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
  3. @mhagger @gitster

    hold_locked_index(): move from lockfile.c to read-cache.c

    mhagger committed with gitster Oct 1, 2014
    lockfile.c contains the general API for locking any file. Code
    specifically about the index file doesn't belong here.
    
    Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
  4. @mhagger @gitster

    hold_lock_file_for_append(): restore errno before returning

    mhagger committed with gitster Oct 1, 2014
    Callers who don't pass LOCK_DIE_ON_ERROR might want to examine errno
    to see what went wrong, so restore errno before returning.
    
    In fact this function only has one caller, add_to_alternates_file(),
    and it *does* use LOCK_DIE_ON_ERROR, but, you know, think of future
    generations.
    
    Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
  5. @mhagger @gitster

    get_locked_file_path(): new function

    mhagger committed with gitster Oct 1, 2014
    Add a function to return the path of the file that is locked by a
    lock_file object. This reduces the knowledge that callers have to have
    about the lock_file layout.
    
    Suggested-by: Ronnie Sahlberg <sahlberg@google.com>
    Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
  6. @mhagger @gitster

    lockfile.c: rename static functions

    mhagger committed with gitster Oct 1, 2014
    * remove_lock_file() -> remove_lock_files()
    * remove_lock_file_on_signal() -> remove_lock_files_on_signal()
    
    Suggested-by: Torsten Bögershausen <tboegi@web.de>
    Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
  7. @mhagger @gitster

    lockfile: rename LOCK_NODEREF to LOCK_NO_DEREF

    mhagger committed with gitster Oct 1, 2014
    This makes it harder to misread the name as LOCK_NODE_REF.
    
    Suggested-by: Torsten Bögershausen <tboegi@web.de>
    Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
  8. @mhagger @gitster

    commit_lock_file_to(): refactor a helper out of commit_lock_file()

    mhagger committed with gitster Oct 1, 2014
    commit_locked_index(), when writing to an alternate index file,
    duplicates (poorly) the code in commit_lock_file(). And anyway, it
    shouldn't have to know so much about the internal workings of lockfile
    objects. So extract a new function commit_lock_file_to() that does the
    work common to the two functions, and call it from both
    commit_lock_file() and commit_locked_index().
    
    Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
  9. @mhagger @gitster

    trim_last_path_component(): replace last_path_elm()

    mhagger committed with gitster Oct 1, 2014
    Rewrite last_path_elm() to take a strbuf parameter and to trim off the
    last path name element in place rather than returning a pointer to the
    beginning of the last path name element. This simplifies the function
    a bit and makes it integrate better with its caller, which is now also
    strbuf-based. Rename the function accordingly and a bit less tersely.
    
    Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
  10. @mhagger @gitster

    resolve_symlink(): take a strbuf parameter

    mhagger committed with gitster Oct 1, 2014
    Change resolve_symlink() to take a strbuf rather than a string as
    parameter.  This simplifies the code and removes an arbitrary pathname
    length restriction.  It also means that lock_file's filename field no
    longer needs to be initialized to a large size.
    
    Helped-by: Torsten Bögershausen <tboegi@web.de>
    Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
  11. @mhagger @gitster

    resolve_symlink(): use a strbuf for internal scratch space

    mhagger committed with gitster Oct 1, 2014
    Aside from shortening and simplifying the code, this removes another
    place where the path name length is arbitrarily limited.
    
    Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
  12. @mhagger @gitster

    lockfile: change lock_file::filename into a strbuf

    mhagger committed with gitster Oct 1, 2014
    For now, we still make sure to allocate at least PATH_MAX characters
    for the strbuf because resolve_symlink() doesn't know how to expand
    the space for its return value.  (That will be fixed in a moment.)
    
    Another alternative would be to just use a strbuf as scratch space in
    lock_file() but then store a pointer to the naked string in struct
    lock_file.  But lock_file objects are often reused.  By reusing the
    same strbuf, we can avoid having to reallocate the string most times
    when a lock_file object is reused.
    
    Helped-by: Torsten Bögershausen <tboegi@web.de>
    Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
  13. @mhagger @gitster

    commit_lock_file(): use a strbuf to manage temporary space

    mhagger committed with gitster Oct 1, 2014
    Avoid relying on the filename length restrictions that are currently
    checked by lock_file().
    
    Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
  14. @mhagger @gitster

    struct lock_file: declare some fields volatile

    mhagger committed with gitster Oct 1, 2014
    The function remove_lock_file_on_signal() is used as a signal handler.
    It is not realistic to make the signal handler conform strictly to the
    C standard, which is very restrictive about what a signal handler is
    allowed to do.  But let's increase the likelihood that it will work:
    
    The lock_file_list global variable and several fields from struct
    lock_file are used by the signal handler.  Declare those values
    "volatile" to (1) force the main process to write the values to RAM
    promptly, and (2) prevent updates to these fields from being reordered
    in a way that leaves an opportunity for a jump to the signal handler
    while the object is in an inconsistent state.
    
    We don't mark the filename field volatile because that would prevent
    the use of strcpy(), and it is anyway unlikely that a compiler
    re-orders a strcpy() call across other expressions.  So in practice it
    should be possible to get away without "volatile" in the "filename"
    case.
    
    Suggested-by: Johannes Sixt <j6t@kdbg.org>
    Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Something went wrong with that request. Please try again.