tempfile: add repo_create_tempfile{,_mode}()
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>
René Scharfe committed
Jul 14, 2026 at 19:59 UTC
8aad1dfc006e129d3276ae6dd5cc2ba7ca2a8f4c
2 files changed
+18
-1
tempfile.c
+7
-1
@@ -135,6 +135,12 @@ static void deactivate_tempfile(struct tempfile *tempfile)
135
136
/* Make sure errno contains a meaningful value on error */
137
struct tempfile *create_tempfile_mode(const char *path, int mode)
138
+{
139
+ return repo_create_tempfile_mode(the_repository, path, mode);
140
+}
141
+
142
+struct tempfile *repo_create_tempfile_mode(struct repository *r,
143
+ const char *path, int mode)
144
{
145
struct tempfile *tempfile = new_tempfile();
146
@@ -150,7 +156,7 @@ struct tempfile *create_tempfile_mode(const char *path, int mode)
156
return NULL;
157
}
158
activate_tempfile(tempfile);
153
- if (adjust_shared_perm(the_repository, tempfile->filename.buf)) {
159
+ if (adjust_shared_perm(r, tempfile->filename.buf)) {
160
int save_errno = errno;
161
error("cannot fix permission bits on %s", tempfile->filename.buf);
162
delete_tempfile(&tempfile);
tempfile.h
+11
@@ -4,6 +4,8 @@
4
#include "list.h"
5
#include "strbuf.h"
6
7
+struct repository;
8
+
9
/*
10
* Handle temporary files.
11
*
@@ -94,11 +96,20 @@ struct tempfile {
96
*/
97
struct tempfile *create_tempfile_mode(const char *path, int mode);
98
99
+struct tempfile *repo_create_tempfile_mode(struct repository *r,
100
+ const char *path, int mode);
101
+
102
static inline struct tempfile *create_tempfile(const char *path)
103
{
104
return create_tempfile_mode(path, 0666);
105
}
106
107
+static inline struct tempfile *repo_create_tempfile(struct repository *r,
108
+ const char *path)
109
+{
110
+ return repo_create_tempfile_mode(r, path, 0666);
111
+}
112
+
113
/*
114
* Register an existing file as a tempfile, meaning that it will be
115
* deleted when the program exits. The tempfile is considered closed,