Merge branch 'jk/colors-fix'
authorJunio C Hamano <gitster@pobox.com>
Fri, 12 Dec 2014 22:31:38 +0000 (14:31 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 12 Dec 2014 22:31:39 +0000 (14:31 -0800)
* jk/colors-fix:
t4026: test "normal" color
config: fix parsing of "git config --get-color some.key -1"
docs: describe ANSI 256-color mode

1  2 
Documentation/config.txt
builtin/config.c
diff --combined Documentation/config.txt
index 922072596fdd80eaaa47746fba5e5591223c5108,9678ab6aa8ee846dabca72bb413820584aaabfe2..f615a5c35442ead9d8718f187c80f6a81289ebc9
@@@ -204,26 -204,13 +204,26 @@@ advice.*:
  --
  
  core.fileMode::
 -      If false, the executable bit differences between the index and
 -      the working tree are ignored; useful on broken filesystems like FAT.
 -      See linkgit:git-update-index[1].
 +      Tells Git if the executable bit of files in the working tree
 +      is to be honored.
  +
 -The default is true, except linkgit:git-clone[1] or linkgit:git-init[1]
 -will probe and set core.fileMode false if appropriate when the
 -repository is created.
 +Some filesystems lose the executable bit when a file that is
 +marked as executable is checked out, or checks out an
 +non-executable file with executable bit on.
 +linkgit:git-clone[1] or linkgit:git-init[1] probe the filesystem
 +to see if it handles the executable bit correctly
 +and this variable is automatically set as necessary.
 ++
 +A repository, however, may be on a filesystem that handles
 +the filemode correctly, and this variable is set to 'true'
 +when created, but later may be made accessible from another
 +environment that loses the filemode (e.g. exporting ext4 via
 +CIFS mount, visiting a Cygwin created repository with
 +Git for Windows or Eclipse).
 +In such a case it may be necessary to set this variable to 'false'.
 +See linkgit:git-update-index[1].
 ++
 +The default is true (when core.filemode is not specified in the config file).
  
  core.ignorecase::
        If true, this option enables various workarounds to enable
@@@ -512,8 -499,7 +512,8 @@@ core.bigFileThreshold:
        Files larger than this size are stored deflated, without
        attempting delta compression.  Storing large files without
        delta compression avoids excessive memory usage, at the
 -      slight expense of increased disk usage.
 +      slight expense of increased disk usage. Additionally files
 +      larger than this size are always treated as binary.
  +
  Default is 512 MiB on all platforms.  This should be reasonable
  for most projects as source code and other text files can still
@@@ -839,6 -825,10 +839,10 @@@ accepted are `normal`, `black`, `red`, 
  `blink` and `reverse`.  The first color given is the foreground; the
  second is the background.  The position of the attribute, if any,
  doesn't matter.
+ +
+ Colors (foreground and background) may also be given as numbers between
+ 0 and 255; these use ANSI 256-color mode (but note that not all
+ terminals may support this).
  
  color.diff::
        Whether to use ANSI escape sequences to add color to patches.
@@@ -885,11 -875,7 +889,11 @@@ color.grep.<slot>:
  `linenumber`;;
        line number prefix (when using `-n`)
  `match`;;
 -      matching text
 +      matching text (same as setting `matchContext` and `matchSelected`)
 +`matchContext`;;
 +      matching text in context lines
 +`matchSelected`;;
 +      matching text in selected lines
  `selected`;;
        non-matching text in selected lines
  `separator`;;
@@@ -1210,7 -1196,7 +1214,7 @@@ gc.autopacklimit:
        default value is 50.  Setting this to 0 disables it.
  
  gc.autodetach::
 -      Make `git gc --auto` return immediately andrun in background
 +      Make `git gc --auto` return immediately and run in background
        if the system supports it. Default is true.
  
  gc.packrefs::
@@@ -1357,7 -1343,7 +1361,7 @@@ gpg.program:
        same command-line interface as GPG, namely, to verify a detached
        signature, "gpg --verify $file - <$signature" is run, and the
        program is expected to signal a good signature by exiting with
 -      code 0, and to generate an ascii-armored detached signature, the
 +      code 0, and to generate an ASCII-armored detached signature, the
        standard input of "gpg -bsau $key" is fed with the contents to be
        signed, and the program is expected to send the result to its
        standard output.
@@@ -1592,7 -1578,7 +1596,7 @@@ http.useragent:
        Can be overridden by the 'GIT_HTTP_USER_AGENT' environment variable.
  
  http.<url>.*::
 -      Any of the http.* options above can be applied selectively to some urls.
 +      Any of the http.* options above can be applied selectively to some URLs.
        For a config key to match a URL, each element of the config key is
        compared to that of the URL, in the following order:
  +
@@@ -1631,8 -1617,8 +1635,8 @@@ if the URL is `https://user@example.com
  +
  All URLs are normalized before attempting any matching (the password part,
  if embedded in the URL, is always ignored for matching purposes) so that
 -equivalent urls that are simply spelled differently will match properly.
 -Environment variable settings always override any matches.  The urls that are
 +equivalent URLs that are simply spelled differently will match properly.
 +Environment variable settings always override any matches.  The URLs that are
  matched against are those given directly to Git commands.  This means any URLs
  visited as a result of a redirection do not participate in matching.
  
@@@ -1794,12 -1780,6 +1798,12 @@@ mergetool.keepTemporaries:
        preserved, otherwise they will be removed after the tool has
        exited. Defaults to `false`.
  
 +mergetool.writeToTemp::
 +      Git writes temporary 'BASE', 'LOCAL', and 'REMOTE' versions of
 +      conflicting files in the worktree by default.  Git will attempt
 +      to use a temporary directory for these files when set `true`.
 +      Defaults to `false`.
 +
  mergetool.prompt::
        Prompt before each invocation of the merge resolution program.
  
@@@ -1860,11 -1840,10 +1864,11 @@@ pack.depth:
        maximum depth is given on the command line. Defaults to 50.
  
  pack.windowMemory::
 -      The window memory size limit used by linkgit:git-pack-objects[1]
 -      when no limit is given on the command line.  The value can be
 -      suffixed with "k", "m", or "g".  Defaults to 0, meaning no
 -      limit.
 +      The maximum size of memory that is consumed by each thread
 +      in linkgit:git-pack-objects[1] for pack window memory when
 +      no limit is given on the command line.  The value can be
 +      suffixed with "k", "m", or "g".  When left unconfigured (or
 +      set explicitly to 0), there will be no limit.
  
  pack.compression::
        An integer -1..9, indicating the compression level for objects
@@@ -2077,25 -2056,6 +2081,25 @@@ receive.autogc:
        receiving data from git-push and updating refs.  You can stop
        it by setting this variable to false.
  
 +receive.certnonceseed::
 +      By setting this variable to a string, `git receive-pack`
 +      will accept a `git push --signed` and verifies it by using
 +      a "nonce" protected by HMAC using this string as a secret
 +      key.
 +
 +receive.certnonceslop::
 +      When a `git push --signed` sent a push certificate with a
 +      "nonce" that was issued by a receive-pack serving the same
 +      repository within this many seconds, export the "nonce"
 +      found in the certificate to `GIT_PUSH_CERT_NONCE` to the
 +      hooks (instead of what the receive-pack asked the sending
 +      side to include).  This may allow writing checks in
 +      `pre-receive` and `post-receive` a bit easier.  Instead of
 +      checking `GIT_PUSH_CERT_NONCE_SLOP` environment variable
 +      that records by how many seconds the nonce is stale to
 +      decide if they want to accept the certificate, they only
 +      can check `GIT_PUSH_CERT_NONCE_STATUS` is `OK`.
 +
  receive.fsckObjects::
        If it is set to true, git-receive-pack will check all received
        objects. It will abort in the case of a malformed object or a
diff --combined builtin/config.c
index 606a3c085621581de01115e97d88c65a6c20e824,84b8e1cfa5515c8a0c1dc5c22c5c1bb708847532..15a7bea936d667042cef27f83c86a863df2caa8f
@@@ -69,8 -69,8 +69,8 @@@ static struct option builtin_config_opt
        OPT_BIT(0, "remove-section", &actions, N_("remove a section: name"), ACTION_REMOVE_SECTION),
        OPT_BIT('l', "list", &actions, N_("list all"), ACTION_LIST),
        OPT_BIT('e', "edit", &actions, N_("open an editor"), ACTION_EDIT),
-       OPT_STRING(0, "get-color", &get_color_slot, N_("slot"), N_("find the color configured: [default]")),
-       OPT_STRING(0, "get-colorbool", &get_colorbool_slot, N_("slot"), N_("find the color setting: [stdout-is-tty]")),
+       OPT_BIT(0, "get-color", &actions, N_("find the color configured: slot [default]"), ACTION_GET_COLOR),
+       OPT_BIT(0, "get-colorbool", &actions, N_("find the color setting: slot [stdout-is-tty]"), ACTION_GET_COLORBOOL),
        OPT_GROUP(N_("Type")),
        OPT_BIT(0, "bool", &types, N_("value is \"true\" or \"false\""), TYPE_BOOL),
        OPT_BIT(0, "int", &types, N_("value is decimal number"), TYPE_INT),
@@@ -296,24 -296,22 +296,25 @@@ static int git_get_color_config(const c
        if (!strcmp(var, get_color_slot)) {
                if (!value)
                        config_error_nonbool(var);
 -              color_parse(value, var, parsed_color);
 +              if (color_parse(value, parsed_color) < 0)
 +                      return -1;
                get_color_found = 1;
        }
        return 0;
  }
  
- static void get_color(const char *def_color)
+ static void get_color(const char *var, const char *def_color)
  {
+       get_color_slot = var;
        get_color_found = 0;
        parsed_color[0] = '\0';
        git_config_with_options(git_get_color_config, NULL,
                                &given_config_source, respect_includes);
  
 -      if (!get_color_found && def_color)
 -              color_parse(def_color, "command line", parsed_color);
 +      if (!get_color_found && def_color) {
 +              if (color_parse(def_color, parsed_color) < 0)
 +                      die(_("unable to parse default color value"));
 +      }
  
        fputs(parsed_color, stdout);
  }
@@@ -333,8 -331,9 +334,9 @@@ static int git_get_colorbool_config(con
        return 0;
  }
  
- static int get_colorbool(int print)
+ static int get_colorbool(const char *var, int print)
  {
+       get_colorbool_slot = var;
        get_colorbool_found = -1;
        get_diff_color_found = -1;
        get_color_ui_found = -1;
@@@ -448,20 -447,6 +450,20 @@@ static int get_urlmatch(const char *var
        return 0;
  }
  
 +static char *default_user_config(void)
 +{
 +      struct strbuf buf = STRBUF_INIT;
 +      strbuf_addf(&buf,
 +                  _("# This is Git's per-user configuration file.\n"
 +                    "[core]\n"
 +                    "# Please adapt and uncomment the following lines:\n"
 +                    "#        user = %s\n"
 +                    "#        email = %s\n"),
 +                  ident_default_name(),
 +                  ident_default_email());
 +      return strbuf_detach(&buf, NULL);
 +}
 +
  int cmd_config(int argc, const char **argv, const char *prefix)
  {
        int nongit = !startup_info->have_repository;
                usage_with_options(builtin_config_usage, builtin_config_options);
        }
  
-       if (get_color_slot)
-           actions |= ACTION_GET_COLOR;
-       if (get_colorbool_slot)
-           actions |= ACTION_GET_COLORBOOL;
-       if ((get_color_slot || get_colorbool_slot) && types) {
+       if ((actions & (ACTION_GET_COLOR|ACTION_GET_COLORBOOL)) && types) {
                error("--get-color and variable type are incoherent");
                usage_with_options(builtin_config_usage, builtin_config_options);
        }
                }
        }
        else if (actions == ACTION_EDIT) {
 +              char *config_file;
 +
                check_argc(argc, 0, 0);
                if (!given_config_source.file && nongit)
                        die("not in a git directory");
                if (given_config_source.blob)
                        die("editing blobs is not supported");
                git_config(git_default_config, NULL);
 -              launch_editor(given_config_source.file ?
 -                            given_config_source.file : git_path("config"),
 -                            NULL, NULL);
 +              config_file = xstrdup(given_config_source.file ?
 +                                    given_config_source.file : git_path("config"));
 +              if (use_global_config) {
 +                      int fd = open(config_file, O_CREAT | O_EXCL | O_WRONLY, 0666);
 +                      if (fd) {
 +                              char *content = default_user_config();
 +                              write_str_in_full(fd, content);
 +                              free(content);
 +                              close(fd);
 +                      }
 +                      else if (errno != EEXIST)
 +                              die_errno(_("cannot create configuration file %s"), config_file);
 +              }
 +              launch_editor(config_file, NULL, NULL);
 +              free(config_file);
        }
        else if (actions == ACTION_SET) {
                int ret;
                        die("No such section!");
        }
        else if (actions == ACTION_GET_COLOR) {
-               get_color(argv[0]);
+               check_argc(argc, 1, 2);
+               get_color(argv[0], argv[1]);
        }
        else if (actions == ACTION_GET_COLORBOOL) {
-               if (argc == 1)
-                       color_stdout_is_tty = git_config_bool("command line", argv[0]);
-               return get_colorbool(argc != 0);
+               check_argc(argc, 1, 2);
+               if (argc == 2)
+                       color_stdout_is_tty = git_config_bool("command line", argv[1]);
+               return get_colorbool(argv[0], argc == 2);
        }
  
        return 0;