[PATCH v9 33/41] environment: add set_index_file()
From: Christian Couder <hidden>
Date: 2016-07-30 17:27:49
Subsystem:
the rest · Maintainer:
Linus Torvalds
Introduce set_index_file() to be able to temporarily change the index file.
It should be used like this:
/* Save current index file */
old_index_file = get_index_file();
set_index_file((char *)tmp_index_file);
/* Do stuff that will use tmp_index_file as the index file */
...
/* When finished reset the index file */
set_index_file(old_index_file);
It is intended to be used by builtins commands, in fact `git am`, to
temporarily change the index file used by libified code.
This is useful when libified code uses the global index, but a builtin
command wants another index file to be used instead.
And yeah this is a short cut and this new function should not be used
by other code.
Signed-off-by: Christian Couder <redacted>
---
cache.h | 1 +
environment.c | 12 ++++++++++++
2 files changed, 13 insertions(+)
diff --git a/cache.h b/cache.h
index b5f76a4..18b96fe 100644
--- a/cache.h
+++ b/cache.h@@ -461,6 +461,7 @@ extern int is_inside_work_tree(void); extern const char *get_git_dir(void); extern const char *get_git_common_dir(void); extern char *get_object_directory(void); +extern void set_index_file(char *index_file); extern char *get_index_file(void); extern char *get_graft_file(void); extern int set_git_dir(const char *path);
diff --git a/environment.c b/environment.c
index ca72464..eb23d01 100644
--- a/environment.c
+++ b/environment.c@@ -292,6 +292,18 @@ int odb_pack_keep(char *name, size_t namesz, const unsigned char *sha1) return open(name, O_RDWR|O_CREAT|O_EXCL, 0600); } +/* + * Temporarily change the index file. + * Please save the current index file using get_index_file() before changing + * the index file. And when finished, reset it to the saved value. + * Yeah, the libification of 'apply' took a short-circuit by adding this + * technical debt; please do not call this function in new codepaths. + */ +void set_index_file(char *index_file) +{ + git_index_file = index_file; +} + char *get_index_file(void) { if (!git_index_file)
--
2.9.2.558.gf53e569