+
Skip to content

add-patch.c: compare oids instead of string literals #1178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 107 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
59f42a7
Merge branch 'cw/protocol-v2-doc-fix' into next
gitster Dec 2, 2021
1ec6866
Merge branch 'vd/sparse-sparsity-fix-on-read' into next
gitster Dec 2, 2021
d7ea169
Merge branch 'gc/remote-with-fewer-static-global-variables' into next
gitster Dec 2, 2021
f722049
Merge branch 'ja/doc-cleanup' into next
gitster Dec 2, 2021
81213be
Merge branch 'if/redact-packfile-uri' into next
gitster Dec 2, 2021
43a5c1e
Merge branch 'jc/fix-first-object-walk' into next
gitster Dec 2, 2021
bc756bc
Merge branch 'js/ci-no-directional-formatting' into next
gitster Dec 2, 2021
d0b158d
Merge branch 'jk/strbuf-addftime-seconds-since-epoch' into next
gitster Dec 2, 2021
9445128
Merge branch 'tw/var-default-branch' into next
gitster Dec 2, 2021
37a575b
Merge branch 'ab/generate-command-list' into next
gitster Dec 2, 2021
c273d40
Merge branch 'jk/test-bitmap-fix' into next
gitster Dec 2, 2021
fea9019
Merge branch 'jk/jump-merge-with-pathspec' into next
gitster Dec 2, 2021
89c3747
Merge branch 'jt/pack-header-lshift-overflow' into next
gitster Dec 2, 2021
5ccd12d
Merge branch 'pw/xdiff-classify-record-in-histogram' into next
gitster Dec 2, 2021
c5b1e5d
Merge branch 'js/trace2-avoid-recursive-errors' into next
gitster Dec 2, 2021
0ac4fd6
Merge branch 'jk/t5319-midx-corruption-test-deflake' into next
gitster Dec 2, 2021
5922388
Merge branch 'ab/checkout-branch-info-leakfix' into next
gitster Dec 2, 2021
1b49913
Merge branch 'ah/advice-pull-has-no-preference-between-rebase-and-mer…
gitster Dec 2, 2021
0490b0f
Merge branch 'rs/mergesort' into next
gitster Dec 2, 2021
489c5b0
Merge branch 'po/size-t-for-vs' into next
gitster Dec 2, 2021
0fae3eb
Merge branch 'tl/midx-docfix' into next
gitster Dec 2, 2021
47b1095
Merge branch 'vd/sparse-reset' into next
gitster Dec 2, 2021
971178f
Merge branch 'hk/ci-checkwhitespace-commentfix' into next
gitster Dec 2, 2021
e2cc1ae
Merge branch 'jk/fetch-pack-avoid-sigpipe-to-index-pack' into next
gitster Dec 2, 2021
1025235
Merge branch 'jk/refs-g11-workaround' into next
gitster Dec 2, 2021
eefd619
Merge branch 'jk/t7006-sigpipe-tests-fix' into next
gitster Dec 2, 2021
eac9f26
Merge branch 'jt/midx-doc-fix' into next
gitster Dec 2, 2021
87ff49b
Merge branch 'hn/create-reflog-simplify' into next
gitster Dec 2, 2021
76aa8bc
Merge branch 'bc/require-c99' into next
gitster Dec 2, 2021
767ec5d
Merge branch 'hn/reftable' into next
gitster Dec 3, 2021
1d8c342
Merge branch 'ab/mark-leak-free-tests-even-more' into next
gitster Dec 3, 2021
5710022
Merge branch 'jc/c99-var-decl-in-for-loop' into next
gitster Dec 3, 2021
afc462a
Merge branch 'mp/absorb-submodule-git-dir-upon-deinit' into next
gitster Dec 3, 2021
22ad721
Merge branch 'em/missing-pager' into next
gitster Dec 3, 2021
4f37a90
Merge branch 'yn/complete-date-format-options' into next
gitster Dec 3, 2021
785278d
Merge branch 'cb/mingw-gmtime-r' into next
gitster Dec 3, 2021
8d4f16e
Merge branch 'cb/add-p-single-key-fix' into next
gitster Dec 3, 2021
a833829
Merge branch 'en/rebase-x-fix' into next
gitster Dec 3, 2021
8cdad7b
Merge branch 'pw/xdiff-classify-record-in-histogram' into next
gitster Dec 7, 2021
fc8a8e0
Merge branch 'fs/test-prereq' into next
gitster Dec 8, 2021
ebf31cb
Merge branch 'ds/trace2-regions-in-tests' into next
gitster Dec 8, 2021
baa3b24
Merge branch 'en/zdiff3' into next
gitster Dec 8, 2021
074438a
Merge branch 'hn/t1404-df-limitation-is-ref-files-only' into next
gitster Dec 8, 2021
5c0bedf
Merge branch 'ab/run-command' into next
gitster Dec 8, 2021
e7862a3
Merge branch 'es/pretty-describe-more' into next
gitster Dec 8, 2021
91039a7
Merge branch 'rj/receive-pack-avoid-sigpipe-during-status-reporting' …
gitster Dec 8, 2021
84d4e4b
Merge branch 'hn/reflog-tests' into next
gitster Dec 8, 2021
1d855a6
Merge branch 'ab/ci-updates' into next
gitster Dec 8, 2021
84ba7de
Merge branch 'es/worktree-chatty-to-stderr' into next
gitster Dec 8, 2021
0ab3e72
Merge branch 'js/test-initial-branch-override-cleanup' into next
gitster Dec 8, 2021
d6487c1
Merge branch 'es/doc-stdout-vs-stderr' into next
gitster Dec 8, 2021
912c270
Merge branch 'tb/pack-revindex-on-disk-cleanup' into next
gitster Dec 8, 2021
44f2663
Merge branch 'en/rebase-x-wo-git-dir-env' into next
gitster Dec 8, 2021
7b7f742
Merge branch 'ds/sparse-deep-pattern-checkout-fix' into next
gitster Dec 8, 2021
e37b4e1
Merge branch 'ew/cbtree-remove-unused-and-broken-cb-unlink' into next
gitster Dec 8, 2021
4b90e48
Merge branch 'ew/test-wo-fsync' into next
gitster Dec 9, 2021
ba56939
Merge branch 'jc/reflog-iterator-callback-doc' into next
gitster Dec 9, 2021
ab3ff50
Merge branch 're/color-default-reset' into next
gitster Dec 9, 2021
f9a2ceb
Merge branch 'ab/parse-options-cleanup' into next
gitster Dec 9, 2021
8fb70ef
Merge branch 'hn/allow-bogus-oid-in-ref-tests' into next
gitster Dec 9, 2021
9b7440f
Merge branch 'ab/die-with-bug' into next
gitster Dec 9, 2021
80585b2
Merge branch 'jk/log-decorate-opts-with-implicit-decorate' into next
gitster Dec 10, 2021
e46385a
Merge branch 'jc/grep-patterntype-default-doc' into next
gitster Dec 10, 2021
d5e7bd8
Merge branch 'fs/ssh-signing-key-lifetime' into next
gitster Dec 10, 2021
2d0c8cb
Merge branch 'fs/ssh-signing-other-keytypes' into next
gitster Dec 10, 2021
dd2c6a5
Merge branch 'ak/protect-any-current-branch' into next
gitster Dec 10, 2021
ae8ec39
Merge branch 'en/name-rev-shorter-output' into next
gitster Dec 10, 2021
57b8993
Merge branch 'ld/sparse-diff-blame' into next
gitster Dec 10, 2021
6248603
Merge branch 'js/scalar' into next
gitster Dec 10, 2021
fae76fe
Sync with master
gitster Dec 10, 2021
d0406f8
Merge branch 'ab/fetch-set-upstream-while-detached' into next
gitster Dec 15, 2021
ff08c86
Merge branch 'ab/common-main-cleanup' into next
gitster Dec 15, 2021
6b40e01
Merge branch 'jk/limit-developers-to-gnu99' into next
gitster Dec 15, 2021
e3f643e
Merge branch 'jz/apply-quiet-and-allow-empty' into next
gitster Dec 15, 2021
49b7a37
Merge branch 'es/chainlint' into next
gitster Dec 15, 2021
a2b2bfd
Sync with master
gitster Dec 15, 2021
702b041
sparse-checkout: fix segfault on malformed patterns
derrickstolee Dec 16, 2021
e4003ef
sparse-checkout: fix OOM error with mixed patterns
derrickstolee Dec 16, 2021
f40d382
sparse-checkout: refuse to add to bad patterns
derrickstolee Dec 16, 2021
d316ff3
Merge branch 'ns/tmp-objdir' into next
gitster Dec 21, 2021
36a98ae
Merge branch 'en/sparse-checkout-set' into next
gitster Dec 21, 2021
d6f56f3
Merge branch 'es/test-chain-lint' into next
gitster Dec 21, 2021
9af51fd
Sync with 'master'
gitster Dec 21, 2021
c39506e
Merge branch 'jc/unleak-log' into next
gitster Dec 22, 2021
21d7827
Sync with 'master'
gitster Dec 23, 2021
d331468
fixup! sparse-checkout: fix OOM error with mixed patterns
gitster Dec 25, 2021
510f9eb
Merge branch 'en/sparse-checkout-set' into next
gitster Dec 25, 2021
650cb24
Merge branch 'jh/p4-rcs-expansion-in-bytestring' into next
gitster Dec 27, 2021
9db6a81
Merge branch 'jc/flex-array-definition' into next
gitster Dec 27, 2021
7cd8f7f
Merge branch 'en/keep-cwd' into next
gitster Dec 27, 2021
562e155
Merge branch 'xw/am-empty' into next
gitster Dec 27, 2021
443dd9f
Merge branch 'pw/diff-color-moved-fix' into next
gitster Dec 27, 2021
2188dc2
Merge branch 'jk/ssh-signing-doc-markup-fix' into next
gitster Dec 27, 2021
3a1afc1
Merge branch 'jv/use-larger-buffer-in-upload-pack' into next
gitster Dec 27, 2021
a16d8fa
Merge branch 'km/help-prompt-fix' into next
gitster Dec 27, 2021
c410caf
Merge branch 'ds/sparse-checkout-malformed-pattern-fix' into next
gitster Dec 27, 2021
01f9fe1
Merge branch 'jc/merge-detached-head-name' into next
gitster Dec 27, 2021
8f8474a
Merge branch 'ds/repack-fixlets' into next
gitster Dec 27, 2021
b09cee1
Merge branch 'rs/t4202-invert-grep-test-fix' into next
gitster Dec 27, 2021
7988d71
Merge branch 'gh/gpg-doc-markup-fix' into next
gitster Dec 27, 2021
861648f
Merge branch 'rs/log-invert-grep-with-headers' into next
gitster Dec 27, 2021
dc2c5db
Merge branch 'jc/t4204-do-not-write-git-on-upstream-of-pipe' into next
gitster Dec 27, 2021
5dc740c
Merge branch 'rs/pcre2-utf' into next
gitster Dec 27, 2021
55b058a
Merge branch 'rs/daemon-plug-leak' into next
gitster Dec 27, 2021
027d9e1
Revert "fixup! sparse-checkout: fix OOM error with mixed patterns"
gitster Dec 30, 2021
c8b2ade
Merge branch 'ds/sparse-checkout-malformed-pattern-fix' into next
gitster Dec 30, 2021
9f3ce1d
add-patch.c: compare oid of rev and HEAD instead of string literals
Jan 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Documentation/config/gpg.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ gpg.minTrustLevel::
* `fully`
* `ultimate`

