mirror of
https://github.com/git/git.git
synced 2024-10-28 04:49:43 +01:00
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>
This commit is contained in:
parent
b92266b79c
commit
26b4df907b
5 changed files with 49 additions and 50 deletions
|
@ -4,7 +4,6 @@
|
||||||
#include "bundle-uri.h"
|
#include "bundle-uri.h"
|
||||||
#include "bundle.h"
|
#include "bundle.h"
|
||||||
#include "copy.h"
|
#include "copy.h"
|
||||||
#include "environment.h"
|
|
||||||
#include "gettext.h"
|
#include "gettext.h"
|
||||||
#include "refs.h"
|
#include "refs.h"
|
||||||
#include "run-command.h"
|
#include "run-command.h"
|
||||||
|
@ -13,6 +12,7 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "fetch-pack.h"
|
#include "fetch-pack.h"
|
||||||
#include "remote.h"
|
#include "remote.h"
|
||||||
|
#include "object-store-ll.h"
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
enum bundle_list_heuristic heuristic;
|
enum bundle_list_heuristic heuristic;
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
#include "commit.h"
|
#include "commit.h"
|
||||||
#include "strvec.h"
|
#include "strvec.h"
|
||||||
#include "object-file.h"
|
#include "object-file.h"
|
||||||
#include "object-store-ll.h"
|
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
#include "replace-object.h"
|
#include "replace-object.h"
|
||||||
#include "tmp-objdir.h"
|
#include "tmp-objdir.h"
|
||||||
|
@ -268,39 +267,6 @@ void set_git_work_tree(const char *new_work_tree)
|
||||||
repo_set_worktree(the_repository, new_work_tree);
|
repo_set_worktree(the_repository, new_work_tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
/*
|
|
||||||
* we let the umask do its job, don't try to be more
|
|
||||||
* restrictive except to remove write permission.
|
|
||||||
*/
|
|
||||||
int mode = 0444;
|
|
||||||
git_path_buf(temp_filename, "objects/%s", pattern);
|
|
||||||
fd = git_mkstemp_mode(temp_filename->buf, mode);
|
|
||||||
if (0 <= fd)
|
|
||||||
return fd;
|
|
||||||
|
|
||||||
/* slow path */
|
|
||||||
/* some mkstemp implementations erase temp_filename on failure */
|
|
||||||
git_path_buf(temp_filename, "objects/%s", pattern);
|
|
||||||
safe_create_leading_directories(temp_filename->buf);
|
|
||||||
return xmkstemp_mode(temp_filename->buf, mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
int odb_pack_keep(const char *name)
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
fd = open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
|
|
||||||
if (0 <= fd)
|
|
||||||
return fd;
|
|
||||||
|
|
||||||
/* slow path */
|
|
||||||
safe_create_leading_directories_const(name);
|
|
||||||
return open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void set_git_dir_1(const char *path)
|
static void set_git_dir_1(const char *path)
|
||||||
{
|
{
|
||||||
xsetenv(GIT_DIR_ENVIRONMENT, path, 1);
|
xsetenv(GIT_DIR_ENVIRONMENT, path, 1);
|
||||||
|
|
|
@ -200,21 +200,6 @@ extern int grafts_keep_true_parents;
|
||||||
|
|
||||||
extern int repository_format_precious_objects;
|
extern int repository_format_precious_objects;
|
||||||
|
|
||||||
/*
|
|
||||||
* Create a temporary file rooted in the object database directory, or
|
|
||||||
* die on failure. The filename is taken from "pattern", which should have the
|
|
||||||
* usual "XXXXXX" trailer, and the resulting filename is written into the
|
|
||||||
* "template" buffer. Returns the open descriptor.
|
|
||||||
*/
|
|
||||||
int odb_mkstemp(struct strbuf *temp_filename, const char *pattern);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Create a pack .keep file named "name" (which should generally be the output
|
|
||||||
* of odb_pack_name). Returns a file descriptor opened for writing, or -1 on
|
|
||||||
* error.
|
|
||||||
*/
|
|
||||||
int odb_pack_keep(const char *name);
|
|
||||||
|
|
||||||
const char *get_log_output_encoding(void);
|
const char *get_log_output_encoding(void);
|
||||||
const char *get_commit_output_encoding(void);
|
const char *get_commit_output_encoding(void);
|
||||||
|
|
||||||
|
|
|
@ -419,6 +419,39 @@ enum scld_error safe_create_leading_directories_const(const char *path)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
/*
|
||||||
|
* we let the umask do its job, don't try to be more
|
||||||
|
* restrictive except to remove write permission.
|
||||||
|
*/
|
||||||
|
int mode = 0444;
|
||||||
|
git_path_buf(temp_filename, "objects/%s", pattern);
|
||||||
|
fd = git_mkstemp_mode(temp_filename->buf, mode);
|
||||||
|
if (0 <= fd)
|
||||||
|
return fd;
|
||||||
|
|
||||||
|
/* slow path */
|
||||||
|
/* some mkstemp implementations erase temp_filename on failure */
|
||||||
|
git_path_buf(temp_filename, "objects/%s", pattern);
|
||||||
|
safe_create_leading_directories(temp_filename->buf);
|
||||||
|
return xmkstemp_mode(temp_filename->buf, mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
int odb_pack_keep(const char *name)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
fd = open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
|
||||||
|
if (0 <= fd)
|
||||||
|
return fd;
|
||||||
|
|
||||||
|
/* slow path */
|
||||||
|
safe_create_leading_directories_const(name);
|
||||||
|
return open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
|
||||||
|
}
|
||||||
|
|
||||||
static void fill_loose_path(struct strbuf *buf, const struct object_id *oid)
|
static void fill_loose_path(struct strbuf *buf, const struct object_id *oid)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
|
@ -231,6 +231,21 @@ struct raw_object_store {
|
||||||
struct raw_object_store *raw_object_store_new(void);
|
struct raw_object_store *raw_object_store_new(void);
|
||||||
void raw_object_store_clear(struct raw_object_store *o);
|
void raw_object_store_clear(struct raw_object_store *o);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create a temporary file rooted in the object database directory, or
|
||||||
|
* die on failure. The filename is taken from "pattern", which should have the
|
||||||
|
* usual "XXXXXX" trailer, and the resulting filename is written into the
|
||||||
|
* "template" buffer. Returns the open descriptor.
|
||||||
|
*/
|
||||||
|
int odb_mkstemp(struct strbuf *temp_filename, const char *pattern);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create a pack .keep file named "name" (which should generally be the output
|
||||||
|
* of odb_pack_name). Returns a file descriptor opened for writing, or -1 on
|
||||||
|
* error.
|
||||||
|
*/
|
||||||
|
int odb_pack_keep(const char *name);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Put in `buf` the name of the file in the local object database that
|
* Put in `buf` the name of the file in the local object database that
|
||||||
* would be used to store a loose object with the specified oid.
|
* would be used to store a loose object with the specified oid.
|
||||||
|
|
Loading…
Reference in a new issue