Merge branch 'ps/copy-wo-the-repository' into next
The 'copy_file()' and 'copy_file_with_time()' functions have been refactored to take a repository parameter, allowing the removal of the implicit dependency on the global 'the_repository' variable in 'copy.c'. * ps/copy-wo-the-repository: copy: drop dependency on `the_repository`next
commit
9e38da0efc
|
|
@ -335,7 +335,7 @@ static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest,
|
|||
die_errno(_("failed to create link '%s'"), dest->buf);
|
||||
option_no_hardlinks = 1;
|
||||
}
|
||||
if (copy_file_with_time(dest->buf, src->buf, 0666))
|
||||
if (copy_file_with_time(the_repository, dest->buf, src->buf, 0666))
|
||||
die_errno(_("failed to copy file to '%s'"), dest->buf);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -552,7 +552,7 @@ static int run_dir_diff(struct repository *repo,
|
|||
struct stat st;
|
||||
if (stat(wtdir.buf, &st))
|
||||
st.st_mode = 0644;
|
||||
if (copy_file(rdir.buf, wtdir.buf,
|
||||
if (copy_file(repo, rdir.buf, wtdir.buf,
|
||||
st.st_mode)) {
|
||||
ret = error("could not copy '%s' to '%s'", wtdir.buf, rdir.buf);
|
||||
goto finish;
|
||||
|
|
@ -658,7 +658,7 @@ static int run_dir_diff(struct repository *repo,
|
|||
warning("%s", "");
|
||||
err = 1;
|
||||
} else if (unlink(wtdir.buf) ||
|
||||
copy_file(wtdir.buf, rdir.buf, st.st_mode))
|
||||
copy_file(repo, wtdir.buf, rdir.buf, st.st_mode))
|
||||
warning_errno(_("could not copy '%s' to '%s'"),
|
||||
rdir.buf, wtdir.buf);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -349,7 +349,7 @@ static void copy_sparse_checkout(const char *worktree_git_dir)
|
|||
|
||||
if (file_exists(from_file)) {
|
||||
if (safe_create_leading_directories(the_repository, to_file) ||
|
||||
copy_file(to_file, from_file, 0666))
|
||||
copy_file(the_repository, to_file, from_file, 0666))
|
||||
error(_("failed to copy '%s' to '%s'; sparse-checkout may not work correctly"),
|
||||
from_file, to_file);
|
||||
}
|
||||
|
|
@ -368,7 +368,7 @@ static void copy_filtered_worktree_config(const char *worktree_git_dir)
|
|||
int bare;
|
||||
|
||||
if (safe_create_leading_directories(the_repository, to_file) ||
|
||||
copy_file(to_file, from_file, 0666)) {
|
||||
copy_file(the_repository, to_file, from_file, 0666)) {
|
||||
error(_("failed to copy worktree config from '%s' to '%s'"),
|
||||
from_file, to_file);
|
||||
goto worktree_copy_cleanup;
|
||||
|
|
|
|||
|
|
@ -396,7 +396,7 @@ static int copy_uri_to_file(const char *filename, const char *uri)
|
|||
uri = out;
|
||||
|
||||
/* Copy as a file */
|
||||
return copy_file(filename, uri, 0);
|
||||
return copy_file(the_repository, filename, uri, 0);
|
||||
}
|
||||
|
||||
static int unbundle_from_file(struct repository *r, const char *file)
|
||||
|
|
|
|||
12
copy.c
12
copy.c
|
|
@ -1,5 +1,3 @@
|
|||
#define USE_THE_REPOSITORY_VARIABLE
|
||||
|
||||
#include "git-compat-util.h"
|
||||
#include "copy.h"
|
||||
#include "path.h"
|
||||
|
|
@ -35,7 +33,8 @@ static int copy_times(const char *dst, const char *src)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int copy_file(const char *dst, const char *src, int mode)
|
||||
int copy_file(struct repository *repo,
|
||||
const char *dst, const char *src, int mode)
|
||||
{
|
||||
int fdi, fdo, status;
|
||||
|
||||
|
|
@ -59,15 +58,16 @@ int copy_file(const char *dst, const char *src, int mode)
|
|||
if (close(fdo) != 0)
|
||||
return error_errno("%s: close error", dst);
|
||||
|
||||
if (!status && adjust_shared_perm(the_repository, dst))
|
||||
if (!status && adjust_shared_perm(repo, dst))
|
||||
return -1;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int copy_file_with_time(const char *dst, const char *src, int mode)
|
||||
int copy_file_with_time(struct repository *repo,
|
||||
const char *dst, const char *src, int mode)
|
||||
{
|
||||
int status = copy_file(dst, src, mode);
|
||||
int status = copy_file(repo, dst, src, mode);
|
||||
if (!status)
|
||||
return copy_times(dst, src);
|
||||
return status;
|
||||
|
|
|
|||
8
copy.h
8
copy.h
|
|
@ -1,10 +1,14 @@
|
|||
#ifndef COPY_H
|
||||
#define COPY_H
|
||||
|
||||
struct repository;
|
||||
|
||||
#define COPY_READ_ERROR (-2)
|
||||
#define COPY_WRITE_ERROR (-3)
|
||||
int copy_fd(int ifd, int ofd);
|
||||
int copy_file(const char *dst, const char *src, int mode);
|
||||
int copy_file_with_time(const char *dst, const char *src, int mode);
|
||||
int copy_file(struct repository *repo,
|
||||
const char *dst, const char *src, int mode);
|
||||
int copy_file_with_time(struct repository *repo,
|
||||
const char *dst, const char *src, int mode);
|
||||
|
||||
#endif /* COPY_H */
|
||||
|
|
|
|||
|
|
@ -1739,7 +1739,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store,
|
|||
goto out;
|
||||
}
|
||||
|
||||
if (copy && log && copy_file(tmp_renamed_log.buf, sb_oldref.buf, 0644)) {
|
||||
if (copy && log && copy_file(refs->base.repo, tmp_renamed_log.buf, sb_oldref.buf, 0644)) {
|
||||
ret = error("unable to copy logfile logs/%s to logs/"TMP_RENAMED_LOG": %s",
|
||||
oldrefname, strerror(errno));
|
||||
goto out;
|
||||
|
|
|
|||
2
rerere.c
2
rerere.c
|
|
@ -756,7 +756,7 @@ static void do_rerere_one_path(struct index_state *istate,
|
|||
/* Has the user resolved it already? */
|
||||
if (variant >= 0) {
|
||||
if (!handle_file(istate, path, NULL, NULL)) {
|
||||
copy_file(rerere_path(&buf, id, "postimage"), path, 0666);
|
||||
copy_file(the_repository, rerere_path(&buf, id, "postimage"), path, 0666);
|
||||
id->collection->status[variant] |= RR_HAS_POSTIMAGE;
|
||||
fprintf_ln(stderr, _("Recorded resolution for '%s'."), path);
|
||||
free_rerere_id(rr_item);
|
||||
|
|
|
|||
|
|
@ -2419,7 +2419,7 @@ static int do_pick_commit(struct repository *r,
|
|||
} else {
|
||||
const char *dest = git_path_squash_msg(r);
|
||||
unlink(dest);
|
||||
if (copy_file(dest, rebase_path_squash_msg(), 0666)) {
|
||||
if (copy_file(r, dest, rebase_path_squash_msg(), 0666)) {
|
||||
res = error(_("could not copy '%s' to '%s'"),
|
||||
rebase_path_squash_msg(), dest);
|
||||
goto leave;
|
||||
|
|
@ -3864,11 +3864,11 @@ static int error_failed_squash(struct repository *r,
|
|||
int subject_len,
|
||||
const char *subject)
|
||||
{
|
||||
if (copy_file(rebase_path_message(), rebase_path_squash_msg(), 0666))
|
||||
if (copy_file(r, rebase_path_message(), rebase_path_squash_msg(), 0666))
|
||||
return error(_("could not copy '%s' to '%s'"),
|
||||
rebase_path_squash_msg(), rebase_path_message());
|
||||
unlink(git_path_merge_msg(r));
|
||||
if (copy_file(git_path_merge_msg(r), rebase_path_message(), 0666))
|
||||
if (copy_file(r, git_path_merge_msg(r), rebase_path_message(), 0666))
|
||||
return error(_("could not copy '%s' to '%s'"),
|
||||
rebase_path_message(),
|
||||
git_path_merge_msg(r));
|
||||
|
|
|
|||
2
setup.c
2
setup.c
|
|
@ -2355,7 +2355,7 @@ static void copy_templates_1(struct repository *repo,
|
|||
strbuf_release(&lnk);
|
||||
}
|
||||
else if (S_ISREG(st_template.st_mode)) {
|
||||
if (copy_file(path->buf, template_path->buf, st_template.st_mode))
|
||||
if (copy_file(repo, path->buf, template_path->buf, st_template.st_mode))
|
||||
die_errno(_("cannot copy '%s' to '%s'"),
|
||||
template_path->buf, path->buf);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue