Skip to content

Commit 1603176

Browse files
dschoGit for Windows Build Agent
authored and
Git for Windows Build Agent
committed
Apply some v2.48 regression bugfixes (#5376)
Now that most of the Git contributors are back from the holidays, there is an influx of bug fixes. This is precisely why I held off from rushing Git for Windows v2.48.0 out the door. These bug fixes are mostly taken from upstream's branches; In some cases, though, I had to apply them directly from the Git mailing list because they did not make it into git/git yet. I deem those bug fixes necessary to get Git for Windows into a somewhat healthy state again.
2 parents 0f0741e + 664c0c6 commit 1603176

13 files changed

+102
-54
lines changed

Diff for: builtin/fetch.c

+8-7
Original file line numberDiff line numberDiff line change
@@ -1618,9 +1618,9 @@ static void report_set_head(const char *remote, const char *head_name,
16181618
}
16191619

16201620
static int set_head(const struct ref *remote_refs, int follow_remote_head,
1621-
const char *no_warn_branch)
1621+
const char *no_warn_branch, int mirror)
16221622
{
1623-
int result = 0, create_only, is_bare, was_detached;
1623+
int result = 0, create_only, baremirror, was_detached;
16241624
struct strbuf b_head = STRBUF_INIT, b_remote_head = STRBUF_INIT,
16251625
b_local_head = STRBUF_INIT;
16261626
const char *remote = gtransport->remote->name;
@@ -1655,17 +1655,17 @@ static int set_head(const struct ref *remote_refs, int follow_remote_head,
16551655

16561656
if (!head_name)
16571657
goto cleanup;
1658-
is_bare = is_bare_repository();
1659-
create_only = follow_remote_head == FOLLOW_REMOTE_ALWAYS ? 0 : !is_bare;
1660-
if (is_bare) {
1658+
baremirror = is_bare_repository() && mirror;
1659+
create_only = follow_remote_head == FOLLOW_REMOTE_ALWAYS ? 0 : !baremirror;
1660+
if (baremirror) {
16611661
strbuf_addstr(&b_head, "HEAD");
16621662
strbuf_addf(&b_remote_head, "refs/heads/%s", head_name);
16631663
} else {
16641664
strbuf_addf(&b_head, "refs/remotes/%s/HEAD", remote);
16651665
strbuf_addf(&b_remote_head, "refs/remotes/%s/%s", remote, head_name);
16661666
}
16671667
/* make sure it's valid */
1668-
if (!is_bare && !refs_ref_exists(refs, b_remote_head.buf)) {
1668+
if (!baremirror && !refs_ref_exists(refs, b_remote_head.buf)) {
16691669
result = 1;
16701670
goto cleanup;
16711671
}
@@ -1925,7 +1925,8 @@ static int do_fetch(struct transport *transport,
19251925
}
19261926
}
19271927
if (set_head(remote_refs, transport->remote->follow_remote_head,
1928-
transport->remote->no_warn_branch))
1928+
transport->remote->no_warn_branch,
1929+
transport->remote->mirror))
19291930
;
19301931
/*
19311932
* Way too many cases where this can go wrong

Diff for: grep.c

+2
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,8 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
16461646

16471647
bol = gs->buf;
16481648
left = gs->size;
1649+
if (left && gs->buf[left-1] == '\n')
1650+
left--;
16491651
while (left) {
16501652
const char *eol;
16511653
int hit;

Diff for: refs.c

+16-8
Original file line numberDiff line numberDiff line change
@@ -1318,13 +1318,21 @@ int ref_transaction_update(struct ref_transaction *transaction,
13181318
return 0;
13191319
}
13201320

1321-
int ref_transaction_update_reflog(struct ref_transaction *transaction,
1322-
const char *refname,
1323-
const struct object_id *new_oid,
1324-
const struct object_id *old_oid,
1325-
const char *committer_info, unsigned int flags,
1326-
const char *msg, unsigned int index,
1327-
struct strbuf *err)
1321+
/*
1322+
* Similar to`ref_transaction_update`, but this function is only for adding
1323+
* a reflog update. Supports providing custom committer information. The index
1324+
* field can be utiltized to order updates as desired. When not used, the
1325+
* updates default to being ordered by refname.
1326+
*/
1327+
static int ref_transaction_update_reflog(struct ref_transaction *transaction,
1328+
const char *refname,
1329+
const struct object_id *new_oid,
1330+
const struct object_id *old_oid,
1331+
const char *committer_info,
1332+
unsigned int flags,
1333+
const char *msg,
1334+
uint64_t index,
1335+
struct strbuf *err)
13281336
{
13291337
struct ref_update *update;
13301338

@@ -2805,7 +2813,7 @@ static int migrate_one_ref(const char *refname, const char *referent UNUSED, con
28052813
}
28062814

28072815
struct reflog_migration_data {
2808-
unsigned int index;
2816+
uint64_t index;
28092817
const char *refname;
28102818
struct ref_store *old_refs;
28112819
struct ref_transaction *transaction;

Diff for: refs.h

-14
Original file line numberDiff line numberDiff line change
@@ -771,20 +771,6 @@ int ref_transaction_update(struct ref_transaction *transaction,
771771
unsigned int flags, const char *msg,
772772
struct strbuf *err);
773773

774-
/*
775-
* Similar to`ref_transaction_update`, but this function is only for adding
776-
* a reflog update. Supports providing custom committer information. The index
777-
* field can be utiltized to order updates as desired. When not used, the
778-
* updates default to being ordered by refname.
779-
*/
780-
int ref_transaction_update_reflog(struct ref_transaction *transaction,
781-
const char *refname,
782-
const struct object_id *new_oid,
783-
const struct object_id *old_oid,
784-
const char *committer_info, unsigned int flags,
785-
const char *msg, unsigned int index,
786-
struct strbuf *err);
787-
788774
/*
789775
* Add a reference creation to transaction. new_oid is the value that
790776
* the reference should have after the update; it must not be

Diff for: refs/refs-internal.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ struct ref_update {
120120
* when migrating reflogs and we want to ensure we carry over the
121121
* same order.
122122
*/
123-
unsigned int index;
123+
uint64_t index;
124124

125125
/*
126126
* If this ref_update was split off of a symref update via
@@ -203,7 +203,7 @@ struct ref_transaction {
203203
enum ref_transaction_state state;
204204
void *backend_data;
205205
unsigned int flags;
206-
unsigned int max_index;
206+
uint64_t max_index;
207207
};
208208

209209
/*

Diff for: refs/reftable-backend.c

+16-6
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ struct write_transaction_table_arg {
942942
size_t updates_nr;
943943
size_t updates_alloc;
944944
size_t updates_expected;
945-
unsigned int max_index;
945+
uint64_t max_index;
946946
};
947947

948948
struct reftable_transaction_data {
@@ -1444,7 +1444,9 @@ static int write_transaction_table(struct reftable_writer *writer, void *cb_data
14441444
* multiple entries. Each entry will contain a different update_index,
14451445
* so set the limits accordingly.
14461446
*/
1447-
reftable_writer_set_limits(writer, ts, ts + arg->max_index);
1447+
ret = reftable_writer_set_limits(writer, ts, ts + arg->max_index);
1448+
if (ret < 0)
1449+
goto done;
14481450

14491451
for (i = 0; i < arg->updates_nr; i++) {
14501452
struct reftable_transaction_update *tx_update = &arg->updates[i];
@@ -1766,7 +1768,9 @@ static int write_copy_table(struct reftable_writer *writer, void *cb_data)
17661768
deletion_ts = creation_ts = reftable_stack_next_update_index(arg->be->stack);
17671769
if (arg->delete_old)
17681770
creation_ts++;
1769-
reftable_writer_set_limits(writer, deletion_ts, creation_ts);
1771+
ret = reftable_writer_set_limits(writer, deletion_ts, creation_ts);
1772+
if (ret < 0)
1773+
goto done;
17701774

17711775
/*
17721776
* Add the new reference. If this is a rename then we also delete the
@@ -2298,7 +2302,9 @@ static int write_reflog_existence_table(struct reftable_writer *writer,
22982302
if (ret <= 0)
22992303
goto done;
23002304

2301-
reftable_writer_set_limits(writer, ts, ts);
2305+
ret = reftable_writer_set_limits(writer, ts, ts);
2306+
if (ret < 0)
2307+
goto done;
23022308

23032309
/*
23042310
* The existence entry has both old and new object ID set to the
@@ -2357,7 +2363,9 @@ static int write_reflog_delete_table(struct reftable_writer *writer, void *cb_da
23572363
uint64_t ts = reftable_stack_next_update_index(arg->stack);
23582364
int ret;
23592365

2360-
reftable_writer_set_limits(writer, ts, ts);
2366+
ret = reftable_writer_set_limits(writer, ts, ts);
2367+
if (ret < 0)
2368+
goto out;
23612369

23622370
ret = reftable_stack_init_log_iterator(arg->stack, &it);
23632371
if (ret < 0)
@@ -2434,7 +2442,9 @@ static int write_reflog_expiry_table(struct reftable_writer *writer, void *cb_da
24342442
if (arg->records[i].value_type == REFTABLE_LOG_UPDATE)
24352443
live_records++;
24362444

2437-
reftable_writer_set_limits(writer, ts, ts);
2445+
ret = reftable_writer_set_limits(writer, ts, ts);
2446+
if (ret < 0)
2447+
return ret;
24382448

24392449
if (!is_null_oid(&arg->update_oid)) {
24402450
struct reftable_ref_record ref = {0};

Diff for: reftable/reftable-error.h

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ enum reftable_error {
3030

3131
/* Misuse of the API:
3232
* - on writing a record with NULL refname.
33+
* - on writing a record before setting the writer limits.
3334
* - on writing a reftable_ref_record outside the table limits
3435
* - on writing a ref or log record before the stack's
3536
* next_update_inde*x

Diff for: reftable/reftable-writer.h

+14-10
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,21 @@ int reftable_writer_new(struct reftable_writer **out,
124124
int (*flush_func)(void *),
125125
void *writer_arg, const struct reftable_write_options *opts);
126126

127-
/* Set the range of update indices for the records we will add. When writing a
128-
table into a stack, the min should be at least
129-
reftable_stack_next_update_index(), or REFTABLE_API_ERROR is returned.
130-
131-
For transactional updates to a stack, typically min==max, and the
132-
update_index can be obtained by inspeciting the stack. When converting an
133-
existing ref database into a single reftable, this would be a range of
134-
update-index timestamps.
127+
/*
128+
* Set the range of update indices for the records we will add. When writing a
129+
* table into a stack, the min should be at least
130+
* reftable_stack_next_update_index(), or REFTABLE_API_ERROR is returned.
131+
*
132+
* For transactional updates to a stack, typically min==max, and the
133+
* update_index can be obtained by inspeciting the stack. When converting an
134+
* existing ref database into a single reftable, this would be a range of
135+
* update-index timestamps.
136+
*
137+
* The function should be called before adding any records to the writer. If not
138+
* it will fail with REFTABLE_API_ERROR.
135139
*/
136-
void reftable_writer_set_limits(struct reftable_writer *w, uint64_t min,
137-
uint64_t max);
140+
int reftable_writer_set_limits(struct reftable_writer *w, uint64_t min,
141+
uint64_t max);
138142

139143
/*
140144
Add a reftable_ref_record. The record should have names that come after

Diff for: reftable/stack.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -1058,8 +1058,10 @@ static int stack_write_compact(struct reftable_stack *st,
10581058

10591059
for (size_t i = first; i <= last; i++)
10601060
st->stats.bytes += st->readers[i]->size;
1061-
reftable_writer_set_limits(wr, st->readers[first]->min_update_index,
1062-
st->readers[last]->max_update_index);
1061+
err = reftable_writer_set_limits(wr, st->readers[first]->min_update_index,
1062+
st->readers[last]->max_update_index);
1063+
if (err < 0)
1064+
goto done;
10631065

10641066
err = reftable_merged_table_new(&mt, st->readers + first, subtabs_len,
10651067
st->opts.hash_id);

Diff for: reftable/writer.c

+11-2
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,20 @@ int reftable_writer_new(struct reftable_writer **out,
179179
return 0;
180180
}
181181

182-
void reftable_writer_set_limits(struct reftable_writer *w, uint64_t min,
183-
uint64_t max)
182+
int reftable_writer_set_limits(struct reftable_writer *w, uint64_t min,
183+
uint64_t max)
184184
{
185+
/*
186+
* The limits should be set before any records are added to the writer.
187+
* Check if any records were added by checking if `last_key` was set.
188+
*/
189+
if (w->last_key.len)
190+
return REFTABLE_API_ERROR;
191+
185192
w->min_update_index = min;
186193
w->max_update_index = max;
194+
195+
return 0;
187196
}
188197

189198
static void writer_release(struct reftable_writer *w)

Diff for: t/t5505-remote.sh

+10
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,16 @@ test_expect_success 'add --mirror setting HEAD' '
589589
)
590590
'
591591

592+
test_expect_success 'non-mirror fetch does not interfere with mirror' '
593+
mkdir headnotmain &&
594+
(
595+
cd headnotmain &&
596+
git init --bare -b notmain &&
597+
git remote add -f other ../two &&
598+
test "$(git symbolic-ref HEAD)" = "refs/heads/notmain"
599+
)
600+
'
601+
592602
test_expect_success 'add --mirror=fetch' '
593603
mkdir mirror-fetch &&
594604
git init -b main mirror-fetch/parent &&

Diff for: t/t5510-fetch.sh

+13
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ test_expect_success "fetch test remote HEAD" '
8181
branch=$(git rev-parse refs/remotes/origin/main) &&
8282
test "z$head" = "z$branch"'
8383

84+
test_expect_success "fetch test remote HEAD in bare repository" '
85+
cd "$D" &&
86+
git init --bare barerepo &&
87+
cd barerepo &&
88+
git remote add upstream ../two &&
89+
git fetch upstream &&
90+
git rev-parse --verify refs/remotes/upstream/HEAD &&
91+
git rev-parse --verify refs/remotes/upstream/main &&
92+
head=$(git rev-parse refs/remotes/upstream/HEAD) &&
93+
branch=$(git rev-parse refs/remotes/upstream/main) &&
94+
test "z$head" = "z$branch"'
95+
96+
8497
test_expect_success "fetch test remote HEAD change" '
8598
cd "$D" &&
8699
cd two &&

Diff for: t/unit-tests/t-reftable-stack.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ static void t_read_file(void)
103103
static int write_test_ref(struct reftable_writer *wr, void *arg)
104104
{
105105
struct reftable_ref_record *ref = arg;
106-
reftable_writer_set_limits(wr, ref->update_index, ref->update_index);
106+
check(!reftable_writer_set_limits(wr, ref->update_index,
107+
ref->update_index));
107108
return reftable_writer_add_ref(wr, ref);
108109
}
109110

@@ -143,7 +144,8 @@ static int write_test_log(struct reftable_writer *wr, void *arg)
143144
{
144145
struct write_log_arg *wla = arg;
145146

146-
reftable_writer_set_limits(wr, wla->update_index, wla->update_index);
147+
check(!reftable_writer_set_limits(wr, wla->update_index,
148+
wla->update_index));
147149
return reftable_writer_add_log(wr, wla->log);
148150
}
149151

@@ -961,7 +963,7 @@ static void t_reflog_expire(void)
961963

962964
static int write_nothing(struct reftable_writer *wr, void *arg UNUSED)
963965
{
964-
reftable_writer_set_limits(wr, 1, 1);
966+
check(!reftable_writer_set_limits(wr, 1, 1));
965967
return 0;
966968
}
967969

0 commit comments

Comments
 (0)