<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/apply.c, branch v2.14.2</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=v2.14.2</id>
<link rel='self' href='https://git.shady.money/git/atom?h=v2.14.2'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2017-09-10T08:03:01Z</updated>
<entry>
<title>Merge branch 'rs/apply-lose-prefix-length' into maint</title>
<updated>2017-09-10T08:03:01Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2017-09-10T08:03:01Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=c7759cd60ab0213024c3fbe9a163dcd49b2bb838'/>
<id>urn:sha1:c7759cd60ab0213024c3fbe9a163dcd49b2bb838</id>
<content type='text'>
Code clean-up.

* rs/apply-lose-prefix-length:
  apply: remove prefix_length member from apply_state
</content>
</entry>
<entry>
<title>Merge branch 'tb/apply-with-crlf' into maint</title>
<updated>2017-09-10T08:02:55Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2017-09-10T08:02:55Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=648a50a08ad3d6718899a30a438ff97b4bdda342'/>
<id>urn:sha1:648a50a08ad3d6718899a30a438ff97b4bdda342</id>
<content type='text'>
"git apply" that is used as a better "patch -p1" failed to apply a
taken from a file with CRLF line endings to a file with CRLF line
endings.  The root cause was because it misused convert_to_git()
that tried to do "safe-crlf" processing by looking at the index
entry at the same path, which is a nonsense---in that mode, "apply"
is not working on the data in (or derived from) the index at all.
This has been fixed.

* tb/apply-with-crlf:
  apply: file commited with CRLF should roundtrip diff and apply
  convert: add SAFE_CRLF_KEEP_CRLF
</content>
</entry>
<entry>
<title>apply: file commited with CRLF should roundtrip diff and apply</title>
<updated>2017-08-19T16:29:25Z</updated>
<author>
<name>Torsten Bögershausen</name>
<email>tboegi@web.de</email>
</author>
<published>2017-08-19T11:28:01Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=c24f3abaceabb590125751a67ec0e32946780ac7'/>
<id>urn:sha1:c24f3abaceabb590125751a67ec0e32946780ac7</id>
<content type='text'>
When a file had been commited with CRLF but now .gitattributes say
"* text=auto" (or core.autocrlf is true), the following does not
roundtrip, `git apply` fails:

    printf "Added line\r\n" &gt;&gt;file &amp;&amp;
    git diff &gt;patch &amp;&amp;
    git checkout -- . &amp;&amp;
    git apply patch

Before applying the patch, the file from working tree is converted
into the index format (clean filter, CRLF conversion, ...).  Here,
when commited with CRLF, the line endings should not be converted.

Note that `git apply --index` or `git apply --cache` doesn't call
convert_to_git() because the source material is already in index
format.

Analyze the patch if there is a) any context line with CRLF, or b)
if any line with CRLF is to be removed.  In this case the patch file
`patch` has mixed line endings, for a) it looks like this:

    diff --git a/one b/one
    index 533790e..c30dea8 100644
    --- a/one
    +++ b/one
    @@ -1 +1,2 @@
     a\r
    +b\r

And for b) it looks like this:

    diff --git a/one b/one
    index 533790e..485540d 100644
    --- a/one
    +++ b/one
    @@ -1 +1 @@
    -a\r
    +b\r

If `git apply` detects that the patch itself has CRLF, (look at the
line " a\r" or "-a\r" above), the new flag crlf_in_old is set in
"struct patch" and two things will happen:

    - read_old_data() will not convert CRLF into LF by calling
      convert_to_git(..., SAFE_CRLF_KEEP_CRLF);
    - The WS_CR_AT_EOL bit is set in the "white space rule",
      CRLF are no longer treated as white space.

While at there, make it clear that read_old_data() in apply.c knows
what it wants convert_to_git() to do with respect to CRLF.  In fact,
this codepath is about applying a patch to a file in the filesystem,
which may not exist in the index, or may exist but may not match
what is recorded in the index, or in the extreme case, we may not
even be in a Git repository.  If convert_to_git() peeked at the
index while doing its work, it *would* be a bug.

Pass NULL instead of &amp;the_index to convert_to_git() to make sure we
catch future bugs to clarify this.

Update the test in t4124: split one test case into 3:

    - Detect the " a\r" line in the patch
    - Detect the "-a\r" line in the patch
    - Use LF in repo and CLRF in the worktree.

