]> git.ipfire.org Git - thirdparty/git.git/commitdiff
tempfile: add repo_create_tempfile{,_mode}()
authorRené Scharfe <l.s.r@web.de>
Tue, 14 Jul 2026 17:59:52 +0000 (19:59 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 14 Jul 2026 19:54:25 +0000 (12:54 -0700)
Add variants of create_tempfile_mode() that handle arbitrary
repositories.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
tempfile.c
tempfile.h

index f0fdf582794ba590d485099634b814e88848537f..3132eb437100360531fbe1555c8d83defd371bd1 100644 (file)
@@ -135,6 +135,12 @@ static void deactivate_tempfile(struct tempfile *tempfile)
 
 /* Make sure errno contains a meaningful value on error */
 struct tempfile *create_tempfile_mode(const char *path, int mode)
+{
+       return repo_create_tempfile_mode(the_repository, path, mode);
+}
+
+struct tempfile *repo_create_tempfile_mode(struct repository *r,
+                                          const char *path, int mode)
 {
        struct tempfile *tempfile = new_tempfile();
 
@@ -150,7 +156,7 @@ struct tempfile *create_tempfile_mode(const char *path, int mode)
                return NULL;
        }
        activate_tempfile(tempfile);
-       if (adjust_shared_perm(the_repository, tempfile->filename.buf)) {
+       if (adjust_shared_perm(r, tempfile->filename.buf)) {
                int save_errno = errno;
                error("cannot fix permission bits on %s", tempfile->filename.buf);
                delete_tempfile(&tempfile);
index 2227a095fd42898ab49643cc51ddbe950b821073..2d17e4dad3faa525baba6231d2d791f77dd09ce7 100644 (file)
@@ -4,6 +4,8 @@
 #include "list.h"
 #include "strbuf.h"
 
+struct repository;
+
 /*
  * Handle temporary files.
  *
@@ -94,11 +96,20 @@ struct tempfile {
  */
 struct tempfile *create_tempfile_mode(const char *path, int mode);
 
+struct tempfile *repo_create_tempfile_mode(struct repository *r,
+                                          const char *path, int mode);
+
 static inline struct tempfile *create_tempfile(const char *path)
 {
        return create_tempfile_mode(path, 0666);
 }
 
+static inline struct tempfile *repo_create_tempfile(struct repository *r,
+                                                   const char *path)
+{
+       return repo_create_tempfile_mode(r, path, 0666);
+}
+
 /*
  * Register an existing file as a tempfile, meaning that it will be
  * deleted when the program exits. The tempfile is considered closed,