Merge branch 'jk/notes-merge-config'
authorJunio C Hamano <gitster@pobox.com>
Mon, 31 Aug 2015 22:39:05 +0000 (15:39 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 31 Aug 2015 22:39:05 +0000 (15:39 -0700)
"git notes merge" can be told with "--strategy=<how>" option how to
automatically handle conflicts; this can now be configured by
setting notes.mergeStrategy configuration variable.

* jk/notes-merge-config:
notes: teach git-notes about notes.<name>.mergeStrategy option
notes: add notes.mergeStrategy option to select default strategy
notes: add tests for --commit/--abort/--strategy exclusivity
notes: extract parse_notes_merge_strategy to notes-utils
notes: extract enum notes_merge_strategy to notes-utils.h
notes: document cat_sort_uniq rewriteMode

1  2 
Documentation/config.txt
builtin/notes.c
diff --combined Documentation/config.txt
index f5d15fff3e50d0d28876750ddcfb4c836cb54002,6cdece45d7fbb71886309837a637f9edc32e11a3..4400a1c9d8909740e6aa15750c8f8100206dc3e4
@@@ -769,14 -769,6 +769,14 @@@ am.keepcr:
        by giving '--no-keep-cr' from the command line.
        See linkgit:git-am[1], linkgit:git-mailsplit[1].
  
 +am.threeWay::
 +      By default, `git am` will fail if the patch does not apply cleanly. When
 +      set to true, this setting tells `git am` to fall back on 3-way merge if
 +      the patch records the identity of blobs it is supposed to apply to and
 +      we have those blobs available locally (equivalent to giving the `--3way`
 +      option from the command line). Defaults to `false`.
 +      See linkgit:git-am[1].
 +
  apply.ignoreWhitespace::
        When set to 'change', tells 'git apply' to ignore changes in
        whitespace, in the same way as the '--ignore-space-change'
@@@ -1250,25 -1242,6 +1250,25 @@@ filter.<driver>.smudge:
        object to a worktree file upon checkout.  See
        linkgit:gitattributes[5] for details.
  
 +fsck.<msg-id>::
 +      Allows overriding the message type (error, warn or ignore) of a
 +      specific message ID such as `missingEmail`.
 ++
 +For convenience, fsck prefixes the error/warning with the message ID,
 +e.g.  "missingEmail: invalid author/committer line - missing email" means
 +that setting `fsck.missingEmail = ignore` will hide that issue.
 ++
 +This feature is intended to support working with legacy repositories
 +which cannot be repaired without disruptive changes.
 +
 +fsck.skipList::
 +      The path to a sorted list of object names (i.e. one SHA-1 per
 +      line) that are known to be broken in a non-fatal way and should
 +      be ignored. This feature is useful when an established project
 +      should be accepted despite early commits containing errors that
 +      can be safely ignored such as invalid committer email addresses.
 +      Note: corrupt objects cannot be skipped with this setting.
 +
  gc.aggressiveDepth::
        The depth parameter used in the delta compression
        algorithm used by 'git gc --aggressive'.  This defaults
@@@ -1307,34 -1280,28 +1307,34 @@@ gc.packRefs:
  gc.pruneExpire::
        When 'git gc' is run, it will call 'prune --expire 2.weeks.ago'.
        Override the grace period with this config variable.  The value
 -      "now" may be used to disable this  grace period and always prune
 -      unreachable objects immediately.
 -
 -gc.pruneWorktreesExpire::
 -      When 'git gc' is run, it will call
 -      'prune --worktrees --expire 3.months.ago'.
 -      Override the grace period with this config variable. The value
 -      "now" may be used to disable the grace period and prune
 -      $GIT_DIR/worktrees immediately.
 +      "now" may be used to disable this grace period and always prune
 +      unreachable objects immediately, or "never" may be used to
 +      suppress pruning.
 +
 +gc.worktreePruneExpire::
 +      When 'git gc' is run, it calls
 +      'git worktree prune --expire 3.months.ago'.
 +      This config variable can be used to set a different grace
 +      period. The value "now" may be used to disable the grace
 +      period and prune $GIT_DIR/worktrees immediately, or "never"
 +      may be used to suppress pruning.
  
  gc.reflogExpire::
  gc.<pattern>.reflogExpire::
        'git reflog expire' removes reflog entries older than
 -      this time; defaults to 90 days.  With "<pattern>" (e.g.
 +      this time; defaults to 90 days. The value "now" expires all
 +      entries immediately, and "never" suppresses expiration
 +      altogether. With "<pattern>" (e.g.
        "refs/stash") in the middle the setting applies only to
        the refs that match the <pattern>.
  
  gc.reflogExpireUnreachable::
 -gc.<ref>.reflogExpireUnreachable::
 +gc.<pattern>.reflogExpireUnreachable::
        'git reflog expire' removes reflog entries older than
        this time and are not reachable from the current tip;
 -      defaults to 30 days.  With "<pattern>" (e.g. "refs/stash")
 +      defaults to 30 days. The value "now" expires all entries
 +      immediately, and "never" suppresses expiration altogether.
 +      With "<pattern>" (e.g. "refs/stash")
        in the middle, the setting applies only to the refs that
        match the <pattern>.
  
@@@ -1609,29 -1576,6 +1609,29 @@@ http.saveCookies:
        If set, store cookies received during requests to the file specified by
        http.cookieFile. Has no effect if http.cookieFile is unset.
  
 +http.sslVersion::
 +      The SSL version to use when negotiating an SSL connection, if you
 +      want to force the default.  The available and default version
 +      depend on whether libcurl was built against NSS or OpenSSL and the
 +      particular configuration of the crypto library in use. Internally
 +      this sets the 'CURLOPT_SSL_VERSION' option; see the libcurl
 +      documentation for more details on the format of this option and
 +      for the ssl version supported. Actually the possible values of
 +      this option are:
 +
 +      - sslv2
 +      - sslv3
 +      - tlsv1
 +      - tlsv1.0
 +      - tlsv1.1
 +      - tlsv1.2
 +
 ++
 +Can be overridden by the 'GIT_SSL_VERSION' environment variable.
 +To force git to use libcurl's default ssl version and ignore any
 +explicit http.sslversion option, set 'GIT_SSL_VERSION' to the
 +empty string.
 +
  http.sslCipherList::
    A list of SSL ciphers to use when negotiating an SSL connection.
    The available ciphers depend on whether libcurl was built against
@@@ -1942,6 -1886,18 +1942,18 @@@ mergetool.writeToTemp:
  mergetool.prompt::
        Prompt before each invocation of the merge resolution program.
  
+ notes.mergeStrategy::
+       Which merge strategy to choose by default when resolving notes
+       conflicts.  Must be one of `manual`, `ours`, `theirs`, `union`, or
+       `cat_sort_uniq`.  Defaults to `manual`.  See "NOTES MERGE STRATEGIES"
+       section of linkgit:git-notes[1] for more information on each strategy.
+ notes.<name>.mergeStrategy::
+       Which merge strategy to choose when doing a notes merge into
+       refs/notes/<name>.  This overrides the more general
+       "notes.mergeStrategy".  See the "NOTES MERGE STRATEGIES" section in
+       linkgit:git-notes[1] for more information on the available strategies.
  notes.displayRef::
        The (fully qualified) refname from which to show notes when
        showing commit messages.  The value of this variable can be set
@@@ -1970,8 -1926,8 +1982,8 @@@ notes.rewriteMode:
        When copying notes during a rewrite (see the
        "notes.rewrite.<command>" option), determines what to do if
        the target commit already has a note.  Must be one of
-       `overwrite`, `concatenate`, or `ignore`.  Defaults to
-       `concatenate`.
+       `overwrite`, `concatenate`, `cat_sort_uniq`, or `ignore`.
+       Defaults to `concatenate`.
  +
  This setting can be overridden with the `GIT_NOTES_REWRITE_MODE`
  environment variable.
@@@ -2217,22 -2173,6 +2229,22 @@@ rebase.autoStash:
        successful rebase might result in non-trivial conflicts.
        Defaults to false.
  
 +rebase.missingCommitsCheck::
 +      If set to "warn", git rebase -i will print a warning if some
 +      commits are removed (e.g. a line was deleted), however the
 +      rebase will still proceed. If set to "error", it will print
 +      the previous warning and stop the rebase, 'git rebase
 +      --edit-todo' can then be used to correct the error. If set to
 +      "ignore", no checking is done.
 +      To drop a commit without warning or error, use the `drop`
 +      command in the todo-list.
 +      Defaults to "ignore".
 +
 +rebase.instructionFormat
 +      A format string, as specified in linkgit:git-log[1], to be used for
 +      the instruction list during an interactive rebase.  The format will automatically
 +      have the long commit hash prepended to the format.
 +
  receive.advertiseAtomic::
        By default, git-receive-pack will advertise the atomic push
        capability to its clients. If you don't want to this capability
@@@ -2269,28 -2209,6 +2281,28 @@@ receive.fsckObjects:
        Defaults to false. If not set, the value of `transfer.fsckObjects`
        is used instead.
  
 +receive.fsck.<msg-id>::
 +      When `receive.fsckObjects` is set to true, errors can be switched
 +      to warnings and vice versa by configuring the `receive.fsck.<msg-id>`
 +      setting where the `<msg-id>` is the fsck message ID and the value
 +      is one of `error`, `warn` or `ignore`. For convenience, fsck prefixes
 +      the error/warning with the message ID, e.g. "missingEmail: invalid
 +      author/committer line - missing email" means that setting
 +      `receive.fsck.missingEmail = ignore` will hide that issue.
 ++
 +This feature is intended to support working with legacy repositories
 +which would not pass pushing when `receive.fsckObjects = true`, allowing
 +the host to accept repositories with certain known issues but still catch
 +other issues.
 +
 +receive.fsck.skipList::
 +      The path to a sorted list of object names (i.e. one SHA-1 per
 +      line) that are known to be broken in a non-fatal way and should
 +      be ignored. This feature is useful when an established project
 +      should be accepted despite early commits containing errors that
 +      can be safely ignored such as invalid committer email addresses.
 +      Note: corrupt objects cannot be skipped with this setting.
 +
  receive.unpackLimit::
        If the number of objects received in a push is below this
        limit then the objects will be unpacked into loose object
@@@ -2336,10 -2254,13 +2348,10 @@@ receive.denyNonFastForwards:
        set when initializing a shared repository.
  
  receive.hideRefs::
 -      String(s) `receive-pack` uses to decide which refs to omit
 -      from its initial advertisement.  Use more than one
 -      definitions to specify multiple prefix strings. A ref that
 -      are under the hierarchies listed on the value of this
 -      variable is excluded, and is hidden when responding to `git
 -      push`, and an attempt to update or delete a hidden ref by
 -      `git push` is rejected.
 +      This variable is the same as `transfer.hideRefs`, but applies
 +      only to `receive-pack` (and so affects pushes, but not fetches).
 +      An attempt to update or delete a hidden ref by `git push` is
 +      rejected.
  
  receive.updateServerInfo::
        If set to true, git-receive-pack will run git-update-server-info
@@@ -2627,18 -2548,9 +2639,18 @@@ transfer.fsckObjects:
        Defaults to false.
  
  transfer.hideRefs::
 -      This variable can be used to set both `receive.hideRefs`
 -      and `uploadpack.hideRefs` at the same time to the same
 -      values.  See entries for these other variables.
 +      String(s) `receive-pack` and `upload-pack` use to decide which
 +      refs to omit from their initial advertisements.  Use more than
 +      one definition to specify multiple prefix strings. A ref that is
 +      under the hierarchies listed in the value of this variable is
 +      excluded, and is hidden when responding to `git push` or `git
 +      fetch`.  See `receive.hideRefs` and `uploadpack.hideRefs` for
 +      program-specific versions of this config.
 ++
 +You may also include a `!` in front of the ref name to negate the entry,
 +explicitly exposing it, even if an earlier entry marked it as hidden.
 +If you have multiple hideRefs values, later entries override earlier ones
 +(and entries in more-specific config files override less-specific ones).
  
  transfer.unpackLimit::
        When `fetch.unpackLimit` or `receive.unpackLimit` are
@@@ -2653,10 -2565,13 +2665,10 @@@ uploadarchive.allowUnreachable:
        `false`.
  
  uploadpack.hideRefs::
 -      String(s) `upload-pack` uses to decide which refs to omit
 -      from its initial advertisement.  Use more than one
 -      definitions to specify multiple prefix strings. A ref that
 -      are under the hierarchies listed on the value of this
 -      variable is excluded, and is hidden from `git ls-remote`,
 -      `git fetch`, etc.  An attempt to fetch a hidden ref by `git
 -      fetch` will fail.  See also `uploadpack.allowTipSHA1InWant`.
 +      This variable is the same as `transfer.hideRefs`, but applies
 +      only to `upload-pack` (and so affects only fetches, not pushes).
 +      An attempt to fetch a hidden ref by `git fetch` will fail.  See
 +      also `uploadpack.allowTipSHA1InWant`.
  
  uploadpack.allowTipSHA1InWant::
        When `uploadpack.hideRefs` is in effect, allow `upload-pack`
diff --combined builtin/notes.c
index 04234808270908ecc5a8b6e015749ceaa29bb081,ebd3e62e87a52e6be7ff07f4e317ebdd2c1ee6c6..3608c64785283ffe7cec6df425618a279d1616c5
@@@ -19,7 -19,6 +19,7 @@@
  #include "string-list.h"
  #include "notes-merge.h"
  #include "notes-utils.h"
 +#include "branch.h"
  
  static const char * const git_notes_usage[] = {
        N_("git notes [--ref <notes-ref>] [list [<object>]]"),
@@@ -738,6 -737,19 +738,19 @@@ static int merge_commit(struct notes_me
        return ret;
  }
  
+ static int git_config_get_notes_strategy(const char *key,
+                                        enum notes_merge_strategy *strategy)
+ {
+       const char *value;
+       if (git_config_get_string_const(key, &value))
+               return 1;
+       if (parse_notes_merge_strategy(value, strategy))
+               git_die_config(key, "unknown notes merge strategy %s", value);
+       return 0;
+ }
  static int merge(int argc, const char **argv, const char *prefix)
  {
        struct strbuf remote_ref = STRBUF_INIT, msg = STRBUF_INIT;
        expand_notes_ref(&remote_ref);
        o.remote_ref = remote_ref.buf;
  
+       t = init_notes_check("merge");
        if (strategy) {
-               if (!strcmp(strategy, "manual"))
-                       o.strategy = NOTES_MERGE_RESOLVE_MANUAL;
-               else if (!strcmp(strategy, "ours"))
-                       o.strategy = NOTES_MERGE_RESOLVE_OURS;
-               else if (!strcmp(strategy, "theirs"))
-                       o.strategy = NOTES_MERGE_RESOLVE_THEIRS;
-               else if (!strcmp(strategy, "union"))
-                       o.strategy = NOTES_MERGE_RESOLVE_UNION;
-               else if (!strcmp(strategy, "cat_sort_uniq"))
-                       o.strategy = NOTES_MERGE_RESOLVE_CAT_SORT_UNIQ;
-               else {
+               if (parse_notes_merge_strategy(strategy, &o.strategy)) {
                        error("Unknown -s/--strategy: %s", strategy);
                        usage_with_options(git_notes_merge_usage, options);
                }
-       }
+       } else {
+               struct strbuf merge_key = STRBUF_INIT;
+               const char *short_ref = NULL;
  
-       t = init_notes_check("merge");
+               if (!skip_prefix(o.local_ref, "refs/notes/", &short_ref))
+                       die("BUG: local ref %s is outside of refs/notes/",
+                           o.local_ref);
+               strbuf_addf(&merge_key, "notes.%s.mergeStrategy", short_ref);
+               if (git_config_get_notes_strategy(merge_key.buf, &o.strategy))
+                       git_config_get_notes_strategy("notes.mergeStrategy", &o.strategy);
+               strbuf_release(&merge_key);
+       }
  
        strbuf_addf(&msg, "notes: Merged notes from %s into %s",
                    remote_ref.buf, default_notes_ref());
                update_ref(msg.buf, default_notes_ref(), result_sha1, NULL,
                           0, UPDATE_REFS_DIE_ON_ERR);
        else { /* Merge has unresolved conflicts */
 +              char *existing;
                /* Update .git/NOTES_MERGE_PARTIAL with partial merge result */
                update_ref(msg.buf, "NOTES_MERGE_PARTIAL", result_sha1, NULL,
                           0, UPDATE_REFS_DIE_ON_ERR);
                /* Store ref-to-be-updated into .git/NOTES_MERGE_REF */
 +              existing = find_shared_symref("NOTES_MERGE_REF", default_notes_ref());
 +              if (existing)
 +                      die(_("A notes merge into %s is already in-progress at %s"),
 +                          default_notes_ref(), existing);
                if (create_symref("NOTES_MERGE_REF", default_notes_ref(), NULL))
                        die("Failed to store link to current notes ref (%s)",
                            default_notes_ref());