Reported-by: Anthony Sottile &lt;asottile@umich.edu&gt;
Signed-off-by: Torsten Bögershausen &lt;tboegi@web.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>apply: remove prefix_length member from apply_state</title>
<updated>2017-08-09T17:21:45Z</updated>
<author>
<name>René Scharfe</name>
<email>l.s.r@web.de</email>
</author>
<published>2017-08-09T15:54:46Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=881529c84656e7ff41379c0684df0ff9a796d444'/>
<id>urn:sha1:881529c84656e7ff41379c0684df0ff9a796d444</id>
<content type='text'>
Use a NULL-and-NUL check to see if we have a prefix and consistently use
C string functions on it instead of storing its length in a member of
struct apply_state.  This avoids strlen() calls and simplifies the code.

Signed-off-by: Rene Scharfe &lt;l.s.r@web.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>apply: use COPY_ARRAY and MOVE_ARRAY in update_image()</title>
<updated>2017-07-17T21:55:10Z</updated>
<author>
<name>René Scharfe</name>
<email>l.s.r@web.de</email>
</author>
<published>2017-07-15T20:20:54Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=177366415b95fb72bc2c37d55a936ff101986285'/>
<id>urn:sha1:177366415b95fb72bc2c37d55a936ff101986285</id>
<content type='text'>
Simplify the code by using the helper macros COPY_ARRAY and MOVE_ARRAY,
which also makes them more robust in the case we copy or move no lines,
as they allow using NULL points in that case, while memcpy(3) and
memmove(3) don't.

Found with Clang's UBSan.

Signed-off-by: Rene Scharfe &lt;l.s.r@web.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'rs/apply-avoid-over-reading'</title>
<updated>2017-07-12T22:18:22Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2017-07-12T22:18:22Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=6fee4ca6255ad5ffe3be98c11e7822166e2d4510'/>
<id>urn:sha1:6fee4ca6255ad5ffe3be98c11e7822166e2d4510</id>
<content type='text'>
Code cleanup.

* rs/apply-avoid-over-reading:
  apply: use strcmp(3) for comparing strings in gitdiff_verify_name()
</content>
</entry>
<entry>
<title>Merge branch 'ab/wildmatch'</title>
<updated>2017-07-10T20:42:51Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2017-07-10T20:42:51Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=0c6435a4d6a45d5947ed4f3a1f63172cdca00d36'/>
<id>urn:sha1:0c6435a4d6a45d5947ed4f3a1f63172cdca00d36</id>
<content type='text'>
Minor code cleanup.

* ab/wildmatch:
  wildmatch: remove unused wildopts parameter
</content>
</entry>
<entry>
<title>apply: use strcmp(3) for comparing strings in gitdiff_verify_name()</title>
<updated>2017-07-09T16:30:42Z</updated>
<author>
<name>René Scharfe</name>
<email>l.s.r@web.de</email>
</author>
<published>2017-07-08T08:58:42Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=2d105451c0768fc3e9600dec7bca2376f482521e'/>
<id>urn:sha1:2d105451c0768fc3e9600dec7bca2376f482521e</id>
<content type='text'>
We don't know the length of the C string "another".  It could be
shorter than "name", which we compare it to using memchr(3).  Call
strcmp(3) instead to avoid running over the end of the former, and
get rid of a strlen(3) call as a bonus.

Signed-off-by: Rene Scharfe &lt;l.s.r@web.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'rs/apply-avoid-over-reading'</title>
<updated>2017-07-07T01:14:45Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2017-07-07T01:14:45Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=f9b3252b2a4b3dbaa9f8434cdd2b8fd3013519f1'/>
<id>urn:sha1:f9b3252b2a4b3dbaa9f8434cdd2b8fd3013519f1</id>
<content type='text'>
Code clean-up to fix possible buffer over-reading.

* rs/apply-avoid-over-reading:
  apply: use starts_with() in gitdiff_verify_name()
</content>
</entry>
<entry>
<title>apply: use starts_with() in gitdiff_verify_name()</title>
<updated>2017-07-01T17:39:51Z</updated>
<author>
<name>René Scharfe</name>
<email>l.s.r@web.de</email>
</author>
<published>2017-07-01T09:10:07Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=8bc172e5f29894d440aab772ae3a49eb2eaf5585'/>
<id>urn:sha1:8bc172e5f29894d440aab772ae3a49eb2eaf5585</id>
<content type='text'>
Avoid running over the end of line -- a C string whose length is not
known to this function -- by using starts_with() instead of memcmp(3)
for checking if it starts with "/dev/null".  Also simply include the
newline in the string constant to compare against.  Drop a comment that
just states the obvious.

Signed-off-by: Rene Scharfe &lt;l.s.r@web.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