gpg.ssh.defaultKeyCommand:
gpg.ssh.defaultKeyCommand::
This command that will be run when user.signingkey is not set and a ssh
signature is requested. On successful exit a valid ssh public key is
expected in the first line of its output. To automatically use the first
Expand All @@ -44,7 +44,7 @@ gpg.ssh.allowedSignersFile::
A file containing ssh public keys which you are willing to trust.
The file consists of one or more lines of principals followed by an ssh
public key.
e.g.: user1@example.com,user2@example.com ssh-rsa AAAAX1...
e.g.: `user1@example.com,user2@example.com ssh-rsa AAAAX1...`
See ssh-keygen(1) "ALLOWED SIGNERS" for details.
The principal is only used to identify the key and is available when
verifying a signature.
Expand Down
16 changes: 15 additions & 1 deletion Documentation/git-am.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ SYNOPSIS
[--exclude=<path>] [--include=<path>] [--reject] [-q | --quiet]
[--[no-]scissors] [-S[<keyid>]] [--patch-format=<format>]
[--quoted-cr=<action>]
[--empty=(stop|drop|keep)]
[(<mbox> | <Maildir>)...]
'git am' (--continue | --skip | --abort | --quit | --show-current-patch[=(diff|raw)])
'git am' (--continue | --skip | --abort | --quit | --show-current-patch[=(diff|raw)] | --allow-empty)

