summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2012-08-22 16:03:35 -0700
committerRussell Belfer <rb@github.com>2012-08-22 16:16:42 -0700
commit85bd17462662905dfdf9247b262480280a616ad4 (patch)
tree88454804c539284aa6cb216943d0a53b7cde211b /src
parentb769e936d0118b7c3870ffc082b44254164bfedd (diff)
downloadlibgit2-85bd17462662905dfdf9247b262480280a616ad4.tar.gz
Some cleanup suggested during review
This cleans up a number of items suggested during code review with @vmg, including: * renaming "outside repo" config API to `git_config_open_default` * killing the `git_config_open_global` API * removing the `git_` prefix from the static functions in fileops * removing some unnecessary functionality from the "cp" command
Diffstat (limited to 'src')
-rw-r--r--src/config.c16
-rw-r--r--src/fileops.c27
-rw-r--r--src/fileops.h10
-rw-r--r--src/repository.c2
-rw-r--r--src/unix/posix.h1
5 files changed, 16 insertions, 40 deletions
diff --git a/src/config.c b/src/config.c
index 3ca49714c..277daaafe 100644
--- a/src/config.c
+++ b/src/config.c
@@ -501,21 +501,7 @@ int git_config_find_system(char *system_config_path, size_t length)
return 0;
}
-int git_config_open_global(git_config **out)
-{
- int error;
- git_buf path = GIT_BUF_INIT;
-
- if ((error = git_config_find_global_r(&path)) < 0)
- return error;
-
- error = git_config_open_ondisk(out, git_buf_cstr(&path));
- git_buf_free(&path);
-
- return error;
-}
-
-int git_config_open_outside_repo(git_config **out)
+int git_config_open_default(git_config **out)
{
int error;
git_config *cfg = NULL;
diff --git a/src/fileops.c b/src/fileops.c
index ceded4338..5df312360 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -511,7 +511,7 @@ int git_futils_fake_symlink(const char *old, const char *new)
return retcode;
}
-static int git_futils_cp_fd(int ifd, int ofd, bool close_fd)
+static int cp_by_fd(int ifd, int ofd, bool close_fd_when_done)
{
int error = 0;
char buffer[4096];
@@ -528,7 +528,7 @@ static int git_futils_cp_fd(int ifd, int ofd, bool close_fd)
error = (int)len;
}
- if (close_fd) {
+ if (close_fd_when_done) {
p_close(ifd);
p_close(ofd);
}
@@ -536,14 +536,10 @@ static int git_futils_cp_fd(int ifd, int ofd, bool close_fd)
return error;
}
-int git_futils_cp_withpath(
- const char *from, const char *to, mode_t filemode, mode_t dirmode)
+int git_futils_cp(const char *from, const char *to, mode_t filemode)
{
int ifd, ofd;
- if (git_futils_mkpath2file(to, dirmode) < 0)
- return -1;
-
if ((ifd = git_futils_open_ro(from)) < 0)
return ifd;
@@ -555,19 +551,18 @@ int git_futils_cp_withpath(
return ofd;
}
- return git_futils_cp_fd(ifd, ofd, true);
+ return cp_by_fd(ifd, ofd, true);
}
-static int git_futils_cplink(
- const char *from, size_t from_filesize, const char *to)
+static int cp_link(const char *from, const char *to, size_t link_size)
{
int error = 0;
ssize_t read_len;
- char *link_data = git__malloc(from_filesize + 1);
+ char *link_data = git__malloc(link_size + 1);
GITERR_CHECK_ALLOC(link_data);
- read_len = p_readlink(from, link_data, from_filesize);
- if (read_len != (ssize_t)from_filesize) {
+ read_len = p_readlink(from, link_data, link_size);
+ if (read_len != (ssize_t)link_size) {
giterr_set(GITERR_OS, "Failed to read symlink data for '%s'", from);
error = -1;
}
@@ -668,11 +663,9 @@ static int _cp_r_callback(void *ref, git_buf *from)
/* make symlink or regular file */
if (S_ISLNK(from_st.st_mode))
- return git_futils_cplink(
- from->ptr, (size_t)from_st.st_size, info->to.ptr);
+ return cp_link(from->ptr, info->to.ptr, (size_t)from_st.st_size);
else
- return git_futils_cp_withpath(
- from->ptr, info->to.ptr, from_st.st_mode, info->dirmode);
+ return git_futils_cp(from->ptr, info->to.ptr, from_st.st_mode);
}
int git_futils_cp_r(
diff --git a/src/fileops.h b/src/fileops.h
index 6f3450373..5c23ce30b 100644
--- a/src/fileops.h
+++ b/src/fileops.h
@@ -130,16 +130,14 @@ extern int git_futils_mktmp(git_buf *path_out, const char *filename);
extern int git_futils_mv_withpath(const char *from, const char *to, const mode_t dirmode);
/**
- * Copy a file, creating the destination path if needed.
+ * Copy a file
*
- * The filemode will be used for the file and the dirmode will be used for
- * any intervening directories if necessary.
+ * The filemode will be used for the newly created file.
*/
-extern int git_futils_cp_withpath(
+extern int git_futils_cp(
const char *from,
const char *to,
- mode_t filemode,
- mode_t dirmode);
+ mode_t filemode);
/**
* Flags that can be passed to `git_futils_cp_r`.
diff --git a/src/repository.c b/src/repository.c
index ebd60360a..8005797b2 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -936,7 +936,7 @@ static int repo_init_structure(
if (opts->template_path)
tdir = opts->template_path;
- else if ((error = git_config_open_outside_repo(&cfg)) < 0)
+ else if ((error = git_config_open_default(&cfg)) < 0)
return error;
else {
error = git_config_get_string(&tdir, cfg, "init.templatedir");
diff --git a/src/unix/posix.h b/src/unix/posix.h
index 45d2b7238..25038c827 100644
--- a/src/unix/posix.h
+++ b/src/unix/posix.h
@@ -20,7 +20,6 @@
#define p_readlink(a, b, c) readlink(a, b, c)
#define p_symlink(o,n) symlink(o, n)
#define p_link(o,n) link(o, n)
-#define p_symlink(o,n) symlink(o,n)
#define p_unlink(p) unlink(p)
#define p_mkdir(p,m) mkdir(p, m)
#define p_fsync(fd) fsync(fd)