mirror of
https://github.com/git/git
synced 2024-08-25 02:35:46 +00:00
Merge branch 'rs/pending'
* rs/pending: commit: factor out clear_commit_marks_for_object_array checkout: use leak_pending flag bundle: use leak_pending flag bisect: use leak_pending flag revision: add leak_pending flag checkout: use add_pending_{object,sha1} in orphan check revision: factor out add_pending_sha1 checkout: check for "Previous HEAD" notice in t2020 Conflicts: builtin/checkout.c revision.c
This commit is contained in:
commit
0941d60545
20
bisect.c
20
bisect.c
|
@ -800,25 +800,25 @@ static int check_ancestors(const char *prefix)
|
|||
{
|
||||
struct rev_info revs;
|
||||
struct object_array pending_copy;
|
||||
int i, res;
|
||||
int res;
|
||||
|
||||
bisect_rev_setup(&revs, prefix, "^%s", "%s", 0);
|
||||
|
||||
/* Save pending objects, so they can be cleaned up later. */
|
||||
memset(&pending_copy, 0, sizeof(pending_copy));
|
||||
for (i = 0; i < revs.pending.nr; i++)
|
||||
add_object_array(revs.pending.objects[i].item,
|
||||
revs.pending.objects[i].name,
|
||||
&pending_copy);
|
||||
pending_copy = revs.pending;
|
||||
revs.leak_pending = 1;
|
||||
|
||||
/*
|
||||
* bisect_common calls prepare_revision_walk right away, which
|
||||
* (together with .leak_pending = 1) makes us the sole owner of
|
||||
* the list of pending objects.
|
||||
*/
|
||||
bisect_common(&revs);
|
||||
res = (revs.commits != NULL);
|
||||
|
||||
/* Clean up objects used, as they will be reused. */
|
||||
for (i = 0; i < pending_copy.nr; i++) {
|
||||
struct object *o = pending_copy.objects[i].item;
|
||||
clear_commit_marks((struct commit *)o, ALL_REV_FLAGS);
|
||||
}
|
||||
clear_commit_marks_for_object_array(&pending_copy, ALL_REV_FLAGS);
|
||||
free(pending_copy.objects);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -589,23 +589,11 @@ static void update_refs_for_switch(struct checkout_opts *opts,
|
|||
report_tracking(new);
|
||||
}
|
||||
|
||||
static int add_one_ref_to_rev_list_arg(const char *refname,
|
||||
static int add_pending_uninteresting_ref(const char *refname,
|
||||
const unsigned char *sha1,
|
||||
int flags,
|
||||
void *cb_data)
|
||||
int flags, void *cb_data)
|
||||
{
|
||||
argv_array_push(cb_data, refname);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int clear_commit_marks_from_one_ref(const char *refname,
|
||||
const unsigned char *sha1,
|
||||
int flags,
|
||||
void *cb_data)
|
||||
{
|
||||
struct commit *commit = lookup_commit_reference_gently(sha1, 1);
|
||||
if (commit)
|
||||
clear_commit_marks(commit, -1);
|
||||
add_pending_sha1(cb_data, refname, sha1, flags | UNINTERESTING);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -674,18 +662,21 @@ static void suggest_reattach(struct commit *commit, struct rev_info *revs)
|
|||
*/
|
||||
static void orphaned_commit_warning(struct commit *commit)
|
||||
{
|
||||
struct argv_array args = ARGV_ARRAY_INIT;
|
||||
struct rev_info revs;
|
||||
|
||||
argv_array_push(&args, "(internal)");
|
||||
argv_array_push(&args, sha1_to_hex(commit->object.sha1));
|
||||
argv_array_push(&args, "--not");
|
||||
for_each_ref(add_one_ref_to_rev_list_arg, &args);
|
||||
argv_array_push(&args, "--");
|
||||
struct object *object = &commit->object;
|
||||
struct object_array refs;
|
||||
|
||||
init_revisions(&revs, NULL);
|
||||
if (setup_revisions(args.argc - 1, args.argv, &revs, NULL) != 1)
|
||||
die(_("internal error: only -- alone should have been left"));
|
||||
setup_revisions(0, NULL, &revs, NULL);
|
||||
|
||||
object->flags &= ~UNINTERESTING;
|
||||
add_pending_object(&revs, object, sha1_to_hex(object->sha1));
|
||||
|
||||
for_each_ref(add_pending_uninteresting_ref, &revs);
|
||||
|
||||
refs = revs.pending;
|
||||
revs.leak_pending = 1;
|
||||
|
||||
if (prepare_revision_walk(&revs))
|
||||
die(_("internal error in revision walk"));
|
||||
if (!(commit->object.flags & UNINTERESTING))
|
||||
|
@ -693,9 +684,8 @@ static void orphaned_commit_warning(struct commit *commit)
|
|||
else
|
||||
describe_detached_head(_("Previous HEAD position was"), commit);
|
||||
|
||||
argv_array_clear(&args);
|
||||
clear_commit_marks(commit, -1);
|
||||
for_each_ref(clear_commit_marks_from_one_ref, NULL);
|
||||
clear_commit_marks_for_object_array(&refs, ALL_REV_FLAGS);
|
||||
free(refs.objects);
|
||||
}
|
||||
|
||||
static int switch_branches(struct checkout_opts *opts, struct branch_info *new)
|
||||
|
|
11
bundle.c
11
bundle.c
|
@ -122,11 +122,8 @@ int verify_bundle(struct bundle_header *header, int verbose)
|
|||
req_nr = revs.pending.nr;
|
||||
setup_revisions(2, argv, &revs, NULL);
|
||||
|
||||
memset(&refs, 0, sizeof(struct object_array));
|
||||
for (i = 0; i < revs.pending.nr; i++) {
|
||||
struct object_array_entry *e = revs.pending.objects + i;
|
||||
add_object_array(e->item, e->name, &refs);
|
||||
}
|
||||
refs = revs.pending;
|
||||
revs.leak_pending = 1;
|
||||
|
||||
if (prepare_revision_walk(&revs))
|
||||
die("revision walk setup failed");
|
||||
|
@ -144,8 +141,8 @@ int verify_bundle(struct bundle_header *header, int verbose)
|
|||
refs.objects[i].name);
|
||||
}
|
||||
|
||||
for (i = 0; i < refs.nr; i++)
|
||||
clear_commit_marks((struct commit *)refs.objects[i].item, -1);
|
||||
clear_commit_marks_for_object_array(&refs, ALL_REV_FLAGS);
|
||||
free(refs.objects);
|
||||
|
||||
if (verbose) {
|
||||
struct ref_list *r;
|
||||
|
|
14
commit.c
14
commit.c
|
@ -442,6 +442,20 @@ void clear_commit_marks(struct commit *commit, unsigned int mark)
|
|||
}
|
||||
}
|
||||
|
||||
void clear_commit_marks_for_object_array(struct object_array *a, unsigned mark)
|
||||
{
|
||||
struct object *object;
|
||||
struct commit *commit;
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < a->nr; i++) {
|
||||
object = a->objects[i].item;
|
||||
commit = lookup_commit_reference_gently(object->sha1, 1);
|
||||
if (commit)
|
||||
clear_commit_marks(commit, mark);
|
||||
}
|
||||
}
|
||||
|
||||
struct commit *pop_commit(struct commit_list **stack)
|
||||
{
|
||||
struct commit_list *top = *stack;
|
||||
|
|
1
commit.h
1
commit.h
|
@ -133,6 +133,7 @@ struct commit *pop_most_recent_commit(struct commit_list **list,
|
|||
struct commit *pop_commit(struct commit_list **stack);
|
||||
|
||||
void clear_commit_marks(struct commit *commit, unsigned int mark);
|
||||
void clear_commit_marks_for_object_array(struct object_array *a, unsigned mark);
|
||||
|
||||
/*
|
||||
* Performs an in-place topological sort of list supplied.
|
||||
|
|
10
revision.c
10
revision.c
|
@ -226,6 +226,13 @@ static struct object *get_reference(struct rev_info *revs, const char *name, con
|
|||
return object;
|
||||
}
|
||||
|
||||
void add_pending_sha1(struct rev_info *revs, const char *name,
|
||||
const unsigned char *sha1, unsigned int flags)
|
||||
{
|
||||
struct object *object = get_reference(revs, name, sha1, flags);
|
||||
add_pending_object(revs, object, name);
|
||||
}
|
||||
|
||||
static struct commit *handle_commit(struct rev_info *revs, struct object *object, const char *name)
|
||||
{
|
||||
unsigned long flags = object->flags;
|
||||
|
@ -897,7 +904,7 @@ static int handle_one_ref(const char *path, const unsigned char *sha1, int flag,
|
|||
struct object *object = get_reference(cb->all_revs, path, sha1,
|
||||
cb->all_flags);
|
||||
add_rev_cmdline(cb->all_revs, object, path, REV_CMD_REF, cb->all_flags);
|
||||
add_pending_object(cb->all_revs, object, path);
|
||||
add_pending_sha1(cb->all_revs, path, sha1, cb->all_flags);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -2050,6 +2057,7 @@ int prepare_revision_walk(struct rev_info *revs)
|
|||
}
|
||||
e++;
|
||||
}
|
||||
if (!revs->leak_pending)
|
||||
free(list);
|
||||
|
||||
if (revs->no_walk)
|
||||
|
|
|
@ -118,6 +118,7 @@ struct rev_info {
|
|||
date_mode_explicit:1,
|
||||
preserve_subject:1;
|
||||
unsigned int disable_stdin:1;
|
||||
unsigned int leak_pending:1;
|
||||
|
||||
enum date_mode date_mode;
|
||||
|
||||
|
@ -214,6 +215,7 @@ extern void add_object(struct object *obj,
|
|||
const char *name);
|
||||
|
||||
extern void add_pending_object(struct rev_info *revs, struct object *obj, const char *name);
|
||||
extern void add_pending_sha1(struct rev_info *revs, const char *name, const unsigned char *sha1, unsigned int flags);
|
||||
|
||||
extern void add_head_to_pending(struct rev_info *);
|
||||
|
||||
|
|
|
@ -12,11 +12,14 @@ check_not_detached () {
|
|||
}
|
||||
|
||||
ORPHAN_WARNING='you are leaving .* commit.*behind'
|
||||
PREV_HEAD_DESC='Previous HEAD position was'
|
||||
check_orphan_warning() {
|
||||
test_i18ngrep "$ORPHAN_WARNING" "$1"
|
||||
test_i18ngrep "$ORPHAN_WARNING" "$1" &&
|
||||
test_i18ngrep ! "$PREV_HEAD_DESC" "$1"
|
||||
}
|
||||
check_no_orphan_warning() {
|
||||
test_i18ngrep ! "$ORPHAN_WARNING" "$1"
|
||||
test_i18ngrep ! "$ORPHAN_WARNING" "$1" &&
|
||||
test_i18ngrep "$PREV_HEAD_DESC" "$1"
|
||||
}
|
||||
|
||||
reset () {
|
||||
|
|
Loading…
Reference in a new issue