DESCRIPTION
-----------
Expand Down Expand Up @@ -63,6 +64,14 @@ OPTIONS
--quoted-cr=<action>::
This flag will be passed down to 'git mailinfo' (see linkgit:git-mailinfo[1]).

--empty=(stop|drop|keep)::
By default, or when the option is set to 'stop', the command
errors out on an input e-mail message lacking a patch
and stops into the middle of the current am session. When this
option is set to 'drop', skip such an e-mail message instead.
When this option is set to 'keep', create an empty commit,
recording the contents of the e-mail message as its log.

-m::
--message-id::
Pass the `-m` flag to 'git mailinfo' (see linkgit:git-mailinfo[1]),
Expand Down Expand Up @@ -191,6 +200,11 @@ default. You can use `--no-utf8` to override this.
the e-mail message; if `diff`, show the diff portion only.
Defaults to `raw`.

--allow-empty::
After a patch failure on an input e-mail message lacking a patch,
create an empty commit with the contents of the e-mail message
as its log message.

DISCUSSION
----------

Expand Down
8 changes: 4 additions & 4 deletions Documentation/git-clone.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ objects from the source repository into a pack in the cloned repository.
configuration variables are created.

--sparse::
Initialize the sparse-checkout file so the working
directory starts with only the files in the root
of the repository. The sparse-checkout file can be
modified to grow the working directory as needed.
Employ a sparse-checkout, with only files in the toplevel
directory initially being present. The
linkgit:git-sparse-checkout[1] command can be used to grow the
working directory as needed.

