environment: add global variable to disable replacement
This new "read_replace_refs" global variable is set to 1 by default, so that replace refs are used by default. But reachability traversal and packing commands ("cmd_fsck", "cmd_prune", "cmd_pack_objects", "upload_pack", "cmd_unpack_objects") set it to 0, as they must work with the original DAG. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Christian Couder committed
Jan 23, 2009 at 10:07 UTC
dae556bdb1e2ad6fb5eafe82e975bde01029fca9
9 files changed
+35
builtin-fsck.c
+1
@@ -589,6 +589,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
589
struct alternate_object_database *alt;
590
591
errors_found = 0;
592
+ read_replace_refs = 0;
593
594
argc = parse_options(argc, argv, prefix, fsck_opts, fsck_usage, 0);
595
if (write_lost_and_found) {
builtin-pack-objects.c
+2
@@ -2103,6 +2103,8 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
2103
int rp_ac_alloc = 64;
2104
int rp_ac;
2105
2106
+ read_replace_refs = 0;
2107
+
2108
rp_av = xcalloc(rp_ac_alloc, sizeof(*rp_av));
2109
2110
rp_av[0] = "pack-objects";
builtin-prune.c
+1
@@ -140,6 +140,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
140
char *s;
141
142
save_commit_buffer = 0;
143
+ read_replace_refs = 0;
144
init_revisions(&revs, prefix);
145
146
argc = parse_options(argc, argv, prefix, options, prune_usage, 0);
builtin-unpack-objects.c
+2
@@ -495,6 +495,8 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
495
int i;
496
unsigned char sha1[20];
497
498
+ read_replace_refs = 0;
499
+
500
git_config(git_default_config, NULL);
501
502
quiet = !isatty(2);
cache.h
+1
@@ -516,6 +516,7 @@ extern size_t packed_git_window_size;
516
extern size_t packed_git_limit;
517
extern size_t delta_base_cache_limit;
518
extern int auto_crlf;
519
+extern int read_replace_refs;
520
extern int fsync_object_files;
521
extern int core_preload_index;
522
environment.c
+1
@@ -38,6 +38,7 @@ int pager_use_color = 1;
38
const char *editor_program;
39
const char *excludes_file;
40
int auto_crlf = 0; /* 1: both ways, -1: only when adding git objects */
41
+int read_replace_refs = 1;
42
enum safe_crlf safe_crlf = SAFE_CRLF_WARN;
43
unsigned whitespace_rule_cfg = WS_DEFAULT_RULE;
44
enum branch_track git_branch_track = BRANCH_TRACK_REMOTE;
replace_object.c
+3
@@ -94,6 +94,9 @@ const unsigned char *lookup_replace_object(const unsigned char *sha1)
94
int pos, depth = MAXREPLACEDEPTH;
95
const unsigned char *cur = sha1;
96
97
+ if (!read_replace_refs)
98
+ return sha1;
99
+
100
prepare_replace_object();
101
102
/* Try to recursively replace the object */
t/t6050-replace.sh
+23
@@ -82,6 +82,29 @@ test_expect_success 'tag replaced commit' '
82
git mktag <tag.sig >.git/refs/tags/mytag 2>message
83
'
84
85
+test_expect_success '"git fsck" works' '
86
+ git fsck master > fsck_master.out &&
87
+ grep "dangling commit $R" fsck_master.out &&
88
+ grep "dangling tag $(cat .git/refs/tags/mytag)" fsck_master.out &&
89
+ test -z "$(git fsck)"
90
+'
91
+
92
+test_expect_success 'repack, clone and fetch work' '
93
+ git repack -a -d &&
94
+ git clone --no-hardlinks . clone_dir &&
95
+ cd clone_dir &&
96
+ git show HEAD~5 | grep "A U Thor" &&
97
+ git show $HASH2 | grep "A U Thor" &&
98
+ git cat-file commit $R &&
99
+ git repack -a -d &&
100
+ test_must_fail git cat-file commit $R &&
101
+ git fetch ../ "refs/replace/*:refs/replace/*" &&
102
+ git show HEAD~5 | grep "O Thor" &&
103
+ git show $HASH2 | grep "O Thor" &&
104
+ git cat-file commit $R &&
105
+ cd ..
106
+'
107
+
108
#
109
#
110
test_done
upload-pack.c
+1
@@ -618,6 +618,7 @@ int main(int argc, char **argv)
618
int strict = 0;
619
620
git_extract_argv0_path(argv[0]);
621
+ read_replace_refs = 0;
622
623
for (i = 1; i < argc; i++) {
624
char *arg = argv[i];