checkout: pass "struct checkout_opts *" as const pointer

This struct contains various switches to system and it feels somewhat
safer to have the compiler reassure us that nowhere else changes it.

One field that is changed, writeout_error, is split out and passed as
another argument.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
checkout: move more parameters to struct checkout_opts

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
checkout: reorder option handling

checkout operates in three different modes. On top of that it tries to
be smart by guessing the branch name for switching. This results in
messy option handling code. This patch reorders it so that

 - cmd_checkout() is responsible for parsing, preparing input and
   determinining mode

 - Code of each mode is in cmd_checkout_paths() and cmd_checkout_branch(),
   where sanity checks are performed per mode

Another slight improvement is always print branch name (or commit
name) when printing errors related ot them. This helps catch the case
where an option is mistaken as branch/commit.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
name-rev: lose unnecessary typedef

Just spell it "struct rev_name"; it makes it more clear what is
going on.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
name_rev: clarify when a new tip-name is assigned to a commit

In preparation for the later changes, restructure the logic a little
bit to separate how the code decides to use the new "tip" for naming
a particular commit, and what happens based on the decision.

Also re-indent and correct style of this function while we are at it.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
name-rev: --weight option (WIP)

Instead of naming a rev after a tip that is topologically closest,
use the tip that is the oldest one among those which contain the
rev.

The semantics "name-rev --weight" would give is closer to what
people expect from "describe --contains".

Note that this is fairly expensive (see NEEDSWORK comment in the
code).

Signed-off-by: Junio C Hamano <gitster@pobox.com>
Merge branch 'jc/maint-config-exit-status' into jch

(Originally merged to 'next' on 2012-07-30)

The exit status code from "git config" was way overspecified while
being incorrect.  Update the implementation to give the documented
status for a case that was documented, and introduce a new code for
"all other errors".

Will merge to 'master' as part of the third batch.

* jc/maint-config-exit-status:
  config: "git config baa" should exit with status 1

Conflicts:
	builtin/config.c
Merge branch 'jc/maint-sane-execvp-notdir' into jch

(Originally merged to 'next' on 2012-08-09)

"git foo" errored out with "Not a directory" when the user had a non
directory on $PATH, and worse yet it masked an alias "foo" to run.

Will merge to 'master' as part of the third batch.

* jc/maint-sane-execvp-notdir:
  sane_execvp(): ignore non-directory on $PATH
Merge branch 'cw/cherry-pick-allow-empty-message' into jch

(Originally merged to 'next' on 2012-08-09)

"git cherry-pick" by default stops when it sees a commit without any
log message.  The "--allow-empty-message" option can be used to
silently proceed.

Will merge to 'master' as part of the third batch.

* cw/cherry-pick-allow-empty-message:
  cherry-pick: add --allow-empty-message option
Merge branch 'jc/send-email-reconfirm' into jch

Validate interactive input to "git send-email" to avoid common
mistakes such as saying "y<RETURN>" to sender mail address whose
prompt is given with a correctly guessed default.

Will merge to 'master' as part of the third batch.

* jc/send-email-reconfirm:
  send-email: validate & reconfirm interactive responses
Merge branch 'jc/daemon-access-hook' into jch

Allow an external command to tell git-daemon to decline service
based on the client address, repository path, etc.

Will merge to 'master' as part of the third batch.

* jc/daemon-access-hook:
  daemon: --access-hook option
Merge branch 'ph/stash-rerere' into jch

"git stash" internally used "git merge-recursive" backend, which did
not trigger "rerere" upon conflicts unlike other mergy operations.

Will merge to 'master' as part of the third batch.

* ph/stash-rerere:
  stash: invoke rerere in case of conflict
  test: git-stash conflict sets up rerere
Merge branch 'sz/submodule-force-update' into jch

"git submodule update --force" used to leave the working tree of the
submodule intact when there were local changes.  It is more intiutive
to make "--force" a sign to run "checkout -f" to overwrite them.

