Skip to content

Commit

Permalink
environment: add global variable to disable replacement
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
chriscool authored and gitster committed Jun 1, 2009
1 parent cc400f5 commit dae556b
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions builtin-fsck.c
Expand Up @@ -589,6 +589,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
struct alternate_object_database *alt;

errors_found = 0;
read_replace_refs = 0;

argc = parse_options(argc, argv, prefix, fsck_opts, fsck_usage, 0);
if (write_lost_and_found) {
Expand Down
2 changes: 2 additions & 0 deletions builtin-pack-objects.c
Expand Up @@ -2103,6 +2103,8 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
int rp_ac_alloc = 64;
int rp_ac;

read_replace_refs = 0;

rp_av = xcalloc(rp_ac_alloc, sizeof(*rp_av));

rp_av[0] = "pack-objects";
Expand Down
1 change: 1 addition & 0 deletions builtin-prune.c
Expand Up @@ -140,6 +140,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
char *s;

save_commit_buffer = 0;
read_replace_refs = 0;
init_revisions(&revs, prefix);

argc = parse_options(argc, argv, prefix, options, prune_usage, 0);
Expand Down
2 changes: 2 additions & 0 deletions builtin-unpack-objects.c
Expand Up @@ -495,6 +495,8 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
int i;
unsigned char sha1[20];

read_replace_refs = 0;

git_config(git_default_config, NULL);

quiet = !isatty(2);
Expand Down
1 change: 1 addition & 0 deletions cache.h
Expand Up @@ -516,6 +516,7 @@ extern size_t packed_git_window_size;
extern size_t packed_git_limit;
extern size_t delta_base_cache_limit;
extern int auto_crlf;
extern int read_replace_refs;
extern int fsync_object_files;
extern int core_preload_index;

Expand Down
1 change: 1 addition & 0 deletions environment.c
Expand Up @@ -38,6 +38,7 @@ int pager_use_color = 1;
const char *editor_program;
const char *excludes_file;
int auto_crlf = 0; /* 1: both ways, -1: only when adding git objects */
int read_replace_refs = 1;
enum safe_crlf safe_crlf = SAFE_CRLF_WARN;
unsigned whitespace_rule_cfg = WS_DEFAULT_RULE;
enum branch_track git_branch_track = BRANCH_TRACK_REMOTE;
Expand Down
3 changes: 3 additions & 0 deletions replace_object.c
Expand Up @@ -94,6 +94,9 @@ const unsigned char *lookup_replace_object(const unsigned char *sha1)
int pos, depth = MAXREPLACEDEPTH;
const unsigned char *cur = sha1;

if (!read_replace_refs)
return sha1;

prepare_replace_object();

/* Try to recursively replace the object */
Expand Down
23 changes: 23 additions & 0 deletions t/t6050-replace.sh
Expand Up @@ -82,6 +82,29 @@ test_expect_success 'tag replaced commit' '
git mktag <tag.sig >.git/refs/tags/mytag 2>message
'

test_expect_success '"git fsck" works' '
git fsck master > fsck_master.out &&
grep "dangling commit $R" fsck_master.out &&
grep "dangling tag $(cat .git/refs/tags/mytag)" fsck_master.out &&
test -z "$(git fsck)"
'

test_expect_success 'repack, clone and fetch work' '
git repack -a -d &&
git clone --no-hardlinks . clone_dir &&
cd clone_dir &&
git show HEAD~5 | grep "A U Thor" &&
git show $HASH2 | grep "A U Thor" &&
git cat-file commit $R &&
git repack -a -d &&
test_must_fail git cat-file commit $R &&
git fetch ../ "refs/replace/*:refs/replace/*" &&
git show HEAD~5 | grep "O Thor" &&
git show $HASH2 | grep "O Thor" &&
git cat-file commit $R &&
cd ..
'

#
#
test_done
1 change: 1 addition & 0 deletions upload-pack.c
Expand Up @@ -618,6 +618,7 @@ int main(int argc, char **argv)
int strict = 0;

git_extract_argv0_path(argv[0]);
read_replace_refs = 0;

for (i = 1; i < argc; i++) {
char *arg = argv[i];
Expand Down

0 comments on commit dae556b

Please sign in to comment.