All the hard work is already in revparse.
Signed-off-by: Greg Price <price@mit.edu>
*/
GIT_EXTERN(void) git_revwalk_sorting(git_revwalk *walk, unsigned int sort_mode);
+/**
+ * Push and hide the respective endpoints of the given range.
+ *
+ * The range should be of the form
+ * <commit>..<commit>
+ * where each <commit> is in the form accepted by 'git_revparse_single'.
+ * The left-hand commit will be hidden and the right-hand commit pushed.
+ *
+ * @param walk the walker being used for the traversal
+ * @param range the range
+ * @return 0 or an error code
+ *
+ */
+GIT_EXTERN(int) git_revwalk_push_range(git_revwalk *walk, const char *range);
+
/**
* Free a revision walker previously allocated.
*
#include "pool.h"
#include "revwalk.h"
+#include "git2/revparse.h"
#include "merge.h"
#include <regex.h>
return push_ref(walk, refname, 0);
}
+int git_revwalk_push_range(git_revwalk *walk, const char *range)
+{
+ git_object *left, *right;
+ int threedots;
+ int error = 0;
+
+ if ((error = git_revparse_rangelike(&left, &right, &threedots, walk->repo, range)))
+ return error;
+ if (threedots) {
+ /* 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)))
+ goto out;
+ error = push_commit(walk, git_object_id(right), 0);
+
+ out:
+ git_object_free(left);
+ git_object_free(right);
+ return error;
+}
+
int git_revwalk_hide_ref(git_revwalk *walk, const char *refname)
{
assert(walk && refname);
{4, 5, 2, 1, 3, 0}
};
+static const int commit_sorting_segment[][6] = {
+ {1, 2, -1, -1, -1, -1}
+};
+
#define commit_count 6
static const int result_bytes = 24;
cl_git_pass(git_oid_fromstr(&oid, "521d87c1ec3aef9824daf6d96cc0ae3710766d91"));
cl_git_fail(git_revwalk_push(_walk, &oid));
}
+
+void test_revwalk_basic__push_range(void)
+{
+ git_revwalk_reset(_walk);
+ git_revwalk_sorting(_walk, 0);
+ cl_git_pass(git_revwalk_push_range(_walk, "9fd738e~2..9fd738e"));
+ cl_git_pass(test_walk_only(_walk, commit_sorting_segment, 1));
+}