--filter=<filter-spec>::
Use the partial clone feature and request that the server sends
Expand Down
6 changes: 5 additions & 1 deletion Documentation/git-fmt-merge-msg.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ git-fmt-merge-msg - Produce a merge commit message
SYNOPSIS
--------
[verse]
'git fmt-merge-msg' [-m <message>] [--log[=<n>] | --no-log]
'git fmt-merge-msg' [-m <message>] [--into-name <branch>] [--log[=<n>] | --no-log]
'git fmt-merge-msg' [-m <message>] [--log[=<n>] | --no-log] -F <file>

DESCRIPTION
Expand Down Expand Up @@ -44,6 +44,10 @@ OPTIONS
Use <message> instead of the branch names for the first line
of the log message. For use with `--log`.

--into-name <branch>::
Prepare the merge message as if merging to the branch `<branch>`,
instead of the name of the real branch to which the merge is made.

-F <file>::
--file <file>::
Take the list of merged objects from <file> instead of
Expand Down
6 changes: 5 additions & 1 deletion Documentation/git-format-patch.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ SYNOPSIS
[-n | --numbered | -N | --no-numbered]
[--start-number <n>] [--numbered-files]
[--in-reply-to=<message id>] [--suffix=.<sfx>]
[--ignore-if-in-upstream]
[--ignore-if-in-upstream] [--always]
[--cover-from-description=<mode>]
[--rfc] [--subject-prefix=<subject prefix>]
[(--reroll-count|-v) <n>]
Expand Down Expand Up @@ -192,6 +192,10 @@ will want to ensure that threading is disabled for `git send-email`.
patches being generated, and any patch that matches is
ignored.

--always::
Include patches for commits that do not introduce any change,
which are omitted by default.

--cover-from-description=<mode>::
Controls which parts of the cover letter will be automatically
populated using the branch's description.
Expand Down
8 changes: 7 additions & 1 deletion Documentation/git-merge.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ SYNOPSIS
'git merge' [-n] [--stat] [--no-commit] [--squash] [--[no-]edit]
[--no-verify] [-s <strategy>] [-X <strategy-option>] [-S[<keyid>]]
[--[no-]allow-unrelated-histories]
[--[no-]rerere-autoupdate] [-m <msg>] [-F <file>] [<commit>...]
[--[no-]rerere-autoupdate] [-m <msg>] [-F <file>]
[--into-name <branch>] [<commit>...]
'git merge' (--continue | --abort | --quit)

DESCRIPTION
Expand Down Expand Up @@ -76,6 +77,11 @@ The 'git fmt-merge-msg' command can be
used to give a good default for automated 'git merge'
invocations. The automated message can include the branch description.

--into-name <branch>::
Prepare the default merge message as if merging to the branch
`<branch>`, instead of the name of the real branch to which
the merge is made.

