Skip to content

Commit ed26177

Browse files
authored
Fix the fedora-breaking-changes CI job failures (#900)
I noticed today that the `fedora-breaking-changes` job started [failing](backport-fedora-breaking-changes-fix): ``` [...] In file included from ../common-main.c:1: ../git-compat-util.h: In function ‘git_find_last_dir_sep’: Error: ../git-compat-util.h:353:16: return discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers] 353 | return strrchr(path, '/'); | ^~~~~~~ cc1: all warnings being treated as errors ``` This is new, I had not seen this before. The reason that this did not fail earlier is that this CI job used to [use Fedora 43](https://github.com/microsoft/git/actions/runs/24733807372/job/72355187872#step:2:38), where it succeeded, whereas now it [uses Fedora 44](https://github.com/microsoft/git/actions/runs/25038293016/job/73335043533#step:2:38), where it fails. Lucky for us, upstream Git already has fixes for this issue & related ones, in [the `cf/constness-fixes` branch](gitgitgadget/git@v2.52.0...cf/constness-fixes), [the `cf/c23-const-preserving-strchr-updates-0 ` branch](gitgitgadget/git@v2.53.0...cf/c23-const-preserving-strchr-updates-0 ), [the `jk/c23-const-preserving-fixes-more` branch](gitgitgadget/git@270e10a...jk/c23-const-preserving-fixes-more), [the `jk/c23-const-preserving-fixes` branch](gitgitgadget/git@41688c1...jk/c23-const-preserving-fixes), [the `jk/ref-filter-lrstrip-optim` branch](gitgitgadget/git@v2.53.0...jk/ref-filter-lrstrip-optim) and [the `ps/history-ergonomics-updates` branch](gitgitgadget/git@453e7b7...ps/history-ergonomics-updates), which I hereby backport to the `vfs-2.53.0` branch.
2 parents 10c0f35 + c9ccdc5 commit ed26177

48 files changed

Lines changed: 198 additions & 190 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

add-patch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ static int parse_hunk_header(struct add_p_state *s, struct hunk *hunk)
342342
{
343343
struct hunk_header *header = &hunk->header;
344344
const char *line = s->plain.buf + hunk->start, *p = line;
345-
char *eol = memchr(p, '\n', s->plain.len - hunk->start);
345+
const char *eol = memchr(p, '\n', s->plain.len - hunk->start);
346346

347347
if (!eol)
348348
eol = s->plain.buf + s->plain.len;

apply.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4164,7 +4164,7 @@ static int preimage_oid_in_gitlink_patch(struct patch *p, struct object_id *oid)
41644164
*/
41654165
struct fragment *hunk = p->fragments;
41664166
static const char heading[] = "-Subproject commit ";
4167-
char *preimage;
4167+
const char *preimage;
41684168

41694169
if (/* does the patch have only one hunk? */
41704170
hunk && !hunk->next &&

bloom.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ struct bloom_filter *get_or_compute_bloom_filter(struct repository *r,
501501
struct hashmap_iter iter;
502502

503503
for (i = 0; i < diff_queued_diff.nr; i++) {
504-
const char *path = diff_queued_diff.queue[i]->two->path;
504+
char *path = diff_queued_diff.queue[i]->two->path;
505505

506506
/*
507507
* Add each leading directory of the changed file, i.e. for
@@ -523,7 +523,7 @@ struct bloom_filter *get_or_compute_bloom_filter(struct repository *r,
523523
free(e);
524524

525525
if (!last_slash)
526-
last_slash = (char*)path;
526+
last_slash = path;
527527
*last_slash = '\0';
528528

529529
} while (*path);

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
933933
logfile);
934934
hook_arg1 = "message";
935935
} else if (use_message) {
936-
char *buffer;
936+
const char *buffer;
937937
buffer = strstr(use_message_buffer, "\n\n");
938938
if (buffer)
939939
strbuf_addstr(&sb, skip_blank_lines(buffer + 2));

builtin/config.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,7 @@ static int get_urlmatch(const struct config_location_options *opts,
838838
const char *var, const char *url)
839839
{
840840
int ret;
841+
char *section;
841842
char *section_tail;
842843
struct config_display_options display_opts = *_display_opts;
843844
struct string_list_item *item;
@@ -851,8 +852,8 @@ static int get_urlmatch(const struct config_location_options *opts,
851852
if (!url_normalize(url, &config.url))
852853
die("%s", config.url.err);
853854

854-
config.section = xstrdup_tolower(var);
855-
section_tail = strchr(config.section, '.');
855+
config.section = section = xstrdup_tolower(var);
856+
section_tail = strchr(section, '.');
856857
if (section_tail) {
857858
*section_tail = '\0';
858859
config.key = section_tail + 1;
@@ -886,7 +887,7 @@ static int get_urlmatch(const struct config_location_options *opts,
886887
string_list_clear(&values, 1);
887888
free(config.url.url);
888889

889-
free((void *)config.section);
890+
free(section);
890891
return ret;
891892
}
892893

builtin/receive-pack.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ struct command {
393393
static void proc_receive_ref_append(const char *prefix)
394394
{
395395
struct proc_receive_ref *ref_pattern;
396-
char *p;
396+
const char *p;
397397
int len;
398398

399399
CALLOC_ARRAY(ref_pattern, 1);
@@ -989,8 +989,8 @@ static int read_proc_receive_report(struct packet_reader *reader,
989989

990990
for (;;) {
991991
struct object_id old_oid, new_oid;
992-
const char *head;
993-
const char *refname;
992+
char *head;
993+
char *refname;
994994
char *p;
995995
enum packet_read_status status;
996996

@@ -1014,7 +1014,8 @@ static int read_proc_receive_report(struct packet_reader *reader,
10141014
}
10151015
*p++ = '\0';
10161016
if (!strcmp(head, "option")) {
1017-
const char *key, *val;
1017+
char *key;
1018+
const char *val;
10181019

10191020
if (!hint || !(report || new_report)) {
10201021
if (!once++)

builtin/remote.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ static int config_read_branches(const char *key, const char *value,
332332
info->remote_name = xstrdup(value);
333333
break;
334334
case MERGE: {
335-
char *space = strchr(value, ' ');
335+
const char *space = strchr(value, ' ');
336336
value = abbrev_branch(value);
337337
while (space) {
338338
char *merge;

builtin/rev-parse.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -267,21 +267,20 @@ static int show_file(const char *arg, int output_prefix)
267267

268268
static int try_difference(const char *arg)
269269
{
270-
char *dotdot;
270+
const char *dotdot;
271271
struct object_id start_oid;
272272
struct object_id end_oid;
273273
const char *end;
274274
const char *start;
275+
char *to_free;
275276
int symmetric;
276277
static const char head_by_default[] = "HEAD";
277278

278279
if (!(dotdot = strstr(arg, "..")))
279280
return 0;
281+
start = to_free = xmemdupz(arg, dotdot - arg);
280282
end = dotdot + 2;
281-
start = arg;
282283
symmetric = (*end == '.');
283-
284-
*dotdot = 0;
285284
end += symmetric;
286285

287286
if (!*end)
@@ -295,7 +294,7 @@ static int try_difference(const char *arg)
295294
* Just ".."? That is not a range but the
296295
* pathspec for the parent directory.
297296
*/
298-
*dotdot = '.';
297+
free(to_free);
299298
return 0;
300299
}
301300

@@ -308,7 +307,7 @@ static int try_difference(const char *arg)
308307
a = lookup_commit_reference(the_repository, &start_oid);
309308
b = lookup_commit_reference(the_repository, &end_oid);
310309
if (!a || !b) {
311-
*dotdot = '.';
310+
free(to_free);
312311
return 0;
313312
}
314313
if (repo_get_merge_bases(the_repository, a, b, &exclude) < 0)
@@ -318,55 +317,56 @@ static int try_difference(const char *arg)
318317
show_rev(REVERSED, &commit->object.oid, NULL);
319318
}
320319
}
321-
*dotdot = '.';
320+
free(to_free);
322321
return 1;
323322
}
324-
*dotdot = '.';
323+
free(to_free);
325324
return 0;
326325
}
327326

328327
static int try_parent_shorthands(const char *arg)
329328
{
330-
char *dotdot;
329+
const char *mark;
331330
struct object_id oid;
332331
struct commit *commit;
333332
struct commit_list *parents;
334333
int parent_number;
335334
int include_rev = 0;
336335
int include_parents = 0;
337336
int exclude_parent = 0;
337+
char *to_free;
338338

339-
if ((dotdot = strstr(arg, "^!"))) {
339+
if ((mark = strstr(arg, "^!"))) {
340340
include_rev = 1;
341-
if (dotdot[2])
341+
if (mark[2])
342342
return 0;
343-
} else if ((dotdot = strstr(arg, "^@"))) {
343+
} else if ((mark = strstr(arg, "^@"))) {
344344
include_parents = 1;
345-
if (dotdot[2])
345+
if (mark[2])
346346
return 0;
347-
} else if ((dotdot = strstr(arg, "^-"))) {
347+
} else if ((mark = strstr(arg, "^-"))) {
348348
include_rev = 1;
349349
exclude_parent = 1;
350350

351-
if (dotdot[2]) {
351+
if (mark[2]) {
352352
char *end;
353-
exclude_parent = strtoul(dotdot + 2, &end, 10);
353+
exclude_parent = strtoul(mark + 2, &end, 10);
354354
if (*end != '\0' || !exclude_parent)
355355
return 0;
356356
}
357357
} else
358358
return 0;
359359

360-
*dotdot = 0;
360+
arg = to_free = xmemdupz(arg, mark - arg);
361361
if (repo_get_oid_committish(the_repository, arg, &oid) ||
362362
!(commit = lookup_commit_reference(the_repository, &oid))) {
363-
*dotdot = '^';
363+
free(to_free);
364364
return 0;
365365
}
366366

367367
if (exclude_parent &&
368368
exclude_parent > commit_list_count(commit->parents)) {
369-
*dotdot = '^';
369+
free(to_free);
370370
return 0;
371371
}
372372

@@ -387,7 +387,7 @@ static int try_parent_shorthands(const char *arg)
387387
free(name);
388388
}
389389

390-
*dotdot = '^';
390+
free(to_free);
391391
return 1;
392392
}
393393

builtin/shortlog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static void insert_one_record(struct shortlog *log,
7676
if (!eol)
7777
eol = oneline + strlen(oneline);
7878
if (starts_with(oneline, "[PATCH")) {
79-
char *eob = strchr(oneline, ']');
79+
const char *eob = strchr(oneline, ']');
8080
if (eob && (!eol || eob < eol))
8181
oneline = eob + 1;
8282
}

config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ static int handle_path_include(const struct key_value_info *kvi,
162162
* based on the including config file.
163163
*/
164164
if (!is_absolute_path(path)) {
165-
char *slash;
165+
const char *slash;
166166

167167
if (!kvi || kvi->origin_type != CONFIG_ORIGIN_FILE) {
168168
ret = error(_("relative config includes must come from files"));

0 commit comments

Comments
 (0)