Skip to content

Commit 723d8e3

Browse files
committed
Move in some generation scripts
1 parent c01a2a3 commit 723d8e3

File tree

9 files changed

+147
-2
lines changed

9 files changed

+147
-2
lines changed

other-test-repos/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/clone/
2+
/repo/

other-test-repos/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Other tests
1+
# Other test repositories
2+
3+
Scripts in this directory can be used to generate the more complex test repositories.
24

35
Tests that are very large will not be included here to keep this repository small:
46

@@ -18,7 +20,7 @@ There are also some tests that could not be included here conveniently:
1820
- <https://github.com/cirosantilli/test-long-filename-256>
1921
- <https://github.com/cirosantilli/test-min-sane>
2022
- <https://github.com/cirosantilli/test-refs-api-tags-pulls-block>
21-
- <https://github.com/cirosantilli/test-streak>, <https://github.com/cirosantilli/test-streak-1000>
23+
- <https://github.com/cirosantilli/test-streak>, <https://github.com/cirosantilli/test-streak-1000>, [streak.py](streak.py), <http://stackoverflow.com/questions/20099235/who-is-the-user-with-the-longest-streak-on-github/27742165#27742165>
2224
- <https://github.com/cirosantilli/test-submodule-contributing>
2325
- <https://github.com/cirosantilli/test-symlink-contributing>
2426
- <https://github.com/cirosantilli/test-symlink-middle-null>

other-test-repos/commit-meta.bashrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Fixed commit metadata.
2+
date='2000-01-01T00:00:00+0000'
3+
4+
name='a'
5+
export GIT_COMMITTER_EMAIL="$email"
6+
export GIT_COMMITTER_NAME="$name"
7+
export GIT_COMMITTER_DATE="$date"
8+
export GIT_AUTHOR_EMAIL="$email"
9+
export GIT_AUTHOR_NAME="$name"
10+
export GIT_AUTHOR_DATE="$date"

other-test-repos/duplicate-parent.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
# Try to create a commit with two times it's parent with git-commit-tree
6+
# Outcome on Git 2.7: commit fails. Will try again with raw object creation from Python later on.
7+
8+
. commit-meta.bashrc
9+
. init.bashrc
10+
11+
# Directory parameters.
12+
blob_content=''
13+
blob_name='a'
14+
blob_mode='100644'
15+
dir_name='directory'
16+
17+
# Blob.
18+
blob_sha="$(printf "$blob_content" | git hash-object --stdin -w)"
19+
20+
# Tree.
21+
tree_sha="$(printf "\
22+
$blob_mode blob $blob_sha\t$blob_name
23+
" | git mktree)"
24+
25+
# Commit 1.
26+
commit_sha="$( \
27+
git commit-tree -m 0 "$tree_sha")"
28+
git branch master "$commit_sha"
29+
30+
# Commit 2 that has the duplicate parent.
31+
commit_sha="$(git commit-tree -m 1 -p "$commit_sha" -p "$commit_sha" "$tree_sha")"
32+
git update-ref master "$commit_sha"

other-test-repos/finish-bare.bashrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
git clone -q repo clone

other-test-repos/init.bashrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
rm -rf repo clone
2+
mkdir -p repo
3+
cd repo
4+
git init -q
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env python3
2+
3+
import datetime
4+
import os
5+
6+
date0 = datetime.date(2000, 1, 1)
7+
datef = datetime.date(2100, 1, 1)
8+
date = date0
9+
while date < datef:
10+
s = date.strftime("%Y-%m-%dT01:00:00")
11+
cmd = 'GIT_COMMITTER_DATE="{0}" git commit --allow-empty --allow-empty-message -m "" --date="{0}"'.format(s)
12+
print cmd
13+
os.system(cmd)
14+
date += datetime.timedelta(days=1)
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
# This was an attempt to calculate SHAs manually.
6+
# It stopped halfway because Bash cannot store NUL characters in variables,
7+
# so we had to move to Python.
8+
9+
. commit-meta.bashrc
10+
. init.bashrc
11+
12+
# Directory parameters.
13+
blob_content='blob content'
14+
blob_name='file'
15+
blob_mode='100644'
16+
dir_name='directory'
17+
18+
strlen() {
19+
printf "$1" | wc -c
20+
}
21+
22+
sha_calc() {
23+
type="$1"
24+
content="$2"
25+
printf "${type} $(strlen "$content")\0${content}" | sha1sum
26+
}
27+
28+
# Blob.
29+
blob_sha="$(printf "$blob_content" | git hash-object --stdin -w)"
30+
echo "$blob_sha"
31+
echo "$(sha_calc "blob" "$blob_content")"
32+
echo
33+
34+
# Tree 1.
35+
sub_tree_sha="$(printf "\
36+
$blob_mode blob $blob_sha\t$blob_name
37+
" | git mktree)"
38+
echo "$sub_tree_sha"
39+
# TODO the problem here is the null character
40+
# which is impossible for bash to put into a variable.
41+
echo "$(sha_calc "tree" "${blob_mode} ${blob_name}\0${blob_sha}")"
42+
echo
43+
44+
# Tree 2.
45+
root_tree="$(printf "\
46+
040000 tree $sub_tree_sha\t$dir_name
47+
100644 blob $blob_sha\t$blob_name
48+
" | git mktree)"
49+
50+
commit="$(git commit-tree -m 0 "$root_tree")"
51+
git branch master "$commit"
52+
53+
# Modify the master branch
54+
root_tree="$((
55+
git ls-tree HEAD:./
56+
printf "\
57+
100644 blob $blob_sha\tb
58+
") | git mktree)"
59+
60+
commit="$(git commit-tree -m 1 -p "$(git rev-parse HEAD)" "$root_tree")"
61+
# Bare
62+
git update-ref master "$commit"

other-test-repos/streak.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env python3
2+
3+
import datetime
4+
import os
5+
6+
repo = 'repo'
7+
os.mkdir(repo)
8+
os.cwd(repo)
9+
10+
date0 = datetime.date(2000, 1, 1)
11+
datef = datetime.date(2100, 1, 1)
12+
date = date0
13+
while date < datef:
14+
s = date.strftime('%Y-%m-%dT01:00:00')
15+
cmd = 'GIT_COMMITTER_DATE="{0}" git commit --allow-empty --allow-empty-message -m "" --date="{0}"'.format(s)
16+
print(cmd)
17+
os.system(cmd)
18+
date += datetime.timedelta(days=1)

0 commit comments

Comments
 (0)