Skip to content

Commit 0eaa5a2

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 0d0c268 + c6bea60 commit 0eaa5a2

Some content is hidden

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

44 files changed

+519
-236
lines changed

Documentation/git-show-index.txt

+1-1
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

+1-2
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

+2-2
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

+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

builtin/for-each-ref.c

-1
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

+12-18
Original file line numberDiff line numberDiff line change
@@ -379,16 +379,18 @@ static const char *open_pack_file(const char *pack_name)
379379

380380
static void parse_pack_header(void)
381381
{
382-
struct pack_header *hdr = fill(sizeof(struct pack_header));
382+
unsigned char *hdr = fill(sizeof(struct pack_header));
383383

384384
/* Header consistency check */
385-
if (hdr->hdr_signature != htonl(PACK_SIGNATURE))
385+
if (get_be32(hdr) != PACK_SIGNATURE)
386386
die(_("pack signature mismatch"));
387-
if (!pack_version_ok(hdr->hdr_version))
387+
hdr += 4;
388+
if (!pack_version_ok_native(get_be32(hdr)))
388389
die(_("pack version %"PRIu32" unsupported"),
389-
ntohl(hdr->hdr_version));
390+
get_be32(hdr));
391+
hdr += 4;
390392

391-
nr_objects = ntohl(hdr->hdr_entries);
393+
nr_objects = get_be32(hdr);
392394
use(sizeof(struct pack_header));
393395
}
394396

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

builtin/show-index.c

+1-1
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

-1
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

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

builtin/verify-tag.c

-1
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

+12-12
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

+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;

object-file.c

+42-24
Original file line numberDiff line numberDiff line change
@@ -1970,54 +1970,59 @@ static void write_object_file_prepare_literally(const struct git_hash_algo *algo
19701970
hash_object_body(algo, &c, buf, len, oid, hdr, hdrlen);
19711971
}
19721972

1973-
static int check_collision(const char *filename_a, const char *filename_b)
1973+
#define CHECK_COLLISION_DEST_VANISHED -2
1974+
1975+
static int check_collision(const char *source, const char *dest)
19741976
{
1975-
char buf_a[4096], buf_b[4096];
1976-
int fd_a = -1, fd_b = -1;
1977+
char buf_source[4096], buf_dest[4096];
1978+
int fd_source = -1, fd_dest = -1;
19771979
int ret = 0;
19781980

1979-
fd_a = open(filename_a, O_RDONLY);
1980-
if (fd_a < 0) {
1981-
ret = error_errno(_("unable to open %s"), filename_a);
1981+
fd_source = open(source, O_RDONLY);
1982+
if (fd_source < 0) {
1983+
ret = error_errno(_("unable to open %s"), source);
19821984
goto out;
19831985
}
19841986

1985-
fd_b = open(filename_b, O_RDONLY);
1986-
if (fd_b < 0) {
1987-
ret = error_errno(_("unable to open %s"), filename_b);
1987+
fd_dest = open(dest, O_RDONLY);
1988+
if (fd_dest < 0) {
1989+
if (errno != ENOENT)
1990+
ret = error_errno(_("unable to open %s"), dest);
1991+
else
1992+
ret = CHECK_COLLISION_DEST_VANISHED;
19881993
goto out;
19891994
}
19901995

19911996
while (1) {
19921997
ssize_t sz_a, sz_b;
19931998

1994-
sz_a = read_in_full(fd_a, buf_a, sizeof(buf_a));
1999+
sz_a = read_in_full(fd_source, buf_source, sizeof(buf_source));
19952000
if (sz_a < 0) {
1996-
ret = error_errno(_("unable to read %s"), filename_a);
2001+
ret = error_errno(_("unable to read %s"), source);
19972002
goto out;
19982003
}
19992004

2000-
sz_b = read_in_full(fd_b, buf_b, sizeof(buf_b));
2005+
sz_b = read_in_full(fd_dest, buf_dest, sizeof(buf_dest));
20012006
if (sz_b < 0) {
2002-
ret = error_errno(_("unable to read %s"), filename_b);
2007+
ret = error_errno(_("unable to read %s"), dest);
20032008
goto out;
20042009
}
20052010

2006-
if (sz_a != sz_b || memcmp(buf_a, buf_b, sz_a)) {
2011+
if (sz_a != sz_b || memcmp(buf_source, buf_dest, sz_a)) {
20072012
ret = error(_("files '%s' and '%s' differ in contents"),
2008-
filename_a, filename_b);
2013+
source, dest);
20092014
goto out;
20102015
}
20112016

2012-
if (sz_a < sizeof(buf_a))
2017+
if (sz_a < sizeof(buf_source))
20132018
break;
20142019
}
20152020

20162021
out:
2017-
if (fd_a > -1)
2018-
close(fd_a);
2019-
if (fd_b > -1)
2020-
close(fd_b);
2022+
if (fd_source > -1)
2023+
close(fd_source);
2024+
if (fd_dest > -1)
2025+
close(fd_dest);
20212026
return ret;
20222027
}
20232028

@@ -2032,8 +2037,11 @@ int finalize_object_file(const char *tmpfile, const char *filename)
20322037
int finalize_object_file_flags(const char *tmpfile, const char *filename,
20332038
enum finalize_object_file_flags flags)
20342039
{
2035-
struct stat st;
2036-
int ret = 0;
2040+
unsigned retries = 0;
2041+
int ret;
2042+
2043+
retry:
2044+
ret = 0;
20372045

20382046
if (object_creation_mode == OBJECT_CREATION_USES_RENAMES)
20392047
goto try_rename;
@@ -2054,6 +2062,8 @@ int finalize_object_file_flags(const char *tmpfile, const char *filename,
20542062
* left to unlink.
20552063
*/
20562064
if (ret && ret != EEXIST) {
2065+
struct stat st;
2066+
20572067
try_rename:
20582068
if (!stat(filename, &st))
20592069
ret = EEXIST;
@@ -2069,9 +2079,17 @@ int finalize_object_file_flags(const char *tmpfile, const char *filename,
20692079
errno = saved_errno;
20702080
return error_errno(_("unable to write file %s"), filename);
20712081
}
2072-
if (!(flags & FOF_SKIP_COLLISION_CHECK) &&
2073-
check_collision(tmpfile, filename))
2082+
if (!(flags & FOF_SKIP_COLLISION_CHECK)) {
2083+
ret = check_collision(tmpfile, filename);
2084+
if (ret == CHECK_COLLISION_DEST_VANISHED) {
2085+
if (retries++ > 5)
2086+
return error(_("unable to write repeatedly vanishing file %s"),
2087+
filename);
2088+
goto retry;
2089+
}
2090+
else if (ret)
20742091
return -1;
2092+
}
20752093
unlink_or_warn(tmpfile);
20762094
}
20772095

0 commit comments

Comments
 (0)