#include "quote.h"
#include "upload-pack.h"
#include "serve.h"
+#include "commit-reach.h"
/* Remember to update object flag allocation in object.h */
#define THEY_HAVE (1u << 11)
#define OUR_REF (1u << 12)
#define WANTED (1u << 13)
#define COMMON_KNOWN (1u << 14)
-#define REACHABLE (1u << 15)
#define SHALLOW (1u << 16)
#define NOT_SHALLOW (1u << 17)
return 0;
}
-static int reachable(struct commit *from, unsigned int with_flag,
- unsigned int assign_flag)
-{
- struct prio_queue work = { compare_commits_by_commit_date };
-
- prio_queue_put(&work, from);
- while (work.nr) {
- struct commit_list *list;
- struct commit *commit = prio_queue_get(&work);
-
- if (commit->object.flags & with_flag) {
- from->object.flags |= assign_flag;
- break;
- }
- if (!commit->object.parsed)
- parse_object(the_repository, &commit->object.oid);
- if (commit->object.flags & REACHABLE)
- continue;
- commit->object.flags |= REACHABLE;
- if (commit->date < oldest_have)
- continue;
- for (list = commit->parents; list; list = list->next) {
- struct commit *parent = list->item;
- if (!(parent->object.flags & REACHABLE))
- prio_queue_put(&work, parent);
- }
- }
- from->object.flags |= REACHABLE;
- clear_commit_marks(from, REACHABLE);
- clear_prio_queue(&work);
- return (from->object.flags & assign_flag);
-}
-
-/*
- * Determine if every commit in 'from' can reach at least one commit
- * that is marked with 'with_flag'. As we traverse, use 'assign_flag'
- * as a marker for commits that are already visited.
- */
-static int can_all_from_reach_with_flag(struct object_array *from,
- unsigned int with_flag,
- unsigned int assign_flag)
-{
- int i;
-
- for (i = 0; i < from->nr; i++) {
- struct object *from_one = from->objects[i].item;
-
- if (from_one->flags & assign_flag)
- continue;
- from_one = deref_tag(the_repository, from_one, "a from object", 0);
- if (!from_one || from_one->type != OBJ_COMMIT) {
- /* no way to tell if this is reachable by
- * looking at the ancestry chain alone, so
- * leave a note to ourselves not to worry about
- * this object anymore.
- */
- from->objects[i].item->flags |= assign_flag;
- continue;
- }
- if (!reachable((struct commit *)from_one, with_flag, assign_flag))
- return 0;
- }
- return 1;
-}
-
static int ok_to_give_up(void)
{
if (!have_obj.nr)
return 0;
- return can_all_from_reach_with_flag(&want_obj, THEY_HAVE, COMMON_KNOWN);
+ return can_all_from_reach_with_flag(&want_obj, THEY_HAVE,
+ COMMON_KNOWN, oldest_have);
}
static int get_common_commits(void)