summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <carlos@cmartin.tk>2011-06-20 18:58:57 +0200
committerCarlos Martín Nieto <carlos@cmartin.tk>2011-06-26 18:18:10 +0200
commit2dc31040a25548c0cc224edc1ec3880dc16a9ca9 (patch)
tree81b04d4f5d94a4ab1f8ab52bd9c80e45a66a8022
parent9c82357be74bc5404038ec3c16706b1805843556 (diff)
downloadlibgit2-2dc31040a25548c0cc224edc1ec3880dc16a9ca9.tar.gz
Abstract the refspec query and parse
Move them to their own functions to avoid duplication and to make it easier to ignore missing configuration. Not finding 'fetch' is considered fatal, though this might not be correct behaviour (push-only remotes?) Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
-rw-r--r--include/git2.h1
-rw-r--r--src/remote.c20
2 files changed, 10 insertions, 11 deletions
diff --git a/include/git2.h b/include/git2.h
index e04b0bd18..6ede73cb5 100644
--- a/include/git2.h
+++ b/include/git2.h
@@ -53,6 +53,7 @@
#include "git2/index.h"
#include "git2/config.h"
+#include "git2/remote.h"
#include "git2/remote.h"
#include "git2/refspec.h"
diff --git a/src/remote.c b/src/remote.c
index 7da6e653e..aa22debce 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -69,7 +69,7 @@ static int parse_remote_refspec(git_config *cfg, git_refspec *refspec, const cha
if (error < GIT_SUCCESS)
return error;
- return git_refspec_parse(refspec, val);
+ return refspec_parse(refspec, val);
}
int git_remote_get(git_remote **out, git_config *cfg, const char *name)
@@ -122,13 +122,11 @@ int git_remote_get(git_remote **out, git_config *cfg, const char *name)
goto cleanup;
}
- error = git_config_get_string(cfg, buf, &val);
- if (error < GIT_SUCCESS)
- goto cleanup;
-
- error = refspec_parse(&remote->fetch, val);
- if (error < GIT_SUCCESS)
+ error = parse_remote_refspec(cfg, &remote->fetch, buf);
+ if (error < GIT_SUCCESS) {
+ error = git__rethrow(error, "Failed to get fetch refspec");
goto cleanup;
+ }
ret = snprintf(buf, buf_len, "%s.%s.%s", "remote", name, "push");
if (ret < 0) {
@@ -136,11 +134,11 @@ int git_remote_get(git_remote **out, git_config *cfg, const char *name)
goto cleanup;
}
- error = git_config_get_string(cfg, buf, &val);
- if (error < GIT_SUCCESS)
- goto cleanup;
+ error = parse_remote_refspec(cfg, &remote->push, buf);
+ /* Not finding push is fine */
+ if (error == GIT_ENOTFOUND)
+ error = GIT_SUCCESS;
- error = refspec_parse(&remote->push, val);
if (error < GIT_SUCCESS)
goto cleanup;