зеркало из https://github.com/microsoft/git.git
revisions API users: use release_revisions() needing REV_INFO_INIT
Use release_revisions() to various users of "struct rev_list" which need to have their "struct rev_info" zero-initialized before we can start using it. For the bundle.c code see the early exit case added in3bbbe467f2
(bundle verify: error out if called without an object database, 2019-05-27). For the relevant bisect.c code see45b6370812
(bisect: libify `check_good_are_ancestors_of_bad` and its dependents, 2020-02-17). For the submodule.c code see the "goto" on "(!left || !right || !sub)" added in8e6df65015
(submodule: refactor show_submodule_summary with helper function, 2016-08-31). Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
296a143845
Коммит
f196c1e908
18
bisect.c
18
bisect.c
|
@ -1010,7 +1010,7 @@ void read_bisect_terms(const char **read_bad, const char **read_good)
|
||||||
*/
|
*/
|
||||||
enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
|
enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
|
||||||
{
|
{
|
||||||
struct rev_info revs;
|
struct rev_info revs = REV_INFO_INIT;
|
||||||
struct commit_list *tried;
|
struct commit_list *tried;
|
||||||
int reaches = 0, all = 0, nr, steps;
|
int reaches = 0, all = 0, nr, steps;
|
||||||
enum bisect_error res = BISECT_OK;
|
enum bisect_error res = BISECT_OK;
|
||||||
|
@ -1035,7 +1035,7 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
|
||||||
|
|
||||||
res = check_good_are_ancestors_of_bad(r, prefix, no_checkout);
|
res = check_good_are_ancestors_of_bad(r, prefix, no_checkout);
|
||||||
if (res)
|
if (res)
|
||||||
return res;
|
goto cleanup;
|
||||||
|
|
||||||
bisect_rev_setup(r, &revs, prefix, "%s", "^%s", 1);
|
bisect_rev_setup(r, &revs, prefix, "%s", "^%s", 1);
|
||||||
|
|
||||||
|
@ -1060,14 +1060,16 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
|
||||||
term_good,
|
term_good,
|
||||||
term_bad);
|
term_bad);
|
||||||
|
|
||||||
return BISECT_FAILED;
|
res = BISECT_FAILED;
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!all) {
|
if (!all) {
|
||||||
fprintf(stderr, _("No testable commit found.\n"
|
fprintf(stderr, _("No testable commit found.\n"
|
||||||
"Maybe you started with bad path arguments?\n"));
|
"Maybe you started with bad path arguments?\n"));
|
||||||
|
|
||||||
return BISECT_NO_TESTABLE_COMMIT;
|
res = BISECT_NO_TESTABLE_COMMIT;
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
bisect_rev = &revs.commits->item->object.oid;
|
bisect_rev = &revs.commits->item->object.oid;
|
||||||
|
@ -1087,7 +1089,8 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
|
||||||
* for negative return values for early returns up
|
* for negative return values for early returns up
|
||||||
* until the cmd_bisect__helper() caller.
|
* until the cmd_bisect__helper() caller.
|
||||||
*/
|
*/
|
||||||
return BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND;
|
res = BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND;
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
nr = all - reaches - 1;
|
nr = all - reaches - 1;
|
||||||
|
@ -1106,7 +1109,10 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
|
||||||
/* Clean up objects used, as they will be reused. */
|
/* Clean up objects used, as they will be reused. */
|
||||||
repo_clear_commit_marks(r, ALL_REV_FLAGS);
|
repo_clear_commit_marks(r, ALL_REV_FLAGS);
|
||||||
|
|
||||||
return bisect_checkout(bisect_rev, no_checkout);
|
res = bisect_checkout(bisect_rev, no_checkout);
|
||||||
|
cleanup:
|
||||||
|
release_revisions(&revs);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int log2i(int n)
|
static inline int log2i(int n)
|
||||||
|
|
|
@ -766,7 +766,7 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
|
||||||
{
|
{
|
||||||
char *displaypath;
|
char *displaypath;
|
||||||
struct strvec diff_files_args = STRVEC_INIT;
|
struct strvec diff_files_args = STRVEC_INIT;
|
||||||
struct rev_info rev;
|
struct rev_info rev = REV_INFO_INIT;
|
||||||
int diff_files_result;
|
int diff_files_result;
|
||||||
struct strbuf buf = STRBUF_INIT;
|
struct strbuf buf = STRBUF_INIT;
|
||||||
const char *git_dir;
|
const char *git_dir;
|
||||||
|
@ -853,6 +853,7 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
|
||||||
cleanup:
|
cleanup:
|
||||||
strvec_clear(&diff_files_args);
|
strvec_clear(&diff_files_args);
|
||||||
free(displaypath);
|
free(displaypath);
|
||||||
|
release_revisions(&rev);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void status_submodule_cb(const struct cache_entry *list_item,
|
static void status_submodule_cb(const struct cache_entry *list_item,
|
||||||
|
|
12
bundle.c
12
bundle.c
|
@ -196,14 +196,16 @@ int verify_bundle(struct repository *r,
|
||||||
* to be verbose about the errors
|
* to be verbose about the errors
|
||||||
*/
|
*/
|
||||||
struct string_list *p = &header->prerequisites;
|
struct string_list *p = &header->prerequisites;
|
||||||
struct rev_info revs;
|
struct rev_info revs = REV_INFO_INIT;
|
||||||
const char *argv[] = {NULL, "--all", NULL};
|
const char *argv[] = {NULL, "--all", NULL};
|
||||||
struct commit *commit;
|
struct commit *commit;
|
||||||
int i, ret = 0, req_nr;
|
int i, ret = 0, req_nr;
|
||||||
const char *message = _("Repository lacks these prerequisite commits:");
|
const char *message = _("Repository lacks these prerequisite commits:");
|
||||||
|
|
||||||
if (!r || !r->objects || !r->objects->odb)
|
if (!r || !r->objects || !r->objects->odb) {
|
||||||
return error(_("need a repository to verify a bundle"));
|
ret = error(_("need a repository to verify a bundle"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
repo_init_revisions(r, &revs, NULL);
|
repo_init_revisions(r, &revs, NULL);
|
||||||
for (i = 0; i < p->nr; i++) {
|
for (i = 0; i < p->nr; i++) {
|
||||||
|
@ -221,7 +223,7 @@ int verify_bundle(struct repository *r,
|
||||||
error("%s %s", oid_to_hex(oid), name);
|
error("%s %s", oid_to_hex(oid), name);
|
||||||
}
|
}
|
||||||
if (revs.pending.nr != p->nr)
|
if (revs.pending.nr != p->nr)
|
||||||
return ret;
|
goto cleanup;
|
||||||
req_nr = revs.pending.nr;
|
req_nr = revs.pending.nr;
|
||||||
setup_revisions(2, argv, &revs, NULL);
|
setup_revisions(2, argv, &revs, NULL);
|
||||||
|
|
||||||
|
@ -284,6 +286,8 @@ int verify_bundle(struct repository *r,
|
||||||
printf_ln("The bundle uses this filter: %s",
|
printf_ln("The bundle uses this filter: %s",
|
||||||
list_objects_filter_spec(&header->filter));
|
list_objects_filter_spec(&header->filter));
|
||||||
}
|
}
|
||||||
|
cleanup:
|
||||||
|
release_revisions(&revs);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
21
revision.h
21
revision.h
|
@ -329,6 +329,25 @@ struct rev_info {
|
||||||
struct tmp_objdir *remerge_objdir;
|
struct tmp_objdir *remerge_objdir;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the "struct rev_info" structure with a macro.
|
||||||
|
*
|
||||||
|
* This will not fully initialize a "struct rev_info", the
|
||||||
|
* repo_init_revisions() function needs to be called before
|
||||||
|
* setup_revisions() and any revision walking takes place.
|
||||||
|
*
|
||||||
|
* Use REV_INFO_INIT to make the "struct rev_info" safe for passing to
|
||||||
|
* release_revisions() when it's inconvenient (e.g. due to a "goto
|
||||||
|
* cleanup" pattern) to arrange for repo_init_revisions() to be called
|
||||||
|
* before release_revisions() is called.
|
||||||
|
*
|
||||||
|
* Initializing with this REV_INFO_INIT is redundant to invoking
|
||||||
|
* repo_init_revisions(). If repo_init_revisions() is guaranteed to be
|
||||||
|
* called before release_revisions() the "struct rev_info" can be left
|
||||||
|
* uninitialized.
|
||||||
|
*/
|
||||||
|
#define REV_INFO_INIT { 0 }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize a rev_info structure with default values. The third parameter may
|
* Initialize a rev_info structure with default values. The third parameter may
|
||||||
* be NULL or can be prefix path, and then the `.prefix` variable will be set
|
* be NULL or can be prefix path, and then the `.prefix` variable will be set
|
||||||
|
@ -363,7 +382,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Free data allocated in a "struct rev_info" after it's been
|
* Free data allocated in a "struct rev_info" after it's been
|
||||||
* initialized with repo_init_revisions().
|
* initialized with repo_init_revisions() or REV_INFO_INIT.
|
||||||
*/
|
*/
|
||||||
void release_revisions(struct rev_info *revs);
|
void release_revisions(struct rev_info *revs);
|
||||||
|
|
||||||
|
|
|
@ -638,7 +638,7 @@ void show_submodule_diff_summary(struct diff_options *o, const char *path,
|
||||||
struct object_id *one, struct object_id *two,
|
struct object_id *one, struct object_id *two,
|
||||||
unsigned dirty_submodule)
|
unsigned dirty_submodule)
|
||||||
{
|
{
|
||||||
struct rev_info rev;
|
struct rev_info rev = REV_INFO_INIT;
|
||||||
struct commit *left = NULL, *right = NULL;
|
struct commit *left = NULL, *right = NULL;
|
||||||
struct commit_list *merge_bases = NULL;
|
struct commit_list *merge_bases = NULL;
|
||||||
struct repository *sub;
|
struct repository *sub;
|
||||||
|
@ -665,6 +665,7 @@ void show_submodule_diff_summary(struct diff_options *o, const char *path,
|
||||||
|
|
||||||
out:
|
out:
|
||||||
free_commit_list(merge_bases);
|
free_commit_list(merge_bases);
|
||||||
|
release_revisions(&rev);
|
||||||
clear_commit_marks(left, ~0);
|
clear_commit_marks(left, ~0);
|
||||||
clear_commit_marks(right, ~0);
|
clear_commit_marks(right, ~0);
|
||||||
if (sub) {
|
if (sub) {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче