*/
GIT_EXTERN(int) git_revwalk_push_glob(git_revwalk *walk, const char *glob);
+/**
+ * Push the repository's HEAD
+ *
+ * @param walk the walker being used for the traversal
+ * @return GIT_SUCCESS or an error code
+ */
+GIT_EXTERN(int) git_revwalk_push_head(git_revwalk *walk);
+
/**
* Mark a commit (and its ancestors) uninteresting for the output.
*
*/
GIT_EXTERN(int) git_revwalk_hide_glob(git_revwalk *walk, const char *glob);
+/**
+ * Hide the repository's HEAD
+ *
+ * @param walk the walker being used for the traversal
+ * @return GIT_SUCCESS or an error code
+ */
+GIT_EXTERN(int) git_revwalk_hide_head(git_revwalk *walk);
+
/**
* Get the next commit from the revision walk.
*
return push_glob(walk, glob, 1);
}
+static int push_head(git_revwalk *walk, int hide)
+{
+ git_reference *ref, *resolved;
+ int error;
+
+ error = git_reference_lookup(&ref, walk->repo, "HEAD");
+ if (error < GIT_SUCCESS) {
+ return error;
+ }
+ error = git_reference_resolve(&resolved, ref);
+ if (error < GIT_SUCCESS) {
+ return error;
+ }
+ git_reference_free(ref);
+
+ error = push_commit(walk, git_reference_oid(resolved), hide);
+
+ git_reference_free(resolved);
+ return error;
+}
+
+int git_revwalk_push_head(git_revwalk *walk)
+{
+ assert(walk);
+ return push_head(walk, 0);
+}
+
+int git_revwalk_hide_head(git_revwalk *walk)
+{
+ assert(walk);
+ return push_head(walk, 1);
+}
+
static int revwalk_enqueue_timesort(git_revwalk *walk, commit_object *commit)
{
return git_pqueue_insert(&walk->iterator_time, commit);
/* git log --branches --oneline | wc -l => 13 */
cl_assert(i == 13);
}
+
+void test_revwalk_basic__push_head(void)
+{
+ int i = 0;
+ git_oid oid;
+
+ cl_git_pass(git_revwalk_push_head(_walk));
+
+ while (git_revwalk_next(&oid, _walk) == GIT_SUCCESS) {
+ i++;
+ }
+
+ /* git log HEAD --oneline | wc -l => 7 */
+ cl_assert(i == 7);
+}