Skip to content

Commit f6c075a

Browse files
committed
Merge branch 'jk/ref-paranoia'
The ref iteration code used to optionally allow dangling refs to be shown, which has been tightened up. * jk/ref-paranoia: refs: drop "broken" flag from for_each_fullref_in() ref-filter: drop broken-ref code entirely ref-filter: stop setting FILTER_REFS_INCLUDE_BROKEN repack, prune: drop GIT_REF_PARANOIA settings refs: turn on GIT_REF_PARANOIA by default refs: omit dangling symrefs when using GIT_REF_PARANOIA refs: add DO_FOR_EACH_OMIT_DANGLING_SYMREFS flag refs-internal.h: reorganize DO_FOR_EACH_* flag documentation refs-internal.h: move DO_FOR_EACH_* flags next to each other t5312: be more assertive about command failure t5312: test non-destructive repack t5312: create bogus ref as necessary t5312: drop "verbose" helper t5600: provide detached HEAD for corruption failures t5516: don't use HEAD ref for invalid ref-deletion tests t7900: clean up some more broken refs
2 parents 97492aa + 67985e4 commit f6c075a

21 files changed

+142
-116
lines changed

Documentation/git.txt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -867,15 +867,16 @@ for full details.
867867
end user, to be recorded in the body of the reflog.
868868

869869
`GIT_REF_PARANOIA`::
870-
If set to `1`, include broken or badly named refs when iterating
871-
over lists of refs. In a normal, non-corrupted repository, this
872-
does nothing. However, enabling it may help git to detect and
873-
abort some operations in the presence of broken refs. Git sets
874-
this variable automatically when performing destructive
875-
operations like linkgit:git-prune[1]. You should not need to set
876-
it yourself unless you want to be paranoid about making sure
877-
an operation has touched every ref (e.g., because you are
878-
cloning a repository to make a backup).
870+
If set to `0`, ignore broken or badly named refs when iterating
871+
over lists of refs. Normally Git will try to include any such
872+
refs, which may cause some operations to fail. This is usually
873+
preferable, as potentially destructive operations (e.g.,
874+
linkgit:git-prune[1]) are better off aborting rather than
875+
ignoring broken refs (and thus considering the history they
876+
point to as not worth saving). The default value is `1` (i.e.,
877+
be paranoid about detecting and aborting all operations). You
878+
should not normally need to set this to `0`, but it may be
879+
useful when trying to salvage data from a corrupted repository.
879880

880881
`GIT_ALLOW_PROTOCOL`::
881882
If set to a colon-separated list of protocols, behave as if

builtin/branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sortin
427427

428428
memset(&array, 0, sizeof(array));
429429

430-
filter_refs(&array, filter, filter->kind | FILTER_REFS_INCLUDE_BROKEN);
430+
filter_refs(&array, filter, filter->kind);
431431

432432
if (filter->verbose)
433433
maxwidth = calc_maxwidth(&array, strlen(remote_prefix));

builtin/for-each-ref.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
7777

7878
filter.name_patterns = argv;
7979
filter.match_as_path = 1;
80-
filter_refs(&array, &filter, FILTER_REFS_ALL | FILTER_REFS_INCLUDE_BROKEN);
80+
filter_refs(&array, &filter, FILTER_REFS_ALL);
8181
ref_array_sort(sorting, &array);
8282

8383
if (!maxcount || array.nr < maxcount)

builtin/prune.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
143143
expire = TIME_MAX;
144144
save_commit_buffer = 0;
145145
read_replace_refs = 0;
146-
ref_paranoia = 1;
147146
repo_init_revisions(the_repository, &revs, prefix);
148147

149148
argc = parse_options(argc, argv, prefix, options, prune_usage, 0);

builtin/repack.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -586,15 +586,12 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
586586
strvec_pushf(&cmd.args,
587587
"--unpack-unreachable=%s",
588588
unpack_unreachable);
589-
strvec_push(&cmd.env_array, "GIT_REF_PARANOIA=1");
590589
} else if (pack_everything & LOOSEN_UNREACHABLE) {
591590
strvec_push(&cmd.args,
592591
"--unpack-unreachable");
593592
} else if (keep_unreachable) {
594593
strvec_push(&cmd.args, "--keep-unreachable");
595594
strvec_push(&cmd.args, "--pack-loose-unreachable");
596-
} else {
597-
strvec_push(&cmd.env_array, "GIT_REF_PARANOIA=1");
598595
}
599596
}
600597
} else if (geometry) {

builtin/rev-parse.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -863,8 +863,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
863863
continue;
864864
}
865865
if (!strcmp(arg, "--bisect")) {
866-
for_each_fullref_in("refs/bisect/bad", show_reference, NULL, 0);
867-
for_each_fullref_in("refs/bisect/good", anti_reference, NULL, 0);
866+
for_each_fullref_in("refs/bisect/bad", show_reference, NULL);
867+
for_each_fullref_in("refs/bisect/good", anti_reference, NULL);
868868
continue;
869869
}
870870
if (opt_with_value(arg, "--branches", &arg)) {

cache.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -994,14 +994,6 @@ extern const char *core_fsmonitor;
994994
extern int core_apply_sparse_checkout;
995995
extern int core_sparse_checkout_cone;
996996

997-
/*
998-
* Include broken refs in all ref iterations, which will
999-
* generally choke dangerous operations rather than letting
1000-
* them silently proceed without taking the broken ref into
1001-
* account.
1002-
*/
1003-
extern int ref_paranoia;
1004-
1005997
/*
1006998
* Returns the boolean value of $GIT_OPTIONAL_LOCKS (or the default value).
1007999
*/

environment.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ int prefer_symlink_refs;
3131
int is_bare_repository_cfg = -1; /* unspecified */
3232
int warn_ambiguous_refs = 1;
3333
int warn_on_object_refname_ambiguity = 1;
34-
int ref_paranoia = -1;
3534
int repository_format_precious_objects;
3635
int repository_format_worktree_config;
3736
const char *git_commit_encoding;

ls-refs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ int ls_refs(struct repository *r, struct packet_reader *request)
189189
if (!data.prefixes.nr)
190190
strvec_push(&data.prefixes, "");
191191
for_each_fullref_in_prefixes(get_git_namespace(), data.prefixes.v,
192-
send_ref, &data, 0);
192+
send_ref, &data);
193193
packet_fflush(stdout);
194194
strvec_clear(&data.prefixes);
195195
strbuf_release(&data.buf);

