1. 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
  2. 17 7月, 2014 1 次提交
  3. 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
  4. 28 5月, 2014 2 次提交
  5. 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
  6. 20 5月, 2014 2 次提交
  7. 07 5月, 2014 1 次提交
  8. 17 4月, 2014 1 次提交
  9. 19 2月, 2014 3 次提交
  10. 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
  11. 07 12月, 2013 1 次提交
  12. 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
  13. 15 10月, 2013 1 次提交
  14. 10 9月, 2013 5 次提交
    • 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
    • J
      config: factor out integer parsing from range checks · 7192777d
      Jeff King 提交于
      When we are parsing integers for config, we use an intmax_t
      (or uintmax_t) internally, and then check against the size
      of our result type at the end. We can parameterize the
      maximum representable value, which will let us re-use the
      parsing code for a variety of range checks.
      
      Unfortunately, we cannot combine the signed and unsigned
      parsing functions easily, as we have to rely on the signed
      and unsigned C types internally.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      7192777d
  15. 27 8月, 2013 1 次提交
    • J
      config: do not use C function names as struct members · 49d6cfa5
      Jeff King 提交于
      According to C99, section 7.1.4:
      
        Any function declared in a header may be additionally
        implemented as a function-like macro defined in the
        header.
      
      Therefore calling our struct member function pointer "fgetc"
      may run afoul of unwanted macro expansion when we call:
      
        char c = cf->fgetc(cf);
      
      This turned out to be a problem on uclibc, which defines
      fgetc as a macro and causes compilation failure.
      
      The standard suggests fixing this in a few ways:
      
        1. Using extra parentheses to inhibit the function-like
           macro expansion. E.g., "(cf->fgetc)(cf)". This is
           undesirable as it's ugly, and each call site needs to
           remember to use it (and on systems without the macro,
           forgetting will compile just fine).
      
        2. Using #undef (because a conforming implementation must
           also be providing fgetc as a function). This is
           undesirable because presumably the implementation was
           using the macro for a performance benefit, and we are
           dropping that optimization.
      
      Instead, we can simply use non-colliding names.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      49d6cfa5
  16. 13 7月, 2013 5 次提交
  17. 10 6月, 2013 1 次提交
  18. 07 5月, 2013 2 次提交
  19. 15 4月, 2013 1 次提交
    • J
      config: allow inaccessible configuration under $HOME · 4698c8fe
      Jonathan Nieder 提交于
      The changes v1.7.12.1~2^2~4 (config: warn on inaccessible files,
      2012-08-21) and v1.8.1.1~22^2~2 (config: treat user and xdg config
      permission problems as errors, 2012-10-13) were intended to prevent
      important configuration (think "[transfer] fsckobjects") from being
      ignored when the configuration is unintentionally unreadable (for
      example with EIO on a flaky filesystem, or with ENOMEM due to a DoS
      attack).  Usually ~/.gitconfig and ~/.config/git are readable by the
      current user, and if they aren't then it would be easy to fix those
      permissions, so the damage from adding this check should have been
      minimal.
      
      Unfortunately the access() check often trips when git is being run as
      a server.  A daemon (such as inetd or git-daemon) starts as "root",
      creates a listening socket, and then drops privileges, meaning that
      when git commands are invoked they cannot access $HOME and die with
      
       fatal: unable to access '/root/.config/git/config': Permission denied
      
      Any patch to fix this would have one of three problems:
      
        1. We annoy sysadmins who need to take an extra step to handle HOME
           when dropping privileges (the current behavior, or any other
           proposal that they have to opt into).
      
        2. We annoy sysadmins who want to set HOME when dropping privileges,
           either by making what they want to do impossible, or making them
           set an extra variable or option to accomplish what used to work
           (e.g., a patch to git-daemon to set HOME when --user is passed).
      
        3. We loosen the check, so some cases which might be noteworthy are
           not caught.
      
      This patch is of type (3).
      
      Treat user and xdg configuration that are inaccessible due to
      permissions (EACCES) as though no user configuration was provided at
      all.
      
      An alternative method would be to check if $HOME is readable, but that
      would not help in cases where the user who dropped privileges had a
      globally readable HOME with only .config or .gitconfig being private.
      
      This does not change the behavior when /etc/gitconfig or .git/config
      is unreadable (since those are more serious configuration errors),
      nor when ~/.gitconfig or ~/.config/git is unreadable due to problems
      other than permissions.
      Signed-off-by: NJonathan Nieder <jrnieder@gmail.com>
      Improved-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      4698c8fe
  20. 24 1月, 2013 1 次提交
  21. 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
  22. 17 1月, 2013 1 次提交
    • J
      Allow custom "comment char" · eff80a9f
      Junio C Hamano 提交于
      Some users do want to write a line that begin with a pound sign, #,
      in their commit log message.  Many tracking system recognise
      a token of #<bugid> form, for example.
      
      The support we offer these use cases is not very friendly to the end
      users.  They have a choice between
      
       - Don't do it.  Avoid such a line by rewrapping or indenting; and
      
       - Use --cleanup=whitespace but remove all the hint lines we add.
      
      Give them a way to set a custom comment char, e.g.
      
          $ git -c core.commentchar="%" commit
      
      so that they do not have to do either of the two workarounds.
      
      [jc: although I started the topic, all the tests and documentation
      updates, many of the call sites of the new strbuf_add_commented_*()
      functions, and the change to git-submodule.sh scripted Porcelain are
      from Ralf.]
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      Signed-off-by: NRalf Thielow <ralf.thielow@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      eff80a9f
  23. 16 12月, 2012 1 次提交
    • J
      silence some -Wuninitialized false positives · a469a101
      Jeff King 提交于
      There are a few error functions that simply wrap error() and
      provide a standardized message text. Like error(), they
      always return -1; knowing that can help the compiler silence
      some false positive -Wuninitialized warnings.
      
      One strategy would be to just declare these as inline in the
      header file so that the compiler can see that they always
      return -1. However, gcc does not always inline them (e.g.,
      it will not inline opterror, even with -O3), which renders
      our change pointless.
      
      Instead, let's follow the same route we did with error() in
      the last patch, and define a macro that makes the constant
      return value obvious to the compiler.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      a469a101
  24. 13 12月, 2012 1 次提交
  25. 24 10月, 2012 1 次提交
    • J
      git-config: fix regexp memory leaks on error conditions · 97ed50f9
      Jeff King 提交于
      The get_value function has a goto label for cleaning up on
      errors, but it only cleans up half of what the function
      might allocate. Let's also clean up the key and regexp
      variables there.
      
      Note that we need to take special care when compiling the
      regex fails to clean it up ourselves, since it is in a
      half-constructed state (we would want to free it, but not
      regfree it).
      
      Similarly, we fix git_config_parse_key to return NULL when
      it fails, not a pointer to some already-freed memory.
      Signed-off-by: NJeff King <peff@peff.net>
      97ed50f9
  26. 15 10月, 2012 1 次提交
    • J
      config: exit on error accessing any config file · 8f2bbe45
      Jonathan Nieder 提交于
      There is convenience in warning and moving on when somebody has a
      bogus permissions on /etc/gitconfig and cannot do anything about it.
      But the cost in predictability and security is too high --- when
      unreadable config files are skipped, it means an I/O error or
      permissions problem causes important configuration to be bypassed.
      
      For example, servers may depend on /etc/gitconfig to enforce security
      policy (setting transfer.fsckObjects or receive.deny*).  Best to
      always error out when encountering trouble accessing a config file.
      
      This may add inconvenience in some cases:
      
        1. You are inspecting somebody else's repo, and you do not have
           access to their .git/config file.  Git typically dies in this
           case already since we cannot read core.repositoryFormatVersion,
           so the change should not be too noticeable.
      
        2. You have used "sudo -u" or a similar tool to switch uid, and your
           environment still points Git at your original user's global
           config, which is not readable.  In this case people really would
           be inconvenienced (they would rather see the harmless warning and
           continue the operation) but they can work around it by setting
           HOME appropriately after switching uids.
      
        3. You do not have access to /etc/gitconfig due to a broken setup.
           In this case, erroring out is a good way to put pressure on the
           sysadmin to fix the setup.  While they wait for a reply, users
           can set GIT_CONFIG_NOSYSTEM to true to keep Git working without
           complaint.
      
      After this patch, errors accessing the repository-local and systemwide
      config files and files requested in include directives cause Git to
      exit, just like errors accessing ~/.gitconfig.
      Explained-by: NJeff King <peff@peff.net>
      Signed-off-by: NJonathan Nieder <jrnieder@gmail.com>
      Acked-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      8f2bbe45
  27. 14 10月, 2012 1 次提交
    • J
      config: treat user and xdg config permission problems as errors · 96b9e0e3
      Jonathan Nieder 提交于
      Git reads multiple configuration files: settings come first from the
      system config file (typically /etc/gitconfig), then the xdg config
      file (typically ~/.config/git/config), then the user's dotfile
      (~/.gitconfig), then the repository configuration (.git/config).
      
      Git has always used access(2) to decide whether to use each file; as
      an unfortunate side effect, that means that if one of these files is
      unreadable (e.g., EPERM or EIO), git skips it.  So if I use
      ~/.gitconfig to override some settings but make a mistake and give it
      the wrong permissions then I am subject to the settings the sysadmin
      chose for /etc/gitconfig.
      
      Better to error out and ask the user to correct the problem.
      
      This only affects the user and xdg config files, since the user
      presumably has enough access to fix their permissions.  If the system
      config file is unreadable, the best we can do is to warn about it so
      the user knows to notify someone and get on with work in the meantime.
      Signed-off-by: NJonathan Nieder <jrnieder@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      96b9e0e3