1. 24 8月, 2015 1 次提交
    • J
      config: silence warnings for command names with invalid keys · 9e9de18f
      Jeff King 提交于
      When we are running the git command "foo", we may have to
      look up the config keys "pager.foo" and "alias.foo". These
      config schemes are mis-designed, as the command names can be
      anything, but the config syntax has some restrictions. For
      example:
      
        $ git foo_bar
        error: invalid key: pager.foo_bar
        error: invalid key: alias.foo_bar
        git: 'foo_bar' is not a git command. See 'git --help'.
      
      You cannot name an alias with an underscore. And if you have
      an external command with one, you cannot configure its
      pager.
      
      In the long run, we may develop a different config scheme
      for these features. But in the near term (and because we'll
      need to support the existing scheme indefinitely), we should
      at least squelch the error messages shown above.
      
      These errors come from git_config_parse_key. Ideally we
      would pass a "quiet" flag to the config machinery, but there
      are many layers between the pager code and the key parsing.
      Passing a flag through all of those would be an invasive
      change.
      
      Instead, let's provide a config function to report on
      whether a key is syntactically valid, and have the pager and
      alias code skip lookup for bogus keys. We can build this
      easily around the existing git_config_parse_key, with two
      minor modifications:
      
        1. We now handle a NULL store_key, to validate but not
           write out the normalized key.
      
        2. We accept a "quiet" flag to avoid writing to stderr.
           This doesn't need to be a full-blown public "flags"
           field, because we can make the existing implementation
           a static helper function, keeping the mess contained
           inside config.c.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      9e9de18f
  2. 18 12月, 2014 2 次提交
    • J
      read-cache: optionally disallow NTFS .git variants · 2b4c6efc
      Johannes Schindelin 提交于
      The point of disallowing ".git" in the index is that we
      would never want to accidentally overwrite files in the
      repository directory. But this means we need to respect the
      filesystem's idea of when two paths are equal. The prior
      commit added a helper to make such a comparison for NTFS
      and FAT32; let's use it in verify_path().
      
      We make this check optional for two reasons:
      
        1. It restricts the set of allowable filenames, which is
           unnecessary for people who are not on NTFS nor FAT32.
           In practice this probably doesn't matter, though, as
           the restricted names are rather obscure and almost
           certainly would never come up in practice.
      
        2. It has a minor performance penalty for every path we
           insert into the index.
      
      This patch ties the check to the core.protectNTFS config
      option. Though this is expected to be most useful on Windows,
      we allow it to be set everywhere, as NTFS may be mounted on
      other platforms. The variable does default to on for Windows,
      though.
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      2b4c6efc
    • J
      read-cache: optionally disallow HFS+ .git variants · a42643aa
      Jeff King 提交于
      The point of disallowing ".git" in the index is that we
      would never want to accidentally overwrite files in the
      repository directory. But this means we need to respect the
      filesystem's idea of when two paths are equal. The prior
      commit added a helper to make such a comparison for HFS+;
      let's use it in verify_path.
      
      We make this check optional for two reasons:
      
        1. It restricts the set of allowable filenames, which is
           unnecessary for people who are not on HFS+. In practice
           this probably doesn't matter, though, as the restricted
           names are rather obscure and almost certainly would
           never come up in practice.
      
        2. It has a minor performance penalty for every path we
           insert into the index.
      
      This patch ties the check to the core.protectHFS config
      option. Though this is expected to be most useful on OS X,
      we allow it to be set everywhere, as HFS+ may be mounted on
      other platforms. The variable does default to on for OS X,
      though.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      a42643aa
  3. 18 11月, 2014 1 次提交
  4. 02 10月, 2014 3 次提交
  5. 12 9月, 2014 1 次提交
  6. 03 9月, 2014 1 次提交
  7. 29 8月, 2014 1 次提交
  8. 19 8月, 2014 1 次提交
    • T
      make config --add behave correctly for empty and NULL values · c8466645
      Tanay Abhra 提交于
      Currently if we have a config file like,
      [foo]
              baz
              bar =
      
      and we try something like, "git config --add foo.baz roll", Git will
      segfault. Moreover, for "git config --add foo.bar roll", it will
      overwrite the original value instead of appending after the existing
      empty value.
      
      The problem lies with the regexp used for simulating --add in
      `git_config_set_multivar_in_file()`, "^$", which in ideal case should
      not match with any string but is true for empty strings. Instead use a
      regexp like "a^" which can not be true for any string, empty or not.
      
      For removing the segfault add a check for NULL values in `matches()` in
      config.c.
      Signed-off-by: NTanay Abhra <tanayabh@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      c8466645
  9. 08 8月, 2014 6 次提交
  10. 06 8月, 2014 1 次提交
  11. 30 7月, 2014 1 次提交
    • T
      add `config_set` API for caching config-like files · 3c8687a7
      Tanay Abhra 提交于
      Currently `git_config()` uses a callback mechanism and file rereads for
      config values. Due to this approach, it is not uncommon for the config
      files to be parsed several times during the run of a git program, with
      different callbacks picking out different variables useful to themselves.
      
      Add a `config_set`, that can be used to construct an in-memory cache for
      config-like files that the caller specifies (i.e., files like `.gitmodules`,
      `~/.gitconfig` etc.). Add two external functions `git_configset_get_value`
      and `git_configset_get_value_multi` for querying from the config sets.
      `git_configset_get_value` follows `last one wins` semantic (i.e. if there
      are multiple matches for the queried key in the files of the configset the
      value returned will be the last entry in `value_list`).
      `git_configset_get_value_multi` returns a list of values sorted in order of
      increasing priority (i.e. last match will be at the end of the list). Add
      type specific query functions like `git_configset_get_bool` and similar.
      
      Add a default `config_set`, `the_config_set` to cache all key-value pairs
      read from usual config files (repo specific .git/config, user wide
      ~/.gitconfig, XDG config and the global /etc/gitconfig). `the_config_set`
      is populated using `git_config()`.
      
      Add two external functions `git_config_get_value` and
      `git_config_get_value_multi` for querying in a non-callback manner from
      `the_config_set`. Also, add type specific query functions that are
      implemented as a thin wrapper around the `config_set` API.
      Signed-off-by: NMatthieu Moy <Matthieu.Moy@imag.fr>
      Signed-off-by: NTanay Abhra <tanayabh@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      3c8687a7
  12. 25 7月, 2014 1 次提交
    • J
      fix memory leak parsing core.commentchar · 649409b7
      Jeff King 提交于
      When we see the core.commentchar config option, we extract
      the string with git_config_string, which does two things:
      
        1. It complains via config_error_nonbool if there is no
           string value.
      
        2. It makes a copy of the string.
      
      Since we immediately parse the string into its
      single-character value, we only care about (1). And in fact
      (2) is a detriment, as it means we leak the copy. Instead,
      let's just check the pointer value ourselves, and parse
      directly from the const string we already have.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      649409b7
  13. 17 7月, 2014 1 次提交
  14. 21 6月, 2014 1 次提交
    • J
      refactor skip_prefix to return a boolean · cf4fff57
      Jeff King 提交于
      The skip_prefix() function returns a pointer to the content
      past the prefix, or NULL if the prefix was not found. While
      this is nice and simple, in practice it makes it hard to use
      for two reasons:
      
        1. When you want to conditionally skip or keep the string
           as-is, you have to introduce a temporary variable.
           For example:
      
             tmp = skip_prefix(buf, "foo");
             if (tmp)
      	       buf = tmp;
      
        2. It is verbose to check the outcome in a conditional, as
           you need extra parentheses to silence compiler
           warnings. For example:
      
             if ((cp = skip_prefix(buf, "foo"))
      	       /* do something with cp */
      
      Both of these make it harder to use for long if-chains, and
      we tend to use starts_with() instead. However, the first line
      of "do something" is often to then skip forward in buf past
      the prefix, either using a magic constant or with an extra
      strlen(3) (which is generally computed at compile time, but
      means we are repeating ourselves).
      
      This patch refactors skip_prefix() to return a simple boolean,
      and to provide the pointer value as an out-parameter. If the
      prefix is not found, the out-parameter is untouched. This
      lets you write:
      
        if (skip_prefix(arg, "foo ", &arg))
      	  do_foo(arg);
        else if (skip_prefix(arg, "bar ", &arg))
      	  do_bar(arg);
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      cf4fff57
  15. 28 5月, 2014 2 次提交
  16. 24 5月, 2014 1 次提交
    • J
      strbuf: add strbuf_tolower function · ffb20ce1
      Jeff King 提交于
      This is a convenience wrapper to call tolower on each
      character of the string.
      
      This makes config's lowercase() function obsolete, though
      note that because we have a strbuf, we are careful to
      operate over the whole strbuf, rather than assuming that a
      NUL is the end-of-string.
      
      We could continue to offer a pure-string lowercase, but
      there would be no callers (in most pure-string cases, we
      actually duplicate and lowercase the duplicate, for which we
      have the xstrdup_tolower wrapper).
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      ffb20ce1
  17. 20 5月, 2014 2 次提交
  18. 07 5月, 2014 1 次提交
  19. 17 4月, 2014 1 次提交
  20. 19 2月, 2014 3 次提交
  21. 29 1月, 2014 1 次提交
    • J
      handle_path_include: don't look at NULL value · 67beb600
      Jeff King 提交于
      When we see config like:
      
        [include]
        path
      
      the expand_user_path helper notices that the config value is
      empty, but we then dereference NULL while printing the error
      message (glibc will helpfully print "(null)" for us here,
      but we cannot rely on that).
      
        $ git -c include.path rev-parse
        error: Could not expand include path '(null)'
        fatal: unable to parse command-line config
      
      Instead of tweaking our message, let's actually use
      config_error_nonbool to match other config variables that
      expect a value:
      
        $ git -c include.path rev-parse
        error: Missing value for 'include.path'
        fatal: unable to parse command-line config
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      67beb600
  22. 07 12月, 2013 1 次提交
  23. 06 12月, 2013 1 次提交
    • C
      replace {pre,suf}fixcmp() with {starts,ends}_with() · 59556548
      Christian Couder 提交于
      Leaving only the function definitions and declarations so that any
      new topic in flight can still make use of the old functions, replace
      existing uses of the prefixcmp() and suffixcmp() with new API
      functions.
      
      The change can be recreated by mechanically applying this:
      
          $ git grep -l -e prefixcmp -e suffixcmp -- \*.c |
            grep -v strbuf\\.c |
            xargs perl -pi -e '
              s|!prefixcmp\(|starts_with\(|g;
              s|prefixcmp\(|!starts_with\(|g;
              s|!suffixcmp\(|ends_with\(|g;
              s|suffixcmp\(|!ends_with\(|g;
            '
      
      on the result of preparatory changes in this series.
      Signed-off-by: NChristian Couder <chriscool@tuxfamily.org>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      59556548
  24. 15 10月, 2013 1 次提交
  25. 10 9月, 2013 4 次提交
    • J
      git-config: always treat --int as 64-bit internally · 00160242
      Jeff King 提交于
      When you run "git config --int", the maximum size of integer
      you get depends on how git was compiled, and what it
      considers to be an "int".
      
      This is almost useful, because your scripts calling "git
      config" will behave similarly to git internally. But relying
      on this is dubious; you have to actually know how git treats
      each value internally (e.g., int versus unsigned long),
      which is not documented and is subject to change. And even
      if you know it is "unsigned long", we do not have a
      git-config option to match that behavior.
      
      Furthermore, you may simply be asking git to store a value
      on your behalf (e.g., configuration for a hook). In that
      case, the relevant range check has nothing at all to do with
      git, but rather with whatever scripting tools you are using
      (and git has no way of knowing what the appropriate range is
      there).
      
      Not only is the range check useless, but it is actively
      harmful, as there is no way at all for scripts to look
      at config variables with large values. For instance, one
      cannot reliably get the value of pack.packSizeLimit via
      git-config. On an LP64 system, git happily uses a 64-bit
      "unsigned long" internally to represent the value, but the
      script cannot read any value over 2G.
      
      Ideally, the "--int" option would simply represent an
      arbitrarily large integer. For practical purposes, however,
      a 64-bit integer is large enough, and is much easier to
      implement (and if somebody overflows it, we will still
      notice the problem, and not simply return garbage).
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      00160242
    • J
      config: make numeric parsing errors more clear · 2f666581
      Jeff King 提交于
      If we try to parse an integer config argument and get a
      number outside of the representable range, we die with the
      cryptic message: "bad config value for '%s'".
      
      We can improve two things:
      
        1. Show the value that produced the error (e.g., bad
           config value '3g' for 'foo.bar').
      
        2. Mention the reason the value was rejected (e.g.,
           "invalid unit" versus "out of range").
      
      A few tests need to be updated with the new output, but that
      should not be representative of real-world breakage, as
      scripts should not be depending on the exact text of our
      stderr output, which is subject to i18n anyway.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      2f666581
    • J
      config: set errno in numeric git_parse_* functions · 33fdd77e
      Jeff King 提交于
      When we are parsing an integer or unsigned long, we use
      the strto*max functions, which properly set errno to ERANGE
      if we get a large value. However, we also do further range
      checks after applying our multiplication factor, but do not
      set ERANGE. This means that a caller cannot tell if an error
      was caused by ERANGE or if the input was simply not a valid
      number.
      
      This patch teaches git_parse_signed and git_parse_unsigned to set
      ERANGE for range errors, and EINVAL for other errors, so that the
      caller can reliably tell these cases apart.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      33fdd77e
    • J
      config: properly range-check integer values · 42d194e9
      Jeff King 提交于
      When we look at a config value as an integer using the
      git_config_int function, we carefully range-check the value
      we get and complain if it is out of our range. But the range
      we compare to is that of a "long", which we then cast to an
      "int" in the function's return value. This means that on
      systems where "int" and "long" have different sizes (e.g.,
      LP64 systems), we may pass the range check, but then return
      nonsense by truncating the value as we cast it to an int.
      
      We can solve this by converting git_parse_long into
      git_parse_int, and range-checking the "int" range. Nobody
      actually cared that we used a "long" internally, since the
      result was truncated anyway. And the only other caller of
      git_parse_long is git_config_maybe_bool, which should be
      fine to just use int (though we will now forbid out-of-range
      nonsense like setting "merge.ff" to "10g" to mean "true",
      which is probably a good thing).
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      42d194e9