Commit 53f51c60afd3c2e4640de622ce274b70b6c1346a

Etienne Samson 2019-08-21T19:48:05

smart: implement by-date insertion when revwalking

diff --git a/src/revwalk.c b/src/revwalk.c
index 38f4083..6f49bf2 100644
--- a/src/revwalk.c
+++ b/src/revwalk.c
@@ -83,7 +83,9 @@ int git_revwalk__push_commit(git_revwalk *walk, const git_oid *oid, const git_re
 
 	commit->uninteresting = opts->uninteresting;
 	list = walk->user_input;
-	if (git_commit_list_insert(commit, &list) == NULL) {
+	if ((opts->insert_by_date &&
+	    git_commit_list_insert_by_date(commit, &list) == NULL) ||
+	    git_commit_list_insert(commit, &list) == NULL) {
 		git_error_set_oom();
 		return -1;
 	}
diff --git a/src/revwalk.h b/src/revwalk.h
index 852ab8b..94b8a6f 100644
--- a/src/revwalk.h
+++ b/src/revwalk.h
@@ -53,6 +53,7 @@ git_commit_list_node *git_revwalk__commit_lookup(git_revwalk *walk, const git_oi
 typedef struct {
 	int uninteresting;
 	int from_glob;
+	int insert_by_date;
 } git_revwalk__push_options;
 
 #define GIT_REVWALK__PUSH_OPTIONS_INIT { 0 }
diff --git a/src/transports/smart_protocol.c b/src/transports/smart_protocol.c
index 1a8ede5..87400bb 100644
--- a/src/transports/smart_protocol.c
+++ b/src/transports/smart_protocol.c
@@ -17,6 +17,7 @@
 #include "pack-objects.h"
 #include "remote.h"
 #include "util.h"
+#include "revwalk.h"
 
 #define NETWORK_XFER_THRESHOLD (100*1024)
 /* The minimal interval between progress updates (in seconds). */
@@ -303,6 +304,7 @@ static int wait_while_ack(gitno_buffer *buf)
 int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, const git_remote_head * const *wants, size_t count)
 {
 	transport_smart *t = (transport_smart *)transport;
+	git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT;
 	gitno_buffer *buf = &t->buffer;
 	git_buf data = GIT_BUF_INIT;
 	git_revwalk *walk = NULL;
@@ -317,7 +319,8 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
 	if ((error = git_revwalk_new(&walk, repo)) < 0)
 		goto on_error;
 
-	if ((error = git_revwalk_push_glob(walk, "refs/*")) < 0)
+	opts.insert_by_date = 1;
+	if ((error = git_revwalk__push_glob(walk, "refs/*", &opts)) < 0)
 		goto on_error;
 
 	/*