Commit graph

1397 commits

Author SHA1 Message Date
Johannes Schindelin 3aef54e8b8 diff: munmap() file contents before running external diff
When running an external diff from, say, a diff tool, it is safe to
assume that we want to write the files in question. On Windows, that
means that there cannot be any other process holding an open handle to
said files, or even just a mapped region.

So let's make sure that `git diff` itself is not holding any open handle
to the files in question.

In fact, we will just release the file pair right away, as the external
diff uses the files we just wrote, so we do not need to hold the file
contents in memory anymore.

This fixes https://github.com/git-for-windows/git/issues/1315

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-07-11 12:11:54 -07:00
Christian Couder b14ed5adaf Use promisor_remote_get_direct() and has_promisor_remote()
Instead of using the repository_format_partial_clone global
and fetch_objects() directly, let's use has_promisor_remote()
and promisor_remote_get_direct().

This way all the configured promisor remotes will be taken
into account, not only the one specified by
extensions.partialClone.

Also when cloning or fetching using a partial clone filter,
remote.origin.promisor will be set to "true" instead of
setting extensions.partialClone to "origin". This makes it
possible to use many promisor remote just by fetching from
them.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-06-25 14:05:37 -07:00
Junio C Hamano 8202d12fca Merge branch 'sb/format-patch-base-patch-id-fix'
The "--base" option of "format-patch" computed the patch-ids for
prerequisite patches in an unstable way, which has been updated to
compute in a way that is compatible with "git patch-id --stable".

* sb/format-patch-base-patch-id-fix:
  format-patch: make --base patch-id output stable
  format-patch: inform user that patch-id generation is unstable
2019-06-13 13:18:46 -07:00
Jiang Xin 8a1569d655 i18n: fix typos found during l10n for git 2.22.0
Fix two typos introduced by the following commits:

+ 31fba9d3b4 (diff-parseopt: convert --[src|dst]-prefix, 2019-03-24)
+ ed8b4132c8 (remote-curl: mark all error messages for translation,
  2019-03-05)

Signed-off-by: Jiang Xin <worldhello.net@gmail.com>
Acked-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-06-03 11:10:53 -07:00
Junio C Hamano 936dce6f93 Merge branch 'ja/diff-opt-typofix'
Typofix.

* ja/diff-opt-typofix:
  diff: fix mistake in translatable strings
2019-05-30 10:50:46 -07:00
Junio C Hamano 20aa7c594f Merge branch 'nd/diff-parseopt'
A brown-paper-bag bugfix to a change already in 'master'.

* nd/diff-parseopt:
  parse-options: check empty value in OPT_INTEGER and OPT_ABBREV
  diff-parseopt: restore -U (no argument) behavior
  diff-parseopt: correct variable types that are used by parseopt
2019-05-30 10:50:44 -07:00
Nguyễn Thái Ngọc Duy 8ef05193bc diff-parseopt: restore -U (no argument) behavior
Before d473e2e0e8 (diff.c: convert -U|--unified, 2019-01-27), -U and
--unified are implemented with a custom parser opt_arg() in diff.c. I
didn't check this code carefully and not realize that it's the
equivalent of PARSE_OPT_NONEG | PARSE_OPT_OPTARG.

In other words, if -U is specified without any argument, the option
should be accepted, and the default value should be used. Without
PARSE_OPT_OPTARG, parse_options() will reject this case and cause a
regression.

Reported-by: Bryan Turner <bturner@atlassian.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-05-29 11:04:32 -07:00
Jean-Noël Avila 8bcd8f4cea diff: fix mistake in translatable strings
Signed-off-by: Jean-Noël Avila <jn.avila@free.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-05-19 11:01:02 +09:00
Stephen Boyd a8f6855f48 format-patch: make --base patch-id output stable
We weren't flushing the context each time we processed a hunk in the
patch-id generation code in diff.c, but we were doing that when we
generated "stable" patch-ids with the 'patch-id' tool. Let's port that
similar logic over from patch-id.c into diff.c so we can get the same
hash when we're generating patch-ids for 'format-patch --base=' types of
command invocations.

Cc: Xiaolong Ye <xiaolong.ye@intel.com>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-05-08 19:27:43 +09:00
Junio C Hamano 32dc15dec1 Merge branch 'jt/batch-fetch-blobs-in-diff'
While running "git diff" in a lazy clone, we can upfront know which
missing blobs we will need, instead of waiting for the on-demand
machinery to discover them one by one.  Aim to achieve better
performance by batching the request for these promised blobs.

