1. 27 6月, 2018 1 次提交
  2. 12 6月, 2018 1 次提交
  3. 29 5月, 2018 1 次提交
  4. 21 5月, 2018 3 次提交
  5. 18 5月, 2018 1 次提交
  6. 16 5月, 2018 1 次提交
    • S
      object-store: move object access functions to object-store.h · cbd53a21
      Stefan Beller 提交于
      This should make these functions easier to find and cache.h less
      overwhelming to read.
      
      In particular, this moves:
      - read_object_file
      - oid_object_info
      - write_object_file
      
      As a result, most of the codebase needs to #include object-store.h.
      In this patch the #include is only added to files that would fail to
      compile otherwise.  It would be better to #include wherever
      identifiers from the header are used.  That can happen later
      when we have better tooling for it.
      Signed-off-by: NStefan Beller <sbeller@google.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      cbd53a21
  7. 06 5月, 2018 1 次提交
    • J
      Replace all die("BUG: ...") calls by BUG() ones · 033abf97
      Johannes Schindelin 提交于
      In d8193743 (usage.c: add BUG() function, 2017-05-12), a new macro
      was introduced to use for reporting bugs instead of die(). It was then
      subsequently used to convert one single caller in 588a538a
      (setup_git_env: convert die("BUG") to BUG(), 2017-05-12).
      
      The cover letter of the patch series containing this patch
      (cf 20170513032414.mfrwabt4hovujde2@sigill.intra.peff.net) is not
      terribly clear why only one call site was converted, or what the plan
      is for other, similar calls to die() to report bugs.
      
      Let's just convert all remaining ones in one fell swoop.
      
      This trick was performed by this invocation:
      
      	sed -i 's/die("BUG: /BUG("/g' $(git grep -l 'die("BUG' \*.c)
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      033abf97
  8. 24 4月, 2018 1 次提交
    • R
      push: colorize errors · 960786e7
      Ryan Dammrose 提交于
      This is an attempt to resolve an issue I experience with people that are
      new to Git -- especially colleagues in a team setting -- where they miss
      that their push to a remote location failed because the failure and
      success both return a block of white text.
      
      An example is if I push something to a remote repository and then a
      colleague attempts to push to the same remote repository and the push
      fails because it requires them to pull first, but they don't notice
      because a success and failure both return a block of white text. They
      then continue about their business, thinking it has been successfully
      pushed.
      
      This patch colorizes the errors and hints (in red and yellow,
      respectively) so whenever there is a failure when pushing to a remote
      repository that fails, it is more noticeable.
      
      [jes: fixed a couple bugs, added the color.{advice,push,transport}
      settings, refactored to use want_color_stderr().]
      
      Signed-off-by: Ryan Dammrose ryandammrose@gmail.com
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      960786e7
  9. 23 4月, 2018 1 次提交
  10. 16 4月, 2018 1 次提交
  11. 11 4月, 2018 2 次提交
  12. 09 4月, 2018 7 次提交
    • J
      git_config_set: reuse empty sections · c71d8bb3
      Johannes Schindelin 提交于
      It can happen quite easily that the last setting in a config section is
      removed, and to avoid confusion when there are comments in the config
      about that section, we keep a lone section header, i.e. an empty
      section.
      
      Now that we use the `event_fn` callback, it is easy to add support for
      re-using empty sections, so let's do that.
      
      Note: t5512-ls-remote requires that this change is applied *after* the
      patch "git config --unset: remove empty sections (in the common case)":
      without that patch, there would be empty `transfer` and `uploadpack`
      sections ready for reuse, but in the *wrong* order (and sconsequently,
      t5512's "overrides work between mixed transfer/upload-pack hideRefs"
      would fail).
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      c71d8bb3
    • J
      git config --unset: remove empty sections (in the common case) · 22aedfcc
      Johannes Schindelin 提交于
      The original reasoning for not removing section headers upon removal of
      the last entry went like this: the user could have added comments about
      the section, or about the entries therein, and if there were other
      comments there, we would not know whether we should remove them.
      
      In particular, a concocted example was presented that looked like this
      (and was added to t1300):
      
      	# some generic comment on the configuration file itself
      	# a comment specific to this "section" section.
      	[section]
      	# some intervening lines
      	# that should also be dropped
      
      	key = value
      	# please be careful when you update the above variable
      
      The ideal thing for `git config --unset section.key` in this case would
      be to leave only the first line behind, because all the other comments
      are now obsolete.
      
      However, this is unfeasible, short of adding a complete Natural Language
      Processing module to Git, which seems not only a lot of work, but a
      totally unreasonable feature (for little benefit to most users).
      
      Now, the real kicker about this problem is: most users do not edit their
      config files at all! In their use case, the config looks like this
      instead:
      
      	[section]
      		key = value
      
      ... and it is totally obvious what should happen if the entry is
      removed: the entire section should vanish.
      
      Let's generalize this observation to this conservative strategy: if we
      are removing the last entry from a section, and there are no comments
      inside that section nor surrounding it, then remove the entire section.
      Otherwise behave as before: leave the now-empty section (including those
      comments, even ones about the now-deleted entry).
      
      We have to be extra careful to handle the case where more than one entry
      is removed: any subset of them might be the last entries of their
      respective sections (and if there are no comments in or around that
      section, the section should be removed, too).
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      22aedfcc
    • J
      git_config_set: make use of the config parser's event stream · 6ae996f2
      Johannes Schindelin 提交于
      In the recent commit with the title "config: introduce an optional event
      stream while parsing", we introduced an optional callback to keep track
      of the config parser's events "comment", "white-space", "section header"
      and "entry".
      
      One motivation for this feature was to make use of it in the code that
      edits the config. And this commit makes it so.
      
      Note: this patch changes the meaning of the `seen` array that records
      whether we saw the config entry that is to be edited: previously, it
      contained the end offset of the found entry. Now, we introduce a new
      array `parsed` that keeps a record of *all* config parser events (with
      begin/end offsets), and the items in the `seen` array now point into the
      `parsed` array.
      
      There are two reasons why we do it this way:
      
      1. To keep the implementation simple, the config parser's event stream
         reports the event only after the config callback was called, so we
         would not receive the begin offset otherwise.
      
      2. In the following patches, we will re-use the `parsed` array to fix two
         long-standing bugs related to empty sections.
      
      Note that this also makes the code more robust with respect to finding the
      begin offset of the part(s) of the config file to be edited, as we no
      longer back-track to find the beginning of the line.
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      6ae996f2
    • J
      git_config_set: do not use a state machine · 5221c315
      Johannes Schindelin 提交于
      While a neat theoretical construct, state machines are hard to read. In
      this instance, it does not even make a whole lot of sense because we are
      more interested in flags, anyway: has the section been seen? Has the key
      been seen? Does the current section match the key we are looking for?
      
      Besides, the state `SECTION_SEEN` was named in a misleading way: it did
      not indicate that we saw the section matching the key we are looking
      for, but it instead indicated that we are *currently* in that section.
      
      Let's just replace the state machine logic by clear and obvious flags.
      
      This will also make it easier to review the upcoming patches to use the
      newly-introduced `event_fn` callback of the config parser.
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      5221c315
    • J
      config_set_store: rename some fields for consistency · 668b9ade
      Johannes Schindelin 提交于
      The `seen` field is the actual length of the `offset` array, and the
      `offset_alloc` field records what was allocated (to avoid resizing
      wherever `seen` has to be incremented).
      
      Elsewhere, we use the convention `name` for the array, where `name` is
      descriptive enough to guess its purpose, `name_nr` for the actual length
      and `name_alloc` to record the maximum length without needing to resize.
      
      Let's make the names of the fields in question consistent with that
      convention.
      
      This will also help with the next steps where we will let the
      git_config_set() machinery use the config event stream that we just
      introduced.
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      668b9ade
    • J
      config: avoid using the global variable `store` · fee8572c
      Johannes Schindelin 提交于
      It is much easier to reason about, when the config code to set/unset
      variables or to remove/rename sections does not rely on a global (or
      file-local) variable.
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      fee8572c
    • J
      config: introduce an optional event stream while parsing · 8032cc44
      Johannes Schindelin 提交于
      This extends our config parser so that it can optionally produce an event
      stream via callback function, where it reports e.g. when a comment was
      parsed, or a section header, etc.
      
      This parser will be used subsequently to handle the scenarios better where
      removing config entries would make sections empty, or where a new entry
      could be added to an already-existing, empty section.
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      8032cc44
  13. 06 4月, 2018 2 次提交
  14. 31 3月, 2018 1 次提交
    • J
      config: move flockfile() closer to unlocked functions · 05e293c1
      Jeff King 提交于
      Commit 260d408e (config: use getc_unlocked when reading
      from file, 2015-04-16) taught git_config_from_file() to lock
      the filehandle so that we could safely use the faster
      unlocked functions to access the handle.
      
      However, it split the logic into two places:
      
        1. The master lock/unlock happens in git_config_from_file().
      
        2. The decision to use the unlocked functions happens in
           do_config_from_file().
      
      That means that if anybody calls the latter function, they
      will accidentally use the unlocked functions without holding
      the lock. And indeed, git_config_from_stdin() does so.
      
      In practice, this hasn't been a problem since this code
      isn't generally multi-threaded (and even if some Git program
      happened to have another thread running, it's unlikely to be
      reading from stdin). But it's a good practice to make sure
      we're always holding the lock before using the unlocked
      functions.
      Helped-by: NJohannes Schindelin <Johannes.Schindelin@gmx.de>
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      05e293c1
  15. 15 3月, 2018 1 次提交
    • B
      sha1_file: convert read_sha1_file to struct object_id · b4f5aca4
      brian m. carlson 提交于
      Convert read_sha1_file to take a pointer to struct object_id and rename
      it read_object_file.  Do the same for read_sha1_file_extended.
      
      Convert one use in grep.c to use the new function without any other code
      change, since the pointer being passed is a void pointer that is already
      initialized with a pointer to struct object_id.  Update the declaration
      and definitions of the modified functions, and apply the following
      semantic patch to convert the remaining callers:
      
      @@
      expression E1, E2, E3;
      @@
      - read_sha1_file(E1.hash, E2, E3)
      + read_object_file(&E1, E2, E3)
      
      @@
      expression E1, E2, E3;
      @@
      - read_sha1_file(E1->hash, E2, E3)
      + read_object_file(E1, E2, E3)
      
      @@
      expression E1, E2, E3, E4;
      @@
      - read_sha1_file_extended(E1.hash, E2, E3, E4)
      + read_object_file_extended(&E1, E2, E3, E4)
      
      @@
      expression E1, E2, E3, E4;
      @@
      - read_sha1_file_extended(E1->hash, E2, E3, E4)
      + read_object_file_extended(E1, E2, E3, E4)
      Signed-off-by: Nbrian m. carlson <sandals@crustytoothpaste.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      b4f5aca4
  16. 17 1月, 2018 1 次提交
    • T
      convert_to_git(): safe_crlf/checksafe becomes int conv_flags · 8462ff43
      Torsten Bögershausen 提交于
      When calling convert_to_git(), the checksafe parameter defined what
      should happen if the EOL conversion (CRLF --> LF --> CRLF) does not
      roundtrip cleanly. In addition, it also defined if line endings should
      be renormalized (CRLF --> LF) or kept as they are.
      
      checksafe was an safe_crlf enum with these values:
      SAFE_CRLF_FALSE:       do nothing in case of EOL roundtrip errors
      SAFE_CRLF_FAIL:        die in case of EOL roundtrip errors
      SAFE_CRLF_WARN:        print a warning in case of EOL roundtrip errors
      SAFE_CRLF_RENORMALIZE: change CRLF to LF
      SAFE_CRLF_KEEP_CRLF:   keep all line endings as they are
      
      In some cases the integer value 0 was passed as checksafe parameter
      instead of the correct enum value SAFE_CRLF_FALSE. That was no problem
      because SAFE_CRLF_FALSE is defined as 0.
      
      FALSE/FAIL/WARN are different from RENORMALIZE and KEEP_CRLF. Therefore,
      an enum is not ideal. Let's use a integer bit pattern instead and rename
      the parameter to conv_flags to make it more generically usable. This
      allows us to extend the bit pattern in a subsequent commit.
      Reported-By: NRandall S. Becker <rsbecker@nexbridge.com>
      Helped-By: NLars Schneider <larsxschneider@gmail.com>
      Signed-off-by: NTorsten Bögershausen <tboegi@web.de>
      Signed-off-by: NLars Schneider <larsxschneider@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      8462ff43
  17. 09 12月, 2017 1 次提交
  18. 18 11月, 2017 2 次提交
    • R
      config: flip return value of write_section() · 782c030e
      René Scharfe 提交于
      d9bd4cbb (config: flip return value of store_write_*()) made
      write_section() follow the convention of write(2) to return -1 on error
      and the number of written bytes on success.  3b48045c (Merge branch
      'sd/branch-copy') changed it back to returning 0 on error and 1 on
      success, but left its callers still checking for negative values.
      
      Let write_section() follow the convention of write(2) again to meet the
      expectations of its callers.
      Reported-by: NJeff King <peff@peff.net>
      Signed-off-by: NRene Scharfe <l.s.r@web.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      782c030e
    • H
      config: add --expiry-date · 5f967424
      Haaris Mehmood 提交于
      Add --expiry-date as a data-type for config files when
      'git config --get' is used. This will return any relative
      or fixed dates from config files as timestamps.
      
      This is useful for scripts (e.g. gc.reflogexpire) that work
      with timestamps so that '2.weeks' can be converted to a format
      acceptable by those scripts/functions.
      
      Following the convention of git_config_pathname(), move
      the helper function required for this feature from
      builtin/reflog.c to builtin/config.c where other similar
      functions exist (e.g. for --bool or --path), and match
      the order of parameters with other functions (i.e. output
      pointer as first parameter).
      Signed-off-by: NHaaris Mehmood <hsed@unimetic.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      5f967424
  19. 16 11月, 2017 1 次提交
  20. 17 10月, 2017 1 次提交
    • J
      Revert "color: check color.ui in git_default_config()" · 33c643bb
      Jeff King 提交于
      This reverts commit 136c8c8b.
      
      That commit was trying to address a bug caused by 4c7f1819
      (make color.ui default to 'auto', 2013-06-10), in which
      plumbing like diff-tree defaulted to "auto" color, but did
      not respect a "color.ui" directive to disable it.
      
      But it also meant that we started respecting "color.ui" set
      to "always". This was a known problem, but 4c7f1819 argued
      that nobody ought to be doing that. However, that turned out
      to be wrong, and we got a number of bug reports related to
      "add -p" regressing in v2.14.2.
      
      Let's revert 136c8c8b, fixing the regression to "add -p".
      This leaves the problem from 4c7f1819 unfixed, but:
      
        1. It's a pretty obscure problem in the first place. I
           only noticed it while working on the color code, and we
           haven't got a single bug report or complaint about it.
      
        2. We can make a more moderate fix on top by respecting
           "never" but not "always" for plumbing commands. This
           is just the minimal fix to go back to the working state
           we had before v2.14.2.
      
      Note that this isn't a pure revert. We now have a test in
      t3701 which shows off the "add -p" regression. This can be
      flipped to success.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      33c643bb
  21. 06 10月, 2017 1 次提交
    • M
      treewide: prefer lockfiles on the stack · 837e34eb
      Martin Ågren 提交于
      There is no longer any need to allocate and leak a `struct lock_file`.
      The previous patch addressed an instance where we needed a minor tweak
      alongside the trivial changes.
      
      Deal with the remaining instances where we allocate and leak a struct
      within a single function. Change them to have the `struct lock_file` on
      the stack instead.
      
      These instances were identified by running `git grep "^\s*struct
      lock_file\s*\*"`.
      Signed-off-by: NMartin Ågren <martin.agren@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      837e34eb
  22. 01 10月, 2017 1 次提交
    • B
      fsmonitor: teach git to optionally utilize a file system monitor to speed up... · 883e248b
      Ben Peart 提交于
      fsmonitor: teach git to optionally utilize a file system monitor to speed up detecting new or changed files.
      
      When the index is read from disk, the fsmonitor index extension is used
      to flag the last known potentially dirty index entries. The registered
      core.fsmonitor command is called with the time the index was last
      updated and returns the list of files changed since that time. This list
      is used to flag any additional dirty cache entries and untracked cache
      directories.
      
      We can then use this valid state to speed up preload_index(),
      ie_match_stat(), and refresh_cache_ent() as they do not need to lstat()
      files to detect potential changes for those entries marked
      CE_FSMONITOR_VALID.
      
      In addition, if the untracked cache is turned on valid_cached_dir() can
      skip checking directories for new or changed files as fsmonitor will
      invalidate the cache only for those directories that have been
      identified as having potential changes.
      
      To keep the CE_FSMONITOR_VALID state accurate during git operations;
      when git updates a cache entry to match the current state on disk,
      it will now set the CE_FSMONITOR_VALID bit.
      
      Inversely, anytime git changes a cache entry, the CE_FSMONITOR_VALID bit
      is cleared and the corresponding untracked cache directory is marked
      invalid.
      Signed-off-by: NBen Peart <benpeart@microsoft.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      883e248b
  23. 22 9月, 2017 2 次提交
    • R
      071bcaab
    • J
      consistently use "fallthrough" comments in switches · 1cf01a34
      Jeff King 提交于
      Gcc 7 adds -Wimplicit-fallthrough, which can warn when a
      switch case falls through to the next case. The general idea
      is that the compiler can't tell if this was intentional or
      not, so you should annotate any intentional fall-throughs as
      such, leaving it to complain about any unannotated ones.
      
      There's a GNU __attribute__ which can be used for
      annotation, but of course we'd have to #ifdef it away on
      non-gcc compilers. Gcc will also recognize
      specially-formatted comments, which matches our current
      practice. Let's extend that practice to all of the
      unannotated sites (which I did look over and verify that
      they were behaving as intended).
      
      Ideally in each case we'd actually give some reasons in the
      comment about why we're falling through, or what we're
      falling through to. And gcc does support that with
      -Wimplicit-fallthrough=2, which relaxes the comment pattern
      matching to anything that contains "fallthrough" (or a
      variety of spelling variants). However, this isn't the
      default for -Wimplicit-fallthrough, nor for -Wextra. In the
      name of simplicity, it's probably better for us to support
      the default level, which requires "fallthrough" to be the
      only thing in the comment (modulo some window dressing like
      "else" and some punctuation; see the gcc manual for the
      complete set of patterns).
      
      This patch suppresses all warnings due to
      -Wimplicit-fallthrough. We might eventually want to add that
      to the DEVELOPER Makefile knob, but we should probably wait
      until gcc 7 is more widely adopted (since earlier versions
      will complain about the unknown warning type).
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      1cf01a34
  24. 14 9月, 2017 3 次提交
    • J
      config: flip return value of store_write_*() · d9bd4cbb
      Jeff King 提交于
      The store_write_section() and store_write_pairs() functions
      are basically high-level wrappers around write(). But their
      return values are flipped from our usual convention, using
      "1" for success and "0" for failure.
      
      Let's flip them to follow the usual write() conventions and
      update all callers. As these are local to config.c, it's
      unlikely that we'd have new callers in any topics in flight
      (which would be silently broken by our change). But just to
      be on the safe side, let's rename them to just
      write_section() and write_pairs().  That also accentuates
      their relationship with write().
      Signed-off-by: NJeff King <peff@peff.net>
      Reviewed-by: NJonathan Nieder <jrnieder@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      d9bd4cbb
    • J
      avoid "write_in_full(fd, buf, len) != len" pattern · 06f46f23
      Jeff King 提交于
      The return value of write_in_full() is either "-1", or the
      requested number of bytes[1]. If we make a partial write
      before seeing an error, we still return -1, not a partial
      value. This goes back to f6aa66cb (write_in_full: really
      write in full or return error on disk full., 2007-01-11).
      
      So checking anything except "was the return value negative"
      is pointless. And there are a couple of reasons not to do
      so:
      
        1. It can do a funny signed/unsigned comparison. If your
           "len" is signed (e.g., a size_t) then the compiler will
           promote the "-1" to its unsigned variant.
      
           This works out for "!= len" (unless you really were
           trying to write the maximum size_t bytes), but is a
           bug if you check "< len" (an example of which was fixed
           recently in config.c).
      
           We should avoid promoting the mental model that you
           need to check the length at all, so that new sites are
           not tempted to copy us.
      
        2. Checking for a negative value is shorter to type,
           especially when the length is an expression.
      
        3. Linus says so. In d34cf19b (Clean up write_in_full()
           users, 2007-01-11), right after the write_in_full()
           semantics were changed, he wrote:
      
             I really wish every "write_in_full()" user would just
             check against "<0" now, but this fixes the nasty and
             stupid ones.
      
           Appeals to authority aside, this makes it clear that
           writing it this way does not have an intentional
           benefit. It's a historical curiosity that we never
           bothered to clean up (and which was undoubtedly
           cargo-culted into new sites).
      
      So let's convert these obviously-correct cases (this
      includes write_str_in_full(), which is just a wrapper for
      write_in_full()).
      
      [1] A careful reader may notice there is one way that
          write_in_full() can return a different value. If we ask
          write() to write N bytes and get a return value that is
          _larger_ than N, we could return a larger total. But
          besides the fact that this would imply a totally broken
          version of write(), it would already invoke undefined
          behavior. Our internal remaining counter is an unsigned
          size_t, which means that subtracting too many byte will
          wrap it around to a very large number. So we'll instantly
          begin reading off the end of the buffer, trying to write
          gigabytes (or petabytes) of data.
      Signed-off-by: NJeff King <peff@peff.net>
      Reviewed-by: NJonathan Nieder <jrnieder@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      06f46f23
    • J
      config: avoid "write_in_full(fd, buf, len) < len" pattern · efacf609
      Jeff King 提交于
      The return type of write_in_full() is a signed ssize_t,
      because we may return "-1" on failure (even if we succeeded
      in writing some bytes). But "len" itself is may be an
      unsigned type (the function takes a size_t, but of course we
      may have something else in the calling function). So while
      it seems like:
      
        if (write_in_full(fd, buf, len) < len)
      	die_errno("write error");
      
      would trigger on error, it won't if "len" is unsigned.  The
      compiler sees a signed/unsigned comparison and promotes the
      signed value, resulting in (size_t)-1, the highest possible
      size_t (or again, whatever type the caller has). This cannot
      possibly be smaller than "len", and so the conditional can
      never trigger.
      
      I scoured the code base for cases of this, but it turns out
      that these two in git_config_set_multivar_in_file_gently()
      are the only ones. Here our "len" is the difference between
      two size_t variables, making the result an unsigned size_t.
      We can fix this by just checking for a negative return value
      directly, as write_in_full() will never return any value
      except -1 or the full count.
      
      There's no addition to the test suite here, since you need
      to convince write() to fail in order to see the problem. The
      simplest reproduction recipe I came up with is to trigger
      ENOSPC:
      
        # make a limited-size filesystem
        dd if=/dev/zero of=small.disk bs=1M count=1
        mke2fs small.disk
        mkdir mnt
        sudo mount -o loop small.disk mnt
        cd mnt
        sudo chown $USER:$USER .
      
        # make a config file with some content
        git config --file=config one.key value
        git config --file=config two.key value
      
        # now fill up the disk
        dd if=/dev/zero of=fill
      
        # and try to delete a key, which requires copying the rest
        # of the file to config.lock, and will fail on write()
        git config --file=config --unset two.key
      
      That final command should (and does after this patch)
      produce an error message due to the failed write, and leave
      the file intact. Instead, it silently ignores the failure
      and renames config.lock into place, leaving you with a
      totally empty config file!
      Reported-by: Ndemerphq <demerphq@gmail.com>
      Signed-off-by: NJeff King <peff@peff.net>
      Reviewed-by: NJonathan Nieder <jrnieder@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      efacf609
  25. 07 9月, 2017 1 次提交
  26. 06 9月, 2017 1 次提交
    • J
      stop leaking lock structs in some simple cases · bfffb48c
      Jeff King 提交于
      Now that it's safe to declare a "struct lock_file" on the
      stack, we can do so (and avoid an intentional leak). These
      leaks were found by running t0000 and t0001 under valgrind
      (though certainly other similar leaks exist and just don't
      happen to be exercised by those tests).
      
      Initializing the lock_file's inner tempfile with NULL is not
      strictly necessary in these cases, but it's a good practice
      to model.  It means that if we were to call a function like
      rollback_lock_file() on a lock that was never taken in the
      first place, it becomes a quiet noop (rather than undefined
      behavior).
      
      Likewise, it's always safe to rollback_lock_file() on a file
      that has already been committed or deleted, since that
      operation is a noop on an inactive lockfile (and that's why
      the case in config.c can drop the "if (lock)" check as we
      move away from using a pointer).
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      bfffb48c