use strchrnul() in place of strchr() and strlen()

Avoid scanning strings twice, once with strchr() and then with
strlen(), by using strchrnul().

Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Rohit Mani <rohit.mani@outlook.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
clean: respect pathspecs with "-d"

git-clean uses read_directory to fill in a `struct dir` with
potential hits. However, read_directory does not actually
check against our pathspec. It uses a simplified version
that may turn up false positives. As a result, we need to
check that any hits match our pathspec. We do so reliably
for non-directories. For directories, if "-d" is not given
we check that the pathspec matched exactly (i.e., we are
even stricter, and require an explicit "git clean foo" to
clean "foo/"). But if "-d" is given, rather than relaxing
the exact match to allow a recursive match, we do not check
the pathspec at all.

This regression was introduced in 113f10f (Make git-clean a
builtin, 2007-11-11).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
clean: simplify dir/not-dir logic

When we get a list of paths from read_directory, we further
prune it to create the final list of items to remove. The
code paths for directories and non-directories repeat the
same "add to list" code.

This patch restructures the code so that we don't repeat
ourselves. Also, by following a "if (condition) continue"
pattern like the pathspec check above, it makes it more
obvious that the conditional is about excluding directories
under certain circumstances.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Merge branch 'jc/check-attr-honor-working-tree' into jch

"git check-attr" when (trying to) work on a repository with a
working tree did not work well when the working tree was specified
via --work-tree (and obviously with --git-dir).

The command also works in a bare repository but it reads from the
(possibly stale, irrelevant and/or nonexistent) index, which may
need to be fixed to read from HEAD, but that is a completely
separate issue.  As a related tangent to this separate issue, we
may want to also fix "check-ignore", which refuses to work in a
bare repository, to also operate in a bare one.

* jc/check-attr-honor-working-tree:
  check-attr: move to the top of working tree when in non-bare repository
  t0003: do not chdir the whole test process

# Conflicts:
# 	t/t0003-attributes.sh
Merge branch 'nd/gitignore-trailing-whitespace' into jch

Warn and then ignore trailing whitespaces in .gitignore files,
unless they are quoted for fnmatch(3), e.g. "path\ ".

Reported to be broken on Windows, at least the new test does not pass.

* nd/gitignore-trailing-whitespace:
  t0008: skip trailing space test on Windows
  dir: ignore trailing spaces in exclude patterns
  dir: warn about trailing spaces in exclude patterns
Merge branch 'ss/completion-rec-sub-fetch-push' into jch

* ss/completion-rec-sub-fetch-push:
  completion: teach --recurse-submodules to fetch, pull and push
Merge branch 'jk/http-no-curl-easy' into jch

Avoid use of the curl-easy family of functions, which interferes
with connection reuse in a negative way.

* jk/http-no-curl-easy:
  http: never use curl_easy_perform
Merge branch 'jk/janitorial-fixes' into jch

* jk/janitorial-fixes:
  open_istream(): do not dereference NULL in the error case
  builtin/mv: don't use memory after free
  utf8: use correct type for values in interval table
  utf8: fix iconv error detection
  notes-utils: handle boolean notes.rewritemode correctly
Merge branch 'ks/config-file-stdin' into jch

* ks/config-file-stdin:
  config: teach "git config --file -" to read from the standard input
  config: change git_config_with_options() interface
  builtin/config.c: rename check_blob_write() -> check_write()
  config: disallow relative include paths from blobs
Merge branch 'lb/contrib-contacts-looser-diff-parsing' into jch

* lb/contrib-contacts-looser-diff-parsing:
  git-contacts: do not fail parsing of good diffs
Merge branch 'nd/reset-setup-worktree' into jch

"git reset" needs to refresh the index when working in a working
tree (it can also be used to match the index to the HEAD in an
otherwise bare repository), but it failed to set up the working
tree properly, causing GIT_WORK_TREE to be ignored.

* nd/reset-setup-worktree:
  reset: optionally setup worktree and refresh index on --mixed

# Conflicts:
# 	t/t7102-reset.sh
Merge branch 'tr/diff-submodule-no-reuse-worktree' into jch

"git diff --external-diff" incorrectly fed the submodule directory
in the working tree to the external diff driver when it knew it is
the same as one of the versions being compared.

* tr/diff-submodule-no-reuse-worktree:
  diff: do not reuse_worktree_file for submodules
Merge branch 'ak/gitweb-fit-image' into jch

Instead of allowing an <img> to be shown in whatever size, force
scaling it to fit on the page with max-height/max-width css style
attributes.

* ak/gitweb-fit-image:
  gitweb: Avoid overflowing page body frame with large images
Merge branch 'nd/no-more-fnmatch' into jch

We started using wildmatch() in place of fnmatch(3); complete the
process and stop using fnmatch(3).

* nd/no-more-fnmatch:
  actually remove compat fnmatch source code
  stop using fnmatch (either native or compat)
  Revert "test-wildmatch: add "perf" command to compare wildmatch and fnmatch"
  use wildmatch() directly without fnmatch() wrapper
Merge branch 'rt/links-for-asciidoctor' into jch

* rt/links-for-asciidoctor:
  Documentation: fix documentation AsciiDoc links for external urls
Merge branch 'jh/note-trees-record-blobs' into jch

"git notes -C <blob>" should not take an object that is not a blob.

* jh/note-trees-record-blobs:
  notes: disallow reusing non-blob as a note object
Merge branch 'jk/commit-dates-parsing-fix' into jch

* jk/commit-dates-parsing-fix:
  show_ident_date: fix tz range check
  log: do not segfault on gmtime errors
  log: handle integer overflow in timestamps
  date: check date overflow against time_t
  fsck: report integer overflow in author timestamps
  t4212: test bogus timestamps with git-log
Merge branch 'jk/remote-pushremote-config-reading' into jch

* jk/remote-pushremote-config-reading:
  remote: handle pushremote config in any order
Merge branch 'jm/stash-doc-k-for-keep' into jch

* jm/stash-doc-k-for-keep:
  stash doc: mention short form -k in save description
Merge branch 'jn/am-doc-hooks' into jch

* jn/am-doc-hooks:
  am doc: add a pointer to relevant hooks