<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/apply.c, branch v2.30.2</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=v2.30.2</id>
<link rel='self' href='https://git.shady.money/git/atom?h=v2.30.2'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2020-12-18T23:15:18Z</updated>
<entry>
<title>Merge branch 'ab/unreachable-break'</title>
<updated>2020-12-18T23:15:18Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2020-12-18T23:15:17Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=3517022568b0cbf2ada289e43c8c562b61132082'/>
<id>urn:sha1:3517022568b0cbf2ada289e43c8c562b61132082</id>
<content type='text'>
Code clean-up.

* ab/unreachable-break:
  style: do not "break" in switch() after "return"
</content>
</entry>
<entry>
<title>style: do not "break" in switch() after "return"</title>
<updated>2020-12-16T00:32:50Z</updated>
<author>
<name>Ævar Arnfjörð Bjarmason</name>
<email>avarab@gmail.com</email>
</author>
<published>2020-12-15T23:50:27Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=56f56ac50b932310c629832fad256e624ca451e3'/>
<id>urn:sha1:56f56ac50b932310c629832fad256e624ca451e3</id>
<content type='text'>
Remove this unreachable code. It was found by SunCC, it's found by a
non-fatal warning emitted by SunCC. It's one of the things it's more
vehement about than GCC &amp; Clang.

It complains about a lot of other similarly unreachable code, e.g. a
BUG(...) without a "return", and a "return 0" after a long if/else,
both of whom have "return" statements. Those are also genuine
redundancies to a compiler, but arguably make the code a bit easier to
read &amp; less fragile to maintain.

These return/break cases are just unnecessary however, and as seen
here the surrounding code just did a plain "return" without a "break"
already.

Signed-off-by: Ævar Arnfjörð Bjarmason &lt;avarab@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'mt/do-not-use-scld-in-working-tree'</title>
<updated>2020-12-08T23:11:20Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2020-12-08T23:11:19Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=9b3b4adb3fc586d14bbe2bfa7ba5f682a87e903d'/>
<id>urn:sha1:9b3b4adb3fc586d14bbe2bfa7ba5f682a87e903d</id>
<content type='text'>
"git apply" adjusted the permission bits of working-tree files and
directories according core.sharedRepository setting by mistake and
for a long time, which has been corrected.

* mt/do-not-use-scld-in-working-tree:
  apply: don't use core.sharedRepository to create working tree files
</content>
</entry>
<entry>
<title>apply: don't use core.sharedRepository to create working tree files</title>
<updated>2020-12-02T22:35:51Z</updated>
<author>
<name>Matheus Tavares</name>
<email>matheus.bernardino@usp.br</email>
</author>
<published>2020-12-01T23:45:04Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=eb3c027e1779d0d1b5bd3b4e96a108461c9759a5'/>
<id>urn:sha1:eb3c027e1779d0d1b5bd3b4e96a108461c9759a5</id>
<content type='text'>
core.sharedRepository defines which permissions Git should set when
creating files in $GIT_DIR, so that the repository may be shared with
other users. But (in its current form) the setting shouldn't affect how
files are created in the working tree. This is not respected by apply
and am (which uses apply), when creating leading directories:

$ cat d.patch
 diff --git a/d/f b/d/f
 new file mode 100644
 index 0000000..e69de29

Apply without the setting:
$ umask 0077
$ git apply d.patch
$ ls -ld d
 drwx------

Apply with the setting:
$ umask 0077
$ git -c core.sharedRepository=0770 apply d.patch
$ ls -ld d
 drwxrws---

Only the leading directories are affected. That's because they are
created with safe_create_leading_directories(), which calls
adjust_shared_perm() to set the directories' permissions based on
core.sharedRepository. To fix that, let's introduce a variant of this
function that ignores the setting, and use it in apply. Also add a
regression test and a note in the function documentation about the use
of each variant according to the destination (working tree or git
dir).

Signed-off-by: Matheus Tavares &lt;matheus.bernardino@usp.br&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>apply: when -R, also reverse list of sections</title>
<updated>2020-10-20T22:21:41Z</updated>
<author>
<name>Jonathan Tan</name>
<email>jonathantanmy@google.com</email>
</author>
<published>2020-10-20T22:04:52Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=b0f266de11e9dc3a140ff9407a47604bef0e257f'/>
<id>urn:sha1:b0f266de11e9dc3a140ff9407a47604bef0e257f</id>
<content type='text'>
A patch changing a symlink into a file is written with 2 sections (in
the code, represented as "struct patch"): firstly, the deletion of the
symlink, and secondly, the creation of the file. When applying that
patch with -R, the sections are reversed, so we get:

 (1) creation of a symlink, then
 (2) deletion of a file.

This causes an issue when the "deletion of a file" section is checked,
because Git observes that the so-called file is not a file but a
symlink, resulting in a "wrong type" error message.

What we want is:

 (1) deletion of a file, then
 (2) creation of a symlink.

In the code, this is reflected in the behavior of previous_patch() when
invoked from check_preimage() when the deletion is checked. Creation
then deletion means that when the deletion is checked, previous_patch()
returns the creation section, triggering a mode conflict resulting in
the "wrong type" error message. But deletion then creation means that
when the deletion is checked, previous_patch() returns NULL, so the
deletion mode is checked against lstat, which is what we want.

