Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2013-04-16 01:18:24 +0400
committerVicent Marti <tanoku@gmail.com>2013-04-16 01:18:24 +0400
commitd064c74794f51e759cd84648f84f2609d3283ecc (patch)
tree8ec58c4678fbc85f0038bf3eff89d67b3879ead7 /src/revparse.c
parent77849ebf1e39126bcb9f1245423749d45d226022 (diff)
parent201566539f38874b4e93c6a36593bd0d10e6352c (diff)
Merge remote-tracking branch 'ben/unified-revparse' into development
Diffstat (limited to 'src/revparse.c')
-rw-r--r--src/revparse.c66
1 files changed, 44 insertions, 22 deletions
diff --git a/src/revparse.c b/src/revparse.c
index fd62a2fd2..d2c14ccbb 100644
--- a/src/revparse.c
+++ b/src/revparse.c
@@ -107,7 +107,7 @@ static int build_regex(regex_t *regex, const char *pattern)
error = regcomp(regex, pattern, REG_EXTENDED);
if (!error)
return 0;
-
+
error = giterr_set_regex(regex, error);
regfree(regex);
@@ -125,7 +125,7 @@ static int maybe_describe(git_object**out, git_repository *repo, const char *spe
if (substr == NULL)
return GIT_ENOTFOUND;
-
+
if (build_regex(&regex, ".+-[0-9]+-g[0-9a-fA-F]+") < 0)
return -1;
@@ -358,7 +358,7 @@ static int retrieve_remote_tracking_reference(git_reference **base_ref, const ch
if ((error = git_branch_upstream(&tracking, ref)) < 0)
goto cleanup;
-
+
*base_ref = tracking;
cleanup:
@@ -508,7 +508,7 @@ static int walk_and_search(git_object **out, git_revwalk *walk, regex_t *regex)
int error;
git_oid oid;
git_object *obj;
-
+
while (!(error = git_revwalk_next(&oid, walk))) {
error = git_object_lookup(&obj, git_revwalk_repository(walk), &oid, GIT_OBJ_COMMIT);
@@ -537,7 +537,7 @@ static int handle_grep_syntax(git_object **out, git_repository *repo, const git_
if ((error = build_regex(&preg, pattern)) < 0)
return error;
-
+
if ((error = git_revwalk_new(&walk, repo)) < 0)
goto cleanup;
@@ -551,7 +551,7 @@ static int handle_grep_syntax(git_object **out, git_repository *repo, const git_
goto cleanup;
error = walk_and_search(out, walk, &preg);
-
+
cleanup:
regfree(&preg);
git_revwalk_free(walk);
@@ -868,27 +868,49 @@ cleanup:
return error;
}
-int git_revparse_rangelike(git_object **left, git_object **right, int *threedots, git_repository *repo, const char *rangelike)
+
+int git_revparse(
+ git_object **left,
+ git_object **right,
+ unsigned int *flags,
+ git_repository *repo,
+ const char *spec)
{
+ unsigned int lflags = 0;
+ const char *dotdot;
int error = 0;
- const char *p, *q;
- char *revspec;
- p = strstr(rangelike, "..");
- if (!p) {
- giterr_set(GITERR_INVALID, "Malformed range (or rangelike syntax): %s", rangelike);
- return GIT_EINVALIDSPEC;
- } else if (p[2] == '.') {
- *threedots = 1;
- q = p + 3;
+ assert(left && repo && spec);
+
+ if ((dotdot = strstr(spec, "..")) != NULL) {
+ char *lstr;
+ const char *rstr;
+ lflags = GIT_REVPARSE_RANGE;
+
+ lstr = git__substrdup(spec, dotdot-spec);
+ rstr = dotdot + 2;
+ if (dotdot[2] == '.') {
+ lflags |= GIT_REVPARSE_MERGE_BASE;
+ rstr++;
+ }
+
+ if ((error = git_revparse_single(left, repo, lstr)) < 0) {
+ return error;
+ }
+ if (right &&
+ (error = git_revparse_single(right, repo, rstr)) < 0) {
+ return error;
+ }
+
+ git__free((void*)lstr);
} else {
- *threedots = 0;
- q = p + 2;
+ lflags = GIT_REVPARSE_SINGLE;
+ error = git_revparse_single(left, repo, spec);
}
- revspec = git__substrdup(rangelike, p - rangelike);
- error = (git_revparse_single(left, repo, revspec)
- || git_revparse_single(right, repo, q));
- git__free(revspec);
+ if (flags)
+ *flags = lflags;
+
return error;
}
+