Skip to content

Commit 174774c

Browse files
committed
Merge branch 'sb/object-store-replace'
The effort to pass the repository in-core structure throughout the API continues. This round deals with the code that implements the refs/replace/ mechanism. * sb/object-store-replace: replace-object: allow lookup_replace_object to handle arbitrary repositories replace-object: allow do_lookup_replace_object to handle arbitrary repositories replace-object: allow prepare_replace_object to handle arbitrary repositories refs: allow for_each_replace_ref to handle arbitrary repositories refs: store the main ref store inside the repository struct replace-object: add repository argument to lookup_replace_object replace-object: add repository argument to do_lookup_replace_object replace-object: add repository argument to prepare_replace_object refs: add repository argument to for_each_replace_ref refs: add repository argument to get_main_ref_store replace-object: check_replace_refs is safe in multi repo environment replace-object: eliminate replace objects prepared flag object-store: move lookup_replace_object to replace-object.h replace-object: move replace_map to object store replace_object: use oidmap
2 parents b10edb2 + 90e777f commit 174774c

17 files changed

+134
-150
lines changed

builtin/mktag.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "builtin.h"
22
#include "tag.h"
3+
#include "replace-object.h"
34

45
/*
56
* A signature file has a very simple fixed format: four lines
@@ -24,7 +25,7 @@ static int verify_object(const struct object_id *oid, const char *expected_type)
2425
enum object_type type;
2526
unsigned long size;
2627
void *buffer = read_object_file(oid, &type, &size);
27-
const struct object_id *repl = lookup_replace_object(oid);
28+
const struct object_id *repl = lookup_replace_object(the_repository, oid);
2829

2930
if (buffer) {
3031
if (type == type_from_string(expected_type))

builtin/pack-refs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "builtin.h"
22
#include "parse-options.h"
33
#include "refs.h"
4+
#include "repository.h"
45

56
static char const * const pack_refs_usage[] = {
67
N_("git pack-refs [<options>]"),
@@ -17,5 +18,5 @@ int cmd_pack_refs(int argc, const char **argv, const char *prefix)
1718
};
1819
if (parse_options(argc, argv, prefix, opts, pack_refs_usage, 0))
1920
usage_with_options(pack_refs_usage, opts);
20-
return refs_pack_refs(get_main_ref_store(), flags);
21+
return refs_pack_refs(get_main_ref_store(the_repository), flags);
2122
}

builtin/replace.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include "refs.h"
1515
#include "parse-options.h"
1616
#include "run-command.h"
17+
#include "object-store.h"
18+
#include "repository.h"
1719
#include "tag.h"
1820

1921
static const char * const git_replace_usage[] = {
@@ -83,7 +85,7 @@ static int list_replace_refs(const char *pattern, const char *format)
8385
"valid formats are 'short', 'medium' and 'long'\n",
8486
format);
8587

86-
for_each_replace_ref(show_reference, (void *)&data);
88+
for_each_replace_ref(the_repository, show_reference, (void *)&data);
8789

8890
return 0;
8991
}

cache.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,25 +1193,6 @@ static inline void *read_object_file(const struct object_id *oid, enum object_ty
11931193
return read_object_file_extended(oid, type, size, 1);
11941194
}
11951195

1196-
/*
1197-
* This internal function is only declared here for the benefit of
1198-
* lookup_replace_object(). Please do not call it directly.
1199-
*/
1200-
extern const struct object_id *do_lookup_replace_object(const struct object_id *oid);
1201-
1202-
/*
1203-
* If object sha1 should be replaced, return the replacement object's
1204-
* name (replaced recursively, if necessary). The return value is
1205-
* either sha1 or a pointer to a permanently-allocated value. When
1206-
* object replacement is suppressed, always return sha1.
1207-
*/
1208-
static inline const struct object_id *lookup_replace_object(const struct object_id *oid)
1209-
{
1210-
if (!check_replace_refs)
1211-
return oid;
1212-
return do_lookup_replace_object(oid);
1213-
}
1214-
12151196
/* Read and unpack an object file into memory, write memory to an object file */
12161197
extern int oid_object_info(const struct object_id *, unsigned long *);
12171198

environment.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const char *editor_program;
5151
const char *askpass_program;
5252
const char *excludes_file;
5353
enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;
54-
int check_replace_refs = 1;
54+
int check_replace_refs = 1; /* NEEDSWORK: rename to read_replace_refs */
5555
char *git_replace_ref_base;
5656
enum eol core_eol = EOL_UNSET;
5757
int global_conv_flags_eol = CONV_EOL_RNDTRP_WARN;

object-store.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef OBJECT_STORE_H
22
#define OBJECT_STORE_H
33

4+
#include "oidmap.h"
5+
46
struct alternate_object_database {
57
struct alternate_object_database *next;
68

@@ -93,6 +95,12 @@ struct raw_object_store {
9395
struct alternate_object_database *alt_odb_list;
9496
struct alternate_object_database **alt_odb_tail;
9597

98+
/*
99+
* Objects that should be substituted by other objects
100+
* (see git-replace(1)).
101+
*/
102+
struct oidmap *replace_map;
103+
96104
/*
97105
* private data
98106
*

object.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "cache.h"
22
#include "object.h"
3+
#include "replace-object.h"
34
#include "blob.h"
45
#include "tree.h"
56
#include "commit.h"
@@ -246,7 +247,7 @@ struct object *parse_object(const struct object_id *oid)
246247
unsigned long size;
247248
enum object_type type;
248249
int eaten;
249-
const struct object_id *repl = lookup_replace_object(oid);
250+
const struct object_id *repl = lookup_replace_object(the_repository, oid);
250251
void *buffer;
251252
struct object *obj;
252253

0 commit comments

Comments
 (0)