1. 14 6月, 2014 5 次提交
  2. 04 3月, 2014 1 次提交
  3. 25 2月, 2014 5 次提交
  4. 06 2月, 2014 1 次提交
  5. 24 1月, 2014 1 次提交
    • J
      read-cache: use get_be32 instead of hand-rolled ntoh_l · c3d8da57
      Jeff King 提交于
      Commit d60c49c2 (read-cache.c: allow unaligned mapping of the
      index file, 2012-04-03) introduced helpers to access
      unaligned data. However, we already have get_be32, which has
      a few advantages:
      
        1. It's already written, so we avoid duplication.
      
        2. It's probably faster, since it does the endian
           conversion and the alignment fix at the same time.
      
        3. The get_be32 code is well-tested, having been in
           block-sha1 for a long time. By contrast, our custom
           helpers were probably almost never used, since the user
           needed to manually define a macro to enable them.
      
      We have to add a get_be16 implementation to the existing
      get_be32, but that is very simple to do.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      c3d8da57
  6. 19 11月, 2013 2 次提交
    • 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
    • K
      name-hash.c: remove cache entries instead of marking them CE_UNHASHED · 419a597f
      Karsten Blees 提交于
      The new hashmap implementation supports remove, so really remove unused
      cache entries from the name hashmap instead of just marking them.
      
      The CE_UNHASHED flag and CE_STATE_MASK are no longer needed.
      
      Keep the CE_HASHED flag to prevent adding entries twice.
      Signed-off-by: NKarsten Blees <blees@dcon.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      419a597f
  7. 18 9月, 2013 2 次提交
    • E
      name-hash: stop storing trailing '/' on paths in index_state.dir_hash · d28eec26
      Eric Sunshine 提交于
      When 5102c617 (Add case insensitivity support for directories when using
      git status, 2010-10-03) added directories to the name-hash there was
      only a single hash table in which both real cache entries and leading
      directory prefixes were registered. To distinguish between the two types
      of entries, directories were stored with a trailing '/'.
      
      2092678c (name-hash.c: fix endless loop with core.ignorecase=true,
      2013-02-28), however, moved directories to a separate hash table
      (index_state.dir_hash) but retained the (now) redundant trailing '/',
      thus callers continue to bear the burden of ensuring the slash's
      presence before searching the index for a directory. Eliminate this
      redundancy by storing paths in the dir-hash without the trailing '/'.
      
      An important benefit of this change is that it eliminates undocumented
      and dangerous behavior of dir.c:directory_exists_in_index_icase() in
      which it assumes not only that it can validly access one character
      beyond the end of its incoming directory argument, but also that that
      character will unconditionally be a '/'. This perilous behavior was
      "tolerated" because the string passed in by its lone caller always had a
      '/' in that position, however, things broke [1] when 2eac2a4c (ls-files
      -k: a directory only can be killed if the index has a non-directory,
      2013-08-15) added a new caller which failed to respect the undocumented
      assumption.
      
      [1]: http://thread.gmane.org/gmane.comp.version-control.git/232727Signed-off-by: NEric Sunshine <sunshine@sunshineco.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      d28eec26
    • E
      employ new explicit "exists in index?" API · ebbd7439
      Eric Sunshine 提交于
      Each caller of index_name_exists() knows whether it is looking for a
      directory or a file, and can avoid the unnecessary indirection of
      index_name_exists() by instead calling index_dir_exists() or
      index_file_exists() directly.
      
      Invoking the appropriate search function explicitly will allow a
      subsequent patch to relieve callers of the artificial burden of having
      to add a trailing '/' to the pathname given to index_dir_exists().
      Signed-off-by: NEric Sunshine <sunshine@sunshineco.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      ebbd7439
  8. 29 8月, 2013 1 次提交
    • J
      write_index: optionally allow broken null sha1s · 83bd7437
      Jeff King 提交于
      Commit 4337b585 (do not write null sha1s to on-disk index,
      2012-07-28) added a safety check preventing git from writing
      null sha1s into the index. The intent was to catch errors in
      other parts of the code that might let such an entry slip
      into the index (or worse, a tree).
      
      Some existing repositories may have invalid trees that
      contain null sha1s already, though.  Until 4337b585, a common
      way to clean this up would be to use git-filter-branch's
      index-filter to repair such broken entries.  That now fails
      when filter-branch tries to write out the index.
      
      Introduce a GIT_ALLOW_NULL_SHA1 environment variable to
      relax this check and make it easier to recover from such a
      history.
      
      It is tempting to not involve filter-branch in this commit
      at all, and instead require the user to manually invoke
      
      	GIT_ALLOW_NULL_SHA1=1 git filter-branch ...
      
      to perform an index-filter on a history with trees with null
      sha1s.  That would be slightly safer, but requires some
      specialized knowledge from the user.  So let's set the
      GIT_ALLOW_NULL_SHA1 variable automatically when checking out
      the to-be-filtered trees.  Advice on using filter-branch to
      remove such entries already exists on places like
      stackoverflow, and this patch makes it Just Work again on
      recent versions of git.
      
      Further commands that touch the index will still notice and
      fail, unless they actually remove the broken entries.  A
      filter-branch whose filters do not touch the index at all
      will not error out (since we complain of the null sha1 only
      on writing, not when making a tree out of the index), but
      this is acceptable, as we still print a loud warning, so the
      problem is unlikely to go unnoticed.
      Signed-off-by: NJeff King <peff@peff.net>
      Reviewed-by: NJonathan Nieder <jrnieder@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      83bd7437
  9. 21 8月, 2013 1 次提交
  10. 30 7月, 2013 1 次提交
  11. 16 7月, 2013 1 次提交
  12. 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
  13. 21 6月, 2013 2 次提交
  14. 10 6月, 2013 1 次提交
    • R
      read-cache: free cache in discard_index · a0fc4db0
      René Scharfe 提交于
      discard_cache doesn't have to free the array of cache entries, because
      the next call of read_cache can simply reuse it, as they all operate on
      the global variable the_index.
      
      discard_index on the other hand does have to free it, because it can be
      used e.g. with index_state variables on the stack, in which case a
      missing free would cause an unrecoverable leak.  This patch releases the
      memory and removes a comment that was relevant for discard_cache but has
      become outdated.
      
      Since discard_cache is just a wrapper around discard_index nowadays, we
      lose the optimization that avoids reallocation of that array within
      loops of read_cache and discard_cache.  That doesn't cause a performance
      regression for me, however (HEAD = this patch, HEAD^ = master + p0002):
      
        Test           //              HEAD^             HEAD
        ---------------\\-----------------------------------------------------
        0002.1: read_ca// 1000 times   0.62(0.58+0.04)   0.61(0.58+0.02) -1.6%
      Suggested-by: NFelipe Contreras <felipe.contreras@gmail.com>
      Signed-off-by: NRené Scharfe <rene.scharfe@lsrfire.ath.cx>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      a0fc4db0
  15. 04 6月, 2013 2 次提交
  16. 03 6月, 2013 1 次提交
  17. 18 4月, 2013 2 次提交
  18. 28 2月, 2013 1 次提交
    • K
      name-hash.c: fix endless loop with core.ignorecase=true · 2092678c
      Karsten Blees 提交于
      With core.ignorecase=true, name-hash.c builds a case insensitive index of
      all tracked directories. Currently, the existing cache entry structures are
      added multiple times to the same hashtable (with different name lengths and
      hash codes). However, there's only one dir_next pointer, which gets
      completely messed up in case of hash collisions. In the worst case, this
      causes an endless loop if ce == ce->dir_next (see t7062).
      
      Use a separate hashtable and separate structures for the directory index
      so that each directory entry has its own next pointer. Use reference
      counting to track which directory entry contains files.
      
      There are only slight changes to the name-hash.c API:
      - new free_name_hash() used by read_cache.c::discard_index()
      - remove_name_hash() takes an additional index_state parameter
      - index_name_exists() for a directory (trailing '/') may return a cache
        entry that has been removed (CE_UNHASHED). This is not a problem as the
        return value is only used to check if the directory exists (dir.c) or to
        normalize casing of directory names (read-cache.c).
      
      Getting rid of cache_entry.dir_next reduces memory consumption, especially
      with core.ignorecase=false (which doesn't use that member at all).
      
      With core.ignorecase=true, building the directory index is slightly faster
      as we add / check the parent directory first (instead of going through all
      directory levels for each file in the index). E.g. with WebKit (~200k
      files, ~7k dirs), time spent in lazy_init_name_hash is reduced from 176ms
      to 130ms.
      Signed-off-by: NKarsten Blees <blees@dcon.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      2092678c
  19. 23 2月, 2013 1 次提交
  20. 23 1月, 2013 1 次提交
    • R
      Enable minimal stat checking · c08e4d5b
      Robin Rosenberg 提交于
      Specifically the fields uid, gid, ctime, ino and dev are set to zero
      by JGit. Other implementations, eg. Git in cygwin are allegedly also
      somewhat incompatible with Git For Windows and on *nix platforms
      the resolution of the timestamps may differ.
      
      Any stat checking by git will then need to check content, which may
      be very slow, particularly on Windows. Since mtime and size
      is typically enough we should allow the user to tell git to avoid
      checking these fields if they are set to zero in the index.
      
      This change introduces a core.checkstat config option where the
      the user can select to check all fields (default), or just size
      and the whole second part of mtime (minimal).
      Signed-off-by: NRobin Rosenberg <robin.rosenberg@dewire.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      c08e4d5b
  21. 16 9月, 2012 1 次提交
  22. 07 8月, 2012 1 次提交
  23. 30 7月, 2012 1 次提交
    • J
      do not write null sha1s to on-disk index · 4337b585
      Jeff King 提交于
      We should never need to write the null sha1 into an index
      entry (short of the 1 in 2^160 chance that somebody actually
      has content that hashes to it). If we attempt to do so, it
      is much more likely that it is a bug, since we use the null
      sha1 as a sentinel value to mean "not valid".
      
      The presence of null sha1s in the index (which can come
      from, among other things, "update-index --cacheinfo", or by
      reading a corrupted tree) can cause problems for later
      readers, because they cannot distinguish the literal null
      sha1 from its use a sentinel value.  For example, "git
      diff-files" on such an entry would make it appear as if it
      is stat-dirty, and until recently, the diff code assumed
      such an entry meant that we should be diffing a working tree
      file rather than a blob.
      
      Ideally, we would stop such entries from entering even our
      in-core index. However, we do sometimes legitimately add
      entries with null sha1s in order to represent these sentinel
      situations; simply forbidding them in add_index_entry breaks
      a lot of the existing code. However, we can at least make
      sure that our in-core sentinel representation never makes it
      to disk.
      
      To be thorough, we will test an attempt to add both a blob
      and a submodule entry. In the former case, we might run into
      problems anyway because we will be missing the blob object.
      But in the latter case, we do not enforce connectivity
      across gitlink entries, making this our only point of
      enforcement. The current implementation does not care which
      type of entry we are seeing, but testing both cases helps
      future-proof the test suite in case that changes.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      4337b585
  24. 12 7月, 2012 2 次提交
    • T
      Strip namelen out of ce_flags into a ce_namelen field · b60e188c
      Thomas Gummerer 提交于
      Strip the name length from the ce_flags field and move it
      into its own ce_namelen field in struct cache_entry. This
      will both give us a tiny bit of a performance enhancement
      when working with long pathnames and is a refactoring for
      more readability of the code.
      
      It enhances readability, by making it more clear what
      is a flag, and where the length is stored and make it clear
      which functions use stages in comparisions and which only
      use the length.
      
      It also makes CE_NAMEMASK private, so that users don't
      mistakenly write the name length in the flags.
      Signed-off-by: NThomas Gummerer <t.gummerer@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      b60e188c
    • J
      cache_name_compare(): do not truncate while comparing paths · d5f53338
      Junio C Hamano 提交于
      We failed to use ce_namelen() equivalent and instead only compared
      up to the CE_NAMEMASK bytes by mistake.  Adding an overlong path
      that shares the same common prefix as an existing entry in the index
      did not add a new entry, but instead replaced the existing one, as
      the result.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      d5f53338
  25. 09 7月, 2012 1 次提交
  26. 05 4月, 2012 1 次提交