Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 13 Feb 2024 15:14:48 +0000 (UTC)
From:      Pedro Giffuni <pfg@freebsd.org>
To:        "src-committers@freebsd.org" <src-committers@freebsd.org>,  "dev-commits-src-all@freebsd.org" <dev-commits-src-all@freebsd.org>,  =?UTF-8?Q?Dag-Erling_Sm=C3=B8rgrav?= <des@FreeBSD.org>
Subject:   Re: git: 851a9da38f07 - main - patch: Support long context  lines.
Message-ID:  <1620767053.1846857.1707837288566@mail.yahoo.com>
In-Reply-To: <202402121826.41CIQUk5080390@gitrepo.freebsd.org>
References:  <202402121826.41CIQUk5080390@gitrepo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
 FWIW ...
We were already supporting very long lines. There was a thread like ages ago about not making them unnecessarily longer.
But I doubt anyone cares about that anymore ;).
Pedro.

    On Monday, February 12, 2024 at 01:26:38 PM GMT-5, Dag-Erling Smørgrav <des@freebsd.org> wrote:  
 
 The branch main has been updated by des:

URL: https://cgit.FreeBSD.org/src/commit/?id=851a9da38f070675c42a6d69c41c47a5d29ee3d0

commit 851a9da38f070675c42a6d69c41c47a5d29ee3d0
Author:    Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2024-02-12 18:26:13 +0000
Commit:    Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2024-02-12 18:26:13 +0000

    patch: Support long context lines.
    
    MFC after:      1 week
    Sponsored by:  Klara, Inc.
    Reviewed by:    allanjude
    Differential Revision:  https://reviews.freebsd.org/D43850
---
 usr.bin/patch/patch.c                    |  2 +-
 usr.bin/patch/pch.c                      | 10 +++++-----
 usr.bin/patch/pch.h                      |  2 +-
 usr.bin/patch/tests/unified_patch_test.sh | 19 +++++++++++++++++++
 4 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/usr.bin/patch/patch.c b/usr.bin/patch/patch.c
index 403189bc92b1..838c721841ea 100644
--- a/usr.bin/patch/patch.c
+++ b/usr.bin/patch/patch.c
@@ -1085,7 +1085,7 @@ patch_match(LINENUM base, LINENUM offset, LINENUM fuzz)
     LINENUM        pat_lines = pch_ptrn_lines() - fuzz;
     const char    *ilineptr;
     const char    *plineptr;
-    unsigned short    plinelen;
+    size_t        plinelen;
 
     /* Patch does not match if we don't have any more context to use */
     if (pline > pat_lines)
diff --git a/usr.bin/patch/pch.c b/usr.bin/patch/pch.c
index d528f06235bf..fb53ff86f9ef 100644
--- a/usr.bin/patch/pch.c
+++ b/usr.bin/patch/pch.c
@@ -55,7 +55,7 @@ static LINENUM    p_max;        /* max allowed value of p_end */
 static LINENUM    p_context = 3;    /* # of context lines */
 static LINENUM    p_input_line = 0;    /* current line # from patch file */
 static char    **p_line = NULL;/* the text of the hunk */
-static unsigned short    *p_len = NULL; /* length of each line */
+static size_t    *p_len = NULL;    /* length of each line */
 static char    *p_char = NULL;    /* +, -, and ! */
 static int    hunkmax = INITHUNKMAX;    /* size of above arrays to begin with */
 static int    p_indent;    /* indent to patch */
@@ -137,7 +137,7 @@ set_hunkmax(void)
     if (p_line == NULL)
         p_line = malloc(hunkmax * sizeof(char *));
     if (p_len == NULL)
-        p_len = malloc(hunkmax * sizeof(unsigned short));
+        p_len = malloc(hunkmax * sizeof(size_t));
     if (p_char == NULL)
         p_char = malloc(hunkmax * sizeof(char));
 }
@@ -154,7 +154,7 @@ grow_hunkmax(void)
         fatal("Internal memory allocation error\n");
 
     p_line = reallocf(p_line, new_hunkmax * sizeof(char *));
