Skip to content

Commit c47679d

Browse files
committed
Merge branch 'mt/parallel-checkout-part-1'
Preparatory API changes for parallel checkout. * mt/parallel-checkout-part-1: entry: add checkout_entry_ca() taking preloaded conv_attrs entry: move conv_attrs lookup up to checkout_entry() entry: extract update_ce_after_write() from write_entry() entry: make fstat_output() and read_blob_entry() public entry: extract a header file for entry.c functions convert: add classification for conv_attrs struct convert: add get_stream_filter_ca() variant convert: add [async_]convert_to_working_tree_ca() variants convert: make convert_attrs() and convert structs public
2 parents a65ce7f + ae22751 commit c47679d

File tree

11 files changed

+277
-137
lines changed

11 files changed

+277
-137
lines changed

apply.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "quote.h"
2222
#include "rerere.h"
2323
#include "apply.h"
24+
#include "entry.h"
2425

2526
struct gitdiff_data {
2627
struct strbuf *root;

builtin/checkout-index.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "quote.h"
1212
#include "cache-tree.h"
1313
#include "parse-options.h"
14+
#include "entry.h"
1415

1516
#define CHECKOUT_ALL 4
1617
static int nul_term_line;

builtin/checkout.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "unpack-trees.h"
2727
#include "wt-status.h"
2828
#include "xdiff-interface.h"
29+
#include "entry.h"
2930

3031
static const char * const checkout_usage[] = {
3132
N_("git checkout [<options>] <branch>"),

builtin/difftool.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "lockfile.h"
2424
#include "object-store.h"
2525
#include "dir.h"
26+
#include "entry.h"
2627

2728
static int trust_exit_code;
2829

builtin/stash.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
#include "strvec.h"
1111
#include "run-command.h"
1212
#include "dir.h"
13+
#include "entry.h"
1314
#include "rerere.h"
1415
#include "revision.h"
1516
#include "log-tree.h"
1617
#include "diffcore.h"
1718
#include "exec-cmd.h"
19+
#include "entry.h"
1820

1921
#define INCLUDE_ALL_FILES 2
2022

cache.h

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,30 +1621,6 @@ const char *show_ident_date(const struct ident_split *id,
16211621
*/
16221622
int ident_cmp(const struct ident_split *, const struct ident_split *);
16231623

1624-
struct checkout {
1625-
struct index_state *istate;
1626-
const char *base_dir;
1627-
int base_dir_len;
1628-
struct delayed_checkout *delayed_checkout;
1629-
struct checkout_metadata meta;
1630-
unsigned force:1,
1631-
quiet:1,
1632-
not_new:1,
1633-
clone:1,
1634-
refresh_cache:1;
1635-
};
1636-
#define CHECKOUT_INIT { NULL, "" }
1637-
1638-
#define TEMPORARY_FILENAME_LENGTH 25
1639-
int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath, int *nr_checkouts);
1640-
void enable_delayed_checkout(struct checkout *state);
1641-
int finish_delayed_checkout(struct checkout *state, int *nr_checkouts);
1642-
/*
1643-
* Unlink the last component and schedule the leading directories for
1644-
* removal, such that empty directories get removed.
1645-
*/
1646-
void unlink_entry(const struct cache_entry *ce);
1647-
16481624
struct cache_def {
16491625
struct strbuf path;
16501626
int flags;

convert.c

Lines changed: 73 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,6 @@
2424
#define CONVERT_STAT_BITS_TXT_CRLF 0x2
2525
#define CONVERT_STAT_BITS_BIN 0x4
2626

27-
enum crlf_action {
28-
CRLF_UNDEFINED,
29-
CRLF_BINARY,
30-
CRLF_TEXT,
31-
CRLF_TEXT_INPUT,
32-
CRLF_TEXT_CRLF,
33-
CRLF_AUTO,
34-
CRLF_AUTO_INPUT,
35-
CRLF_AUTO_CRLF
36-
};
37-
3827
struct text_stat {
3928
/* NUL, CR, LF and CRLF counts */
4029
unsigned nul, lonecr, lonelf, crlf;
@@ -172,7 +161,7 @@ static int text_eol_is_crlf(void)
172161
return 0;
173162
}
174163

175-
static enum eol output_eol(enum crlf_action crlf_action)
164+
static enum eol output_eol(enum convert_crlf_action crlf_action)
176165
{
177166
switch (crlf_action) {
178167
case CRLF_BINARY:
@@ -246,7 +235,7 @@ static int has_crlf_in_index(const struct index_state *istate, const char *path)
246235
}
247236

248237
static int will_convert_lf_to_crlf(struct text_stat *stats,
249-
enum crlf_action crlf_action)
238+
enum convert_crlf_action crlf_action)
250239
{
251240
if (output_eol(crlf_action) != EOL_CRLF)
252241
return 0;
@@ -499,7 +488,7 @@ static int encode_to_worktree(const char *path, const char *src, size_t src_len,
499488
static int crlf_to_git(const struct index_state *istate,
500489
const char *path, const char *src, size_t len,
501490
struct strbuf *buf,
502-
enum crlf_action crlf_action, int conv_flags)
491+
enum convert_crlf_action crlf_action, int conv_flags)
503492
{
504493
struct text_stat stats;
505494
char *dst;
@@ -585,8 +574,8 @@ static int crlf_to_git(const struct index_state *istate,
585574
return 1;
586575
}
587576

588-
static int crlf_to_worktree(const char *src, size_t len,
589-
struct strbuf *buf, enum crlf_action crlf_action)
577+
static int crlf_to_worktree(const char *src, size_t len, struct strbuf *buf,
578+
enum convert_crlf_action crlf_action)
590579
{
591580
char *to_free = NULL;
592581
struct text_stat stats;
@@ -1247,7 +1236,7 @@ static const char *git_path_check_encoding(struct attr_check_item *check)
12471236
return value;
12481237
}
12491238

1250-
static enum crlf_action git_path_check_crlf(struct attr_check_item *check)
1239+
static enum convert_crlf_action git_path_check_crlf(struct attr_check_item *check)
12511240
{
12521241
const char *value = check->value;
12531242

@@ -1297,18 +1286,10 @@ static int git_path_check_ident(struct attr_check_item *check)
12971286
return !!ATTR_TRUE(value);
12981287
}
12991288

1300-
struct conv_attrs {
1301-
struct convert_driver *drv;
1302-
enum crlf_action attr_action; /* What attr says */
1303-
enum crlf_action crlf_action; /* When no attr is set, use core.autocrlf */
1304-
int ident;
1305-
const char *working_tree_encoding; /* Supported encoding or default encoding if NULL */
1306-
};
1307-
13081289
static struct attr_check *check;
13091290

1310-
static void convert_attrs(const struct index_state *istate,
1311-
struct conv_attrs *ca, const char *path)
1291+
void convert_attrs(const struct index_state *istate,
1292+
struct conv_attrs *ca, const char *path)
13121293
{
13131294
struct attr_check_item *ccheck = NULL;
13141295

@@ -1465,19 +1446,16 @@ void convert_to_git_filter_fd(const struct index_state *istate,
14651446
ident_to_git(dst->buf, dst->len, dst, ca.ident);
14661447
}
14671448

1468-
static int convert_to_working_tree_internal(const struct index_state *istate,
1469-
const char *path, const char *src,
1470-
size_t len, struct strbuf *dst,
1471-
int normalizing,
1472-
const struct checkout_metadata *meta,
1473-
struct delayed_checkout *dco)
1449+
static int convert_to_working_tree_ca_internal(const struct conv_attrs *ca,
1450+
const char *path, const char *src,
1451+
size_t len, struct strbuf *dst,
1452+
int normalizing,
1453+
const struct checkout_metadata *meta,
1454+
struct delayed_checkout *dco)
14741455
{
14751456
int ret = 0, ret_filter = 0;
1476-
struct conv_attrs ca;
1477-
1478-
convert_attrs(istate, &ca, path);
14791457

1480-
ret |= ident_to_worktree(src, len, dst, ca.ident);
1458+
ret |= ident_to_worktree(src, len, dst, ca->ident);
14811459
if (ret) {
14821460
src = dst->buf;
14831461
len = dst->len;
@@ -1487,49 +1465,56 @@ static int convert_to_working_tree_internal(const struct index_state *istate,
14871465
* is a smudge or process filter (even if the process filter doesn't
14881466
* support smudge). The filters might expect CRLFs.
14891467
*/
1490-
if ((ca.drv && (ca.drv->smudge || ca.drv->process)) || !normalizing) {
1491-
ret |= crlf_to_worktree(src, len, dst, ca.crlf_action);
1468+
if ((ca->drv && (ca->drv->smudge || ca->drv->process)) || !normalizing) {
1469+
ret |= crlf_to_worktree(src, len, dst, ca->crlf_action);
14921470
if (ret) {
14931471
src = dst->buf;
14941472
len = dst->len;
14951473
}
14961474
}
14971475

1498-
ret |= encode_to_worktree(path, src, len, dst, ca.working_tree_encoding);
1476+
ret |= encode_to_worktree(path, src, len, dst, ca->working_tree_encoding);
14991477
if (ret) {
15001478
src = dst->buf;
15011479
len = dst->len;
15021480
}
15031481

15041482
ret_filter = apply_filter(
1505-
path, src, len, -1, dst, ca.drv, CAP_SMUDGE, meta, dco);
1506-
if (!ret_filter && ca.drv && ca.drv->required)
1507-
die(_("%s: smudge filter %s failed"), path, ca.drv->name);
1483+
path, src, len, -1, dst, ca->drv, CAP_SMUDGE, meta, dco);
1484+
if (!ret_filter && ca->drv && ca->drv->required)
1485+
die(_("%s: smudge filter %s failed"), path, ca->drv->name);
15081486

15091487
return ret | ret_filter;
15101488
}
15111489

1512-
int async_convert_to_working_tree(const struct index_state *istate,
1513-
const char *path, const char *src,
1514-
size_t len, struct strbuf *dst,
1515-
const struct checkout_metadata *meta,
1516-
void *dco)
1490+
int async_convert_to_working_tree_ca(const struct conv_attrs *ca,
1491+
const char *path, const char *src,
1492+
size_t len, struct strbuf *dst,
1493+
const struct checkout_metadata *meta,
1494+
void *dco)
15171495
{
1518-
return convert_to_working_tree_internal(istate, path, src, len, dst, 0, meta, dco);
1496+
return convert_to_working_tree_ca_internal(ca, path, src, len, dst, 0,
1497+
meta, dco);
15191498
}
15201499

1521-
int convert_to_working_tree(const struct index_state *istate,
1522-
const char *path, const char *src,
1523-
size_t len, struct strbuf *dst,
1524-
const struct checkout_metadata *meta)
1500+
int convert_to_working_tree_ca(const struct conv_attrs *ca,
1501+
const char *path, const char *src,
1502+
size_t len, struct strbuf *dst,
1503+
const struct checkout_metadata *meta)
15251504
{
1526-
return convert_to_working_tree_internal(istate, path, src, len, dst, 0, meta, NULL);
1505+
return convert_to_working_tree_ca_internal(ca, path, src, len, dst, 0,
1506+
meta, NULL);
15271507
}
15281508

15291509
int renormalize_buffer(const struct index_state *istate, const char *path,
15301510
const char *src, size_t len, struct strbuf *dst)
15311511
{
1532-
int ret = convert_to_working_tree_internal(istate, path, src, len, dst, 1, NULL, NULL);
1512+
struct conv_attrs ca;
1513+
int ret;
1514+
1515+
convert_attrs(istate, &ca, path);
1516+
ret = convert_to_working_tree_ca_internal(&ca, path, src, len, dst, 1,
1517+
NULL, NULL);
15331518
if (ret) {
15341519
src = dst->buf;
15351520
len = dst->len;
@@ -1956,41 +1941,41 @@ static struct stream_filter *ident_filter(const struct object_id *oid)
19561941
}
19571942

19581943
/*
1959-
* Return an appropriately constructed filter for the path, or NULL if
1944+
* Return an appropriately constructed filter for the given ca, or NULL if
19601945
* the contents cannot be filtered without reading the whole thing
19611946
* in-core.
19621947
*
19631948
* Note that you would be crazy to set CRLF, smudge/clean or ident to a
19641949
* large binary blob you would want us not to slurp into the memory!
19651950
*/
1966-
struct stream_filter *get_stream_filter(const struct index_state *istate,
1967-
const char *path,
1968-
const struct object_id *oid)
1951+
struct stream_filter *get_stream_filter_ca(const struct conv_attrs *ca,
1952+
const struct object_id *oid)
19691953
{
1970-
struct conv_attrs ca;
19711954
struct stream_filter *filter = NULL;
19721955

1973-
convert_attrs(istate, &ca, path);
1974-
if (ca.drv && (ca.drv->process || ca.drv->smudge || ca.drv->clean))
1975-
return NULL;
1976-
1977-
if (ca.working_tree_encoding)
1956+
if (classify_conv_attrs(ca) != CA_CLASS_STREAMABLE)
19781957
return NULL;
19791958

1980-
if (ca.crlf_action == CRLF_AUTO || ca.crlf_action == CRLF_AUTO_CRLF)
1981-
return NULL;
1982-
1983-
if (ca.ident)
1959+
if (ca->ident)
19841960
filter = ident_filter(oid);
19851961

1986-
if (output_eol(ca.crlf_action) == EOL_CRLF)
1962+
if (output_eol(ca->crlf_action) == EOL_CRLF)
19871963
filter = cascade_filter(filter, lf_to_crlf_filter());
19881964
else
19891965
filter = cascade_filter(filter, &null_filter_singleton);
19901966

19911967
return filter;
19921968
}
19931969

1970+
struct stream_filter *get_stream_filter(const struct index_state *istate,
1971+
const char *path,
1972+
const struct object_id *oid)
1973+
{
1974+
struct conv_attrs ca;
1975+
convert_attrs(istate, &ca, path);
1976+
return get_stream_filter_ca(&ca, oid);
1977+
}
1978+
19941979
void free_stream_filter(struct stream_filter *filter)
19951980
{
19961981
filter->vtbl->free(filter);
@@ -2024,3 +2009,21 @@ void clone_checkout_metadata(struct checkout_metadata *dst,
20242009
if (blob)
20252010
oidcpy(&dst->blob, blob);
20262011
}
2012+
2013+
enum conv_attrs_classification classify_conv_attrs(const struct conv_attrs *ca)
2014+
{
2015+
if (ca->drv) {
2016+
if (ca->drv->process)
2017+
return CA_CLASS_INCORE_PROCESS;
2018+
if (ca->drv->smudge || ca->drv->clean)
2019+
return CA_CLASS_INCORE_FILTER;
2020+
}
2021+
2022+
if (ca->working_tree_encoding)
2023+
return CA_CLASS_INCORE;
2024+
2025+
if (ca->crlf_action == CRLF_AUTO || ca->crlf_action == CRLF_AUTO_CRLF)
2026+
return CA_CLASS_INCORE;
2027+
2028+
return CA_CLASS_STREAMABLE;
2029+
}

0 commit comments

Comments
 (0)