diff options
author | Christopher Larson <kergoth@gmail.com> | 2017-05-13 02:46:27 +0500 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-06-02 13:36:57 +0100 |
commit | 2a60c406372d400437ecaa8712e6dc80b3d9fcec (patch) | |
tree | bdbd2d112e04d36a475c98735ed4cb7c054b702b /bitbake/lib/bb | |
parent | ab4e578b86efcf533c43dfa76e97ea98cd9a5808 (diff) | |
download | poky-2a60c406372d400437ecaa8712e6dc80b3d9fcec.tar.gz |
bitbake: git-make-shallow: add script to make a git repo shallow
This script will be used by the git fetcher to create shallow mirror tarballs.
usage: git-make-shallow [-h] [--ref REF] [--shrink] REVISION [REVISION ...]
Remove the history of the specified revisions, then optionally filter the
available refs to those specified.
positional arguments:
REVISION a git revision/commit
optional arguments:
-h, --help show this help message and exit
--ref REF, -r REF remove all but the specified refs (cumulative)
--shrink, -s shrink the git repository by repacking and pruning
While git does provide the ability to clone at a specific depth, and fetch all
remote refs at a particular depth, the depth is across all branches/tags, and
doesn't provide the flexibility we need, hence this script.
Refs (branches+tags) can be filtered, as the process of history removal scales
up rapidly with the number of refs. Even the existing `git fetch --depth=` is
extremely slow on an upstream kernel repository with all the branches and tags
kept.
This uses the same underlying mechanism to implement the history removal which
git itself uses (.git/shallow), and the results, when configured similarly, are
in line with the results git itself produces with `fetch --depth`.
(Bitbake rev: 0254020f0e1911c0eaf99111b91828d2a74a4ee1)
Signed-off-by: Christopher Larson <chris_larson@mentor.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb')
-rw-r--r-- | bitbake/lib/bb/tests/fetch.py | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py index 0fd2c02163..510071d25d 100644 --- a/bitbake/lib/bb/tests/fetch.py +++ b/bitbake/lib/bb/tests/fetch.py | |||
@@ -852,3 +852,130 @@ class FetchCheckStatusTest(FetcherTest): | |||
852 | self.assertTrue(ret, msg="URI %s, can't check status" % (u)) | 852 | self.assertTrue(ret, msg="URI %s, can't check status" % (u)) |
853 | 853 | ||
854 | connection_cache.close_connections() | 854 | connection_cache.close_connections() |
855 | |||
856 | |||
857 | class GitMakeShallowTest(FetcherTest): | ||
858 | bitbake_dir = os.path.join(os.path.dirname(os.path.join(__file__)), '..', '..', '..') | ||
859 | make_shallow_path = os.path.join(bitbake_dir, 'bin', 'git-make-shallow') | ||
860 | |||
861 | def setUp(self): | ||
862 | FetcherTest.setUp(self) | ||
863 | self.gitdir = os.path.join(self.tempdir, 'gitshallow') | ||
864 | bb.utils.mkdirhier(self.gitdir) | ||
865 | bb.process.run('git init', cwd=self.gitdir) | ||
866 | |||
867 | def assertRefs(self, expected_refs): | ||
868 | actual_refs = self.git(['for-each-ref', '--format=%(refname)']).splitlines() | ||
869 | full_expected = self.git(['rev-parse', '--symbolic-full-name'] + expected_refs).splitlines() | ||
870 | self.assertEqual(sorted(full_expected), sorted(actual_refs)) | ||
871 | |||
872 | def assertRevCount(self, expected_count, args=None): | ||
873 | if args is None: | ||
874 | args = ['HEAD'] | ||
875 | revs = self.git(['rev-list'] + args) | ||
876 | actual_count = len(revs.splitlines()) | ||
877 | self.assertEqual(expected_count, actual_count, msg='Object count `%d` is not the expected `%d`' % (actual_count, expected_count)) | ||
878 | |||
879 | def git(self, cmd): | ||
880 | if isinstance(cmd, str): | ||
881 | cmd = 'git ' + cmd | ||
882 | else: | ||
883 | cmd = ['git'] + cmd | ||
884 | return bb.process.run(cmd, cwd=self.gitdir)[0] | ||
885 | |||
886 | def make_shallow(self, args=None): | ||
887 | if args is None: | ||
888 | args = ['HEAD'] | ||
889 | return bb.process.run([self.make_shallow_path] + args, cwd=self.gitdir) | ||
890 | |||
891 | def add_empty_file(self, path, msg=None): | ||
892 | if msg is None: | ||
893 | msg = path | ||
894 | open(os.path.join(self.gitdir, path), 'w').close() | ||
895 | self.git(['add', path]) | ||
896 | self.git(['commit', '-m', msg, path]) | ||
897 | |||
898 | def test_make_shallow_single_branch_no_merge(self): | ||
899 | self.add_empty_file('a') | ||
900 | self.add_empty_file('b') | ||
901 | self.assertRevCount(2) | ||
902 | self.make_shallow() | ||
903 | self.assertRevCount(1) | ||
904 | |||
905 | def test_make_shallow_single_branch_one_merge(self): | ||
906 | self.add_empty_file('a') | ||
907 | self.add_empty_file('b') | ||
908 | self.git('checkout -b a_branch') | ||
909 | self.add_empty_file('c') | ||
910 | self.git('checkout master') | ||
911 | self.add_empty_file('d') | ||
912 | self.git('merge --no-ff --no-edit a_branch') | ||
913 | self.git('branch -d a_branch') | ||
914 | self.add_empty_file('e') | ||
915 | self.assertRevCount(6) | ||
916 | self.make_shallow(['HEAD~2']) | ||
917 | self.assertRevCount(5) | ||
918 | |||
919 | def test_make_shallow_at_merge(self): | ||
920 | self.add_empty_file('a') | ||
921 | self.git('checkout -b a_branch') | ||
922 | self.add_empty_file('b') | ||
923 | self.git('checkout master') | ||
924 | self.git('merge --no-ff --no-edit a_branch') | ||
925 | self.git('branch -d a_branch') | ||
926 | self.assertRevCount(3) | ||
927 | self.make_shallow() | ||
928 | self.assertRevCount(1) | ||
929 | |||
930 | def test_make_shallow_annotated_tag(self): | ||
931 | self.add_empty_file('a') | ||
932 | self.add_empty_file('b') | ||
933 | self.git('tag -a -m a_tag a_tag') | ||
934 | self.assertRevCount(2) | ||
935 | self.make_shallow(['a_tag']) | ||
936 | self.assertRevCount(1) | ||
937 | |||
938 | def test_make_shallow_multi_ref(self): | ||
939 | self.add_empty_file('a') | ||
940 | self.add_empty_file('b') | ||
941 | self.git('checkout -b a_branch') | ||
942 | self.add_empty_file('c') | ||
943 | self.git('checkout master') | ||
944 | self.add_empty_file('d') | ||
945 | self.git('checkout -b a_branch_2') | ||
946 | self.add_empty_file('a_tag') | ||
947 | self.git('tag a_tag') | ||
948 | self.git('checkout master') | ||
949 | self.git('branch -D a_branch_2') | ||
950 | self.add_empty_file('e') | ||
951 | self.assertRevCount(6, ['--all']) | ||
952 | self.make_shallow() | ||
953 | self.assertRevCount(5, ['--all']) | ||
954 | |||
955 | def test_make_shallow_multi_ref_trim(self): | ||
956 | self.add_empty_file('a') | ||
957 | self.git('checkout -b a_branch') | ||
958 | self.add_empty_file('c') | ||
959 | self.git('checkout master') | ||
960 | self.assertRevCount(1) | ||
961 | self.assertRevCount(2, ['--all']) | ||
962 | self.assertRefs(['master', 'a_branch']) | ||
963 | self.make_shallow(['-r', 'master', 'HEAD']) | ||
964 | self.assertRevCount(1, ['--all']) | ||
965 | self.assertRefs(['master']) | ||
966 | |||
967 | def test_make_shallow_noop(self): | ||
968 | self.add_empty_file('a') | ||
969 | self.assertRevCount(1) | ||
970 | self.make_shallow() | ||
971 | self.assertRevCount(1) | ||
972 | |||
973 | if os.environ.get("BB_SKIP_NETTESTS") == "yes": | ||
974 | print("Unset BB_SKIP_NETTESTS to run network tests") | ||
975 | else: | ||
976 | def test_make_shallow_bitbake(self): | ||
977 | self.git('remote add origin https://github.com/openembedded/bitbake') | ||
978 | self.git('fetch --tags origin') | ||
979 | orig_revs = len(self.git('rev-list --all').splitlines()) | ||
980 | self.make_shallow(['refs/tags/1.10.0']) | ||
981 | self.assertRevCount(orig_revs - 1746, ['--all']) | ||