summaryrefslogtreecommitdiff
path: root/tmp-objdir.h
diff options
context:
space:
mode:
authorNeeraj Singh <neerajsi@microsoft.com>2021-12-06 22:05:04 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-12-08 22:06:36 (GMT)
commitb3cecf49eac00d62e361bf6e6e81392f5a2fb571 (patch)
treeae4937eebd6d08bb828dd1967d043369c496c945 /tmp-objdir.h
parentcefe983a320c03d7843ac78e73bd513a27806845 (diff)
downloadgit-b3cecf49eac00d62e361bf6e6e81392f5a2fb571.zip
git-b3cecf49eac00d62e361bf6e6e81392f5a2fb571.tar.gz
git-b3cecf49eac00d62e361bf6e6e81392f5a2fb571.tar.bz2
tmp-objdir: new API for creating temporary writable databases
The tmp_objdir API provides the ability to create temporary object directories, but was designed with the goal of having subprocesses access these object stores, followed by the main process migrating objects from it to the main object store or just deleting it. The subprocesses would view it as their primary datastore and write to it. Here we add the tmp_objdir_replace_primary_odb function that replaces the current process's writable "main" object directory with the specified one. The previous main object directory is restored in either tmp_objdir_migrate or tmp_objdir_destroy. For the --remerge-diff usecase, add a new `will_destroy` flag in `struct object_database` to mark ephemeral object databases that do not require fsync durability. Add 'git prune' support for removing temporary object databases, and make sure that they have a name starting with tmp_ and containing an operation-specific name. Based-on-patch-by: Elijah Newren <newren@gmail.com> Signed-off-by: Neeraj Singh <neerajsi@microsoft.com> Reviewed-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'tmp-objdir.h')
-rw-r--r--tmp-objdir.h29
1 files changed, 26 insertions, 3 deletions
diff --git a/tmp-objdir.h b/tmp-objdir.h
index b1e45b4..cda5ec7 100644
--- a/tmp-objdir.h
+++ b/tmp-objdir.h
@@ -10,7 +10,7 @@
*
* Example:
*
- * struct tmp_objdir *t = tmp_objdir_create();
+ * struct tmp_objdir *t = tmp_objdir_create("incoming");
* if (!run_command_v_opt_cd_env(cmd, 0, NULL, tmp_objdir_env(t)) &&
* !tmp_objdir_migrate(t))
* printf("success!\n");
@@ -22,9 +22,10 @@
struct tmp_objdir;
/*
- * Create a new temporary object directory; returns NULL on failure.
+ * Create a new temporary object directory with the specified prefix;
+ * returns NULL on failure.
*/
-struct tmp_objdir *tmp_objdir_create(void);
+struct tmp_objdir *tmp_objdir_create(const char *prefix);
/*
* Return a list of environment strings, suitable for use with
@@ -51,4 +52,26 @@ int tmp_objdir_destroy(struct tmp_objdir *);
*/
void tmp_objdir_add_as_alternate(const struct tmp_objdir *);
+/*
+ * Replaces the writable object store in the current process with the temporary
+ * object directory and makes the former main object store an alternate.
+ * If will_destroy is nonzero, the object directory may not be migrated.
+ */
+void tmp_objdir_replace_primary_odb(struct tmp_objdir *, int will_destroy);
+
+/*
+ * If the primary object database was replaced by a temporary object directory,
+ * restore it to its original value while keeping the directory contents around.
+ * Returns NULL if the primary object database was not replaced.
+ */
+struct tmp_objdir *tmp_objdir_unapply_primary_odb(void);
+
+/*
+ * Reapplies the former primary temporary object database, after potentially
+ * changing its relative path.
+ */
+void tmp_objdir_reapply_primary_odb(struct tmp_objdir *, const char *old_cwd,
+ const char *new_cwd);
+
+
#endif /* TMP_OBJDIR_H */