diff options
author | Vicent Martà <vicent@github.com> | 2013-04-15 15:47:38 -0700 |
---|---|---|
committer | Vicent Martà <vicent@github.com> | 2013-04-15 15:47:38 -0700 |
commit | 24f61bc53a9843f86ce79bae92a38e0e4565734b (patch) | |
tree | 2cf068e5be081f7a0d1cfeeda948ac4eadead2c0 /src | |
parent | 54e05482348c3844c6002b3a96ab05264cf66993 (diff) | |
parent | 32ef1d1c7cc8c603ab78416262cc421b80a8c2df (diff) | |
download | libgit2-24f61bc53a9843f86ce79bae92a38e0e4565734b.tar.gz |
Merge pull request #1469 from libgit2/vmg/unified-revision
Unified rev-parse, with a revision object
Diffstat (limited to 'src')
-rw-r--r-- | src/push.c | 20 | ||||
-rw-r--r-- | src/revparse.c | 62 | ||||
-rw-r--r-- | src/revwalk.c | 19 |
3 files changed, 59 insertions, 42 deletions
diff --git a/src/push.c b/src/push.c index f81a0aee9..cec4c64af 100644 --- a/src/push.c +++ b/src/push.c @@ -99,19 +99,17 @@ static int check_lref(git_push *push, char *ref) /* lref must be resolvable to an existing object */ git_object *obj; int error = git_revparse_single(&obj, push->repo, ref); + git_object_free(obj); - if (error) { - if (error == GIT_ENOTFOUND) - giterr_set(GITERR_REFERENCE, - "src refspec '%s' does not match any existing object", ref); - else - giterr_set(GITERR_INVALID, "Not a valid reference '%s'", ref); + if (!error) + return 0; - return -1; - } else - git_object_free(obj); - - return 0; + if (error == GIT_ENOTFOUND) + giterr_set(GITERR_REFERENCE, + "src refspec '%s' does not match any existing object", ref); + else + giterr_set(GITERR_INVALID, "Not a valid reference '%s'", ref); + return -1; } static int parse_refspec(git_push *push, push_spec **spec, const char *str) diff --git a/src/revparse.c b/src/revparse.c index fd62a2fd2..74635ed04 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(®ex, ".+-[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,45 @@ 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_revspec *revspec, + git_repository *repo, + const char *spec) { + 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(revspec && repo && spec); + + memset(revspec, 0x0, sizeof(*revspec)); + + if ((dotdot = strstr(spec, "..")) != NULL) { + char *lstr; + const char *rstr; + revspec->flags = GIT_REVPARSE_RANGE; + + lstr = git__substrdup(spec, dotdot - spec); + rstr = dotdot + 2; + if (dotdot[2] == '.') { + revspec->flags |= GIT_REVPARSE_MERGE_BASE; + rstr++; + } + + if ((error = git_revparse_single(&revspec->from, repo, lstr)) < 0) { + return error; + } + + if ((error = git_revparse_single(&revspec->to, repo, rstr)) < 0) { + return error; + } + + git__free((void*)lstr); } else { - *threedots = 0; - q = p + 2; + revspec->flags = GIT_REVPARSE_SINGLE; + error = git_revparse_single(&revspec->from, repo, spec); } - revspec = git__substrdup(rangelike, p - rangelike); - error = (git_revparse_single(left, repo, revspec) - || git_revparse_single(right, repo, q)); - git__free(revspec); return error; } + diff --git a/src/revwalk.c b/src/revwalk.c index c1071843b..16f06624d 100644 --- a/src/revwalk.c +++ b/src/revwalk.c @@ -231,25 +231,26 @@ int git_revwalk_push_ref(git_revwalk *walk, const char *refname) int git_revwalk_push_range(git_revwalk *walk, const char *range) { - git_object *left, *right; - int threedots; + git_revspec revspec; int error = 0; - if ((error = git_revparse_rangelike(&left, &right, &threedots, walk->repo, range))) + if ((error = git_revparse(&revspec, walk->repo, range))) return error; - if (threedots) { + + if (revspec.flags & GIT_REVPARSE_MERGE_BASE) { /* TODO: support "<commit>...<commit>" */ giterr_set(GITERR_INVALID, "Symmetric differences not implemented in revwalk"); return GIT_EINVALIDSPEC; } - if ((error = push_commit(walk, git_object_id(left), 1))) + if ((error = push_commit(walk, git_object_id(revspec.from), 1))) goto out; - error = push_commit(walk, git_object_id(right), 0); - out: - git_object_free(left); - git_object_free(right); + error = push_commit(walk, git_object_id(revspec.to), 0); + +out: + git_object_free(revspec.from); + git_object_free(revspec.to); return error; } |