-    p_len = reallocf(p_len, new_hunkmax * sizeof(unsigned short));
+    p_len = reallocf(p_len, new_hunkmax * sizeof(size_t));
     p_char = reallocf(p_char, new_hunkmax * sizeof(char));
 
     if (p_line != NULL && p_len != NULL && p_char != NULL) {
@@ -1251,7 +1251,7 @@ bool
 pch_swap(void)
 {
     char    **tp_line;    /* the text of the hunk */
-    unsigned short    *tp_len;/* length of each line */
+    size_t    *tp_len;    /* length of each line */
     char    *tp_char;    /* +, -, and ! */
     LINENUM    i;
     LINENUM    n;
@@ -1408,7 +1408,7 @@ pch_context(void)
 /*
  * Return the length of a particular patch line.
  */
-unsigned short
+size_t
 pch_line_len(LINENUM line)
 {
     return p_len[line];
diff --git a/usr.bin/patch/pch.h b/usr.bin/patch/pch.h
index 5ce4f72497c7..b6c6363155a5 100644
--- a/usr.bin/patch/pch.h
+++ b/usr.bin/patch/pch.h
@@ -45,7 +45,7 @@ bool        there_is_another_patch(void);
 bool        another_hunk(void);
 bool        pch_swap(void);
 char        *pfetch(LINENUM);
-unsigned short    pch_line_len(LINENUM);
+size_t        pch_line_len(LINENUM);
 LINENUM        pch_first(void);
 LINENUM        pch_ptrn_lines(void);
 LINENUM        pch_newfirst(void);
diff --git a/usr.bin/patch/tests/unified_patch_test.sh b/usr.bin/patch/tests/unified_patch_test.sh
index 43b0d8373cfa..7d4b74182c41 100755
--- a/usr.bin/patch/tests/unified_patch_test.sh
+++ b/usr.bin/patch/tests/unified_patch_test.sh
@@ -141,6 +141,24 @@ file_removal_body()
     atf_check -o inline:"y\n" cat foo
 }
 
+atf_test_case plinelen
+plinelen_body()
+{
+    hello="$(jot -b hello -s, 20000 | tee foo.txt)"
+    cp foo.txt bar.txt
+    echo "world" >>bar.txt
+    cat >foo.diff <<EOF
+--- foo.txt.orig
++++ foo.txt
+@@ -1,1 +1,2 @@
+ $hello
++world
+EOF
+    atf_check -o match:"Hunk #1 succeeded" \
+          patch <foo.diff
+    atf_check -o file:bar.txt cat foo.txt
+}
+
 atf_init_test_cases()
 {
     atf_add_test_case basic
@@ -148,4 +166,5 @@ atf_init_test_cases()
     atf_add_test_case file_creation
     atf_add_test_case file_nodupe
     atf_add_test_case file_removal
+    atf_add_test_case plinelen
 }
  
[-- Attachment #2 --]
<html><head></head><body><div class="ydp9fe492cdyahoo-style-wrap" style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:16px;"><div></div>
        <div dir="ltr" data-setdir="false"><div><div dir="ltr" data-setdir="false" style="color: rgb(0, 0, 0); font-family: Helvetica Neue, Helvetica, Arial, sans-serif; font-size: 16px;">FWIW ...</div><div dir="ltr" data-setdir="false" style="color: rgb(0, 0, 0); font-family: Helvetica Neue, Helvetica, Arial, sans-serif; font-size: 16px;"><br></div><div dir="ltr" data-setdir="false" style="color: rgb(0, 0, 0); font-family: Helvetica Neue, Helvetica, Arial, sans-serif; font-size: 16px;">We were already supporting very long lines. There was a thread like ages ago about not making them unnecessarily longer.</div><div dir="ltr" data-setdir="false" style="color: rgb(0, 0, 0); font-family: Helvetica Neue, Helvetica, Arial, sans-serif; font-size: 16px;"><br></div><div dir="ltr" data-setdir="false" style="color: rgb(0, 0, 0); font-family: Helvetica Neue, Helvetica, Arial, sans-serif; font-size: 16px;">But I doubt anyone cares about that anymore ;).</div><div dir="ltr" data-setdir="false" style="color: rgb(0, 0, 0); font-family: Helvetica Neue, Helvetica, Arial, sans-serif; font-size: 16px;"><br></div><div dir="ltr" data-setdir="false" style="color: rgb(0, 0, 0); font-family: Helvetica Neue, Helvetica, Arial, sans-serif; font-size: 16px;">Pedro.</div></div><br></div><div><br></div>
        
        </div><div id="ydpa2b2e994yahoo_quoted_8834098867" class="ydpa2b2e994yahoo_quoted">
            <div style="font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;color:#26282a;">
                
                <div>
                    On Monday, February 12, 2024 at 01:26:38 PM GMT-5, Dag-Erling Smørgrav &lt;des@freebsd.org&gt; wrote:
                </div>
                <div><br></div>
                <div><br></div>
                <div><div dir="ltr">The branch main has been updated by des:<br></div><div dir="ltr"><br></div><div dir="ltr">URL: <a href="https://cgit.FreeBSD.org/src/commit/?id=851a9da38f070675c42a6d69c41c47a5d29ee3d0" rel="nofollow" target="_blank">https://cgit.FreeBSD.org/src/commit/?id=851a9da38f070675c42a6d69c41c47a5d29ee3d0</a><br></div><div dir="ltr"><br></div><div dir="ltr">commit 851a9da38f070675c42a6d69c41c47a5d29ee3d0<br></div><div dir="ltr">Author:&nbsp; &nbsp;  Dag-Erling Smørgrav &lt;<a href="mailto:des@FreeBSD.org" rel="nofollow" target="_blank">des@FreeBSD.org</a>&gt;<br></div><div dir="ltr">AuthorDate: 2024-02-12 18:26:13 +0000<br></div><div dir="ltr">Commit:&nbsp; &nbsp;  Dag-Erling Smørgrav &lt;<a href="mailto:des@FreeBSD.org" rel="nofollow" target="_blank">des@FreeBSD.org</a>&gt;<br></div><div dir="ltr">CommitDate: 2024-02-12 18:26:13 +0000<br></div><div dir="ltr"><br></div><div dir="ltr">&nbsp; &nbsp; patch: Support long context lines.<br></div><div dir="ltr">&nbsp; &nbsp; <br></div><div dir="ltr">&nbsp; &nbsp; MFC after:&nbsp; &nbsp; &nbsp; 1 week<br></div><div dir="ltr">&nbsp; &nbsp; Sponsored by:&nbsp;  Klara, Inc.<br></div><div dir="ltr">&nbsp; &nbsp; Reviewed by:&nbsp; &nbsp; allanjude<br></div><div dir="ltr">&nbsp; &nbsp; Differential Revision:&nbsp; <a href="https://reviews.freebsd.org/D43850" rel="nofollow" target="_blank">https://reviews.freebsd.org/D43850</a><br></div><div dir="ltr">---<br></div><div dir="ltr"> usr.bin/patch/patch.c&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  |&nbsp; 2 +-<br></div><div dir="ltr"> usr.bin/patch/pch.c&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  | 10 +++++-----<br></div><div dir="ltr"> usr.bin/patch/pch.h&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  |&nbsp; 2 +-<br></div><div dir="ltr"> usr.bin/patch/tests/unified_patch_test.sh | 19 +++++++++++++++++++<br></div><div dir="ltr"> 4 files changed, 26 insertions(+), 7 deletions(-)<br></div><div dir="ltr"><br></div><div dir="ltr">diff --git a/usr.bin/patch/patch.c b/usr.bin/patch/patch.c<br></div><div dir="ltr">index 403189bc92b1..838c721841ea 100644<br></div><div dir="ltr">--- a/usr.bin/patch/patch.c<br></div><div dir="ltr">+++ b/usr.bin/patch/patch.c<br></div><div dir="ltr">@@ -1085,7 +1085,7 @@ patch_match(LINENUM base, LINENUM offset, LINENUM fuzz)<br></div><div dir="ltr"> &nbsp;&nbsp;&nbsp; LINENUM&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pat_lines = pch_ptrn_lines() - fuzz;<br></div><div dir="ltr"> &nbsp;&nbsp;&nbsp; const char&nbsp;&nbsp;&nbsp; *ilineptr;<br></div><div dir="ltr"> &nbsp;&nbsp;&nbsp; const char&nbsp;&nbsp;&nbsp; *plineptr;<br></div><div dir="ltr">-&nbsp;&nbsp;&nbsp; unsigned short&nbsp;&nbsp;&nbsp; plinelen;<br></div><div dir="ltr">+&nbsp;&nbsp;&nbsp; size_t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; plinelen;<br></div><div dir="ltr"> <br></div><div dir="ltr"> &nbsp;&nbsp;&nbsp; /* Patch does not match if we don't have any more context to use */<br></div><div dir="ltr"> &nbsp;&nbsp;&nbsp; if (pline &gt; pat_lines)<br></div><div dir="ltr">diff --git a/usr.bin/patch/pch.c b/usr.bin/patch/pch.c<br></div><div dir="ltr">index d528f06235bf..fb53ff86f9ef 100644<br></div><div dir="ltr">--- a/usr.bin/patch/pch.c<br></div><div dir="ltr">+++ b/usr.bin/patch/pch.c<br></div><div dir="ltr">@@ -55,7 +55,7 @@ static LINENUM&nbsp;&nbsp;&nbsp; p_max;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; /* max allowed value of p_end */<br></div><div dir="ltr"> static LINENUM&nbsp;&nbsp;&nbsp; p_context = 3;&nbsp;&nbsp;&nbsp; /* # of context lines */<br></div><div dir="ltr"> static LINENUM&nbsp;&nbsp;&nbsp; p_input_line = 0;&nbsp;&nbsp;&nbsp; /* current line # from patch file */<br></div><div dir="ltr"> static char&nbsp;&nbsp;&nbsp; **p_line = NULL;/* the text of the hunk */<br></div><div dir="ltr">-static unsigned short&nbsp;&nbsp;&nbsp; *p_len = NULL; /* length of each line */<br></div><div dir="ltr">+static size_t&nbsp;&nbsp;&nbsp; *p_len = NULL;&nbsp;&nbsp;&nbsp; /* length of each line */<br></div><div dir="ltr"> static char&nbsp;&nbsp;&nbsp; *p_char = NULL;&nbsp;&nbsp;&nbsp; /* +, -, and ! */<br></div><div dir="ltr"> static int&nbsp;&nbsp;&nbsp; hunkmax = INITHUNKMAX;&nbsp;&nbsp;&nbsp; /* size of above arrays to begin with */<br></div><div dir="ltr"> static int&nbsp;&nbsp;&nbsp; p_indent;&nbsp;&nbsp;&nbsp; /* indent to patch */<br></div><div dir="ltr">@@ -137,7 +137,7 @@ set_hunkmax(void)<br></div><div dir="ltr"> &nbsp;&nbsp;&nbsp; if (p_line == NULL)<br></div><div dir="ltr"> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; p_line = malloc(hunkmax * sizeof(char *));<br></div><div dir="ltr"> &nbsp;&nbsp;&nbsp; if (p_len == NULL)<br></div><div dir="ltr">-&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; p_len = malloc(hunkmax * sizeof(unsigned short));<br></div><div dir="ltr">+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; p_len = malloc(hunkmax * sizeof(size_t));<br></div><div dir="ltr"> &nbsp;&nbsp;&nbsp; if (p_char == NULL)<br></div><div dir="ltr"> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; p_char = malloc(hunkmax * sizeof(char));<br></div><div dir="ltr"> }<br></div><div dir="ltr">@@ -154,7 +154,7 @@ grow_hunkmax(void)<br></div><div dir="ltr"> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fatal("Internal memory allocation error\n");<br></div><div dir="ltr"> <br></div><div dir="ltr"> &nbsp;&nbsp;&nbsp; p_line = reallocf(p_line, new_hunkmax * sizeof(char *));<br></div><div dir="ltr">-&nbsp;&nbsp;&nbsp; p_len = reallocf(p_len, new_hunkmax * sizeof(unsigned short));<br></div><div dir="ltr">+&nbsp;&nbsp;&nbsp; p_len = reallocf(p_len, new_hunkmax * sizeof(size_t));<br></div><div dir="ltr"> &nbsp;&nbsp;&nbsp; p_char = reallocf(p_char, new_hunkmax * sizeof(char));<br></div><div dir="ltr"> <br></div><div dir="ltr"> &nbsp;&nbsp;&nbsp; if (p_line != NULL &amp;&amp; p_len != NULL &amp;&amp; p_char != NULL) {<br></div><div dir="ltr">@@ -1251,7 +1251,7 @@ bool<br></div><div dir="ltr"> pch_swap(void)<br></div><div dir="ltr"> {<br></div><div dir="ltr"> &nbsp;&nbsp;&nbsp; char&nbsp;&nbsp;&nbsp; **tp_line;&nbsp;&nbsp;&nbsp; /* the text of the hunk */<br></div><div dir="ltr">-&nbsp;&nbsp;&nbsp; unsigned short&nbsp;&nbsp;&nbsp; *tp_len;/* length of each line */<br></div><div dir="ltr">+&nbsp;&nbsp;&nbsp; size_t&nbsp;&nbsp;&nbsp; *tp_len;&nbsp;&nbsp;&nbsp; /* length of each line */<br></div><div dir="ltr"> &nbsp;&nbsp;&nbsp; char&nbsp;&nbsp;&nbsp; *tp_char;&nbsp;&nbsp;&nbsp; /* +, -, and ! */<br></div><div dir="ltr"> &nbsp;&nbsp;&nbsp; LINENUM&nbsp;&nbsp;&nbsp; i;<br></div><div dir="ltr"> &nbsp;&nbsp;&nbsp; LINENUM&nbsp;&nbsp;&nbsp; n;<br></div><div dir="ltr">@@ -1408,7 +1408,7 @@ pch_context(void)<br></div><div dir="ltr"> /*<br></div><div dir="ltr">&nbsp; * Return the length of a particular patch line.<br></div><div dir="ltr">&nbsp; */<br></div><div dir="ltr">-unsigned short<br></div><div dir="ltr">+size_t<br></div><div dir="ltr"> pch_line_len(LINENUM line)<br></div><div dir="ltr"> {<br></div><div dir="ltr"> &nbsp;&nbsp;&nbsp; return p_len[line];<br></div><div dir="ltr">diff --git a/usr.bin/patch/pch.h b/usr.bin/patch/pch.h<br></div><div dir="ltr">index 5ce4f72497c7..b6c6363155a5 100644<br></div><div dir="ltr">--- a/usr.bin/patch/pch.h<br></div><div dir="ltr">+++ b/usr.bin/patch/pch.h<br></div><div dir="ltr">@@ -45,7 +45,7 @@ bool&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; there_is_another_patch(void);<br></div><div dir="ltr"> bool&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; another_hunk(void);<br></div><div dir="ltr"> bool&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pch_swap(void);<br></div><div dir="ltr"> char&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *pfetch(LINENUM);<br></div><div dir="ltr">-unsigned short&nbsp;&nbsp;&nbsp; pch_line_len(LINENUM);<br></div><div dir="ltr">+size_t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pch_line_len(LINENUM);<br></div><div dir="ltr"> LINENUM&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pch_first(void);<br></div><div dir="ltr"> LINENUM&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pch_ptrn_lines(void);<br></div><div dir="ltr"> LINENUM&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pch_newfirst(void);<br></div><div dir="ltr">diff --git a/usr.bin/patch/tests/unified_patch_test.sh b/usr.bin/patch/tests/unified_patch_test.sh<br></div><div dir="ltr">index 43b0d8373cfa..7d4b74182c41 100755<br></div><div dir="ltr">--- a/usr.bin/patch/tests/unified_patch_test.sh<br></div><div dir="ltr">+++ b/usr.bin/patch/tests/unified_patch_test.sh<br></div><div dir="ltr">@@ -141,6 +141,24 @@ file_removal_body()<br></div><div dir="ltr"> &nbsp;&nbsp;&nbsp; atf_check -o inline:"y\n" cat foo<br></div><div dir="ltr"> }<br></div><div dir="ltr"> <br></div><div dir="ltr">+atf_test_case plinelen<br></div><div dir="ltr">+plinelen_body()<br></div><div dir="ltr">+{<br></div><div dir="ltr">+&nbsp;&nbsp;&nbsp; hello="$(jot -b hello -s, 20000 | tee foo.txt)"<br></div><div dir="ltr">+&nbsp;&nbsp;&nbsp; cp foo.txt bar.txt<br></div><div dir="ltr">+&nbsp;&nbsp;&nbsp; echo "world" &gt;&gt;bar.txt<br></div><div dir="ltr">+&nbsp;&nbsp;&nbsp; cat &gt;foo.diff &lt;&lt;EOF<br></div><div dir="ltr">+--- foo.txt.orig<br></div><div dir="ltr">++++ foo.txt<br></div><div dir="ltr">+@@ -1,1 +1,2 @@<br></div><div dir="ltr">+ $hello<br></div><div dir="ltr">++world<br></div><div dir="ltr">+EOF<br></div><div dir="ltr">+&nbsp;&nbsp;&nbsp; atf_check -o match:"Hunk #1 succeeded" \<br></div><div dir="ltr">+&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; patch &lt;foo.diff<br></div><div dir="ltr">+&nbsp;&nbsp;&nbsp; atf_check -o file:bar.txt cat foo.txt<br></div><div dir="ltr">+}<br></div><div dir="ltr">+<br></div><div dir="ltr"> atf_init_test_cases()<br></div><div dir="ltr"> {<br></div><div dir="ltr"> &nbsp;&nbsp;&nbsp; atf_add_test_case basic<br></div><div dir="ltr">@@ -148,4 +166,5 @@ atf_init_test_cases()<br></div><div dir="ltr"> &nbsp;&nbsp;&nbsp; atf_add_test_case file_creation<br></div><div dir="ltr"> &nbsp;&nbsp;&nbsp; atf_add_test_case file_nodupe<br></div><div dir="ltr"> &nbsp;&nbsp;&nbsp; atf_add_test_case file_removal<br></div><div dir="ltr">+&nbsp;&nbsp;&nbsp; atf_add_test_case plinelen<br></div><div dir="ltr"> }<br></div></div>
            </div>
        </div></body></html>

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1620767053.1846857.1707837288566>