-F <file>::
--file=<file>::
Read the commit message to be used for the merge commit (in
Expand Down
5 changes: 3 additions & 2 deletions Documentation/git-repack.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ to the new separate pack will be written.
linkgit:git-pack-objects[1].

-q::
Pass the `-q` option to 'git pack-objects'. See
linkgit:git-pack-objects[1].
--quiet::
Show no progress over the standard error stream and pass the `-q`
option to 'git pack-objects'. See linkgit:git-pack-objects[1].

-n::
Do not update the server information with
Expand Down
100 changes: 56 additions & 44 deletions Documentation/git-sparse-checkout.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,36 @@ COMMANDS
'list'::
Describe the patterns in the sparse-checkout file.

'init'::
Enable the `core.sparseCheckout` setting. If the
sparse-checkout file does not exist, then populate it with
patterns that match every file in the root directory and
no other directories, then will remove all directories tracked
by Git. Add patterns to the sparse-checkout file to
repopulate the working directory.
'set'::
Enable the necessary config settings
(extensions.worktreeConfig, core.sparseCheckout,
core.sparseCheckoutCone) if they are not already enabled, and
write a set of patterns to the sparse-checkout file from the
list of arguments following the 'set' subcommand. Update the
working directory to match the new patterns.
+
To avoid interfering with other worktrees, it first enables the
`extensions.worktreeConfig` setting and makes sure to set the
`core.sparseCheckout` setting in the worktree-specific config file.
When the `--stdin` option is provided, the patterns are read from
standard in as a newline-delimited list instead of from the arguments.
+
When `--cone` is provided, the `core.sparseCheckoutCone` setting is
also set, allowing for better performance with a limited set of
patterns (see 'CONE PATTERN SET' below).
When `--cone` is passed or `core.sparseCheckoutCone` is enabled, the
input list is considered a list of directories instead of
sparse-checkout patterns. This allows for better performance with a
limited set of patterns (see 'CONE PATTERN SET' below). Note that the
set command will write patterns to the sparse-checkout file to include
all files contained in those directories (recursively) as well as
files that are siblings of ancestor directories. The input format
matches the output of `git ls-tree --name-only`. This includes
interpreting pathnames that begin with a double quote (") as C-style
quoted strings. This may become the default in the future; --no-cone
can be passed to request non-cone mode.
+
Use the `--[no-]sparse-index` option to toggle the use of the sparse
index format. This reduces the size of the index to be more closely
aligned with your sparse-checkout definition. This can have significant
performance advantages for commands such as `git status` or `git add`.
This feature is still experimental. Some commands might be slower with
a sparse index until they are properly integrated with the feature.
Use the `--[no-]sparse-index` option to use a sparse index (the
default is to not use it). A sparse index reduces the size of the
index to be more closely aligned with your sparse-checkout
definition. This can have significant performance advantages for
commands such as `git status` or `git add`. This feature is still
experimental. Some commands might be slower with a sparse index until
they are properly integrated with the feature.
+
**WARNING:** Using a sparse index requires modifying the index in a way
that is not completely understood by external tools. If you have trouble
Expand All @@ -60,23 +68,6 @@ to rewrite your index to not be sparse. Older versions of Git will not
understand the sparse directory entries index extension and may fail to
interact with your repository until it is disabled.

'set'::
Write a set of patterns to the sparse-checkout file, as given as
a list of arguments following the 'set' subcommand. Update the
working directory to match the new patterns. Enable the
core.sparseCheckout config setting if it is not already enabled.
+
When the `--stdin` option is provided, the patterns are read from
standard in as a newline-delimited list instead of from the arguments.
+
When `core.sparseCheckoutCone` is enabled, the input list is considered a
list of directories instead of sparse-checkout patterns. The command writes
patterns to the sparse-checkout file to include all files contained in those
directories (recursively) as well as files that are siblings of ancestor
directories. The input format matches the output of `git ls-tree --name-only`.
This includes interpreting pathnames that begin with a double quote (") as
C-style quoted strings.

'add'::
Update the sparse-checkout file to include additional patterns.
By default, these patterns are read from the command-line arguments,
Expand All @@ -93,12 +84,35 @@ C-style quoted strings.
cases, it can make sense to run `git sparse-checkout reapply` later
after cleaning up affected paths (e.g. resolving conflicts, undoing
or committing changes, etc.).
+
The `reapply` command can also take `--[no-]cone` and `--[no-]sparse-index`
flags, with the same meaning as the flags from the `set` command, in order
to change which sparsity mode you are using without needing to also respecify
all sparsity paths.

'disable'::
Disable the `core.sparseCheckout` config setting, and restore the
working directory to include all files. Leaves the sparse-checkout
file intact so a later 'git sparse-checkout init' command may
return the working directory to the same state.
working directory to include all files.

'init'::
Deprecated command that behaves like `set` with no specified paths.
May be removed in the future.
+
Historically, `set` did not handle all the necessary config settings,
which meant that both `init` and `set` had to be called. Invoking
both meant the `init` step would first remove nearly all tracked files
(and in cone mode, ignored files too), then the `set` step would add
many of the tracked files (but not ignored files) back. In addition
to the lost files, the performance and UI of this combination was
poor.
+
Also, historically, `init` would not actually initialize the
sparse-checkout file if it already existed. This meant it was
possible to return to a sparse-checkout without remembering which
paths to pass to a subsequent 'set' or 'add' command. However,
`--cone` and `--sparse-index` options would not be remembered across
the disable command, so the easy restore of calling a plain `init`
decreased in utility.

SPARSE CHECKOUT
---------------
Expand All @@ -107,7 +121,7 @@ SPARSE CHECKOUT
It uses the skip-worktree bit (see linkgit:git-update-index[1]) to tell
Git whether a file in the working directory is worth looking at. If
the skip-worktree bit is set, then the file is ignored in the working
directory. Git will not populate the contents of those files, which
directory. Git will avoid populating the contents of those files, which
makes a sparse checkout helpful when working in a repository with many
files, but only a few are important to the current user.

Expand All @@ -117,10 +131,8 @@ directory, it updates the skip-worktree bits in the index based
on this file. The files matching the patterns in the file will
appear in the working directory, and the rest will not.

To enable the sparse-checkout feature, run `git sparse-checkout init` to
initialize a simple sparse-checkout file and enable the `core.sparseCheckout`
config setting. Then, run `git sparse-checkout set` to modify the patterns in
the sparse-checkout file.
To enable the sparse-checkout feature, run `git sparse-checkout set` to
set the patterns you want to use.

To repopulate the working directory with all files, use the
`git sparse-checkout disable` command.
Expand Down
24 changes: 13 additions & 11 deletions add-patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "diff.h"
#include "compat/terminal.h"
#include "prompt.h"
#include "refs.h"

enum prompt_mode_type {
PROMPT_MODE_CHANGE = 0, PROMPT_DELETION, PROMPT_ADDITION, PROMPT_HUNK,
Expand Down Expand Up @@ -1695,35 +1696,36 @@ int run_add_p(struct repository *r, enum add_p_mode mode,
{ r }, STRBUF_INIT, STRBUF_INIT, STRBUF_INIT, STRBUF_INIT
};
size_t i, binary_count = 0;
struct object_id rev_oid, head_oid;
int rev_equals_head = 0;

init_add_i_state(&s.s, r);

if (mode == ADD_P_STASH)
s.mode = &patch_mode_stash;
else if (mode == ADD_P_RESET) {
/*
* NEEDSWORK: Instead of comparing to the literal "HEAD",
* compare the commit objects instead so that other ways of
* saying the same thing (such as "@") are also handled
* appropriately.
*
* This applies to the cases below too.
*/
if (!revision || !strcmp(revision, "HEAD"))
if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL))
die("no such ref: HEAD");
if (revision) {
if (!resolve_ref_unsafe(revision, RESOLVE_REF_READING, &rev_oid, NULL))
die("no such ref: %s", revision);
rev_equals_head = strcmp(oid_to_hex(&rev_oid), oid_to_hex(&head_oid));
}
if (!revision || !rev_equals_head)
s.mode = &patch_mode_reset_head;
else
s.mode = &patch_mode_reset_nothead;
} else if (mode == ADD_P_CHECKOUT) {
if (!revision)
s.mode = &patch_mode_checkout_index;
else if (!strcmp(revision, "HEAD"))
else if (!rev_equals_head)
s.mode = &patch_mode_checkout_head;
else
s.mode = &patch_mode_checkout_nothead;
} else if (mode == ADD_P_WORKTREE) {
if (!revision)
s.mode = &patch_mode_checkout_index;
else if (!strcmp(revision, "HEAD"))
else if (!rev_equals_head)
s.mode = &patch_mode_worktree_head;
else
s.mode = &patch_mode_worktree_nothead;
Expand Down
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载