1. 11 4月, 2018 1 次提交
  2. 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
  3. 09 12月, 2017 1 次提交
  4. 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
  5. 16 11月, 2017 1 次提交
  6. 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
  7. 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
  8. 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
  9. 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
  10. 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
  11. 07 9月, 2017 1 次提交
  12. 06 9月, 2017 2 次提交
    • 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
    • J
      config: use a static lock_file struct · f991761e
      Jeff King 提交于
      When modifying git config, we xcalloc() a struct lock_file
      but never free it. This is necessary because the tempfile
      code (upon which the locking code is built) requires that
      the resulting struct remain valid through the life of the
      program. However, it also confuses leak-checkers like
      valgrind because only the inner "struct tempfile" is still
      reachable; no pointer to the outer lock_file is kept.
      
      Other code paths solve this by using a single static lock
      struct. We can do the same here, because we know that we'll
      only lock and modify one config file at a time (and
      assertions within the lockfile code will ensure that this
      remains the case).
      
      That removes a real leak (when we fail to free the struct
      after locking fails) as well as removes the valgrind false
      positive. It also means that doing N sequential
      config-writes will use a constant amount of memory, rather
      than leaving stale lock_files for each.
      
      Note that since "lock" is no longer a pointer, it can't be
      NULL anymore. But that's OK. We used that feature only to
      avoid calling rollback_lock_file() on an already-committed
      lock. Since the lockfile code keeps its own "active" flag,
      it's a noop to rollback an inactive lock, and we don't have
      to worry about this ourselves.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      f991761e
  13. 23 8月, 2017 1 次提交
    • J
      rerere: allow approxidate in gc.rerereResolved/gc.rerereUnresolved · 6e96cb52
      Junio C Hamano 提交于
      These two configuration variables are described in the documentation
      to take an expiry period expressed in the number of days:
      
          gc.rerereResolved::
      	    Records of conflicted merge you resolved earlier are
      	    kept for this many days when 'git rerere gc' is run.
      	    The default is 60 days.
      
          gc.rerereUnresolved::
      	    Records of conflicted merge you have not resolved are
      	    kept for this many days when 'git rerere gc' is run.
      	    The default is 15 days.
      
      There is no strong reason not to allow a more general "approxidate"
      expiry specification, e.g. "5.days.ago", or "never".
      
      Rename the config_get_expiry() helper introduced in the previous
      step to git_config_get_expiry_in_days() and move it to a more
      generic place, config.c, and use date.c::parse_expiry_date() to do
      so.  Give it an ability to allow the caller to tell among three
      cases (i.e. there is no "gc.rerereResolved" config, there is and it
      is correctly parsed into the *expiry variable, and there was an
      error in parsing the given value).  The current caller can work
      correctly without using the return value, though.
      
      In the future, we may find other variables that only allow an
      integer that specifies "this many days" or other unit of time, and
      when it happens we may need to drop "_days" suffix from the name of
      the function and instead pass the "scale" value as another parameter.
      
      But this will do for now.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      6e96cb52
  14. 08 8月, 2017 3 次提交
    • M
      treewide: deprecate git_config_maybe_bool, use git_parse_maybe_bool · 89576613
      Martin Ågren 提交于
      The only difference between these is that the former takes an argument
      `name` which it ignores completely. Still, the callers are quite careful
      to provide reasonable values for it.
      
      Once in-flight topics have landed, we should be able to remove
      git_config_maybe_bool. In the meantime, document it as deprecated in the
      technical documentation. While at it, document git_parse_maybe_bool.
      Signed-off-by: NMartin Ågren <martin.agren@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      89576613
    • M
      config: make git_{config,parse}_maybe_bool equivalent · 46667418
      Martin Ågren 提交于
      Both of these act on a string `value` which they parse as a boolean. The
      "parse"-variant was introduced as a replacement for the "config"-variant
      which for historical reasons takes an unused argument `name`. That it
      was intended as a replacement is not obvious from commit 9a549d43
      ("config.c: rename git_config_maybe_bool_text and export it as
      git_parse_maybe_bool", 2015-08-19), but that is what the background on
      the mailing list suggests [1].
      
      However, these two functions do not parse `value` in exactly the same
      way. In particular, git_config_maybe_bool accepts integers (0 for false,
      non-0 for true). This means there are two slightly different definitions
      of "maybe_bool" in the code-base, and that every time a call to
      git_config_maybe_bool is changed to use git_parse_maybe_bool, it risks
      breaking someone's workflow.
      
      Move the implementation of "config" into "parse" and make the latter a
      trivial wrapper.
      
      This also fixes the only user of git_parse_maybe_bool, `git push
      --signed=..`.
      
      [1] https://public-inbox.org/git/xmqq7fotd71o.fsf@gitster.dls.corp.google.com/Signed-off-by: NMartin Ågren <martin.agren@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      46667418
    • M
      config: introduce git_parse_maybe_bool_text · 9be04d64
      Martin Ågren 提交于
      Commit 9a549d43 ("config.c: rename git_config_maybe_bool_text and export
      it as git_parse_maybe_bool", 2015-08-19) intended git_parse_maybe_bool
      to be a replacement for git_config_maybe_bool, which could then be
      retired. That is not obvious from the commit message, but that is what
      the background on the mailing list suggests [1].
      
      However, git_{config,parse}_maybe_bool do not handle all input the same.
      Before the rename, that was by design and there is a caller in config.c
      which requires git_parse_maybe_bool to behave exactly as it does.
      
      Prepare for the next patch by renaming git_parse_maybe_bool to ..._text
      and reimplementing the first one as a simple call to the second one. Let
      the existing users in config.c use ..._text, since it does what they
      need.
      
      [1] https://public-inbox.org/git/xmqq7fotd71o.fsf@gitster.dls.corp.google.com/Signed-off-by: NMartin Ågren <martin.agren@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      9be04d64
  15. 03 8月, 2017 1 次提交
  16. 18 7月, 2017 1 次提交
  17. 14 7月, 2017 1 次提交
    • J
      color: check color.ui in git_default_config() · 136c8c8b
      Jeff King 提交于
      Back in prehistoric times, our decision on whether or not to
      show color by default relied on using a config callback that
      either did or didn't load color config like color.diff.
      When we introduced color.ui, we put it in the same boat:
      commands had to manually respect it by using git_color_config()
      or its git_color_default_config() convenience wrapper.
      
      But in 4c7f1819 (make color.ui default to 'auto',
      2013-06-10), that changed. Since then, we default color.ui
      to auto in all programs, meaning that even plumbing commands
      like "git diff-tree --pretty" might colorize the output.
      Nobody seems to have complained in the intervening years,
      presumably because the "is stdout a tty" check does a good
      job of catching the right cases.
      
      But that leaves an interesting curiosity: color.ui defaults
      to auto even in plumbing, but you can't actually _disable_
      the color via config. So if you really hate color and set
      "color.ui" to false, diff-tree will still show color (but
      porcelain like git-diff won't).  Nobody noticed that either,
      probably because very few people disable color.
      
      One could argue that the plumbing should _always_ disable
      color unless an explicit --color option is given on the
      command line. But in practice, this creates a lot of
      complications for scripts which do want plumbing to show
      user-visible output. They can't just pass "--color" blindly;
      they need to check the user's config and decide what to
      send.
      
      Given that nobody has complained about the current behavior,
      let's assume it's a good path, and follow it to its
      conclusion: supporting color.ui everywhere.
      
      Note that you can create havoc by setting color.ui=always in
      your config, but that's more or less already the case. We
      could disallow it entirely, but it is handy for one-offs
      like:
      
        git -c color.ui=always foo >not-a-tty
      
      when "foo" does not take a --color option itself.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      136c8c8b
  18. 06 7月, 2017 1 次提交
  19. 01 7月, 2017 1 次提交
    • S
      hashmap.h: compare function has access to a data field · 7663cdc8
      Stefan Beller 提交于
      When using the hashmap a common need is to have access to caller provided
      data in the compare function. A couple of times we abuse the keydata field
      to pass in the data needed. This happens for example in patch-ids.c.
      
      This patch changes the function signature of the compare function
      to have one more void pointer available. The pointer given for each
      invocation of the compare function must be defined in the init function
      of the hashmap and is just passed through.
      
      Documentation of this new feature is deferred to a later patch.
      This is a rather mechanical conversion, just adding the new pass-through
      parameter.  However while at it improve the naming of the fields of all
      compare functions used by hashmaps by ensuring unused parameters are
      prefixed with 'unused_' and naming the parameters what they are (instead
      of 'unused' make it 'unused_keydata').
      Signed-off-by: NStefan Beller <sbeller@google.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      7663cdc8
  20. 24 6月, 2017 2 次提交
    • Æ
      wildmatch: remove unused wildopts parameter · 55d34269
      Ævar Arnfjörð Bjarmason 提交于
      Remove the unused wildopts placeholder struct from being passed to all
      wildmatch() invocations, or rather remove all the boilerplate NULL
      parameters.
      
      This parameter was added back in commit 9b3497ca ("wildmatch: rename
      constants and update prototype", 2013-01-01) as a placeholder for
      future use. Over 4 years later nothing has made use of it, let's just
      remove it. It can be added in the future if we find some reason to
      start using such a parameter.
      Signed-off-by: NÆvar Arnfjörð Bjarmason <avarab@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      55d34269
    • B
      config: read config from a repository object · 3b256228
      Brandon Williams 提交于
      Teach the config machinery to read config information from a repository
      object.  This involves storing a 'struct config_set' inside the
      repository object and adding a number of functions (repo_config*) to be
      able to query a repository's config.
      
      The current config API enables lazy-loading of the config.  This means
      that when 'git_config_get_int()' is called, if the_config_set hasn't
      been populated yet, then it will be populated and properly initialized by
      reading the necessary config files (system wide .gitconfig, user's home
      .gitconfig, and the repository's config).  To maintain this paradigm,
      the new API to read from a repository object's config will also perform
      this lazy-initialization.
      
      Since both APIs (git_config_get* and repo_config_get*) have the same
      semantics we can migrate the default config to be stored within
      'the_repository' and just have the 'git_config_get*' family of functions
      redirect to the 'repo_config_get*' functions.
      Signed-off-by: NBrandon Williams <bmwill@google.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      3b256228
  21. 19 6月, 2017 2 次提交
    • S
      branch: add a --copy (-c) option to go with --move (-m) · 52d59cc6
      Sahil Dua 提交于
      Add the ability to --copy a branch and its reflog and configuration,
      this uses the same underlying machinery as the --move (-m) option
      except the reflog and configuration is copied instead of being moved.
      
      This is useful for e.g. copying a topic branch to a new version,
      e.g. work to work-2 after submitting the work topic to the list, while
      preserving all the tracking info and other configuration that goes
      with the branch, and unlike --move keeping the other already-submitted
      branch around for reference.
      
      Like --move, when the source branch is the currently checked out
      branch the HEAD is moved to the destination branch. In the case of
      --move we don't really have a choice (other than remaining on a
      detached HEAD) and in order to keep the functionality consistent, we
      are doing it in similar way for --copy too.
      
      The most common usage of this feature is expected to be moving to a
      new topic branch which is a copy of the current one, in that case
      moving to the target branch is what the user wants, and doesn't
      unexpectedly behave differently than --move would.
      
      One outstanding caveat of this implementation is that:
      
          git checkout maint &&
          git checkout master &&
          git branch -c topic &&
          git checkout -
      
      Will check out 'maint' instead of 'master'. This is because the @{-N}
      feature (or its -1 shorthand "-") relies on HEAD reflogs created by
      the checkout command, so in this case we'll checkout maint instead of
      master, as the user might expect. What to do about that is left to a
      future change.
      Helped-by: NÆvar Arnfjörð Bjarmason <avarab@gmail.com>
      Signed-off-by: NÆvar Arnfjörð Bjarmason <avarab@gmail.com>
      Signed-off-by: NSahil Dua <sahildua2305@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      52d59cc6
    • S
      config: create a function to format section headers · 5463caab
      Sahil Dua 提交于
      Factor out the logic which creates section headers in the config file,
      e.g. the 'branch.foo' key will be turned into '[branch "foo"]'.
      
      This introduces no function changes, but is needed for a later change
      which adds support for copying branch sections in the config file.
      Signed-off-by: NÆvar Arnfjörð Bjarmason <avarab@gmail.com>
      Signed-off-by: NRamsay Jones <ramsay@ramsayjones.plus.com>
      Signed-off-by: NSahil Dua <sahildua2305@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      5463caab
  22. 17 6月, 2017 1 次提交
  23. 16 6月, 2017 5 次提交
    • B
      config: don't implicitly use gitdir or commondir · dc8441fd
      Brandon Williams 提交于
      'git_config_with_options()' takes a 'config_options' struct which
      contains feilds for 'git_dir' and 'commondir'.  If those feilds happen
      to be NULL the config machinery falls back to querying global repository
      state.  Let's change this and instead use these fields in the
      'config_options' struct explicilty all the time.  Since the API is
      slightly changing to require these two fields to be set if callers want
      the config machinery to load the repository's config, let's change the
      name to 'config_with_optison()'.  This allows the config machinery to
      not implicitly rely on any global repository state.
      Signed-off-by: NBrandon Williams <bmwill@google.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      dc8441fd
    • B
      config: respect commondir · a577fb5f
      Brandon Williams 提交于
      Worktrees present an interesting problem when it comes to the config.
      Historically we could assume that the per-repository config lives at
      'gitdir/config', but since worktrees were introduced this isn't the case
      anymore.  There is currently no way to specify per-worktree
      configuration, and as such the repository config is shared with all
      worktrees and is located at 'commondir/config'.
      
      Many users of the config machinery correctly set
      'config_options.git_dir' with the repository's commondir, allowing the
      config to be properly loaded when operating in a worktree.  But other's,
      like 'read_early_config()', set 'config_options.git_dir' with the
      repository's gitdir which can be incorrect when using worktrees.
      
      To fix this issue, and to make things less ambiguous, lets add a
      'commondir' field to the 'config_options' struct and have all callers
      properly set both the 'git_dir' and 'commondir' fields so that the
      config machinery is able to properly find the repository's config.
      Signed-off-by: NBrandon Williams <bmwill@google.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      a577fb5f
    • B
      setup: teach discover_git_directory to respect the commondir · d3fb71b3
      Brandon Williams 提交于
      Currently 'discover_git_directory' only looks at the gitdir to determine
      if a git directory was discovered.  This causes a problem in the event
      that the gitdir which was discovered was in fact a per-worktree git
      directory and not the common git directory.  This is because the
      repository config, which is checked to verify the repository's format,
      is stored in the commondir and not in the per-worktree gitdir.  Correct
      this behavior by checking the config stored in the commondir.
      
      It will also be of use for callers to have access to the commondir, so
      lets also return that upon successfully discovering a git directory.
      Signed-off-by: NBrandon Williams <bmwill@google.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      d3fb71b3
    • B
      config: don't include config.h by default · b2141fc1
      Brandon Williams 提交于
      Stop including config.h by default in cache.h.  Instead only include
      config.h in those files which require use of the config system.
      Signed-off-by: NBrandon Williams <bmwill@google.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      b2141fc1
    • J
      config: report correct line number upon error · e2e14251
      Johannes Schindelin 提交于
      When get_value() parses a key/value pair, it is possible that the line
      number is decreased (because the \n has been consumed already) before the
      key/value pair is passed to the callback function, to allow for the
      correct line to be attributed in case of an error.
      
      However, when git_parse_source() asks get_value() to parse the key/value
      pair, the error reporting is performed *after* get_value() returns.
      
      Which means that we have to be careful not to increase the line number
      in get_value() after the callback function returned an error.
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Reviewed-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      e2e14251
  24. 26 5月, 2017 2 次提交
  25. 17 5月, 2017 1 次提交
    • Æ
      config: match both symlink & realpath versions in IncludeIf.gitdir:* · 0624c63c
      Ævar Arnfjörð Bjarmason 提交于
      Change the conditional inclusion mechanism to support
      e.g. gitdir:~/git_tree/repo where ~/git_tree is a symlink to
      /mnt/stuff/repo.
      
      This worked in the initial version of this facility[1], but regressed
      later in the series while solving a related bug[2].
      
      Now gitdir: will match against the symlinked
      path (e.g. gitdir:~/git_tree/repo) in addition to the current
      /mnt/stuff/repo path.
      
      Since this is already in a release version note in the documentation
      that this behavior changed, so users who expect their configuration to
      work on both v2.13.0 and some future version of git with this fix
      aren't utterly confused.
      
      1. commit 3efd0bed ("config: add conditional include", 2017-03-01)
      2. commit 86f95157 ("config: resolve symlinks in conditional
         include's patterns", 2017-04-05)
      Signed-off-by: NÆvar Arnfjörð Bjarmason <avarab@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      0624c63c
  26. 08 5月, 2017 1 次提交