1. 20 8月, 2011 4 次提交
    • J
      want_color: automatically fallback to color.ui · c9bfb953
      Jeff King 提交于
      All of the "do we want color" flags default to -1 to
      indicate that we don't have any color configured. This value
      is handled in one of two ways:
      
        1. In porcelain, we check early on whether the value is
           still -1 after reading the config, and set it to the
           value of color.ui (which defaults to 0).
      
        2. In plumbing, it stays untouched as -1, and want_color
           defaults it to off.
      
      This works fine, but means that every porcelain has to check
      and reassign its color flag. Now that want_color gives us a
      place to put this check in a single spot, we can do that,
      simplifying the calling code.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      c9bfb953
    • J
      diff: don't load color config in plumbing · 3e1dd17a
      Jeff King 提交于
      The diff config callback is split into two functions: one
      which loads "ui" config, and one which loads "basic" config.
      The former chains to the latter, as the diff UI config is a
      superset of the plumbing config.
      
      The color.diff variable is only loaded in the UI config.
      However, the basic config actually chains to
      git_color_default_config, which loads color.ui. This doesn't
      actually cause any bugs, because the plumbing diff code does
      not actually look at the value of color.ui.
      
      However, it is somewhat nonsensical, and it makes it
      difficult to refactor the color code. It probably came about
      because there is no git_color_config to load only color
      config, but rather just git_color_default_config, which
      loads color config and chains to git_default_config.
      
      This patch splits out the color-specific portion of
      git_color_default_config so that the diff UI config can call
      it directly. This is perhaps better explained by the
      chaining of callbacks. Before we had:
      
        git_diff_ui_config
          -> git_diff_basic_config
            -> git_color_default_config
              -> git_default_config
      
      Now we have:
      
        git_diff_ui_config
          -> git_color_config
          -> git_diff_basic_config
            -> git_default_config
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      3e1dd17a
    • J
      config: refactor get_colorbool function · c659f55b
      Jeff King 提交于
      For "git config --get-colorbool color.foo", we use a custom
      callback that looks not only for the key that the user gave
      us, but also for "diff.color" (for backwards compatibility)
      and "color.ui" (as a fallback).
      
      For the former, we use a custom variable to store the
      diff.color value. For the latter, though, we store it in the
      main "git_use_color_default" variable, turning on color.ui
      for any other parts of git that respect this value.
      
      In practice, this doesn't cause any bugs, because git-config
      runs without caring about git_use_color_default, and then
      exits. But it crosses module boundaries in an unusual and
      confusing way, and it makes refactoring color handling
      harder than it needs to be.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      c659f55b
    • J
      color: delay auto-color decision until point of use · daa0c3d9
      Jeff King 提交于
      When we read a color value either from a config file or from
      the command line, we use git_config_colorbool to convert it
      from the tristate always/never/auto into a single yes/no
      boolean value.
      
      This has some timing implications with respect to starting
      a pager.
      
      If we start (or decide not to start) the pager before
      checking the colorbool, everything is fine. Either isatty(1)
      will give us the right information, or we will properly
      check for pager_in_use().
      
      However, if we decide to start a pager after we have checked
      the colorbool, things are not so simple. If stdout is a tty,
      then we will have already decided to use color. However, the
      user may also have configured color.pager not to use color
      with the pager. In this case, we need to actually turn off
      color. Unfortunately, the pager code has no idea which color
      variables were turned on (and there are many of them
      throughout the code, and they may even have been manipulated
      after the colorbool selection by something like "--color" on
      the command line).
      
      This bug can be seen any time a pager is started after
      config and command line options are checked. This has
      affected "git diff" since 89d07f75 (diff: don't run pager if
      user asked for a diff style exit code, 2007-08-12). It has
      also affect the log family since 1fda91b5 (Fix 'git log'
      early pager startup error case, 2010-08-24).
      
      This patch splits the notion of parsing a colorbool and
      actually checking the configuration. The "use_color"
      variables now have an additional possible value,
      GIT_COLOR_AUTO. Users of the variable should use the new
      "want_color()" wrapper, which will lazily determine and
      cache the auto-color decision.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      daa0c3d9
  2. 19 8月, 2011 6 次提交
    • J
      git_config_colorbool: refactor stdout_is_tty handling · e269eb79
      Jeff King 提交于
      Usually this function figures out for itself whether stdout
      is a tty. However, it has an extra parameter just to allow
      git-config to override the auto-detection for its
      --get-colorbool option.
      
      Instead of an extra parameter, let's just use a global
      variable. This makes calling easier in the common case, and
      will make refactoring the colorbool code much simpler.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      e269eb79
    • J
      diff: refactor COLOR_DIFF from a flag into an int · f1c96261
      Jeff King 提交于
      This lets us store more than just a bit flag for whether we
      want color; we can also store whether we want automatic
      colors. This can be useful for making the automatic-color
      decision closer to the point of use.
      
      This mostly just involves replacing DIFF_OPT_* calls with
      manipulations of the flag. The biggest exception is that
      calls to DIFF_OPT_TST must check for "o->use_color > 0",
      which lets an "unknown" value (i.e., the default) stay at
      "no color". In the previous code, a value of "-1" was not
      propagated at all.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      f1c96261
    • J
      setup_pager: set GIT_PAGER_IN_USE · 2e6c012e
      Jeff King 提交于
      We have always set a global "spawned_pager" variable when we
      start the pager. This lets us make the auto-color decision
      later in the program as as "we are outputting to a terminal,
      or to a pager which can handle colors".
      
      Commit 6e9af863 added support for the GIT_PAGER_IN_USE
      environment variable. An external program calling git (e.g.,
      git-svn) could set this variable to indicate that it had
      already started the pager, and that the decision about
      auto-coloring should take that into account.
      
      However, 6e9af863 failed to do the reverse, which is to tell
      external programs when git itself has started the pager.
      Thus a git command implemented as an external script that
      has the pager turned on (e.g., "git -p stash show") would
      not realize it was going to a pager, and would suppress
      colors.
      
      This patch remedies that; we always set GIT_PAGER_IN_USE
      when we start the pager, and the value is respected by both
      this program and any spawned children.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      2e6c012e
    • J
      t7006: use test_config helpers · 8d68a6d5
      Jeff King 提交于
      In some cases, this is just making the test script a little
      shorter and easier to read. However, there are several
      places where we didn't take proper precautions against
      polluting downstream tests with our config; this fixes them,
      too.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      8d68a6d5
    • J
      test-lib: add helper functions for config · d960c47a
      Jeff King 提交于
      There are a few common tasks when working with configuration
      variables in tests; this patch aims to make them a little
      easier to write and less error-prone.
      
      When setting a variable, you should typically make sure to
      clean it up after the test is finished, so as not to pollute
      other tests. Like:
      
         test_when_finished 'git config --unset foo.bar' &&
         git config foo.bar baz
      
      This patch lets you just write:
      
        test_config foo.bar baz
      
      When clearing a variable that does not exist, git-config
      will report a specific non-zero error code. Meaning that
      tests which call "git config --unset" often either rely on
      the prior tests having actually set it, or must use
      test_might_fail. With this patch, the previous:
      
        test_might_fail git config --unset foo.bar
      
      becomes:
      
        test_unconfig foo.bar
      
      Not only is this easier to type, but it is more robust; it
      will correctly detect errors from git-config besides "key
      was not set".
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      d960c47a
    • J
      t7006: modernize calls to unset · 212ad944
      Jeff King 提交于
      These tests break &&-chaining to deal with broken "unset"
      implementations. Instead, they should just use sane_unset.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      212ad944
  3. 18 8月, 2011 1 次提交
  4. 17 8月, 2011 23 次提交
  5. 09 8月, 2011 3 次提交
  6. 06 8月, 2011 1 次提交
    • J
      fast-export: quote paths in output · 6280dfdc
      Jeff King 提交于
      Many pathnames in a fast-import stream need to be quoted. In
      particular:
      
        1. Pathnames at the end of an "M" or "D" line need quoting
           if they contain a LF or start with double-quote.
      
        2. Pathnames on a "C" or "R" line need quoting as above,
           but also if they contain spaces.
      
      For (1), we weren't quoting at all. For (2), we put
      double-quotes around the paths to handle spaces, but ignored
      the possibility that they would need further quoting.
      
      This patch checks whether each pathname needs c-style
      quoting, and uses it. This is slightly overkill for (1),
      which doesn't actually need to quote many characters that
      vanilla c-style quoting does. However, it shouldn't hurt, as
      any implementation needs to be ready to handle quoted
      strings anyway.
      
      In addition to adding a test, we have to tweak a test which
      blindly assumed that case (2) would always use
      double-quotes, whether it needed to or not.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      6280dfdc
  7. 04 8月, 2011 2 次提交