Will merge to 'master' as part of the third batch.

* sz/submodule-force-update:
  Make 'git submodule update --force' always check out submodules.
Merge branch 'tr/maint-parseopt-avoid-empty' into jch

A workaround to avoid doing _(""), which translates to unwanted
magic string in the .po files.

Will merge to 'master' as part of the fourth batch.

* tr/maint-parseopt-avoid-empty:
  gettext: do not translate empty string
Merge branch 'pw/p4-use-client-spec-branch-detection' into jch

Fixes "git p4" when "--use-client-spec" and "--detect-branches" are
used together (the command used to misdetect branches).

Will merge to 'master' as part of the fourth batch.

* pw/p4-use-client-spec-branch-detection:
  git p4: make branch detection work with --use-client-spec
  git p4: do wildcard decoding in stripRepoPath
  git p4: set self.branchPrefixes in initialization
  git p4 test: add broken --use-client-spec --detect-branches tests
  git p4 test: move client_view() function to library
Merge branch 'lt/commit-tree-guess-utf-8' into jch

Teaches "git commit" and "git commit-tree" the "we are told to use
utf-8 in log message, but this does not look like utf-8---attempt to
pass it through convert-from-latin1-to-utf8 and see if it makes
sense" heuristics "git mailinfo" already uses.

Will merge to 'master' as part of the fourth batch.

* lt/commit-tree-guess-utf-8:
  commit/commit-tree: correct latin1 to utf-8
Merge branch 'kk/maint-for-each-ref-multi-sort' into jch

"git for-each-ref" did not currectly support more than one --sort
option.

Will merge to 'master' as part of the fourth batch.

* kk/maint-for-each-ref-multi-sort:
  for-each-ref: Fix sort with multiple keys
  t6300: test sort with multiple keys
Merge branch 'jk/config-warn-on-inaccessible-paths' into jch

When looking for $HOME/.gitconfig etc., it is OK if we cannot read
them because they do not exist, but unable to read existing ones
need to be diagnosed.

Will merge to 'master' as part of the fourth batch.

* jk/config-warn-on-inaccessible-paths:
  warn_on_inaccessible(): a helper to warn on inaccessible paths
  attr: warn on inaccessible attribute files
  gitignore: report access errors of exclude files
  config: warn on inaccessible files
Merge branch 'nd/i18n-parseopt-help' into jch

A lot of i18n mark-up for the help text from "git <cmd> -h".

Will merge to 'master' as part of the fourth batch.

* nd/i18n-parseopt-help: (66 commits)
  Use imperative form in help usage to describe an action
  Reduce translations by using same terminologies
  i18n: write-tree: mark parseopt strings for translation
  i18n: verify-tag: mark parseopt strings for translation
  i18n: verify-pack: mark parseopt strings for translation
  i18n: update-server-info: mark parseopt strings for translation
  i18n: update-ref: mark parseopt strings for translation
  i18n: update-index: mark parseopt strings for translation
  i18n: tag: mark parseopt strings for translation
  i18n: symbolic-ref: mark parseopt strings for translation
  i18n: show-ref: mark parseopt strings for translation
  i18n: show-branch: mark parseopt strings for translation
  i18n: shortlog: mark parseopt strings for translation
  i18n: rm: mark parseopt strings for translation
  i18n: revert, cherry-pick: mark parseopt strings for translation
  i18n: rev-parse: mark parseopt strings for translation
  i18n: reset: mark parseopt strings for translation
  i18n: rerere: mark parseopt strings for translation
  i18n: status: mark parseopt strings for translation
  i18n: replace: mark parseopt strings for translation
  ...

Conflicts:
	builtin/grep.c
	builtin/revert.c
Merge branch 'nd/am-i18n-fix' into jch

"git am" wasn't marked up for i18n properly.

Will merge to 'master' as part of the fourth batch.

* nd/am-i18n-fix:
  am: quote string for translation before passing to eval_gettextln