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

[PATCH v12 12/13] apply: learn to use a different index file

From
Christian Couder <christian.couder@gmail.com>
Date
Aug 11, 2016, 18:45 UTC
Message-ID
<20160811184501.384-13-chriscool@tuxfamily.org>
In-Reply-To
<20160811184501.384-1-chriscool@tuxfamily.org>
Sometimes we want to apply in a different index file.

Before the apply functionality was libified it was possible to use the GIT_INDEX_FILE environment variable, for this purpose.

But now, as the apply functionality has been libified, it should be possible to do that in a libified way.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 apply.c | 10 ++++++++--
 apply.h |  1 +
 2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/apply.c b/apply.c
index 2ec2a8a..7e561a4 100644
--- a/apply.c
+++ b/apply.c
@@ -4674,8 +4674,14 @@ static int apply_patch(struct apply_state *state,
 		state->apply = 0;
 
 	state->update_index = state->check_index && state->apply;
-	if (state->update_index && state->newfd < 0)
-		state->newfd = hold_locked_index(state->lock_file, 1);
+	if (state->update_index && state->newfd < 0) {
+		if (state->index_file)
+			state->newfd = hold_lock_file_for_update(state->lock_file,
+								 state->index_file,
+								 LOCK_DIE_ON_ERROR);
+		else
+			state->newfd = hold_locked_index(state->lock_file, 1);
+	}
 
 	if (state->check_index && read_cache() < 0) {
 		error(_("unable to read index file"));
diff --git a/apply.h b/apply.h
index e2b89e8..1ba4f8d 100644
--- a/apply.h
+++ b/apply.h
@@ -63,6 +63,7 @@ struct apply_state {
 	int unsafe_paths;
 
 	/* Other non boolean parameters */
+	const char *index_file;
 	enum apply_verbosity apply_verbosity;
 	const char *fake_ancestor;
 	const char *patch_input_file;
-- 
2.9.2.769.gc0f0333
Previous: Christian CouderNext: Junio C Hamano
Message 13 of 15 in “libify apply and use lib in am, part 3”
  1. 00/13 libify apply and use lib in am, part 3Christian Couder, Aug 11, 2016
  2. 01/13 builtin/apply: rename option parsing functionsChristian Couder, Aug 11, 2016
  3. 02/13 apply: rename and move opt constants to apply.hChristian Couder, Aug 11, 2016
  4. 04/13 apply: make some parsing functions static againChristian Couder, Aug 11, 2016
  5. 06/13 apply: make it possible to silently applyChristian Couder, Aug 11, 2016
  6. 05/13 apply: use error_errno() where possibleChristian Couder, Aug 11, 2016
  7. 07/13 apply: don't print on stdout in verbosity_silent modeChristian Couder, Aug 11, 2016
  8. 09/13 usage: add get_error_routine() and get_warn_routine()Christian Couder, Aug 11, 2016
  9. 11/13 apply: refactor `git apply` option parsingChristian Couder, Aug 11, 2016
  10. 08/13 usage: add set_warn_routine()Christian Couder, Aug 11, 2016
  11. 10/13 apply: change error_routine when silentChristian Couder, Aug 11, 2016
  12. 13/13 builtin/am: use apply API in run_apply()Christian Couder, Aug 11, 2016
  13. 12/13 apply: learn to use a different index fileChristian Couder, Aug 11, 2016
  14. Junio C HamanoAug 11, 2016
  15. Christian CouderAug 26, 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.