There are also other ways a patch can contain 2 sections referencing the
same file, for example, in 7a07841c0b ("git-apply: handle a patch that
touches the same path more than once better", 2008-06-27). "git apply
-R" fails in the same way, and this commit makes this case succeed.

Therefore, when building the list of sections, build them in reverse
order (by adding to the front of the list instead of the back) when -R
is passed.

Helped-by: Junio C Hamano &lt;gitster@pobox.com&gt;
Signed-off-by: Jonathan Tan &lt;jonathantanmy@google.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'jk/leakfix'</title>
<updated>2020-08-27T21:04:49Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2020-08-27T21:04:49Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=0d9a8e33f9fd07efa10072576df01a9cae5d89e6'/>
<id>urn:sha1:0d9a8e33f9fd07efa10072576df01a9cae5d89e6</id>
<content type='text'>
Code clean-up.

* jk/leakfix:
  submodule--helper: fix leak of core.worktree value
  config: fix leak in git_config_get_expiry_in_days()
  config: drop git_config_get_string_const()
  config: fix leaks from git_config_get_string_const()
  checkout: fix leak of non-existent branch names
  submodule--helper: use strbuf_release() to free strbufs
  clear_pattern_list(): clear embedded hashmaps
</content>
</entry>
<entry>
<title>Merge branch 'rp/apply-cached-with-i-t-a'</title>
<updated>2020-08-18T00:02:46Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2020-08-18T00:02:46Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=ca81676a105dbd387c28fbcc428e8959990678ec'/>
<id>urn:sha1:ca81676a105dbd387c28fbcc428e8959990678ec</id>
<content type='text'>
Recent versions of "git diff-files" shows a diff between the index
and the working tree for "intent-to-add" paths as a "new file"
patch; "git apply --cached" should be able to take "git diff-files"
and should act as an equivalent to "git add" for the path, but the
command failed to do so for such a path.

* rp/apply-cached-with-i-t-a:
  t4140: test apply with i-t-a paths
  apply: make i-t-a entries never match worktree
  apply: allow "new file" patches on i-t-a entries
</content>
</entry>
<entry>
<title>config: drop git_config_get_string_const()</title>
<updated>2020-08-17T22:35:47Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2020-08-17T21:33:11Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=9a53219f69bd470053cf93c3f4d2a77b6d4df3e5'/>
<id>urn:sha1:9a53219f69bd470053cf93c3f4d2a77b6d4df3e5</id>
<content type='text'>
As evidenced by the leak fixes in the previous commit, the "const" in
git_config_get_string_const() clearly misleads people into thinking that
it does not allocate a copy of the string. We can fix this by renaming
it, but it's easier still to just drop it. Of the four remaining
callers:

  - The one in git_config_parse_expiry() still needs to allocate, since
    that's what its callers expect. We can just use the non-const
    version and cast our pointer. Slightly ugly, but the damage is
    contained in one spot.

  - The two in apply are writing to global "const char *" variables, and
    need to continue allocating. We often mark these as const because we
    assign default string literals to them. But in this case we don't do
    that, so we can just declare them as real "char *" pointers and use
    the non-const version.

  - The call in checkout doesn't actually need a copy; it can just use
    the non-allocating "tmp" version of the function.

The function is also mentioned in the MyFirstContribution document. We
can swap that call out for the non-allocating "tmp" variant, which fits
well in the example given.

We'll drop the "configset" and "repo" variants, as well (which are
unused).

Note that this frees up the "const" name, so we could rename the "tmp"
variant back to that. But let's give some time for topics in flight to
adapt to the new code before doing so (if we do it too soon, the
function semantics will change but the compiler won't alert us).

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>apply: make i-t-a entries never match worktree</title>
<updated>2020-08-09T18:00:46Z</updated>
<author>
<name>Raymond E. Pasco</name>
<email>ray@ameretat.dev</email>
</author>
<published>2020-08-08T07:49:58Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=e3cc41b4f939a64c74b6d4a2d59f6efe006c4e4b'/>
<id>urn:sha1:e3cc41b4f939a64c74b6d4a2d59f6efe006c4e4b</id>
<content type='text'>
By definition, an intent-to-add index entry can never match the
worktree, because worktrees have no concept of intent-to-add entries.
Therefore, "apply --index" should always fail on intent-to-add paths.

Because check_preimage() calls verify_index_match(), it already fails
for patches other than creation patches, which check_preimage() ignores.
This patch adds a check to check_preimage()'s rough equivalent for
creation patches, check_to_create().

Helped-by: Junio C Hamano &lt;gitster@pobox.com&gt;
Signed-off-by: Raymond E. Pasco &lt;ray@ameretat.dev&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>apply: allow "new file" patches on i-t-a entries</title>
<updated>2020-08-06T20:07:52Z</updated>
<author>
<name>Raymond E. Pasco</name>
<email>ray@ameretat.dev</email>
</author>
<published>2020-08-06T06:01:17Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=7cfde3fa0f175d6c184d7876576c236b367d97bb'/>
<id>urn:sha1:7cfde3fa0f175d6c184d7876576c236b367d97bb</id>
<content type='text'>
diff-files recently changed to treat changes to paths marked "intent to
add" in the index as new file diffs rather than diffs from the empty
blob.  However, apply refuses to apply new file diffs on top of existing
index entries, except in the case of renames. This causes "git add -p",
which uses apply, to fail when attempting to stage hunks from a file
when intent to add has been recorded.

This changes the logic in check_to_create() which checks if an entry
already exists in an index in two ways: first, we only search for an
index entry at all if ok_if_exists is false; second, we check for the
CE_INTENT_TO_ADD flag on any index entries we find and allow the apply
to proceed if it is set.

Helped-by: Junio C Hamano &lt;gitster@pobox.com&gt;
Signed-off-by: Raymond E. Pasco &lt;ray@ameretat.dev&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
