Skip to content

Commit 26b4df9

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b92266b commit 26b4df9

File tree

5 files changed

+49
-50
lines changed

5 files changed

+49
-50
lines changed

bundle-uri.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "bundle-uri.h"
55
#include "bundle.h"
66
#include "copy.h"
7-
#include "environment.h"
87
#include "gettext.h"
98
#include "refs.h"
109
#include "run-command.h"
@@ -13,6 +12,7 @@
1312
#include "config.h"
1413
#include "fetch-pack.h"
1514
#include "remote.h"
15+
#include "object-store-ll.h"
1616

1717
static struct {
1818
enum bundle_list_heuristic heuristic;

environment.c

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "commit.h"
2424
#include "strvec.h"
2525
#include "object-file.h"
26-
#include "object-store-ll.h"
2726
#include "path.h"
2827
#include "replace-object.h"
2928
#include "tmp-objdir.h"
@@ -268,39 +267,6 @@ void set_git_work_tree(const char *new_work_tree)
268267
repo_set_worktree(the_repository, new_work_tree);
269268
}
270269

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-
304270
static void set_git_dir_1(const char *path)
305271
{
306272
xsetenv(GIT_DIR_ENVIRONMENT, path, 1);

environment.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -200,21 +200,6 @@ extern int grafts_keep_true_parents;
200200

201201
extern int repository_format_precious_objects;
202202

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-
218203
const char *get_log_output_encoding(void);
219204
const char *get_commit_output_encoding(void);
220205

object-file.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,39 @@ enum scld_error safe_create_leading_directories_const(const char *path)
419419
return result;
420420
}
421421

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+
422455
static void fill_loose_path(struct strbuf *buf, const struct object_id *oid)
423456
{
424457
int i;

object-store-ll.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,21 @@ struct raw_object_store {
231231
struct raw_object_store *raw_object_store_new(void);
232232
void raw_object_store_clear(struct raw_object_store *o);
233233

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+
234249
/*
235250
* Put in `buf` the name of the file in the local object database that
236251
* would be used to store a loose object with the specified oid.

0 commit comments

Comments
 (0)