* jt/batch-fetch-blobs-in-diff:
  diff: batch fetching of missing blobs
  sha1-file: support OBJECT_INFO_FOR_PREFETCH
2019-04-25 16:41:19 +09:00
Junio C Hamano dcd6a8c09a Merge branch 'nd/diff-parseopt-4'
Fourth batch to teach the diff machinery to use the parse-options
API.

* nd/diff-parseopt-4:
  am: avoid diff_opt_parse()
  diff --no-index: use parse_options() instead of diff_opt_parse()
  range-diff: use parse_options() instead of diff_opt_parse()
  diff.c: allow --no-color-moved-ws
  diff-parseopt: convert --color-moved-ws
  diff-parseopt: convert --[no-]color-moved
  diff-parseopt: convert --inter-hunk-context
  diff-parseopt: convert --no-prefix
  diff-parseopt: convert --line-prefix
  diff-parseopt: convert --[src|dst]-prefix
  diff-parseopt: convert --[no-]abbrev
  diff-parseopt: convert --diff-filter
  diff-parseopt: convert --find-object
  diff-parseopt: convert -O
  diff-parseopt: convert --pickaxe-all|--pickaxe-regex
  diff-parseopt: convert -S|-G
  diff-parseopt: convert -l
  diff-parseopt: convert -z
  diff-parseopt: convert --ita-[in]visible-in-index
  diff-parseopt: convert --ws-error-highlight
2019-04-25 16:41:12 +09:00
Junio C Hamano 8a9a837a63 Merge branch 'nd/diff-parseopt-3'
Third batch to teach the diff machinery to use the parse-options
API.

* nd/diff-parseopt-3:
  diff-parseopt: convert --submodule
  diff-parseopt: convert --ignore-submodules
  diff-parseopt: convert --textconv
  diff-parseopt: convert --ext-diff
  diff-parseopt: convert --quiet
  diff-parseopt: convert --exit-code
  diff-parseopt: convert --color-words
  diff-parseopt: convert --word-diff-regex
  diff-parseopt: convert --word-diff
  diff-parseopt: convert --[no-]color
  diff-parseopt: convert --[no-]follow
  diff-parseopt: convert -R
  diff-parseopt: convert -a|--text
  diff-parseopt: convert --full-index
  diff-parseopt: convert --binary
  diff-parseopt: convert --anchored
  diff-parseopt: convert --diff-algorithm
  diff-parseopt: convert --histogram
  diff-parseopt: convert --patience
  diff-parseopt: convert --[no-]indent-heuristic
2019-04-16 19:28:03 +09:00
Jonathan Tan 7fbbcb21b1 diff: batch fetching of missing blobs
When running a command like "git show" or "git diff" in a partial clone,
batch all missing blobs to be fetched as one request.