ref-filter.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2100,16 +2100,15 @@ static int filter_pattern_match(struct ref_filter *filter, const char *refname)
21002100
*/
21012101
static int for_each_fullref_in_pattern(struct ref_filter *filter,
21022102
each_ref_fn cb,
2103-
void *cb_data,
2104-
int broken)
2103+
void *cb_data)
21052104
{
21062105
if (!filter->match_as_path) {
21072106
/*
21082107
* in this case, the patterns are applied after
21092108
* prefixes like "refs/heads/" etc. are stripped off,
21102109
* so we have to look at everything:
21112110
*/
2112-
return for_each_fullref_in("", cb, cb_data, broken);
2111+
return for_each_fullref_in("", cb, cb_data);
21132112
}
21142113

21152114
if (filter->ignore_case) {
@@ -2118,16 +2117,16 @@ static int for_each_fullref_in_pattern(struct ref_filter *filter,
21182117
* so just return everything and let the caller
21192118
* sort it out.
21202119
*/
2121-
return for_each_fullref_in("", cb, cb_data, broken);
2120+
return for_each_fullref_in("", cb, cb_data);
21222121
}
21232122

21242123
if (!filter->name_patterns[0]) {
21252124
/* no patterns; we have to look at everything */
2126-
return for_each_fullref_in("", cb, cb_data, broken);
2125+
return for_each_fullref_in("", cb, cb_data);
21272126
}
21282127

21292128
return for_each_fullref_in_prefixes(NULL, filter->name_patterns,
2130-
cb, cb_data, broken);
2129+
cb, cb_data);
21312130
}
21322131

21332132
/*
@@ -2405,13 +2404,10 @@ int filter_refs(struct ref_array *array, struct ref_filter *filter, unsigned int
24052404
{
24062405
struct ref_filter_cbdata ref_cbdata;
24072406
int ret = 0;
2408-
unsigned int broken = 0;
24092407

24102408
ref_cbdata.array = array;
24112409
ref_cbdata.filter = filter;
24122410

2413-
if (type & FILTER_REFS_INCLUDE_BROKEN)
2414-
broken = 1;
24152411
filter->kind = type & FILTER_REFS_KIND_MASK;
24162412

24172413
init_contains_cache(&ref_cbdata.contains_cache);
@@ -2428,13 +2424,13 @@ int filter_refs(struct ref_array *array, struct ref_filter *filter, unsigned int
24282424
* of filter_ref_kind().
24292425
*/
24302426
if (filter->kind == FILTER_REFS_BRANCHES)
2431-
ret = for_each_fullref_in("refs/heads/", ref_filter_handler, &ref_cbdata, broken);
2427+
ret = for_each_fullref_in("refs/heads/", ref_filter_handler, &ref_cbdata);
24322428
else if (filter->kind == FILTER_REFS_REMOTES)
2433-
ret = for_each_fullref_in("refs/remotes/", ref_filter_handler, &ref_cbdata, broken);
2429+
ret = for_each_fullref_in("refs/remotes/", ref_filter_handler, &ref_cbdata);
24342430
else if (filter->kind == FILTER_REFS_TAGS)
2435-
ret = for_each_fullref_in("refs/tags/", ref_filter_handler, &ref_cbdata, broken);
2431+
ret = for_each_fullref_in("refs/tags/", ref_filter_handler, &ref_cbdata);
24362432
else if (filter->kind & FILTER_REFS_ALL)
2437-
ret = for_each_fullref_in_pattern(filter, ref_filter_handler, &ref_cbdata, broken);
2433+
ret = for_each_fullref_in_pattern(filter, ref_filter_handler, &ref_cbdata);
24382434
if (!ret && (filter->kind & FILTER_REFS_DETACHED_HEAD))
24392435
head_ref(ref_filter_handler, &ref_cbdata);
24402436
}

0 commit comments

Comments
 (0)