commit - 09838ffc9388f0cdbc316deb5eaae54ec4841207
commit + bb64b79860632effc06224a66e840f56e41f6ac6
blob - 2aa285a3281b14706191512d7f095677ed3fa2ef
blob + b5bed4ad76b6c5e4ce90833eb8d31dbc4e39147c
--- got/got.c
+++ got/got.c
const struct got_error *err = NULL;
const char *uri, *branch_filter, *dirname;
char *proto, *host, *port, *repo_name, *server_path;
+ char *default_destdir = NULL;
+ const char *repo_path;
+ struct got_repository *repo = NULL;
int ch;
while ((ch = getopt(argc, argv, "b:")) != -1) {
if (err)
goto done;
+ if (dirname == NULL) {
+ if (asprintf(&default_destdir, "%s.git", repo_name) == -1) {
+ err = got_error_from_errno("asprintf");
+ goto done;
+ }
+ repo_path = default_destdir;
+ } else
+ repo_path = dirname;
+
+ err = got_path_mkdir(repo_path);
+ if (err)
+ goto done;
+
+ err = got_repo_init(repo_path);
+ if (err != NULL)
+ goto done;
+
+ err = got_repo_open(&repo, repo_path, NULL);
+ if (err)
+ goto done;
+
err = got_fetch(proto, host, port, server_path, repo_name,
- branch_filter, dirname);
+ branch_filter, repo);
done:
+ if (repo)
+ got_repo_close(repo);
free(proto);
free(host);
free(port);
free(server_path);
free(repo_name);
+ free(default_destdir);
return err;
}
blob - 3af0abb9fe9bfa5b38d3eecfa6328ee6cbe3f661
blob + 76bf04d5f314663647550667aff141ee3b18cde1
--- include/got_fetch.h
+++ include/got_fetch.h
char **, char **, const char *);
const struct got_error *got_fetch(const char *, const char *,
const char *, const char *, const char *, const char *,
- const char *);
+ struct got_repository *);
blob - ff271353f0679b85ebb06d45b1dbcbf0ef2500be
blob + 4b57d0579703a7ad6c7c7179a89bd26fb80877a7
--- lib/fetch.c
+++ lib/fetch.c
const struct got_error*
got_fetch(const char *proto, const char *host, const char *port,
const char *server_path, const char *repo_name,
- const char *branch_filter, const char *destdir)
+ const char *branch_filter, struct got_repository *repo)
{
int imsg_fetchfds[2], imsg_idxfds[2], fetchfd = -1;
int packfd = -1, npackfd = -1, idxfd = -1, nidxfd = -1;
const struct got_error *err;
struct imsgbuf ibuf;
pid_t pid;
- char *tmppackpath = NULL, *tmpidxpath = NULL, *default_destdir = NULL;
+ char *tmppackpath = NULL, *tmpidxpath = NULL;
char *packpath = NULL, *idxpath = NULL, *id_str = NULL;
- const char *repo_path;
+ const char *repo_path = got_repo_get_path(repo);
struct got_pathlist_head symrefs;
struct got_pathlist_entry *pe;
- struct got_repository *repo = NULL;
char *path;
TAILQ_INIT(&symrefs);
fetchfd = -1;
- if (destdir == NULL) {
- if (asprintf(&default_destdir, "%s.git", repo_name) == -1)
- return got_error_from_errno("asprintf");
- repo_path = default_destdir;
- } else
- repo_path = destdir;
- err = got_repo_init(repo_path);
- if (err != NULL)
- goto done;
+
if (asprintf(&path, "%s/objects/path", repo_path) == -1) {
err = got_error_from_errno("asprintf");
goto done;
goto done;
}
- err = got_repo_open(&repo, repo_path, NULL);
- if (err)
- goto done;
-
while (!done) {
struct got_object_id *id;
char *refname;
err = got_error_from_errno("close");
if (idxfd != -1 && close(idxfd) == -1 && err == NULL)
err = got_error_from_errno("close");
- if (repo)
- got_repo_close(repo);
free(tmppackpath);
free(tmpidxpath);
free(idxpath);
free(packpath);
- free(default_destdir);
free(packhash);
TAILQ_FOREACH(pe, &symrefs, entry) {
free((void *)pe->path);