git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
fd3e37918c1178a1e9ee7abf97fa2852e59c414c blob 3962 bytes (raw)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
 
#!/bin/sh

test_description='basic tests for transfering external ODBs'

. ./test-lib.sh

ORIG_SOURCE="$PWD/.git"
export ORIG_SOURCE

ALT_SOURCE1="$PWD/alt-repo1/.git"
export ALT_SOURCE1
write_script odb-helper1 <<\EOF
die() {
	printf >&2 "%s\n" "$@"
	exit 1
}
GIT_DIR=$ALT_SOURCE1; export GIT_DIR
case "$1" in
init)
	echo "capability=get_git_obj"
	echo "capability=have"
	;;
have)
	git cat-file --batch-check --batch-all-objects |
	awk '{print $1 " " $3 " " $2}'
	;;
get_git_obj)
	cat "$GIT_DIR"/objects/$(echo $2 | sed 's#..#&/#')
	;;
put_raw_obj)
	sha1="$2"
	size="$3"
	kind="$4"
	writen=$(git hash-object -w -t "$kind" --stdin)
	test "$writen" = "$sha1" || die "bad sha1 passed '$sha1' vs writen '$writen'"
	ref_hash=$(echo "$sha1 $size $kind" | GIT_DIR=$ORIG_SOURCE GIT_NO_EXTERNAL_ODB=1 git hash-object -w -t blob --stdin) || exit
	GIT_DIR=$ORIG_SOURCE git update-ref refs/odbs/magic/"$sha1" "$ref_hash"
	;;
*)
	die "unknown command '$1'"
	;;
esac
EOF
HELPER1="\"$PWD\"/odb-helper1"

OTHER_SOURCE="$PWD/.git"
export OTHER_SOURCE

ALT_SOURCE2="$PWD/alt-repo2/.git"
export ALT_SOURCE2
write_script odb-helper2 <<\EOF
die() {
	printf >&2 "%s\n" "$@"
	exit 1
}
GIT_DIR=$ALT_SOURCE2; export GIT_DIR
case "$1" in
init)
	echo "capability=get_git_obj"
	echo "capability=have"
	;;
have)
	GIT_DIR=$OTHER_SOURCE git for-each-ref --format='%(objectname)' refs/odbs/magic/ | GIT_DIR=$OTHER_SOURCE xargs git show
	;;
get_git_obj)
	OBJ_FILE="$GIT_DIR"/objects/$(echo $2 | sed 's#..#&/#')
	if ! test -f "$OBJ_FILE"
	then
		# "Download" the missing object by copying it from alt-repo1
		OBJ_DIR=$(echo $2 | sed 's/\(..\).*/\1/')
		OBJ_BASE=$(basename "$OBJ_FILE")
		ALT_OBJ_DIR1="$ALT_SOURCE1/objects/$OBJ_DIR"
		ALT_OBJ_DIR2="$ALT_SOURCE2/objects/$OBJ_DIR"
		mkdir -p "$ALT_OBJ_DIR2" || die "Could not mkdir '$ALT_OBJ_DIR2'"
		OBJ_SRC="$ALT_OBJ_DIR1/$OBJ_BASE"
		cp "$OBJ_SRC" "$ALT_OBJ_DIR2" ||
		die "Could not cp '$OBJ_SRC' into '$ALT_OBJ_DIR2'"
	fi
	cat "$OBJ_FILE" || die "Could not cat '$OBJ_FILE'"
	;;
put_raw_obj)
	sha1="$2"
	size="$3"
	kind="$4"
	writen=$(git hash-object -w -t "$kind" --stdin)
	test "$writen" = "$sha1" || die "bad sha1 passed '$sha1' vs writen '$writen'"
	ref_hash=$(echo "$sha1 $size $kind" | GIT_DIR=$OTHER_SOURCE GIT_NO_EXTERNAL_ODB=1 git hash-object -w -t blob --stdin) || exit
	GIT_DIR=$OTHER_SOURCE git update-ref refs/odbs/magic/"$sha1" "$ref_hash"
	;;
*)
	die "unknown command '$1'"
	;;
esac
EOF
HELPER2="\"$PWD\"/odb-helper2"

test_expect_success 'setup first alternate repo' '
	git init alt-repo1 &&
	test_commit zero &&
	git config odb.magic.scriptCommand "$HELPER1"
'

test_expect_success 'setup other repo and its alternate repo' '
	git init other-repo &&
	git init alt-repo2 &&
	(cd other-repo &&
	 git remote add origin .. &&
	 git pull origin master &&
	 git checkout master &&
	 git log)
'

test_expect_success 'new blobs are put in first object store' '
	echo "* odb=magic" >.gitattributes &&
	GIT_NO_EXTERNAL_ODB=1 git add .gitattributes &&
	GIT_NO_EXTERNAL_ODB=1 git commit -m "Add .gitattributes" &&
	test_commit one &&
	hash1=$(git ls-tree HEAD | grep one.t | cut -f1 | cut -d\  -f3) &&
	content=$(cd alt-repo1 && git show "$hash1") &&
	test "$content" = "one" &&
	test_commit two &&
	hash2=$(git ls-tree HEAD | grep two.t | cut -f1 | cut -d\  -f3) &&
	content=$(cd alt-repo1 && git show "$hash2") &&
	test "$content" = "two"
'

test_expect_success 'other repo gets the blobs from object store' '
	(cd other-repo &&
	 git fetch origin "refs/odbs/magic/*:refs/odbs/magic/*" &&
	 test_must_fail git cat-file blob "$hash1" &&
	 test_must_fail git cat-file blob "$hash2" &&
	 git config odb.magic.scriptCommand "$HELPER2" &&
	 git cat-file blob "$hash1" &&
	 git cat-file blob "$hash2"
	)
'

test_expect_success 'other repo gets everything else' '
	(cd other-repo &&
	 git fetch origin &&
	 content=$(git show "$hash1") &&
	 test "$content" = "one" &&
	 content=$(git show "$hash2") &&
	 test "$content" = "two")
'

test_done
debug log:

solving fd3e37918c ...
found fd3e37918c in https://public-inbox.org/git/20180319133147.15413-36-chriscool@tuxfamily.org/
found 065ec7d759 in https://public-inbox.org/git/20180319133147.15413-21-chriscool@tuxfamily.org/

applying [1/2] https://public-inbox.org/git/20180319133147.15413-21-chriscool@tuxfamily.org/
diff --git a/t/t0510-transfer-e-odb.sh b/t/t0510-transfer-e-odb.sh
new file mode 100755
index 0000000000..065ec7d759


applying [2/2] https://public-inbox.org/git/20180319133147.15413-36-chriscool@tuxfamily.org/
diff --git a/t/t0510-transfer-e-odb.sh b/t/t0510-transfer-e-odb.sh
index 065ec7d759..fd3e37918c 100755

Checking patch t/t0510-transfer-e-odb.sh...
Applied patch t/t0510-transfer-e-odb.sh cleanly.
Checking patch t/t0510-transfer-e-odb.sh...
Applied patch t/t0510-transfer-e-odb.sh cleanly.

index at:
100755 fd3e37918c1178a1e9ee7abf97fa2852e59c414c	t/t0510-transfer-e-odb.sh

Code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).