1. 14 9月, 2016 1 次提交
    • J
      pager: stop loading git_default_config() · 4babb839
      Jeff King 提交于
      In git_pager(), we really only care about getting the value
      of core.pager. But to do so, we use the git_default_config()
      callback, which loads many other values. Ordinarily it
      isn't a big deal to load this config an extra time, as it
      simply overwrites the values from the previous run. But it's
      a bad idea here, for two reasons:
      
        1. The pager setup may be called very early in the
           program, before we have found the git repository. As a
           result, we may fail to read the correct repo-level
           config file.  This is a problem for core.pager, too,
           but we should at least try to minimize the pollution to
           other configured values.
      
        2. Because we call setup_pager() from git.c, basically
           every builtin command _may_ end up reading this config
           and getting an implicit git_default_config() setup.
      
           Which doesn't sound like a terrible thing, except that
           we don't do it consistently; it triggers only when
           stdout is a tty. So if a command forgets to load the
           default config itself (but depends on it anyway), it
           may appear to work, and then mysteriously fail when the
           pager is not in use.
      
      We can improve this by loading _just_ the core.pager config
      from git_pager().
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      4babb839
  2. 12 5月, 2016 1 次提交
    • J
      mingw: introduce the 'core.hideDotFiles' setting · f30afdab
      Johannes Schindelin 提交于
      On Unix (and Linux), files and directories whose names start with a dot
      are usually not shown by default. This convention is used by Git: the
      .git/ directory should be left alone by regular users, and only accessed
      through Git itself.
      
      On Windows, no such convention exists. Instead, there is an explicit flag
      to mark files or directories as hidden.
      
      In the early days, Git for Windows did not mark the .git/ directory (or
      for that matter, any file or directory whose name starts with a dot)
      hidden. This lead to quite a bit of confusion, and even loss of data.
      
      Consequently, Git for Windows introduced the core.hideDotFiles setting,
      with three possible values: true, false, and dotGitOnly, defaulting to
      marking only the .git/ directory as hidden.
      
      The rationale: users do not need to access .git/ directly, and indeed (as
      was demonstrated) should not really see that directory, either. However,
      not all dot files should be hidden by default, as e.g. Eclipse does not
      show them (and the user would therefore be unable to see, say, a
      .gitattributes file).
      
      In over five years since the last attempt to bring this patch into core
      Git, a slightly buggy version of this patch has served Git for Windows'
      users well: no single report indicated problems with the hidden .git/
      directory, and the stream of problems caused by the previously non-hidden
      .git/ directory simply stopped. The bugs have been fixed during the
      process of getting this patch upstream.
      
      Note that there is a funny quirk we have to pay attention to when
      creating hidden files: we use Win32's _wopen() function which
      transmogrifies its arguments and hands off to Win32's CreateFile()
      function. That latter function errors out with ERROR_ACCESS_DENIED (the
      equivalent of EACCES) when the equivalent of the O_CREAT flag was passed
      and the file attributes (including the hidden flag) do not match an
      existing file's. And _wopen() accepts no parameter that would be
      transmogrified into said hidden flag. Therefore, we simply try again
      without O_CREAT.
      
      A slightly different method is required for our fopen()/freopen()
      function as we cannot even *remove* the implicit O_CREAT flag.
      Therefore, we briefly mark existing files as unhidden when opening them
      via fopen()/freopen().
      
      The ERROR_ACCESS_DENIED error can also be triggered by opening a file
      that is marked as a system file (which is unlikely to be tracked in
      Git), and by trying to create a file that has *just* been deleted and is
      awaiting the last open handles to be released (which would be handled
      better by the "Try again?" logic, a story for a different patch series,
      though). In both cases, it does not matter much if we try again without
      the O_CREAT flag, read: it does not hurt, either.
      
      For details how ERROR_ACCESS_DENIED can be triggered, see
      https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858Original-patch-by: NErik Faye-Lund <kusmabite@gmail.com>
      Initial-Test-By: NPat Thoyts <patthoyts@users.sourceforge.net>
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      f30afdab
  3. 29 4月, 2016 1 次提交
  4. 26 4月, 2016 1 次提交
  5. 11 4月, 2016 3 次提交
    • J
      git_config_set_multivar_in_file: handle "unset" errors · 1cae428e
      Jeff King 提交于
      We pass off to the "_gently" form to do the real work, and
      just die() if it returned an error. However, our die message
      de-references "value", which may be NULL if the request was
      to unset a variable. Nobody using glibc noticed, because it
      simply prints "(null)", which is good enough for the test
      suite (and presumably very few people run across this in
      practice). But other libc implementations (like Solaris) may
      segfault.
      
      Let's not only fix that, but let's make the message more
      clear about what is going on in the "unset" case.
      Reported-by: N"Tom G. Christensen" <tgc@jupiterrise.com>
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      1cae428e
    • J
      git_config_set_multivar_in_file: all non-zero returns are errors · 9c14bb08
      Jeff King 提交于
      This function is just a thin wrapper for the "_gently" form
      of the function. But the gently form is designed to feed
      builtin/config.c, which passes our return code directly to
      its exit status, and thus uses positive error values for
      some cases. We check only negative values, meaning we would
      fail to die in some cases (e.g., a malformed key).
      
      This may or may not be triggerable in practice; we tend to
      use this non-gentle form only when setting internal
      variables, which would not have malformed keys.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      9c14bb08
    • J
      config: lower-case first word of error strings · 8c3ca351
      Jeff King 提交于
      This follows our usual style (both throughout git, and
      throughout the rest of this file).
      
      This covers the whole file, but note that I left the capitalization in
      the multi-sentence:
      
        error: malformed value...
        error: Must be one of ...
      
      because it helps make it clear that we are starting a new sentence in
      the second one.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      8c3ca351
  6. 12 3月, 2016 1 次提交
  7. 23 2月, 2016 4 次提交
  8. 20 2月, 2016 1 次提交
  9. 17 2月, 2016 1 次提交
    • P
      config: introduce set_or_die wrappers · b4c8aba6
      Patrick Steinhardt 提交于
      A lot of call-sites for the existing family of `git_config_set`
      functions do not check for errors that may occur, e.g. when the
      configuration file is locked. In many cases we simply want to die
      when such a situation arises.
      
      Introduce wrappers that will cause the program to die in those
      cases. These wrappers are temporary only to ease the transition
      to let `git_config_set` die by default. They will be removed
      later on when `git_config_set` itself has been replaced by
      `git_config_set_gently`.
      Signed-off-by: NPatrick Steinhardt <ps@pks.im>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      b4c8aba6
  10. 28 1月, 2016 2 次提交
    • C
      test-dump-untracked-cache: don't modify the untracked cache · dae6c322
      Christian Couder 提交于
      To correctly perform its testing function,
      test-dump-untracked-cache should not change the state of the
      untracked cache in the index.
      
      As a previous patch makes read_index_from() change the state of
      the untracked cache and as test-dump-untracked-cache indirectly
      calls this function, we need a mechanism to prevent
      read_index_from() from changing the untracked cache state when
      it's called from test-dump-untracked-cache.
      Signed-off-by: NChristian Couder <chriscool@tuxfamily.org>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      dae6c322
    • C
      config: add core.untrackedCache · 435ec090
      Christian Couder 提交于
      When we know that mtime on directory as given by the environment
      is usable for the purpose of untracked cache, we may want the
      untracked cache to be always used without any mtime test or
      kernel name check being performed.
      
      Also when we know that mtime is not usable for the purpose of
      untracked cache, for example because the repo is shared over a
      network file system, we may want the untracked-cache to be
      automatically removed from the index.
      
      Allow the user to express such preference by setting the
      'core.untrackedCache' configuration variable, which can take
      'keep', 'false', or 'true' and default to 'keep'.
      
      When read_index_from() is called, it now adds or removes the
      untracked cache in the index to respect the value of this
      variable. So it does nothing if the value is `keep` or if the
      variable is unset; it adds the untracked cache if the value is
      `true`; and it removes the cache if the value is `false`.
      
      `git update-index --[no-|force-]untracked-cache` still adds the
      untracked cache to, or removes it, from the index, but this
      shows a warning if it goes against the value of
      core.untrackedCache, because the next time the index is read
      the untracked cache will be added or removed if the
      configuration is set to do so.
      
      Also `--untracked-cache` used to check that the underlying
      operating system and file system change `st_mtime` field of a
      directory if files are added or deleted in that directory. But
      because those tests take a long time, `--untracked-cache` no
      longer performs them. Instead, there is now
      `--test-untracked-cache` to perform the tests. This change
      makes `--untracked-cache` the same as `--force-untracked-cache`.
      
      This last change is backward incompatible and should be
      mentioned in the release notes.
      Helped-by: NDuy Nguyen <pclouds@gmail.com>
      Helped-by: NTorsten Bögershausen <tboegi@web.de>
      Helped-by: NStefan Beller <sbeller@google.com>
      Signed-off-by: NChristian Couder <chriscool@tuxfamily.org>
      Signed-off-by: NÆvar Arnfjörð Bjarmason <avarab@gmail.com>
      
      read-cache: Duy'sfixup
      Signed-off-by: NChristian Couder <chriscool@tuxfamily.org>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      435ec090
  11. 02 12月, 2015 1 次提交
    • S
      Make error message after failing commit_lock_file() less confusing · 08a3651f
      SZEDER Gábor 提交于
      The error message after a failing commit_lock_file() call sometimes
      looks like this, causing confusion:
      
        $ git remote add remote git@server.com/repo.git
        error: could not commit config file .git/config
        # Huh?!
        # I didn't want to commit anything, especially not my config file!
      
      While in the narrow context of the lockfile module using the verb
      'commit' in the error message makes perfect sense, in the broader
      context of git the word 'commit' already has a very specific meaning,
      hence the confusion.
      
      Reword these error messages to say "could not write" instead of "could
      not commit".
      
      While at it, include strerror in the error messages after writing the
      config file or the credential store fails to provide some information
      about the cause of the failure, and update the style of the error
      message after writing the reflog fails to match surrounding error
      messages (i.e. no '' around the pathname and no () around the error
      description).
      Signed-off-by: NSZEDER Gábor <szeder@ira.uka.de>
      Signed-off-by: NJeff King <peff@peff.net>
      08a3651f
  12. 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
  13. 20 8月, 2015 1 次提交
  14. 15 8月, 2015 1 次提交
  15. 11 8月, 2015 1 次提交
  16. 01 7月, 2015 1 次提交
  17. 29 5月, 2015 3 次提交
    • J
      config.c: rewrite ENODEV into EISDIR when mmap fails · 0e8771f1
      Jeff King 提交于
      If we try to mmap a directory, we'll get ENODEV. This
      translates to "no such device" for the user, which is not
      very helpful. Since we've just fstat()'d the file, we can
      easily check whether the problem was a directory to give a
      better message.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      0e8771f1
    • J
      config.c: avoid xmmap error messages · 1570856b
      Jeff King 提交于
      The config-writing code uses xmmap to map the existing
      config file, which will die if the map fails. This has two
      downsides:
      
        1. The error message is not very helpful, as it lacks any
           context about the file we are mapping:
      
             $ mkdir foo
             $ git config --file=foo some.key value
             fatal: Out of memory? mmap failed: No such device
      
        2. We normally do not die in this code path; instead, we'd
           rather report the error and return an appropriate exit
           status (which is part of the public interface
           documented in git-config.1).
      
      This patch introduces a "gentle" form of xmmap which lets us
      produce our own error message. We do not want to use mmap
      directly, because we would like to use the other
      compatibility elements of xmmap (e.g., handling 0-length
      maps portably).
      
      The end result is:
      
          $ git.compile config --file=foo some.key value
          error: unable to mmap 'foo': No such device
          $ echo $?
          3
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      1570856b
    • J
      config.c: fix mmap leak when writing config · 3a1b3126
      Jeff King 提交于
      We mmap the existing config file, but fail to unmap it if we
      hit an error. The function already has a shared exit path,
      so we can fix this by moving the mmap pointer to the
      function scope and clearing it in the shared exit.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      3a1b3126
  18. 07 5月, 2015 1 次提交
  19. 17 4月, 2015 1 次提交
  20. 16 4月, 2015 1 次提交
    • J
      config: use getc_unlocked when reading from file · 260d408e
      Jeff King 提交于
      We read config files character-by-character from a stdio
      handle using fgetc(). This incurs significant locking
      overhead, even though we know that only one thread can
      possibly access the handle. We can speed this up by taking
      the lock ourselves, and then using getc_unlocked to read
      each character.
      
      On a silly pathological case:
      
        perl -le '
          print "[core]";
          print "key$_ = value$_" for (1..1000000)
        ' >input
        git config -f input core.key1
      
      this dropped the time to run git-config from:
      
        real    0m0.263s
        user    0m0.260s
        sys     0m0.000s
      
      to:
      
        real    0m0.159s
        user    0m0.152s
        sys     0m0.004s
      
      for a savings of 39%.  Most config files are not this big,
      but the savings should be proportional to the size of the
      file (i.e., we always save 39%, just of a much smaller
      number).
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      260d408e
  21. 06 2月, 2015 2 次提交
    • J
      config_buf_ungetc: warn when pushing back a random character · 1d0655c1
      Jeff King 提交于
      Our config code simulates a stdio stream around a buffer,
      but our fake ungetc() does not behave quite like the real
      one. In particular, we only rewind the position by one
      character, but do _not_ actually put the character from the
      caller into position.
      
      It turns out that this does not matter, because we only ever
      push back the character we just read. In other words, such
      an assignment would be a noop. But because the function is
      called ungetc, and because it takes a character parameter,
      it is a mistake waiting to happen.
      
      Actually assigning the character into the buffer would be
      ideal, but our pointer is actually a "const" copy of the
      buffer. We do not know who the real owner of the buffer is
      in this code, and would not want to munge their contents.
      
      Instead, we can simply add an assertion that matches what
      the current caller does, and will let us know if new callers
      are added that violate the contract.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      1d0655c1
    • J
      config: do not ungetc EOF · 5e0be134
      Jeff King 提交于
      When we are parsing a config value, if we see a carriage
      return, we fgetc the next character to see if it is a
      line feed (in which case we silently drop the CR). If it
      isn't, we then ungetc the character, and take the literal
      CR.
      
      But we never check whether we in fact got a character at
      all. If the config file ends in CR, we will get EOF here,
      and try to ungetc EOF. This works OK for a real stdio
      stream. The ungetc returns an error, and the next fgetc will
      then return EOF again.
      
      However, our custom buffer-based stream is not so fortunate.
      It happily rewinds the position of the stream by one
      character, ignoring the fact that we fed it EOF. The next
      fgetc call returns the final CR again, over and over, and we
      end up in an infinite loop.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      5e0be134
  22. 14 1月, 2015 1 次提交
  23. 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
  24. 18 11月, 2014 1 次提交
  25. 02 10月, 2014 3 次提交
  26. 12 9月, 2014 1 次提交
  27. 03 9月, 2014 1 次提交
  28. 29 8月, 2014 1 次提交