1. 02 3月, 2018 1 次提交
    • M
      write_locked_index(): add flag to avoid writing unchanged index · 61000814
      Martin Ågren 提交于
      We have several callers like
      
      	if (active_cache_changed && write_locked_index(...))
      		handle_error();
      	rollback_lock_file(...);
      
      where the final rollback is needed because "!active_cache_changed"
      shortcuts the if-expression. There are also a few variants of this,
      including some if-else constructs that make it more clear when the
      explicit rollback is really needed.
      
      Teach `write_locked_index()` to take a new flag SKIP_IF_UNCHANGED and
      simplify the callers. Leave the most complicated of the callers (in
      builtin/update-index.c) unchanged. Rewriting it to use this new flag
      would end up duplicating logic.
      
      We could have made the new flag behave the other way round
      ("FORCE_WRITE"), but that could break existing users behind their backs.
      Let's take the more conservative approach. We can still migrate existing
      callers to use our new flag. Later we might even be able to flip the
      default, possibly without entirely ignoring the risk to in-flight or
      out-of-tree topics.
      Suggested-by: NJeff King <peff@peff.net>
      Signed-off-by: NMartin Ågren <martin.agren@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      61000814
  2. 13 12月, 2017 1 次提交
  3. 04 8月, 2017 1 次提交
  4. 03 8月, 2017 1 次提交
  5. 16 6月, 2017 1 次提交
  6. 30 5月, 2017 1 次提交
  7. 12 5月, 2017 1 次提交
  8. 14 2月, 2017 1 次提交
  9. 28 12月, 2016 2 次提交
    • S
      rm: absorb a submodules git dir before deletion · 55856a35
      Stefan Beller 提交于
      When deleting a submodule, we need to keep the actual git directory around,
      such that we do not lose local changes in there and at a later checkout
      of the submodule we don't need to clone it again.
      
      Now that the functionality is available to absorb the git directory of a
      submodule, rewrite the checking in git-rm to not complain, but rather
      relocate the git directories inside the superproject.
      
      An alternative solution was discussed to have a function
      `depopulate_submodule`. That would couple the check for its git directory
      and possible relocation before the the removal, such that it is less
      likely to miss the check in the future.  But the indirection with such
      a function added seemed also complex. The reason for that was that this
      possible move of the git directory was also implemented in
      `ok_to_remove_submodule`, such that this function could truthfully
      answer whether it is ok to remove the submodule.
      
      The solution proposed here defers all these checks to the caller.
      Signed-off-by: NStefan Beller <sbeller@google.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      55856a35
    • S
      submodule: rename and add flags to ok_to_remove_submodule · 83b76966
      Stefan Beller 提交于
      In different contexts the question "Is it ok to delete a submodule?"
      may be answered differently.
      
      In 293ab15e (submodule: teach rm to remove submodules unless they
      contain a git directory, 2012-09-26) a case was made that we can safely
      ignore ignored untracked files for removal as we explicitely ask for the
      removal of the submodule.
      
      In a later patch we want to remove submodules even when the user doesn't
      explicitly ask for it (e.g. checking out a tree-ish in which the submodule
      doesn't exist).  In that case we want to be more careful when it comes
      to deletion of untracked files. As of this patch it is unclear how this
      will be implemented exactly, so we'll offer flags in which the caller
      can specify how the different untracked files ought to be handled.
      
      As the flags allow the function to not die on an error when spawning
      a child process, we need to find an appropriate return code for the
      case when the child process could not be started. As in that case we
      cannot tell if the submodule is ok to remove, we'd want to return 'false'.
      
      As only 0 is understood as false, rename the function to invert the
      meaning, i.e. the return code of 0 signals the removal of the submodule
      is fine, and other values can be used to return a more precise answer
      what went wrong.
      Signed-off-by: NStefan Beller <sbeller@google.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      83b76966
  10. 08 12月, 2016 1 次提交
    • J
      hold_locked_index(): align error handling with hold_lockfile_for_update() · b3e83cc7
      Junio C Hamano 提交于
      Callers of the hold_locked_index() function pass 0 when they want to
      prepare to write a new version of the index file without wishing to
      die or emit an error message when the request fails (e.g. somebody
      else already held the lock), and pass 1 when they want the call to
      die upon failure.
      
      This option is called LOCK_DIE_ON_ERROR by the underlying lockfile
      API, and the hold_locked_index() function translates the paramter to
      LOCK_DIE_ON_ERROR when calling the hold_lock_file_for_update().
      
      Replace these hardcoded '1' with LOCK_DIE_ON_ERROR and stop
      translating.  Callers other than the ones that are replaced with
      this change pass '0' to the function; no behaviour change is
      intended with this patch.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      ---
      
      Among the callers of hold_locked_index() that passes 0:
      
       - diff.c::refresh_index_quietly() at the end of "git diff" is an
         opportunistic update; it leaks the lockfile structure but it is
         just before the program exits and nobody should care.
      
       - builtin/describe.c::cmd_describe(),
         builtin/commit.c::cmd_status(),
         sequencer.c::read_and_refresh_cache() are all opportunistic
         updates and they are OK.
      
       - builtin/update-index.c::cmd_update_index() takes a lock upfront
         but we may end up not needing to update the index (i.e. the
         entries may be fully up-to-date), in which case we do not need to
         issue an error upon failure to acquire the lock.  We do diagnose
         and die if we indeed need to update, so it is OK.
      
       - wt-status.c::require_clean_work_tree() IS BUGGY.  It asks
         silence, does not check the returned value.  Compare with
         callsites like cmd_describe() and cmd_status() to notice that it
         is wrong to call update_index_if_able() unconditionally.
      b3e83cc7
  11. 08 9月, 2016 2 次提交
  12. 13 7月, 2016 1 次提交
  13. 10 5月, 2016 1 次提交
  14. 13 4月, 2016 1 次提交
  15. 07 9月, 2015 1 次提交
  16. 21 5月, 2015 1 次提交
  17. 15 1月, 2015 1 次提交
  18. 02 10月, 2014 1 次提交
  19. 03 9月, 2014 1 次提交
  20. 14 6月, 2014 1 次提交
  21. 25 2月, 2014 1 次提交
  22. 19 11月, 2013 1 次提交
    • K
      read-cache.c: fix memory leaks caused by removed cache entries · 5699d17e
      Karsten Blees 提交于
      When cache_entry structs are removed from index_state.cache, they are not
      properly freed. Freeing those entries wasn't possible before because we
      couldn't remove them from index_state.name_hash.
      
      Now that we _do_ remove the entries from name_hash, we can also free them.
      Add 'free(cache_entry)' to all call sites of name-hash.c::remove_name_hash
      in read-cache.c (we could free() directly in remove_name_hash(), but
      name-hash.c isn't concerned with cache_entry allocation at all).
      
      Accessing a cache_entry after removing it from the index is now no longer
      allowed, as the memory has been freed. The following functions need minor
      fixes (typically by copying ce->name before use):
       - builtin/rm.c::cmd_rm
       - builtin/update-index.c::do_reupdate
       - read-cache.c::read_index_unmerged
       - resolve-undo.c::unmerge_index_entry_at
      Signed-off-by: NKarsten Blees <blees@dcon.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      5699d17e
  23. 14 9月, 2013 1 次提交
  24. 10 8月, 2013 1 次提交
    • S
      rm: remove unneeded null pointer check · f8aae0b5
      Stefan Beller 提交于
      As of 7612a1ef (2006-06-09 git-rm: honor -n flag.) the variable
      'pathspec' seems to be assumed to be never NULL after calling get_pathspec
      There was a NULL pointer check after the seen = NULL assignment, which
      was removed by that commit. So if pathspec would be NULL now, we'd segfault
      in the line accessing the pathspec:
      	for (i = 0; pathspec[i] ; i++)
      
      A few lines later, 'pathspec' still cannot be NULL, but that check was
      overlooked, hence removing it now.
      
      As the null pointer check was removed, it makes no sense to assign NULL
      to seen and 3 lines later another value as there are no conditions in
      between.
      Signed-off-by: NStefan Beller <stefanbeller@googlemail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      f8aae0b5
  25. 07 8月, 2013 1 次提交
    • J
      rm: delete .gitmodules entry of submodules removed from the work tree · 95c16418
      Jens Lehmann 提交于
      Currently using "git rm" on a submodule removes the submodule's work tree
      from that of the superproject and the gitlink from the index. But the
      submodule's section in .gitmodules is left untouched, which is a leftover
      of the now removed submodule and might irritate users (as opposed to the
      setting in .git/config, this must stay as a reminder that the user showed
      interest in this submodule so it will be repopulated later when an older
      commit is checked out).
      
      Let "git rm" help the user by not only removing the submodule from the
      work tree but by also removing the "submodule.<submodule name>" section
      from the .gitmodules file and stage both. This doesn't happen when the
      "--cached" option is used, as it would modify the work tree. This also
      silently does nothing when no .gitmodules file is found and only issues a
      warning when it doesn't have a section for this submodule. This is because
      the user might just use plain gitlinks without the .gitmodules file or has
      already removed the section by hand before issuing the "git rm" command
      (in which case the warning reminds him that rm would have done that for
      him). Only when .gitmodules is found and contains merge conflicts the rm
      command will fail and tell the user to resolve the conflict before trying
      again.
      
      Also extend the man page to inform the user about this new feature. While
      at it promote the submodule sub-section to a chapter as it made not much
      sense under "REMOVING FILES THAT HAVE DISAPPEARED FROM THE FILESYSTEM".
      
      In t7610 three uses of "git rm submod" had to be replaced with "git rm
      --cached submod" because that test expects .gitmodules and the work tree
      to stay untouched. Also in t7400 the tests for the remaining settings in
      the .gitmodules file had to be changed to assert that these settings are
      missing.
      Signed-off-by: NJens Lehmann <Jens.Lehmann@web.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      95c16418
  26. 06 8月, 2013 1 次提交
  27. 26 7月, 2013 1 次提交
  28. 24 7月, 2013 1 次提交
  29. 16 7月, 2013 2 次提交
  30. 10 7月, 2013 1 次提交
    • N
      Convert "struct cache_entry *" to "const ..." wherever possible · 9c5e6c80
      Nguyễn Thái Ngọc Duy 提交于
      I attempted to make index_state->cache[] a "const struct cache_entry **"
      to find out how existing entries in index are modified and where. The
      question I have is what do we do if we really need to keep track of on-disk
      changes in the index. The result is
      
       - diff-lib.c: setting CE_UPTODATE
      
       - name-hash.c: setting CE_HASHED
      
       - preload-index.c, read-cache.c, unpack-trees.c and
         builtin/update-index: obvious
      
       - entry.c: write_entry() may refresh the checked out entry via
         fill_stat_cache_info(). This causes "non-const struct cache_entry
         *" in builtin/apply.c, builtin/checkout-index.c and
         builtin/checkout.c
      
       - builtin/ls-files.c: --with-tree changes stagemask and may set
         CE_UPDATE
      
      Of these, write_entry() and its call sites are probably most
      interesting because it modifies on-disk info. But this is stat info
      and can be retrieved via refresh, at least for porcelain
      commands. Other just uses ce_flags for local purposes.
      
      So, keeping track of "dirty" entries is just a matter of setting a
      flag in index modification functions exposed by read-cache.c. Except
      unpack-trees, the rest of the code base does not do anything funny
      behind read-cache's back.
      
      The actual patch is less valueable than the summary above. But if
      anyone wants to re-identify the above sites. Applying this patch, then
      this:
      
          diff --git a/cache.h b/cache.h
          index 430d021..1692891 100644
          --- a/cache.h
          +++ b/cache.h
          @@ -267,7 +267,7 @@ static inline unsigned int canon_mode(unsigned int mode)
           #define cache_entry_size(len) (offsetof(struct cache_entry,name) + (len) + 1)
      
           struct index_state {
          -	struct cache_entry **cache;
          +	const struct cache_entry **cache;
           	unsigned int version;
           	unsigned int cache_nr, cache_alloc, cache_changed;
           	struct string_list *resolve_undo;
      
      will help quickly identify them without bogus warnings.
      Signed-off-by: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      9c5e6c80
  31. 13 6月, 2013 2 次提交
  32. 05 4月, 2013 1 次提交
    • J
      rm: do not complain about d/f conflicts during deletion · 9a6728d4
      Jeff King 提交于
      If we used to have an index entry "d/f", but "d" has been
      replaced by a non-directory entry, the user may still want
      to run "git rm" to delete the stale index entry. They could
      use "git rm --cached" to just touch the index, but "git rm"
      should also work: we explicitly try to handle the case that
      the file has already been removed from the working tree.
      
      However, because unlinking "d/f" in this case will not yield
      ENOENT, but rather ENOTDIR, we do not notice that the file
      is already gone. Instead, we report it as an error.
      
      The simple solution is to treat ENOTDIR in this case exactly
      like ENOENT; all we want to know is whether the file is
      already gone, and if a leading path is no longer a
      directory, then by definition the sub-path is gone.
      Reported-by: Njpinheiro <7jpinheiro@gmail.com>
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      9a6728d4
  33. 24 11月, 2012 1 次提交
    • J
      Teach rm to remove submodules when given with a trailing '/' · 53e4c5dc
      Jens Lehmann 提交于
      Doing a "git rm submod/" on a submodule results in an error:
      	fatal: pathspec 'submod/' did not match any files
      This is really inconvenient as e.g. using TAB completion in a shell on a
      submodule automatically adds the trailing '/' when it completes the path
      of the submodule directory. The user has then to remove the '/' herself to
      make a "git rm" succeed. Doing a "git rm -r somedir/" is working fine, so
      there is no reason why that shouldn't work for submodules too.
      
      Teach git rm to not error out when a '/' is appended to the path of a
      submodule. Achieve this by chopping off trailing slashes from the path
      names given if they represent directories. Add tests to make sure that
      logic only applies to directories and not to files.
      Signed-off-by: NJens Lehmann <Jens.Lehmann@web.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      53e4c5dc
  34. 30 9月, 2012 1 次提交
    • J
      submodule: teach rm to remove submodules unless they contain a git directory · 293ab15e
      Jens Lehmann 提交于
      Currently using "git rm" on a submodule - populated or not - fails with
      this error:
      
      	fatal: git rm: '<submodule path>': Is a directory
      
      This made sense in the past as there was no way to remove a submodule
      without possibly removing unpushed parts of the submodule's history
      contained in its .git directory too, so erroring out here protected the
      user from possible loss of data.
      
      But submodules cloned with a recent git version do not contain the .git
      directory anymore, they use a gitfile to point to their git directory
      which is safely stored inside the superproject's .git directory. The work
      tree of these submodules can safely be removed without losing history, so
      let's teach git to do so.
      
      Using rm on an unpopulated submodule now removes the empty directory from
      the work tree and the gitlink from the index. If the submodule's directory
      is missing from the work tree, it will still be removed from the index.
      
      Using rm on a populated submodule using a gitfile will apply the usual
      checks for work tree modification adapted to submodules (unless forced).
      For a submodule that means that the HEAD is the same as recorded in the
      index, no tracked files are modified and no untracked files that aren't
      ignored are present in the submodules work tree (ignored files are deemed
      expendable and won't stop a submodule's work tree from being removed).
      That logic has to be applied in all nested submodules too.
      
      Using rm on a submodule which has its .git directory inside the work trees
      top level directory will just error out like it did before to protect the
      repository, even when forced. In the future git could either provide a
      message informing the user to convert the submodule to use a gitfile or
      even attempt to do the conversion itself, but that is not part of this
      change.
      Signed-off-by: NJens Lehmann <Jens.Lehmann@web.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      293ab15e
  35. 21 8月, 2012 1 次提交
  36. 10 3月, 2011 1 次提交