From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Cc: Thomas Gummerer <t.gummerer@gmail.com>
Subject: [PATCH 1/3] range-diff: drop useless "offset" variable from read_patches()
Date: Mon, 9 Aug 2021 18:47:42 -0400 [thread overview]
Message-ID: <YRGwjgAIyLPb7g50@coredump.intra.peff.net> (raw)
In-Reply-To: <YRGwGDvOte/o9vkd@coredump.intra.peff.net>
The "offset" variable was was introduced in 44b67cb62b (range-diff:
split lines manually, 2019-07-11), but it has never done anything
useful. We use it to count up the number of bytes we've consumed, but we
never look at the result. It was probably copied accidentally from an
almost-identical loop in apply.c:find_header() (and the point of that
commit was to make use of the parse_git_diff_header() function which
underlies both).
Because the variable was set but not used, most compilers didn't seem to
notice, but the upcoming clang-14 does complain about it, via its
-Wunused-but-set-variable warning.
Signed-off-by: Jeff King <peff@peff.net>
---
The for-loop with an empty initializer and a doubled post-loop operation
is a little funny to see. I didn't see an easy way to make it less ugly
(pushing the line/size initialization into the for() would work, but the
resulting line is awfully long).
range-diff.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/range-diff.c b/range-diff.c
index e9479794b4..551600c774 100644
--- a/range-diff.c
+++ b/range-diff.c
@@ -49,7 +49,7 @@ static int read_patches(const char *range, struct string_list *list,
struct patch_util *util = NULL;
int in_header = 1;
char *line, *current_filename = NULL;
- int offset, len;
+ int len;
size_t size;
strvec_pushl(&cp.args, "log", "--no-color", "-p", "--no-merges",
@@ -86,7 +86,7 @@ static int read_patches(const char *range, struct string_list *list,
line = contents.buf;
size = contents.len;
- for (offset = 0; size > 0; offset += len, size -= len, line += len) {
+ for (; size > 0; size -= len, line += len) {
const char *p;
len = find_end_of_line(line, size);
--
2.33.0.rc1.475.g023efe0ae4
next prev parent reply other threads:[~2021-08-09 22:47 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-09 22:45 [PATCH 0/3] some small range-diff read_patches() fixes Jeff King
2021-08-09 22:47 ` Jeff King [this message]
2021-08-09 22:48 ` [PATCH 2/3] range-diff: handle unterminated lines in read_patches() Jeff King
2021-08-09 22:48 ` [PATCH 3/3] range-diff: use ssize_t for parsed "len" " Jeff King
2021-08-10 14:47 ` [PATCH 0/3] some small range-diff read_patches() fixes Derrick Stolee
2021-08-14 21:48 ` Johannes Schindelin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YRGwjgAIyLPb7g50@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=t.gummerer@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).