Skip to content

Commit 1e4fdd2

Browse files
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 14f4011 + d617d20 commit 1e4fdd2

38 files changed

+353
-196
lines changed

Documentation/git-show-index.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ git-show-index - Show packed archive index
99
SYNOPSIS
1010
--------
1111
[verse]
12-
'git show-index' [--object-format=<hash-algorithm>]
12+
'git show-index' [--object-format=<hash-algorithm>] < <pack-idx-file>
1313

1414

1515
DESCRIPTION

builtin/branch.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sortin
473473
if (verify_ref_format(format))
474474
die(_("unable to parse format string"));
475475

476-
filter_ahead_behind(the_repository, format, &array);
476+
filter_ahead_behind(the_repository, &array);
477477
ref_array_sort(sorting, &array);
478478

479479
if (column_active(colopts)) {
@@ -884,7 +884,6 @@ int cmd_branch(int argc,
884884
string_list_clear(&output, 0);
885885
ref_sorting_release(sorting);
886886
ref_filter_clear(&filter);
887-
ref_format_clear(&format);
888887

889888
ret = 0;
890889
goto out;

builtin/credential-cache--daemon.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ static void serve_one_client(FILE *in, FILE *out)
142142
fprintf(out, "username=%s\n", e->item.username);
143143
if (e->item.password)
144144
fprintf(out, "password=%s\n", e->item.password);
145-
if (credential_has_capability(&c.capa_authtype, CREDENTIAL_OP_HELPER) && e->item.authtype)
145+
if (credential_has_capability(&c.capa_authtype, CREDENTIAL_OP_RESPONSE) && e->item.authtype)
146146
fprintf(out, "authtype=%s\n", e->item.authtype);
147-
if (credential_has_capability(&c.capa_authtype, CREDENTIAL_OP_HELPER) && e->item.credential)
147+
if (credential_has_capability(&c.capa_authtype, CREDENTIAL_OP_RESPONSE) && e->item.credential)
148148
fprintf(out, "credential=%s\n", e->item.credential);
149149
if (e->item.password_expiry_utc != TIME_MAX)
150150
fprintf(out, "password_expiry_utc=%"PRItime"\n",

builtin/fetch.c

Lines changed: 8 additions & 7 deletions
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

builtin/for-each-ref.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ int cmd_for_each_ref(int argc,
108108
filter_and_format_refs(&filter, flags, sorting, &format);
109109

110110
ref_filter_clear(&filter);
111-
ref_format_clear(&format);
112111
ref_sorting_release(sorting);
113112
strvec_clear(&vec);
114113
return 0;

builtin/index-pack.c

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -380,16 +380,18 @@ static const char *open_pack_file(const char *pack_name)
380380

381381
static void parse_pack_header(void)
382382
{
383-
struct pack_header *hdr = fill(sizeof(struct pack_header));
383+
unsigned char *hdr = fill(sizeof(struct pack_header));
384384

385385
/* Header consistency check */
386-
if (hdr->hdr_signature != htonl(PACK_SIGNATURE))
386+
if (get_be32(hdr) != PACK_SIGNATURE)
387387
die(_("pack signature mismatch"));
388-
if (!pack_version_ok(hdr->hdr_version))
388+
hdr += 4;
389+
if (!pack_version_ok_native(get_be32(hdr)))
389390
die(_("pack version %"PRIu32" unsupported"),
390-
ntohl(hdr->hdr_version));
391+
get_be32(hdr));
392+
hdr += 4;
391393

392-
nr_objects = ntohl(hdr->hdr_entries);
394+
nr_objects = get_be32(hdr);
393395
use(sizeof(struct pack_header));
394396
}
395397

@@ -1957,19 +1959,11 @@ int cmd_index_pack(int argc,
19571959
warning(_("no threads support, ignoring %s"), arg);
19581960
nr_threads = 1;
19591961
}
1960-
} else if (starts_with(arg, "--pack_header=")) {
1961-
struct pack_header *hdr;
1962-
char *c;
1963-
1964-
hdr = (struct pack_header *)input_buffer;
1965-
hdr->hdr_signature = htonl(PACK_SIGNATURE);
1966-
hdr->hdr_version = htonl(strtoul(arg + 14, &c, 10));
1967-
if (*c != ',')
1968-
die(_("bad %s"), arg);
1969-
hdr->hdr_entries = htonl(strtoul(c + 1, &c, 10));
1970-
if (*c)
1971-
die(_("bad %s"), arg);
1972-
input_len = sizeof(*hdr);
1962+
} else if (skip_prefix(arg, "--pack_header=", &arg)) {
1963+
if (parse_pack_header_option(arg,
1964+
input_buffer,
1965+
&input_len) < 0)
1966+
die(_("bad --pack_header: %s"), arg);
19731967
} else if (!strcmp(arg, "-v")) {
19741968
verbose = 1;
19751969
} else if (!strcmp(arg, "--progress-title")) {

builtin/show-index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "parse-options.h"
1010

1111
static const char *const show_index_usage[] = {
12-
"git show-index [--object-format=<hash-algorithm>]",
12+
"git show-index [--object-format=<hash-algorithm>] < <pack-idx-file>",
1313
NULL
1414
};
1515

builtin/tag.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,6 @@ int cmd_tag(int argc,
698698
cleanup:
699699
ref_sorting_release(sorting);
700700
ref_filter_clear(&filter);
701-
ref_format_clear(&format);
702701
strbuf_release(&buf);
703702
strbuf_release(&ref);
704703
strbuf_release(&reflog_msg);

builtin/unpack-objects.c

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "progress.h"
1919
#include "decorate.h"
2020
#include "fsck.h"
21+
#include "packfile.h"
2122

2223
static int dry_run, quiet, recover, has_errors, strict;
2324
static const char unpack_usage[] = "git unpack-objects [-n] [-q] [-r] [--strict]";
@@ -578,15 +579,16 @@ static void unpack_one(unsigned nr)
578579
static void unpack_all(void)
579580
{
580581
int i;
581-
struct pack_header *hdr = fill(sizeof(struct pack_header));
582+
unsigned char *hdr = fill(sizeof(struct pack_header));
582583

583-
nr_objects = ntohl(hdr->hdr_entries);
584-
585-
if (ntohl(hdr->hdr_signature) != PACK_SIGNATURE)
584+
if (get_be32(hdr) != PACK_SIGNATURE)
586585
die("bad pack file");
587-
if (!pack_version_ok(hdr->hdr_version))
586+
hdr += 4;
587+
if (!pack_version_ok_native(get_be32(hdr)))
588588
die("unknown pack file version %"PRIu32,
589-
ntohl(hdr->hdr_version));
589+
get_be32(hdr));
590+
hdr += 4;
591+
nr_objects = get_be32(hdr);
590592
use(sizeof(struct pack_header));
591593

592594
if (!quiet)
@@ -645,19 +647,10 @@ int cmd_unpack_objects(int argc,
645647
fsck_set_msg_types(&fsck_options, arg);
646648
continue;
647649
}
648-
if (starts_with(arg, "--pack_header=")) {
649-
struct pack_header *hdr;
650-
char *c;
651-
652-
hdr = (struct pack_header *)buffer;
653-
hdr->hdr_signature = htonl(PACK_SIGNATURE);
654-
hdr->hdr_version = htonl(strtoul(arg + 14, &c, 10));
655-
if (*c != ',')
656-
die("bad %s", arg);
657-
hdr->hdr_entries = htonl(strtoul(c + 1, &c, 10));
658-
if (*c)
659-
die("bad %s", arg);
660-
len = sizeof(*hdr);
650+
if (skip_prefix(arg, "--pack_header=", &arg)) {
651+
if (parse_pack_header_option(arg,
652+
buffer, &len) < 0)
653+
die(_("bad --pack_header: %s"), arg);
661654
continue;
662655
}
663656
if (skip_prefix(arg, "--max-input-size=", &arg)) {

builtin/verify-tag.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,5 @@ int cmd_verify_tag(int argc,
6969
if (format.format)
7070
pretty_print_ref(name, &oid, &format);
7171
}
72-
ref_format_clear(&format);
7372
return had_error;
7473
}

compat/bswap.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,23 +171,23 @@ static inline uint64_t get_be64(const void *ptr)
171171
static inline void put_be32(void *ptr, uint32_t value)
172172
{
173173
unsigned char *p = ptr;
174-
p[0] = value >> 24;
175-
p[1] = value >> 16;
176-
p[2] = value >> 8;
177-
p[3] = value >> 0;
174+
p[0] = (value >> 24) & 0xff;
175+
p[1] = (value >> 16) & 0xff;
176+
p[2] = (value >> 8) & 0xff;
177+
p[3] = (value >> 0) & 0xff;
178178
}
179179

180180
static inline void put_be64(void *ptr, uint64_t value)
181181
{
182182
unsigned char *p = ptr;
183-
p[0] = value >> 56;
184-
p[1] = value >> 48;
185-
p[2] = value >> 40;
186-
p[3] = value >> 32;
187-
p[4] = value >> 24;
188-
p[5] = value >> 16;
189-
p[6] = value >> 8;
190-
p[7] = value >> 0;
183+
p[0] = (value >> 56) & 0xff;
184+
p[1] = (value >> 48) & 0xff;
185+
p[2] = (value >> 40) & 0xff;
186+
p[3] = (value >> 32) & 0xff;
187+
p[4] = (value >> 24) & 0xff;
188+
p[5] = (value >> 16) & 0xff;
189+
p[6] = (value >> 8) & 0xff;
190+
p[7] = (value >> 0) & 0xff;
191191
}
192192

193193
#endif /* COMPAT_BSWAP_H */

grep.c

Lines changed: 2 additions & 0 deletions
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;

pack.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ struct repository;
1313
*/
1414
#define PACK_SIGNATURE 0x5041434b /* "PACK" */
1515
#define PACK_VERSION 2
16-
#define pack_version_ok(v) ((v) == htonl(2) || (v) == htonl(3))
16+
#define pack_version_ok(v) pack_version_ok_native(ntohl(v))
17+
#define pack_version_ok_native(v) ((v) == 2 || (v) == 3)
1718
struct pack_header {
1819
uint32_t hdr_signature;
1920
uint32_t hdr_version;

packfile.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2315,3 +2315,23 @@ int is_promisor_object(struct repository *r, const struct object_id *oid)
23152315
}
23162316
return oidset_contains(&promisor_objects, oid);
23172317
}
2318+
2319+
int parse_pack_header_option(const char *in, unsigned char *out, unsigned int *len)
2320+
{
2321+
unsigned char *hdr;
2322+
char *c;
2323+
2324+
hdr = out;
2325+
put_be32(hdr, PACK_SIGNATURE);
2326+
hdr += 4;
2327+
put_be32(hdr, strtoul(in, &c, 10));
2328+
hdr += 4;
2329+
if (*c != ',')
2330+
return -1;
2331+
put_be32(hdr, strtoul(c + 1, &c, 10));
2332+
hdr += 4;
2333+
if (*c)
2334+
return -1;
2335+
*len = hdr - out;
2336+
return 0;
2337+
}

packfile.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,10 @@ int is_promisor_object(struct repository *r, const struct object_id *oid);
216216
int load_idx(const char *path, const unsigned int hashsz, void *idx_map,
217217
size_t idx_size, struct packed_git *p);
218218

219+
/*
220+
* Parse a --pack_header option as accepted by index-pack and unpack-objects,
221+
* turning it into the matching bytes we'd find in a pack.
222+
*/
223+
int parse_pack_header_option(const char *in, unsigned char *out, unsigned int *len);
224+
219225
#endif

0 commit comments

Comments
 (0)