This is similar to c0c578b33c ("unpack-trees: batch fetching of missing
blobs", 2017-12-08), but for another command.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-04-08 14:04:50 +09:00
Nguyễn Thái Ngọc Duy cdb5330a9b am: avoid diff_opt_parse()
diff_opt_parse() is a heavy hammer to just set diff filter. But it's
the only way because of the diff_status_letters[] mapping. Add a new
API to set diff filter and use it in git-am. diff_opt_parse()'s only
remaining call site in revision.c will be gone soon and having it here
just because of git-am does not make sense.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-24 22:21:24 +09:00
Nguyễn Thái Ngọc Duy bb9872904e diff.c: allow --no-color-moved-ws
This option is added in commit b73bcbac4a (diff: allow
--no-color-moved-ws - 2018-11-23) in pw/diff-color-moved-ws-fix. To ease
merge conflict resolution, re-implement the option handling here so that
the conflict could be resolved by taking this side of change.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-24 22:21:23 +09:00
Nguyễn Thái Ngọc Duy 8ce2020ff0 diff-parseopt: convert --color-moved-ws
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-24 22:21:23 +09:00
Nguyễn Thái Ngọc Duy 59311a9820 diff-parseopt: convert --[no-]color-moved
Mark one more string for translation while at there

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-24 22:21:23 +09:00
Nguyễn Thái Ngọc Duy 16ed6c97cc diff-parseopt: convert --inter-hunk-context
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-24 22:21:23 +09:00
Nguyễn Thái Ngọc Duy 11c659d890 diff-parseopt: convert --no-prefix
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-24 22:21:23 +09:00
Nguyễn Thái Ngọc Duy 2f81cf9895 diff-parseopt: convert --line-prefix
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-24 22:21:23 +09:00
Nguyễn Thái Ngọc Duy 31fba9d3b4 diff-parseopt: convert --[src|dst]-prefix
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-24 22:21:23 +09:00
Nguyễn Thái Ngọc Duy d877418390 diff-parseopt: convert --[no-]abbrev
OPT__ABBREV() has the same behavior as the deleted code with one
difference: it does check for valid number and error out if not. And the
'40' change is self explanatory.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-24 22:21:22 +09:00
Nguyễn Thái Ngọc Duy d2d3f27300 diff-parseopt: convert --diff-filter
While at it, mark one more string for translation

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-24 22:21:22 +09:00
Nguyễn Thái Ngọc Duy a75f28cbda diff-parseopt: convert --find-object
While at it, mark one more string for translation.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-24 22:21:22 +09:00
Nguyễn Thái Ngọc Duy f731814b3a diff-parseopt: convert -O
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-24 22:21:22 +09:00
Nguyễn Thái Ngọc Duy 85f8e889ea diff-parseopt: convert --pickaxe-all|--pickaxe-regex
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-24 22:21:22 +09:00
Nguyễn Thái Ngọc Duy a41cfb3203 diff-parseopt: convert -S|-G
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-24 22:21:22 +09:00
Nguyễn Thái Ngọc Duy bffee749a8 diff-parseopt: convert -l
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-24 22:21:22 +09:00
Nguyễn Thái Ngọc Duy 1a1eb164cf diff-parseopt: convert -z
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-24 22:21:22 +09:00
Nguyễn Thái Ngọc Duy 96860e48d3 diff-parseopt: convert --ita-[in]visible-in-index
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-24 22:21:21 +09:00
Nguyễn Thái Ngọc Duy 5a749d9f97 diff-parseopt: convert --ws-error-highlight
Mark one more string for translation while at there.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-24 22:21:21 +09:00
Junio C Hamano 4ab0f13857 Merge branch 'nd/diff-parseopt-2'
Second batch to teach the diff machinery to use the parse-options
API.

* nd/diff-parseopt-2: (21 commits)
  diff-parseopt: convert --ignore-some-changes
  diff-parseopt: convert --[no-]minimal
  diff-parseopt: convert --relative
  diff-parseopt: convert --no-renames|--[no--rename-empty
  diff-parseopt: convert --find-copies-harder
  diff-parseopt: convert -C|--find-copies
  diff-parseopt: convert -D|--irreversible-delete
  diff-parseopt: convert -M|--find-renames
  diff-parseopt: convert -B|--break-rewrites
  diff-parseopt: convert --output-*
  diff-parseopt: convert --[no-]compact-summary
  diff-parseopt: convert --stat*
  diff-parseopt: convert -s|--no-patch
  diff-parseopt: convert --name-status
  diff-parseopt: convert --name-only
  diff-parseopt: convert --patch-with-stat
  diff-parseopt: convert --summary
  diff-parseopt: convert --check
  diff-parseopt: convert --dirstat and friends
  diff-parseopt: convert --numstat and --shortstat
  ...
2019-03-07 09:59:58 +09:00
Junio C Hamano b0e7fb2e5c Merge branch 'nd/completion-more-parameters'
The command line completion (in contrib/) has been taught to
complete more subcommand parameters.

* nd/completion-more-parameters:
  completion: add more parameter value completion
2019-03-07 09:59:58 +09:00
Junio C Hamano 1dc2f8c122 Merge branch 'jk/unused-params'
Code clean-up.

* jk/unused-params:
  ref-filter: drop unused "sz" parameters
  ref-filter: drop unused "obj" parameters
  ref-filter: drop unused buf/sz pairs
  files-backend: drop refs parameter from split_symref_update()
  pack-objects: drop unused parameter from oe_map_new_pack()
  merge-recursive: drop several unused parameters
  diff: drop complete_rewrite parameter from run_external_diff()
  diff: drop unused emit data parameter from sane_truncate_line()
  diff: drop unused color reset parameters
  diff: drop options parameter from diffcore_fix_diff_index()
2019-03-07 09:59:57 +09:00
Junio C Hamano 54b469b9e9 Merge branch 'nd/diff-parseopt'
The diff machinery, one of the oldest parts of the system, which
long predates the parse-options API, uses fairly long and complex
handcrafted option parser.  This is being rewritten to use the
parse-options API.

* nd/diff-parseopt:
  diff.c: convert --raw
  diff.c: convert -W|--[no-]function-context
  diff.c: convert -U|--unified
  diff.c: convert -u|-p|--patch
  diff.c: prepare to use parse_options() for parsing
  diff.h: avoid bit fields in struct diff_flags
  diff.h: keep forward struct declarations sorted
  parse-options: allow ll_callback with OPTION_CALLBACK
  parse-options: avoid magic return codes
  parse-options: stop abusing 'callback' for lowlevel callbacks
  parse-options: add OPT_BITOP()
  parse-options: disable option abbreviation with PARSE_OPT_KEEP_UNKNOWN
  parse-options: add one-shot mode
  parse-options.h: remove extern on function prototypes
2019-03-07 09:59:52 +09:00
Nguyễn Thái Ngọc Duy 125dcea963 diff-parseopt: convert --submodule
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-07 08:02:22 +09:00
Nguyễn Thái Ngọc Duy b680ee1495 diff-parseopt: convert --ignore-submodules
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-07 08:02:22 +09:00
Nguyễn Thái Ngọc Duy 8ab76977ad diff-parseopt: convert --textconv
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-07 08:02:22 +09:00
Nguyễn Thái Ngọc Duy 0cda1003b7 diff-parseopt: convert --ext-diff
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-07 08:02:22 +09:00
Nguyễn Thái Ngọc Duy 9bbaf1ce34 diff-parseopt: convert --quiet
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-07 08:02:22 +09:00
Nguyễn Thái Ngọc Duy 1086ea0cc2 diff-parseopt: convert --exit-code
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-07 08:02:22 +09:00
Nguyễn Thái Ngọc Duy 212db69d8c diff-parseopt: convert --color-words
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-07 08:02:22 +09:00
Nguyễn Thái Ngọc Duy 797df119a2 diff-parseopt: convert --word-diff-regex
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-07 08:02:22 +09:00
Nguyễn Thái Ngọc Duy e9fb39b668 diff-parseopt: convert --word-diff
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-07 08:02:22 +09:00
Nguyễn Thái Ngọc Duy 8b81c26e5c diff-parseopt: convert --[no-]color
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-07 08:02:22 +09:00
Nguyễn Thái Ngọc Duy 1e9250b5aa diff-parseopt: convert --[no-]follow
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-07 08:02:22 +09:00
Nguyễn Thái Ngọc Duy 4f99f29905 diff-parseopt: convert -R
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-07 08:02:22 +09:00
Nguyễn Thái Ngọc Duy c37d4c0a3c diff-parseopt: convert -a|--text
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-07 08:02:21 +09:00
Nguyễn Thái Ngọc Duy 4fe0167215 diff-parseopt: convert --full-index
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-07 08:02:21 +09:00
Nguyễn Thái Ngọc Duy 6d9af6f4da diff-parseopt: convert --binary
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-07 08:02:21 +09:00
Nguyễn Thái Ngọc Duy df84a43627 diff-parseopt: convert --anchored
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-07 08:02:21 +09:00
Nguyễn Thái Ngọc Duy 10f35b1cc0 diff-parseopt: convert --diff-algorithm
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-07 08:02:21 +09:00
Nguyễn Thái Ngọc Duy f1e68ef561 diff-parseopt: convert --histogram
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-07 08:02:21 +09:00
Nguyễn Thái Ngọc Duy 31fd640e95 diff-parseopt: convert --patience
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-07 08:02:21 +09:00
Nguyễn Thái Ngọc Duy 06f77518db diff-parseopt: convert --[no-]indent-heuristic
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-07 08:02:21 +09:00
Nguyễn Thái Ngọc Duy 87649a1674 diff-parseopt: convert --ignore-some-changes
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-02-21 15:16:59 -08:00
Nguyễn Thái Ngọc Duy 2e75f922f3 diff-parseopt: convert --[no-]minimal
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-02-21 15:16:59 -08:00
Nguyễn Thái Ngọc Duy 0b1c5b59f0 diff-parseopt: convert --relative
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-02-21 15:16:59 -08:00
Nguyễn Thái Ngọc Duy cdc43eb0b8 diff-parseopt: convert --no-renames|--[no--rename-empty
For --rename-empty, see 90d43b0768 (teach diffcore-rename to
optionally ignore empty content - 2012-03-22) for more information.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-02-21 15:16:59 -08:00
Nguyễn Thái Ngọc Duy bdd4741bfd diff-parseopt: convert --find-copies-harder
--no-find-copies-harder is also added on purpose (because I don't see
why we should not have the --no- version for this)

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-02-21 15:16:59 -08:00
Nguyễn Thái Ngọc Duy 7f64850d36 diff-parseopt: convert -C|--find-copies
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-02-21 15:16:59 -08:00
Nguyễn Thái Ngọc Duy 1e5332968a diff-parseopt: convert -D|--irreversible-delete
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-02-21 15:16:59 -08:00
Nguyễn Thái Ngọc Duy f476308b27 diff-parseopt: convert -M|--find-renames
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-02-21 15:16:59 -08:00
Nguyễn Thái Ngọc Duy ced4e179fe diff-parseopt: convert -B|--break-rewrites
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-02-21 15:16:59 -08:00
Nguyễn Thái Ngọc Duy af2f368091 diff-parseopt: convert --output-*
This also validates that the user specifies a single character in
--output-indicator-*, not a string.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-02-21 15:16:59 -08:00
Nguyễn Thái Ngọc Duy 7d7942b796 diff-parseopt: convert --[no-]compact-summary
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-02-21 15:16:59 -08:00
Nguyễn Thái Ngọc Duy 84b5089e41 diff-parseopt: convert --stat*
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-02-21 15:16:59 -08:00
Nguyễn Thái Ngọc Duy e01df7a33d diff-parseopt: convert -s|--no-patch
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-02-21 15:16:59 -08:00
Nguyễn Thái Ngọc Duy a23874726b diff-parseopt: convert --name-status
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-02-21 15:16:58 -08:00
Nguyễn Thái Ngọc Duy 0e840e2af4 diff-parseopt: convert --name-only
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-02-21 15:16:58 -08:00
Nguyễn Thái Ngọc Duy e550f58551 diff-parseopt: convert --patch-with-stat
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-02-21 15:16:58 -08:00
Nguyễn Thái Ngọc Duy 70a304179a diff-parseopt: convert --summary
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-02-21 15:16:58 -08:00
Nguyễn Thái Ngọc Duy fc6af3e92a diff-parseopt: convert --check
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-02-21 15:16:58 -08:00
Nguyễn Thái Ngọc Duy 4ce7aab5a5 diff-parseopt: convert --dirstat and friends
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-02-21 15:16:58 -08:00
Nguyễn Thái Ngọc Duy e56736203e diff-parseopt: convert --numstat and --shortstat
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-02-20 12:32:53 -08:00
Nguyễn Thái Ngọc Duy c659f30398 diff-parseopt: convert --patch-with-raw
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-02-20 12:32:53 -08:00
Nguyễn Thái Ngọc Duy 5a59a2301f completion: add more parameter value completion
This adds value completion for a couple more paramters. To make it
easier to maintain these hard coded lists, add a comment at the original
list/code to remind people to update git-completion.bash too.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-02-20 12:31:56 -08:00
Jeff King 4bc1792750 diff: drop complete_rewrite parameter from run_external_diff()
Our builtin_diff() wants to know whether break-detection found a
complete rewrite, because it changes how the diff is shown. However,
when calling out to an external diff, we don't pass this information
along (and doing so would require designing a new interface to the
user-provided program).

Let's drop the unused parameter to make this fact more clear.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-02-14 15:26:14 -08:00
Jeff King 19b9046eed diff: drop unused emit data parameter from sane_truncate_line()
We pass the "struct emit_callback" (which contains all of the context
for our diff) into sane_truncate_line(), but that function doesn't
actually use it. In theory we might eventually develop a diff option
that impacts this, but in the meantime let's not mislead anybody reading
the code. Since the function is static, it would be easy to pass it
again if it should ever become useful.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-02-14 15:26:14 -08:00
Jeff King e04df61256 diff: drop unused color reset parameters
Several of the emit_* functions take a "reset" color parameter, but
never actually look at it (instead, they call into emit_diff_symbol,
which handles the colors itself). Let's drop these unused parameters.

Note that emit_line() does still take a color/reset pair, and actually
uses it. It cannot be refactored to match these other functions because
it's the thing that emit_diff_symbol eventually calls into (i.e., it
does not by itself know which colors to use, and must be told by the
caller).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-02-14 15:26:14 -08:00
Jeff King 784c0daed5 diff: drop options parameter from diffcore_fix_diff_index()
The sole purpose of this function is to fix the sorting order of the
queued diff entries. It doesn't need to know about any diff options, so
we can drop the unused parameter.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-02-14 15:26:14 -08:00
Junio C Hamano 5d2710bd3c Merge branch 'jk/diff-cc-stat-fixes'
"git diff --color-moved --cc --stat -p" did not work well due to
funny interaction between a bug in color-moved and the rest, which
has been fixed.

* jk/diff-cc-stat-fixes:
  combine-diff: treat --dirstat like --stat
  combine-diff: treat --summary like --stat
  combine-diff: treat --shortstat like --stat
  combine-diff: factor out stat-format mask
  diff: clear emitted_symbols flag after use
  t4006: resurrect commented-out tests
2019-02-05 14:26:17 -08:00
Junio C Hamano 773e408881 Merge branch 'jk/save-getenv-result'
There were many places the code relied on the string returned from
getenv() to be non-volatile, which is not true, that have been
corrected.

* jk/save-getenv-result:
  builtin_diff(): read $GIT_DIFF_OPTS closer to use
  merge-recursive: copy $GITHEAD strings
  init: make a copy of $GIT_DIR string
  config: make a copy of $GIT_CONFIG string
  commit: copy saved getenv() result
  get_super_prefix(): copy getenv() result
2019-01-29 12:47:54 -08:00
Junio C Hamano 15b07cba0b Merge branch 'pw/diff-color-moved-ws-fix'
"git diff --color-moved-ws" updates.

* pw/diff-color-moved-ws-fix:
  diff --color-moved-ws: handle blank lines
  diff --color-moved-ws: modify allow-indentation-change
  diff --color-moved-ws: optimize allow-indentation-change
  diff --color-moved=zebra: be stricter with color alternation
  diff --color-moved-ws: fix false positives
  diff --color-moved-ws: demonstrate false positives
  diff: allow --no-color-moved-ws
  Use "whitespace" consistently
  diff: document --no-color-moved
2019-01-29 12:47:53 -08:00
Junio C Hamano 6a015cecbe Merge branch 'kg/external-diff-save-env'
The code to drive GIT_EXTERNAL_DIFF command relied on the string
returned from getenv() to be non-volatile, which is not true, that
has been corrected.

* kg/external-diff-save-env:
  diff: ensure correct lifetime of external_diff_cmd
2019-01-29 12:47:52 -08:00
Nguyễn Thái Ngọc Duy ed88148674 diff.c: convert --raw
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-01-27 16:28:18 -08:00
Nguyễn Thái Ngọc Duy 7fd9a1ba03 diff.c: convert -W|--[no-]function-context
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-01-27 16:28:18 -08:00
Nguyễn Thái Ngọc Duy d473e2e0e8 diff.c: convert -U|--unified
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-01-27 16:28:18 -08:00
Nguyễn Thái Ngọc Duy cc013c224c diff.c: convert -u|-p|--patch
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-01-27 16:28:18 -08:00
Nguyễn Thái Ngọc Duy 4a28847839 diff.c: prepare to use parse_options() for parsing
This is a preparation step to start using parse_options() to parse
diff/revision options instead of what we have now. There are a couple
of good things from using parse_options():

- better help usage
- easier to add new options
- better completion support
- help usage generation
- better integration with main command option parser. We can just
  concat the main command's option array and diffopt's together and
  parse all in one go.
- detect colidding options (e.g. --reverse is used by revision code,
  so diff code can't use it as long name for -R)
- consistent syntax, e.g. option that takes mandatory argument will
  now accept both "--option=value" and "--option value".

The plan is migrate all diff/rev options to parse_options(). Then we
could get rid of diff_opt_parse() and expose parseopts[] directly to
the caller.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-01-27 16:28:18 -08:00
Jeff King 48edf3a02a diff: clear emitted_symbols flag after use
There's an odd bug when "log --color-moved" is used with the combination
of "--cc --stat -p": the stat for merge commits is erroneously shown
with the diff of the _next_ commit.

The included test demonstrates the issue. Our history looks something
like this:

  A-B-M--D
   \ /
    C

When we run "git log --cc --stat -p --color-moved" starting at D, we get
this sequence of events:

  1. The diff for D is using -p, so diff_flush() calls into
     diff_flush_patch_all_file_pairs(). There we see that o->color_moved
     is in effect, so we point o->emitted_symbols to a static local
     struct, causing diff_flush_patch() to queue the symbols instead of
     actually writing them out.

     We then do our move detection, emit the symbols, and clear the
     struct. But we leave o->emitted_symbols pointing to our struct.

  2. Next we compute the diff for M. This is a merge, so we use the
     combined diff code. In find_paths_generic(), we compute the
     pairwise diff between each commit and its parent. Normally this is
     done with DIFF_FORMAT_NO_OUTPUT, since we're just looking for
     intersecting paths. But since "--stat --cc" shows the first-parent
     stat, and since we're computing that diff anyway, we enable
     DIFF_FORMAT_DIFFSTAT for the first parent. This outputs the stat
     information immediately, saving us from running a separate
     first-parent diff later.

     But where does that output go? Normally it goes directly to stdout,
     but because o->emitted_symbols is set, we queue it. As a result, we
     don't actually print the diffstat for the merge commit (yet), which
     is wrong.

  3. Next we compute the diff for C. We're actually showing a patch
     again, so we end up in diff_flush_patch_all_file_pairs(), but this
     time we have the queued stat from step 2 waiting in our struct.

     We add new elements to it for C's diff, and then flush the whole
     thing. And we see the diffstat from M as part of C's diff, which is
     wrong.

So triggering the bug really does require the combination of all of
those options.

To fix it, we can simply restore o->emitted_symbols to NULL after
flushing it, so that it does not affect anything outside of
diff_flush_patch_all_file_pairs(). This intuitively makes sense, since
nobody outside of that function is going to bother flushing it, so we
would not want them to write to it either.

In fact, we could take this a step further and turn the local "esm"
struct into a non-static variable that goes away after the function
ends. However, since it contains a dynamically sized array, we benefit
from amortizing the cost of allocations over many calls. So we'll leave
it as static to retain that benefit.

But let's push the zero-ing of esm.nr into the conditional for "if
(o->emitted_symbols)" to make it clear that we do not expect esm to hold
any values if we did not just try to use it. With the code as it is
written now, if we did encounter such a case (which I think would be a
bug), we'd silently leak those values without even bothering to display
them. With this change, we'd at least eventually show them, and somebody
would notice.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-01-24 11:59:07 -08:00
Junio C Hamano 3434569fc2 Merge branch 'nd/style-opening-brace'
Code clean-up.

* nd/style-opening-brace:
  style: the opening '{' of a function is in a separate line
2019-01-18 13:49:52 -08:00
Junio C Hamano 932b867be0 Merge branch 'sb/diff-color-moved-config-option-fixup'
Minor inconsistency fix.

* sb/diff-color-moved-config-option-fixup:
  diff: align move detection error handling with other options
2019-01-14 15:29:31 -08:00
Jeff King 0da0e9268b builtin_diff(): read $GIT_DIFF_OPTS closer to use
The value returned by getenv() is not guaranteed to remain valid across
other environment function calls. But in between our call and using the
value, we run fill_textconv(), which may do quite a bit of work,
including spawning sub-processes.

We can make this safer by calling getenv() right before we actually look
at its value.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-01-11 18:48:59 -08:00
Kim Gybels 6776a84dae diff: ensure correct lifetime of external_diff_cmd
According to getenv(3)'s notes:

    The implementation of getenv() is not required to be reentrant.  The
    string pointed to by the return value of getenv() may be statically
    allocated, and can be modified by a subsequent call to getenv(),
    putenv(3), setenv(3), or unsetenv(3).

Since strings returned by getenv() are allowed to change on subsequent
calls to getenv(), make sure to duplicate when caching external_diff_cmd
from environment.

This problem becomes apparent on Git for Windows since fe21c6b285
(mingw: reencode environment variables on the fly (UTF-16 <-> UTF-8)),
when the getenv() implementation provided in compat/mingw.c was changed
to keep a certain amount of alloc'ed strings and freeing them on
subsequent calls.

This fixes https://github.com/git-for-windows/git/issues/2007:

    $ yes n | git -c difftool.prompt=yes difftool fe21c6b285 fe21c6b285df~100

    Viewing (1/404): '.gitignore'
    Launch 'bc3' [Y/n]?
    Viewing (2/404): 'Documentation/.gitignore'
    Launch 'bc3' [Y/n]?
    Viewing (3/404): 'Documentation/Makefile'
    Launch 'bc3' [Y/n]?
    Viewing (4/404): 'Documentation/RelNotes/2.14.5.txt'
    Launch 'bc3' [Y/n]?
    Viewing (5/404): 'Documentation/RelNotes/2.15.3.txt'
    Launch 'bc3' [Y/n]?
    Viewing (6/404): 'Documentation/RelNotes/2.16.5.txt'
    Launch 'bc3' [Y/n]?
    Viewing (7/404): 'Documentation/RelNotes/2.17.2.txt'
    Launch 'bc3' [Y/n]?
    Viewing (8/404): 'Documentation/RelNotes/2.18.1.txt'
    Launch 'bc3' [Y/n]?
    Viewing (9/404): 'Documentation/RelNotes/2.19.0.txt'
    Launch 'bc3' [Y/n]? error: cannot spawn ¦?: No such file or directory
    fatal: external diff died, stopping at Documentation/RelNotes/2.19.1.txt

Signed-off-by: Kim Gybels <kgybels@infogroep.be>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-01-11 18:32:38 -08:00
Phillip Wood 0cd51e9d05 diff --color-moved-ws: handle blank lines
When using --color-moved-ws=allow-indentation-change allow lines with
the same indentation change to be grouped across blank lines. For now
this only works if the blank lines have been moved as well, not for
blocks that have just had their indentation changed.

This completes the changes to the implementation of
--color-moved=allow-indentation-change. Running

  git diff --color-moved=allow-indentation-change v2.18.0 v2.19.0

now takes 5.0s. This is a saving of 41% from 8.5s for the optimized
version of the previous implementation and 66% from the original which
took 14.6s.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Reviewed-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-01-10 10:38:29 -08:00
Phillip Wood 21536d077f diff --color-moved-ws: modify allow-indentation-change
Currently diff --color-moved-ws=allow-indentation-change does not
support indentation that contains a mix of tabs and spaces. For
example in commit 546f70f377 ("convert.h: drop 'extern' from function
declaration", 2018-06-30) the function parameters in the following
lines are not colored as moved [1].

-extern int stream_filter(struct stream_filter *,
-                        const char *input, size_t *isize_p,
-                        char *output, size_t *osize_p);
+int stream_filter(struct stream_filter *,
+                 const char *input, size_t *isize_p,
+                 char *output, size_t *osize_p);

This commit changes the way the indentation is handled to track the
visual size of the indentation rather than the characters in the
indentation. This has the benefit that any whitespace errors do not
interfer with the move detection (the whitespace errors will still be
highlighted according to --ws-error-highlight). During the discussion
of this feature there were concerns about the correct detection of
indentation for python. However those concerns apply whether or not
we're detecting moved lines so no attempt is made to determine if the
indentation is 'pythonic'.

[1] Note that before the commit to fix the erroneous coloring of moved
    lines each line was colored as a different block, since that commit
    they are uncolored.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Reviewed-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-01-10 10:38:24 -08:00
Phillip Wood 7a4252c4df diff --color-moved-ws: optimize allow-indentation-change
When running

  git diff --color-moved-ws=allow-indentation-change v2.18.0 v2.19.0

cmp_in_block_with_wsd() is called 694908327 times. Of those 42.7%
return after comparing a and b. By comparing the lengths first we can
return early in all but 0.03% of those cases without dereferencing the
string pointers. The comparison between a and c fails in 6.8% of
calls, by comparing the lengths first we reject all the failing calls
without dereferencing the string pointers.

This reduces the time to run the command above by by 42% from 14.6s to
8.5s. This is still much slower than the normal --color-moved which
takes ~0.6-0.7s to run but is a significant improvement.

The next commits will replace the current implementation with one that
works with mixed tabs and spaces in the indentation. I think it is
worth optimizing the current implementation first to enable a fair
comparison between the two implementations.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Reviewed-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-01-10 10:38:19 -08:00
Phillip Wood b0a2ba4776 diff --color-moved=zebra: be stricter with color alternation
Currently when using --color-moved=zebra the color of moved blocks
depends on the number of lines separating them. This means that adding
an odd number of unmoved lines between blocks that are already separated
by one or more unmoved lines will change the color of subsequent moved
blocks. This does not make much sense as the blocks were already
separated by unmoved lines and causes problems when adding lines to test
cases.

Fix this by only using the alternate colors for adjacent moved blocks.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Reviewed-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-01-10 10:38:15 -08:00
Phillip Wood 2034b473e1 diff --color-moved-ws: fix false positives
'diff --color-moved-ws=allow-indentation-change' can color lines as
moved when they are in fact different. For example in commit
1a07e59c3e ("Update messages in preparation for i18n", 2018-07-21) the
lines

-               die (_("must end with a color"));
+               die(_("must end with a color"));

are colored as moved even though they are different.

This is because if there is a fuzzy match for the first line of
a potential moved block the line is marked as moved before the
potential match is checked to see if it actually matches. The fix is
to delay marking the line as moved until after we have checked that
there really is at least one matching potential moved block.

Note that the test modified in the last commit still fails because
adding an unmoved line between two moved blocks that are already
separated by unmoved lines changes the color of the block following the
addition. This should not be the case and will be fixed in the next
commit.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Reviewed-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-01-10 10:38:08 -08:00