[Notes] [Git][BuildStream/buildstream][master] 3 commits: buildstream/_gitsourcebase.py: Reduce git history for git describe.



Title: GitLab

Valentin David pushed to branch master at BuildStream / buildstream

Commits:

2 changed files:

Changes:

  • buildstream/_gitsourcebase.py
    ... ... @@ -296,18 +296,24 @@ class GitMirror(SourceFetcher):
    296 296
                 shallow = set()
    
    297 297
                 for _, commit_ref, _ in self.tags:
    
    298 298
     
    
    299
    -                _, out = self.source.check_output([self.source.host_git, 'rev-list',
    
    300
    -                                                   '--boundary', '{}..{}'.format(commit_ref, self.ref)],
    
    301
    -                                                  fail="Failed to get git history {}..{} in directory: {}"
    
    302
    -                                                  .format(commit_ref, self.ref, fullpath),
    
    303
    -                                                  fail_temporarily=True,
    
    304
    -                                                  cwd=self.mirror)
    
    305
    -                for line in out.splitlines():
    
    306
    -                    rev = line.lstrip('-')
    
    307
    -                    if line[0] == '-':
    
    308
    -                        shallow.add(rev)
    
    309
    -                    else:
    
    310
    -                        included.add(rev)
    
    299
    +                if commit_ref == self.ref:
    
    300
    +                    # rev-list does not work in case of same rev
    
    301
    +                    shallow.add(self.ref)
    
    302
    +                else:
    
    303
    +                    _, out = self.source.check_output([self.source.host_git, 'rev-list',
    
    304
    +                                                       '--ancestry-path', '--boundary',
    
    305
    +                                                       '{}..{}'.format(commit_ref, self.ref)],
    
    306
    +                                                      fail="Failed to get git history {}..{} in directory: {}"
    
    307
    +                                                      .format(commit_ref, self.ref, fullpath),
    
    308
    +                                                      fail_temporarily=True,
    
    309
    +                                                      cwd=self.mirror)
    
    310
    +                    self.source.warn("refs {}..{}: {}".format(commit_ref, self.ref, out.splitlines()))
    
    311
    +                    for line in out.splitlines():
    
    312
    +                        rev = line.lstrip('-')
    
    313
    +                        if line[0] == '-':
    
    314
    +                            shallow.add(rev)
    
    315
    +                        else:
    
    316
    +                            included.add(rev)
    
    311 317
     
    
    312 318
                 shallow -= included
    
    313 319
                 included |= shallow
    

  • tests/sources/git.py
    ... ... @@ -883,6 +883,195 @@ def test_git_describe(cli, tmpdir, datafiles, ref_storage, tag_type):
    883 883
         assert p.returncode != 0
    
    884 884
     
    
    885 885
     
    
    886
    +@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
    
    887
    +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'template'))
    
    888
    +@pytest.mark.parametrize("ref_storage", [('inline'), ('project.refs')])
    
    889
    +@pytest.mark.parametrize("tag_type", [('annotated'), ('lightweight')])
    
    890
    +def test_git_describe_head_is_tagged(cli, tmpdir, datafiles, ref_storage, tag_type):
    
    891
    +    project = str(datafiles)
    
    892
    +
    
    893
    +    project_config = _yaml.load(os.path.join(project, 'project.conf'))
    
    894
    +    project_config['ref-storage'] = ref_storage
    
    895
    +    _yaml.dump(_yaml.node_sanitize(project_config), os.path.join(project, 'project.conf'))
    
    896
    +
    
    897
    +    repofiles = os.path.join(str(tmpdir), 'repofiles')
    
    898
    +    os.makedirs(repofiles, exist_ok=True)
    
    899
    +    file0 = os.path.join(repofiles, 'file0')
    
    900
    +    with open(file0, 'w') as f:
    
    901
    +        f.write('test\n')
    
    902
    +
    
    903
    +    repo = create_repo('git', str(tmpdir))
    
    904
    +
    
    905
    +    def tag(name):
    
    906
    +        if tag_type == 'annotated':
    
    907
    +            repo.add_annotated_tag(name, name)
    
    908
    +        else:
    
    909
    +            repo.add_tag(name)
    
    910
    +
    
    911
    +    ref = repo.create(repofiles)
    
    912
    +    tag('uselesstag')
    
    913
    +
    
    914
    +    file1 = os.path.join(str(tmpdir), 'file1')
    
    915
    +    with open(file1, 'w') as f:
    
    916
    +        f.write('test\n')
    
    917
    +    repo.add_file(file1)
    
    918
    +
    
    919
    +    file2 = os.path.join(str(tmpdir), 'file2')
    
    920
    +    with open(file2, 'w') as f:
    
    921
    +        f.write('test\n')
    
    922
    +    repo.branch('branch2')
    
    923
    +    repo.add_file(file2)
    
    924
    +
    
    925
    +    repo.checkout('master')
    
    926
    +    file3 = os.path.join(str(tmpdir), 'file3')
    
    927
    +    with open(file3, 'w') as f:
    
    928
    +        f.write('test\n')
    
    929
    +    repo.add_file(file3)
    
    930
    +
    
    931
    +    tagged_ref = repo.merge('branch2')
    
    932
    +    tag('tag')
    
    933
    +
    
    934
    +    config = repo.source_config()
    
    935
    +    config['track'] = repo.latest_commit()
    
    936
    +    config['track-tags'] = True
    
    937
    +
    
    938
    +    # Write out our test target
    
    939
    +    element = {
    
    940
    +        'kind': 'import',
    
    941
    +        'sources': [
    
    942
    +            config
    
    943
    +        ],
    
    944
    +    }
    
    945
    +    element_path = os.path.join(project, 'target.bst')
    
    946
    +    _yaml.dump(element, element_path)
    
    947
    +
    
    948
    +    if ref_storage == 'inline':
    
    949
    +        result = cli.run(project=project, args=['source', 'track', 'target.bst'])
    
    950
    +        result.assert_success()
    
    951
    +    else:
    
    952
    +        result = cli.run(project=project, args=['source', 'track', 'target.bst', '--deps', 'all'])
    
    953
    +        result.assert_success()
    
    954
    +
    
    955
    +    if ref_storage == 'inline':
    
    956
    +        element = _yaml.load(element_path)
    
    957
    +        tags = _yaml.node_sanitize(element['sources'][0]['tags'])
    
    958
    +        assert len(tags) == 1
    
    959
    +        for tag in tags:
    
    960
    +            assert 'tag' in tag
    
    961
    +            assert 'commit' in tag
    
    962
    +            assert 'annotated' in tag
    
    963
    +            assert tag['annotated'] == (tag_type == 'annotated')
    
    964
    +
    
    965
    +        assert set([(tag['tag'], tag['commit']) for tag in tags]) == set([('tag', repo.rev_parse('tag^{commit}'))])
    
    966
    +
    
    967
    +    checkout = os.path.join(str(tmpdir), 'checkout')
    
    968
    +
    
    969
    +    result = cli.run(project=project, args=['build', 'target.bst'])
    
    970
    +    result.assert_success()
    
    971
    +    result = cli.run(project=project, args=['checkout', 'target.bst', checkout])
    
    972
    +    result.assert_success()
    
    973
    +
    
    974
    +    if tag_type == 'annotated':
    
    975
    +        options = []
    
    976
    +    else:
    
    977
    +        options = ['--tags']
    
    978
    +    describe = subprocess.check_output(['git', 'describe'] + options,
    
    979
    +                                       cwd=checkout).decode('ascii')
    
    980
    +    assert describe.startswith('tag')
    
    981
    +
    
    982
    +    tags = subprocess.check_output(['git', 'tag'],
    
    983
    +                                   cwd=checkout).decode('ascii')
    
    984
    +    tags = set(tags.splitlines())
    
    985
    +    assert tags == set(['tag'])
    
    986
    +
    
    987
    +    rev_list = subprocess.check_output(['git', 'rev-list', '--all'],
    
    988
    +                                       cwd=checkout).decode('ascii')
    
    989
    +
    
    990
    +    assert set(rev_list.splitlines()) == set([tagged_ref])
    
    991
    +
    
    992
    +    p = subprocess.run(['git', 'log', repo.rev_parse('uselesstag')],
    
    993
    +                       cwd=checkout)
    
    994
    +    assert p.returncode != 0
    
    995
    +
    
    996
    +
    
    997
    +@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
    
    998
    +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'template'))
    
    999
    +def test_git_describe_relevant_history(cli, tmpdir, datafiles):
    
    1000
    +    project = str(datafiles)
    
    1001
    +
    
    1002
    +    project_config = _yaml.load(os.path.join(project, 'project.conf'))
    
    1003
    +    project_config['ref-storage'] = 'project.refs'
    
    1004
    +    _yaml.dump(_yaml.node_sanitize(project_config), os.path.join(project, 'project.conf'))
    
    1005
    +
    
    1006
    +    repofiles = os.path.join(str(tmpdir), 'repofiles')
    
    1007
    +    os.makedirs(repofiles, exist_ok=True)
    
    1008
    +    file0 = os.path.join(repofiles, 'file0')
    
    1009
    +    with open(file0, 'w') as f:
    
    1010
    +        f.write('test\n')
    
    1011
    +
    
    1012
    +    repo = create_repo('git', str(tmpdir))
    
    1013
    +    repo.create(repofiles)
    
    1014
    +
    
    1015
    +    file1 = os.path.join(str(tmpdir), 'file1')
    
    1016
    +    with open(file1, 'w') as f:
    
    1017
    +        f.write('test\n')
    
    1018
    +    repo.add_file(file1)
    
    1019
    +    repo.branch('branch')
    
    1020
    +    repo.checkout('master')
    
    1021
    +
    
    1022
    +    file2 = os.path.join(str(tmpdir), 'file2')
    
    1023
    +    with open(file2, 'w') as f:
    
    1024
    +        f.write('test\n')
    
    1025
    +    repo.add_file(file2)
    
    1026
    +
    
    1027
    +    file3 = os.path.join(str(tmpdir), 'file3')
    
    1028
    +    with open(file3, 'w') as f:
    
    1029
    +        f.write('test\n')
    
    1030
    +    branch_boundary = repo.add_file(file3)
    
    1031
    +
    
    1032
    +    repo.checkout('branch')
    
    1033
    +    file4 = os.path.join(str(tmpdir), 'file4')
    
    1034
    +    with open(file4, 'w') as f:
    
    1035
    +        f.write('test\n')
    
    1036
    +    tagged_ref = repo.add_file(file4)
    
    1037
    +    repo.add_annotated_tag('tag1', 'tag1')
    
    1038
    +
    
    1039
    +    head = repo.merge('master')
    
    1040
    +
    
    1041
    +    config = repo.source_config()
    
    1042
    +    config['track'] = head
    
    1043
    +    config['track-tags'] = True
    
    1044
    +
    
    1045
    +    # Write out our test target
    
    1046
    +    element = {
    
    1047
    +        'kind': 'import',
    
    1048
    +        'sources': [
    
    1049
    +            config
    
    1050
    +        ],
    
    1051
    +    }
    
    1052
    +    element_path = os.path.join(project, 'target.bst')
    
    1053
    +    _yaml.dump(element, element_path)
    
    1054
    +
    
    1055
    +    result = cli.run(project=project, args=['source', 'track', 'target.bst', '--deps', 'all'])
    
    1056
    +    result.assert_success()
    
    1057
    +
    
    1058
    +    checkout = os.path.join(str(tmpdir), 'checkout')
    
    1059
    +
    
    1060
    +    result = cli.run(project=project, args=['build', 'target.bst'])
    
    1061
    +    result.assert_success()
    
    1062
    +    result = cli.run(project=project, args=['checkout', 'target.bst', checkout])
    
    1063
    +    result.assert_success()
    
    1064
    +
    
    1065
    +    describe = subprocess.check_output(['git', 'describe'],
    
    1066
    +                                       cwd=checkout).decode('ascii')
    
    1067
    +    assert describe.startswith('tag1-2-')
    
    1068
    +
    
    1069
    +    rev_list = subprocess.check_output(['git', 'rev-list', '--all'],
    
    1070
    +                                       cwd=checkout).decode('ascii')
    
    1071
    +
    
    1072
    +    assert set(rev_list.splitlines()) == set([head, tagged_ref, branch_boundary])
    
    1073
    +
    
    1074
    +
    
    886 1075
     @pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
    
    887 1076
     @pytest.mark.datafiles(os.path.join(DATA_DIR, 'template'))
    
    888 1077
     def test_default_do_not_track_tags(cli, tmpdir, datafiles):
    



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]