Skip to content

Commit dec0401

Browse files
committed
Merge branch 'jk/alt-odb-cleanup'
Codepaths involved in interacting alternate object store have been cleaned up. * jk/alt-odb-cleanup: alternates: use fspathcmp to detect duplicates sha1_file: always allow relative paths to alternates count-objects: report alternates via verbose mode fill_sha1_file: write into a strbuf alternates: store scratch buffer as strbuf fill_sha1_file: write "boring" characters alternates: use a separate scratch space alternates: encapsulate alt->base munging alternates: provide helper for allocating alternate alternates: provide helper for adding to alternates list link_alt_odb_entry: refactor string handling link_alt_odb_entry: handle normalize_path errors t5613: clarify "too deep" recursion tests t5613: do not chdir in main process t5613: whitespace/style cleanups t5613: use test_must_fail t5613: drop test_valid_repo function t5613: drop reachable_via function
2 parents af9a70c + ea0fc3b commit dec0401

File tree

12 files changed

+308
-222
lines changed

12 files changed

+308
-222
lines changed

Documentation/git-count-objects.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ objects nor valid packs
3838
+
3939
size-garbage: disk space consumed by garbage files, in KiB (unless -H is
4040
specified)
41+
+
42+
alternate: absolute path of alternate object databases; may appear
43+
multiple times, one line per path. Note that if the path contains
44+
non-printable characters, it may be surrounded by double-quotes and
45+
contain C-style backslashed escape sequences.
4146

4247
-H::
4348
--human-readable::

builtin/count-objects.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "dir.h"
99
#include "builtin.h"
1010
#include "parse-options.h"
11+
#include "quote.h"
1112

1213
static unsigned long garbage;
1314
static off_t size_garbage;
@@ -73,6 +74,14 @@ static int count_cruft(const char *basename, const char *path, void *data)
7374
return 0;
7475
}
7576

77+
static int print_alternate(struct alternate_object_database *alt, void *data)
78+
{
79+
printf("alternate: ");
80+
quote_c_style(alt->path, NULL, stdout, 0);
81+
putchar('\n');
82+
return 0;
83+
}
84+
7685
static char const * const count_objects_usage[] = {
7786
N_("git count-objects [-v] [-H | --human-readable]"),
7887
NULL
@@ -88,6 +97,8 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
8897
OPT_END(),
8998
};
9099

100+
git_config(git_default_config, NULL);
101+
91102
argc = parse_options(argc, argv, prefix, opts, count_objects_usage, 0);
92103
/* we do not take arguments other than flags for now */
93104
if (argc)
@@ -140,6 +151,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
140151
printf("prune-packable: %lu\n", packed_loose);
141152
printf("garbage: %lu\n", garbage);
142153
printf("size-garbage: %s\n", garbage_buf.buf);
154+
foreach_alt_odb(print_alternate, NULL);
143155
strbuf_release(&loose_buf);
144156
strbuf_release(&pack_buf);
145157
strbuf_release(&garbage_buf);

builtin/fsck.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -644,14 +644,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
644644
fsck_object_dir(get_object_directory());
645645

646646
prepare_alt_odb();
647-
for (alt = alt_odb_list; alt; alt = alt->next) {
648-
/* directory name, minus trailing slash */
649-
size_t namelen = alt->name - alt->base - 1;
650-
struct strbuf name = STRBUF_INIT;
651-
strbuf_add(&name, alt->base, namelen);
652-
fsck_object_dir(name.buf);
653-
strbuf_release(&name);
654-
}
647+
for (alt = alt_odb_list; alt; alt = alt->next)
648+
fsck_object_dir(alt->path);
655649
}
656650

657651
if (check_full) {

builtin/submodule--helper.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -492,20 +492,16 @@ static int add_possible_reference_from_superproject(
492492
{
493493
struct submodule_alternate_setup *sas = sas_cb;
494494

495-
/* directory name, minus trailing slash */
496-
size_t namelen = alt->name - alt->base - 1;
497-
struct strbuf name = STRBUF_INIT;
498-
strbuf_add(&name, alt->base, namelen);
499-
500495
/*
501496
* If the alternate object store is another repository, try the
502497
* standard layout with .git/modules/<name>/objects
503498
*/
504-
if (ends_with(name.buf, ".git/objects")) {
499+
if (ends_with(alt->path, ".git/objects")) {
505500
char *sm_alternate;
506501
struct strbuf sb = STRBUF_INIT;
507502
struct strbuf err = STRBUF_INIT;
508-
strbuf_add(&sb, name.buf, name.len - strlen("objects"));
503+
strbuf_add(&sb, alt->path, strlen(alt->path) - strlen("objects"));
504+
509505
/*
510506
* We need to end the new path with '/' to mark it as a dir,
511507
* otherwise a submodule name containing '/' will be broken
@@ -533,7 +529,6 @@ static int add_possible_reference_from_superproject(
533529
strbuf_release(&sb);
534530
}
535531

536-
strbuf_release(&name);
537532
return 0;
538533
}
539534

cache.h

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,16 +1390,46 @@ extern void remove_scheduled_dirs(void);
13901390

13911391
extern struct alternate_object_database {
13921392
struct alternate_object_database *next;
1393-
char *name;
1394-
char base[FLEX_ARRAY]; /* more */
1393+
1394+
/* see alt_scratch_buf() */
1395+
struct strbuf scratch;
1396+
size_t base_len;
1397+
1398+
char path[FLEX_ARRAY];
13951399
} *alt_odb_list;
13961400
extern void prepare_alt_odb(void);
13971401
extern void read_info_alternates(const char * relative_base, int depth);
13981402
extern char *compute_alternate_path(const char *path, struct strbuf *err);
1399-
extern void add_to_alternates_file(const char *reference);
14001403
typedef int alt_odb_fn(struct alternate_object_database *, void *);
14011404
extern int foreach_alt_odb(alt_odb_fn, void*);
14021405

1406+
/*
1407+
* Allocate a "struct alternate_object_database" but do _not_ actually
1408+
* add it to the list of alternates.
1409+
*/
1410+
struct alternate_object_database *alloc_alt_odb(const char *dir);
1411+
1412+
/*
1413+
* Add the directory to the on-disk alternates file; the new entry will also
1414+
* take effect in the current process.
1415+
*/
1416+
extern void add_to_alternates_file(const char *dir);
1417+
1418+
/*
1419+
* Add the directory to the in-memory list of alternates (along with any
1420+
* recursive alternates it points to), but do not modify the on-disk alternates
1421+
* file.
1422+
*/
1423+
extern void add_to_alternates_memory(const char *dir);
1424+
1425+
/*
1426+
* Returns a scratch strbuf pre-filled with the alternate object directory,
1427+
* including a trailing slash, which can be used to access paths in the
1428+
* alternate. Always use this over direct access to alt->scratch, as it
1429+
* cleans up any previous use of the scratch buffer.
1430+
*/
1431+
extern struct strbuf *alt_scratch_buf(struct alternate_object_database *alt);
1432+
14031433
struct pack_window {
14041434
struct pack_window *next;
14051435
unsigned char *base;

0 commit comments

Comments
 (0)