From: Derrick Stolee
Signed-off-by: Derrick Stolee
---
builtin/remote.c | 1 +
commit-reach.c | 54
commit-reach.h | 2 ++
http-push.c | 1 +
remote.c | 50 +---
remote.h | 1 -
6 files changed, 59 insertions(+), 50 deletions(-)
diff --git a/builtin/remote.c b/builtin/remote.c
index c74ee8869..79b032644 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -10,6 +10,7 @@
#include "refspec.h"
#include "object-store.h"
#include "argv-array.h"
+#include "commit-reach.h"
static const char * const builtin_remote_usage[] = {
N_("git remote [-v | --verbose]"),
diff --git a/commit-reach.c b/commit-reach.c
index f2e2f7461..a6bc4781a 100644
--- a/commit-reach.c
+++ b/commit-reach.c
@@ -1,5 +1,10 @@
#include "cache.h"
+#include "commit.h"
+#include "decorate.h"
#include "prio-queue.h"
+#include "tree.h"
+#include "revision.h"
+#include "tag.h"
#include "commit-reach.h"
/* Remember to update object flag allocation in object.h */
@@ -357,3 +362,52 @@ void reduce_heads_replace(struct commit_list **heads)
free_commit_list(*heads);
*heads = result;
}
+
+static void unmark_and_free(struct commit_list *list, unsigned int mark)
+{
+ while (list) {
+ struct commit *commit = pop_commit();
+ commit->object.flags &= ~mark;
+ }
+}
+
+int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid)
+{
+ struct object *o;
+ struct commit *old_commit, *new_commit;
+ struct commit_list *list, *used;
+ int found = 0;
+
+ /*
+* Both new_commit and old_commit must be commit-ish and new_commit is
descendant of
+* old_commit. Otherwise we require --force.
+*/
+ o = deref_tag(the_repository, parse_object(the_repository, old_oid),
+ NULL, 0);
+ if (!o || o->type != OBJ_COMMIT)
+ return 0;
+ old_commit = (struct commit *) o;
+
+ o = deref_tag(the_repository, parse_object(the_repository, new_oid),
+ NULL, 0);
+ if (!o || o->type != OBJ_COMMIT)
+ return 0;
+ new_commit = (struct commit *) o;
+
+ if (parse_commit(new_commit) < 0)
+ return 0;
+
+ used = list = NULL;
+ commit_list_insert(new_commit, );
+ while (list) {
+ new_commit = pop_most_recent_commit(, TMP_MARK);
+ commit_list_insert(new_commit, );
+ if (new_commit == old_commit) {
+ found = 1;
+ break;
+ }
+ }
+ unmark_and_free(list, TMP_MARK);
+ unmark_and_free(used, TMP_MARK);
+ return found;
+}
diff --git a/commit-reach.h b/commit-reach.h
index 244f48c5f..35ec9f0dd 100644
--- a/commit-reach.h
+++ b/commit-reach.h
@@ -38,4 +38,6 @@ struct commit_list *reduce_heads(struct commit_list *heads);
*/
void reduce_heads_replace(struct commit_list **heads);
+int ref_newer(const struct object_id *new_oid, const struct object_id
*old_oid);
+
#endif
diff --git a/http-push.c b/http-push.c
index 5eaf551b5..e007cb5a6 100644
--- a/http-push.c
+++ b/http-push.c
@@ -14,6 +14,7 @@
#include "argv-array.h"
#include "packfile.h"
#include "object-store.h"
+#include "commit-reach.h"
#ifdef EXPAT_NEEDS_XMLPARSE_H
diff --git a/remote.c b/remote.c
index 26b1fbd9a..f0c23bae4 100644
--- a/remote.c
+++ b/remote.c
@@ -12,6 +12,7 @@
#include "string-list.h"
#include "mergesort.h"
#include "argv-array.h"
+#include "commit-reach.h"
enum map_direction { FROM_SRC, FROM_DST };
@@ -1783,55 +1784,6 @@ int resolve_remote_symref(struct ref *ref, struct ref
*list)
return 1;
}
-static void unmark_and_free(struct commit_list *list, unsigned int mark)
-{
- while (list) {
- struct commit *commit = pop_commit();
- commit->object.flags &= ~mark;
- }
-}
-
-int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid)
-{
- struct object *o;
- struct commit *old_commit, *new_commit;
- struct commit_list *list, *used;
- int found = 0;
-
- /*
-* Both new_commit and old_commit must be commit-ish and new_commit is
descendant of
-* old_commit. Otherwise we require --force.
-*/
- o = deref_tag(the_repository, parse_object(the_repository, old_oid),
- NULL, 0);
- if (!o || o->type != OBJ_COMMIT)
- return 0;
- old_commit = (struct commit *) o;
-
- o = deref_tag(the_repository, parse_object(the_repository, new_oid),
- NULL, 0);
- if (!o || o->type != OBJ_COMMIT)
- return 0;
- new_commit = (struct commit *) o;
-
- if (parse_commit(new_commit) < 0)
- return 0;
-
- used = list = NULL;
- commit_list_insert(new_commit, );
- while (list)