Merge ~racb/git-ubuntu:source-tree into git-ubuntu:master

Proposed by Robie Basak
Status: Merged
Merged at revision: f55596fd57b26a63883148f07c59334a1991eebb
Proposed branch: ~racb/git-ubuntu:source-tree
Merge into: git-ubuntu:master
Prerequisite: ~racb/git-ubuntu:decouple-gitubunturepository
Diff against target: 90 lines (+47/-0)
1 file modified
gitubuntu/repo_builder.py (+47/-0)
Reviewer Review Type Date Requested Status
Nish Aravamudan Approve
Server Team CI bot continuous-integration Approve
Review via email: mp+337577@code.launchpad.net

This proposal supersedes a proposal from 2018-02-12.

Description of the change

Documentation of this is included in docstrings and comments.

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

FAILED: Continuous integration, rev:7a87399d0536f845c27e17c62b337b02249a1a8f
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/282/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Style Check
    SUCCESS: Unit Tests
    FAILED: Integration Tests

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/282/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

FAILED: Continuous integration, rev:7a87399d0536f845c27e17c62b337b02249a1a8f
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/284/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Style Check
    SUCCESS: Unit Tests
    FAILED: Integration Tests

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/284/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:7a87399d0536f845c27e17c62b337b02249a1a8f
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/286/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Style Check
    SUCCESS: Unit Tests
    SUCCESS: Integration Tests
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/286/rebuild

review: Approve (continuous-integration)
Revision history for this message
Nish Aravamudan (nacc) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/gitubuntu/repo_builder.py b/gitubuntu/repo_builder.py
2index cb93278..76d9209 100644
3--- a/gitubuntu/repo_builder.py
4+++ b/gitubuntu/repo_builder.py
5@@ -1,3 +1,4 @@
6+import binascii
7 import functools
8 import tempfile
9 import unittest
10@@ -5,6 +6,16 @@ import unittest
11 import pygit2
12 import pytest
13
14+import gitubuntu.importer
15+from gitubuntu.test_fixtures import (
16+ repo,
17+ pygit2_repo,
18+)
19+
20+# Only for tests; can move to repo_builder_test when the move is done
21+import gitubuntu.git_repository
22+from gitubuntu.source_builder import Source
23+
24
25 """Build test git repositories as data structures
26
27@@ -12,6 +23,12 @@ Represent a git repository as a data structure, nesting using Tree objects as
28 required. Name objects in a flat namespace using the name keyword object to
29 these constructors.
30
31+Use a SourceTree object to get something that behaves like a Tree but is
32+actually the exact source of a full, unpacked source package described using
33+source_builder.Source. As source_builder.Source is slow, however, using a Tree
34+directly is preferred when the behaviour under test does not need a complete
35+source tree.
36+
37 Reference the same object with a Placeholder giving the name of the target to
38 its constructor. This allows a build in a single data structure instead of
39 having to use multiple statements to grab references to other parts of the same
40@@ -29,6 +46,7 @@ __all__ = [
41 'Blob',
42 'Commit',
43 'ExecutableBlob',
44+ 'SourceTree',
45 'Symlink',
46 'Placeholder',
47 'Tree',
48@@ -165,6 +183,25 @@ class Tree(NamedMixin, WriteMixin):
49 return tree_builder.write()
50
51
52+class SourceTree(NamedMixin, WriteMixin):
53+ def __init__(self, source, **kwargs):
54+ """Construct a git tree representation of a source_builder.Source
55+
56+ :param source_tree.SourceBuilder source: the source whose git tree this
57+ object will represent
58+ """
59+ super().__init__(**kwargs)
60+ self.source = source
61+
62+ def walk(self, parent=None):
63+ yield parent, self
64+
65+ def _obj_to_oid(self, repo, record):
66+ with self.source as dsc_path:
67+ oid_str = gitubuntu.importer.dsc_to_tree_hash(repo, dsc_path)
68+ return pygit2.Oid(binascii.unhexlify(oid_str))
69+
70+
71 class Commit(NamedMixin, WriteMixin):
72 def __init__(self, tree, **kwargs):
73 super().__init__(**kwargs)
74@@ -236,6 +273,16 @@ class TestObjectCreation(unittest.TestCase):
75 commit['absent']
76
77
78+def test_source_tree(pygit2_repo):
79+ commit_str = Commit(SourceTree(Source())).write(pygit2_repo)
80+ commit = pygit2_repo.get(commit_str)
81+ assert gitubuntu.git_repository.follow_symlinks_to_blob(
82+ repo=pygit2_repo,
83+ treeish_object=commit,
84+ path='debian/changelog',
85+ )
86+
87+
88 @pytest.mark.parametrize('cls', [
89 functools.partial(Blob, b'qux'),
90 functools.partial(ExecutableBlob, b'qux'),

Subscribers

People subscribed via source and target branches