environment: move object database functions into object layer
The `odb_mkstemp()` and `odb_pack_keep()` functions are quite clearly tied to the object store, but regardless of that they are located in "environment.c". Move them over, which also helps to get rid of dependencies on `the_repository` in the environment subsystem. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Sep 12, 2024 at 13:29 UTC
26b4df907bca4829df44dc7eee23ccf7720898f7
5 files changed
+49
-50
bundle-uri.c
+1
-1
@@ -4,7 +4,6 @@
4
#include "bundle-uri.h"
5
#include "bundle.h"
6
#include "copy.h"
7
-#include "environment.h"
7
#include "gettext.h"
8
#include "refs.h"
9
#include "run-command.h"
@@ -13,6 +12,7 @@
12
#include "config.h"
13
#include "fetch-pack.h"
14
#include "remote.h"
15
+#include "object-store-ll.h"
16
17
static struct {
18
enum bundle_list_heuristic heuristic;
environment.c
-34
@@ -23,7 +23,6 @@
23
#include "commit.h"
24
#include "strvec.h"
25
#include "object-file.h"
26
-#include "object-store-ll.h"
26
#include "path.h"
27
#include "replace-object.h"
28
#include "tmp-objdir.h"
@@ -268,39 +267,6 @@ void set_git_work_tree(const char *new_work_tree)
267
repo_set_worktree(the_repository, new_work_tree);
268
}
269
271
-int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
272
-{
273
- int fd;
274
- /*
275
- * we let the umask do its job, don't try to be more
276
- * restrictive except to remove write permission.
277
- */
278
- int mode = 0444;
279
- git_path_buf(temp_filename, "objects/%s", pattern);
280
- fd = git_mkstemp_mode(temp_filename->buf, mode);
281
- if (0 <= fd)
282
- return fd;
283
-
284
- /* slow path */
285
- /* some mkstemp implementations erase temp_filename on failure */
286
- git_path_buf(temp_filename, "objects/%s", pattern);
287
- safe_create_leading_directories(temp_filename->buf);
288
- return xmkstemp_mode(temp_filename->buf, mode);
289
-}
290
-
291
-int odb_pack_keep(const char *name)
292
-{
293
- int fd;
294
-
295
- fd = open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
296
- if (0 <= fd)
297
- return fd;
298
-
299
- /* slow path */
300
- safe_create_leading_directories_const(name);
301
- return open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
302
-}
303
-
270
static void set_git_dir_1(const char *path)
271
{
272
xsetenv(GIT_DIR_ENVIRONMENT, path, 1);
environment.h
-15
@@ -200,21 +200,6 @@ extern int grafts_keep_true_parents;
200
201
extern int repository_format_precious_objects;
202
203
-/*
204
- * Create a temporary file rooted in the object database directory, or
205
- * die on failure. The filename is taken from "pattern", which should have the
206
- * usual "XXXXXX" trailer, and the resulting filename is written into the
207
- * "template" buffer. Returns the open descriptor.
208
- */
209
-int odb_mkstemp(struct strbuf *temp_filename, const char *pattern);
210
-
211
-/*
212
- * Create a pack .keep file named "name" (which should generally be the output
213
- * of odb_pack_name). Returns a file descriptor opened for writing, or -1 on
214
- * error.
215
- */
216
-int odb_pack_keep(const char *name);
217
-
203
const char *get_log_output_encoding(void);
204
const char *get_commit_output_encoding(void);
205
object-file.c
+33
@@ -419,6 +419,39 @@ enum scld_error safe_create_leading_directories_const(const char *path)
419
return result;
420
}
421
422
+int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
423
+{
424
+ int fd;
425
+ /*
426
+ * we let the umask do its job, don't try to be more
427
+ * restrictive except to remove write permission.
428
+ */
429
+ int mode = 0444;
430
+ git_path_buf(temp_filename, "objects/%s", pattern);
431
+ fd = git_mkstemp_mode(temp_filename->buf, mode);
432
+ if (0 <= fd)
433
+ return fd;
434
+
435
+ /* slow path */
436
+ /* some mkstemp implementations erase temp_filename on failure */
437
+ git_path_buf(temp_filename, "objects/%s", pattern);
438
+ safe_create_leading_directories(temp_filename->buf);
439
+ return xmkstemp_mode(temp_filename->buf, mode);
440
+}
441
+
442
+int odb_pack_keep(const char *name)
443
+{
444
+ int fd;
445
+
446
+ fd = open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
447
+ if (0 <= fd)
448
+ return fd;
449
+
450
+ /* slow path */
451
+ safe_create_leading_directories_const(name);
452
+ return open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
453
+}
454
+
455
static void fill_loose_path(struct strbuf *buf, const struct object_id *oid)
456
{
457
int i;
object-store-ll.h
+15
@@ -231,6 +231,21 @@ struct raw_object_store {
231
struct raw_object_store *raw_object_store_new(void);
232
void raw_object_store_clear(struct raw_object_store *o);
233
234
+/*
235
+ * Create a temporary file rooted in the object database directory, or
236
+ * die on failure. The filename is taken from "pattern", which should have the
237
+ * usual "XXXXXX" trailer, and the resulting filename is written into the
238
+ * "template" buffer. Returns the open descriptor.
239
+ */
240
+int odb_mkstemp(struct strbuf *temp_filename, const char *pattern);
241
+
242
+/*
243
+ * Create a pack .keep file named "name" (which should generally be the output
244
+ * of odb_pack_name). Returns a file descriptor opened for writing, or -1 on
245
+ * error.
246
+ */
247
+int odb_pack_keep(const char *name);
248
+
249
/*
250
* Put in `buf` the name of the file in the local object database that
251
* would be used to store a loose object with the specified oid.