git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v5 2/2] builtin/apply: move 'newfd' global into 'struct apply_state'

From
Christian Couder <christian.couder@gmail.com>
Date
Jun 6, 2016, 09:56 UTC
Message-ID
<20160606095658.1815-2-chriscool@tuxfamily.org>
In-Reply-To
<20160606095658.1815-1-chriscool@tuxfamily.org>
From: Christian Couder <christian.couder@gmail.com>

To libify the apply functionality the 'newfd' variable should not be static and global to the file. Let's move it into 'struct apply_state'.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
This is to replace:
"[PATCH v3 49/49] builtin/apply: move 'newfd' global into 'struct apply_state'"
from the "libify apply and use lib in am, part 1" patch series, and
"[PATCH v4 2/2] builtin/apply: move 'newfd' global into 'struct apply_state'"
that was sent previously to replace v3 49/49 above.

There is no change compared to both previous version except that this patch should apply cleanly on top of PATCH v5 1/2.

 builtin/apply.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/builtin/apply.c b/builtin/apply.c
index bbe0df1..b3eb704 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -54,6 +54,7 @@ struct apply_state {
 
 	/* These are lock_file related */
 	struct lock_file *lock_file;
+	int newfd;
 
 	/* These control what gets looked at and modified */
 	int apply; /* this is not a dry-run */
@@ -117,8 +118,6 @@ struct apply_state {
 	int applied_after_fixing_ws;
 };
 
-static int newfd = -1;
-
 static const char * const apply_usage[] = {
 	N_("git apply [<options>] [<patch>...]"),
 	NULL
@@ -4549,8 +4548,8 @@ static int apply_patch(struct apply_state *state,
 		state->apply = 0;
 
 	state->update_index = state->check_index && state->apply;
-	if (state->update_index && newfd < 0)
-		newfd = hold_locked_index(state->lock_file, 1);
+	if (state->update_index && state->newfd < 0)
+		state->newfd = hold_locked_index(state->lock_file, 1);
 
 	if (state->check_index) {
 		if (read_cache() < 0)
@@ -4659,6 +4658,7 @@ static void init_apply_state(struct apply_state *state,
 	state->prefix = prefix;
 	state->prefix_length = state->prefix ? strlen(state->prefix) : 0;
 	state->lock_file = lock_file;
+	state->newfd = -1;
 	state->apply = 1;
 	state->line_termination = '\n';
 	state->p_value = 1;
@@ -4779,6 +4779,7 @@ static int apply_all_patches(struct apply_state *state,
 	if (state->update_index) {
 		if (write_locked_index(&the_index, state->lock_file, COMMIT_LOCK))
 			die(_("Unable to write new index file"));
+		state->newfd = -1;
 	}
 
 	return !!errs;
-- 
2.8.2.445.g4623162
Previous: Christian Couder
Message 2 of 2 in “builtin/apply: add 'lock_file' pointer into 'struct apply_state'”
  1. 1/2 builtin/apply: add 'lock_file' pointer into 'struct apply_state'Christian Couder, Jun 6, 2016
  2. 2/2 builtin/apply: move 'newfd' global into 'struct apply_state'Christian Couder, Jun 6, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.