Exemplo n.º 1
0
def _make_wrap(workdir, name: str, repo: git.Repo, branch: str) -> wrap.Wrap:
    revision_id = gitutils.get_revision(repo, repo.head.commit)
    upstream_file = os.path.join(workdir, 'upstream.wrap')
    definition = upstream.UpstreamWrap.from_file(upstream_file)
    _check_definition(definition)
    with io.BytesIO() as zipf:
        _make_zip(zipf, workdir, definition.directory)
        zip_contents = zipf.getvalue()
    source_hash = hashlib.sha256(zip_contents).hexdigest()
    with io.StringIO() as wrapfile:
        url = _OUT_URL_BASE_DEFAULT % (name, branch, revision_id)
        with open(upstream_file) as basewrap:
            # preserve whatever formatting user has provided
            wrapfile.write(basewrap.read())
        wrapfile.write('\n')
        wrapfile.write('patch_url = %s\n' % url)
        zip_name = wrap.zip_name(name, branch, revision_id)
        wrapfile.write('patch_filename = %s\n' % zip_name)
        wrapfile.write('patch_hash = %s\n' % source_hash)
        wrap_contents = wrapfile.getvalue()
    return wrap.Wrap(name=name,
                     version=branch,
                     revision=revision_id,
                     wrap=wrap_contents,
                     zip=zip_contents)
Exemplo n.º 2
0
def _make_wrap(workdir, name, repo_url, branch):
    repo = git.Repo.clone_from(repo_url, workdir, branch=branch)
    revision_id = gitutils.get_revision(repo, repo.head.commit)
    upstream_file = os.path.join(workdir, 'upstream.wrap')
    definition = upstream.UpstreamWrap.from_file(upstream_file)
    _check_definition(definition)
    base_name = (name + '-' +
                 branch + '-' +
                 str(revision_id) + '-wrap')
    zip_name = base_name + '.zip'
    wrap_name = base_name + '.wrap'
    with io.BytesIO() as zipf:
        _make_zip(zipf, workdir, definition.directory)
        zip_contents = zipf.getvalue()
    source_hash = hashlib.sha256(zip_contents).hexdigest()
    with io.StringIO() as wrapfile:
        url = _OUT_URL_BASE_DEFAULT % (name, branch, revision_id)
        with open(upstream_file) as basewrap:
            # preserve whatever formatting user has provided
            wrapfile.write(basewrap.read())
        wrapfile.write('\n')
        wrapfile.write('patch_url = %s\n' % url)
        wrapfile.write('patch_filename = %s\n' % zip_name)
        wrapfile.write('patch_hash = %s\n' % source_hash)
        wrap_contents = wrapfile.getvalue()
    return Wrap(wrap=wrap_contents, zip=zip_contents, revision=revision_id,
                wrap_name=wrap_name, zip_name=zip_name)
Exemplo n.º 3
0
 def test_no_upstream_wrap_version(self):
     self.commit('first')
     self.commit('second [wrap version]')
     with self.open('upstream.wrap', 'w') as f:
         f.write('foo')
     self.commit('third')
     self.assertEqual(gitutils.get_revision(self.repo), 1)
Exemplo n.º 4
0
 def test_merge(self):
     with self.open('upstream.wrap', 'w') as f:
         f.write('hello')
     self.commit('first')
     r = self.commit('second')
     self.commit('third')
     r = self.commit('fourth', [r], head=False)
     self.commit('fifth', [self.repo.head.commit, r])
     self.assertEqual(gitutils.get_revision(self.repo), 5)
Exemplo n.º 5
0
 def test_upstream_wrap(self):
     with self.open('hello.txt', 'w') as f:
         f.write('foo')
     self.commit('first')
     self.commit('second')
     with self.open('upstream.wrap', 'w') as f:
         f.write('hello')
     self.commit('project r1')
     self.commit('project r2')
     self.assertEqual(gitutils.get_revision(self.repo), 2)
Exemplo n.º 6
0
 def test_wrap_version(self):
     with self.open('hello.txt', 'w') as f:
         f.write('foo')
     self.commit('first')
     self.commit('second')
     with self.open('upstream.wrap', 'w') as f:
         f.write('hello')
     self.commit('project r1')
     self.commit('project r2')
     self.commit('Some new [wrap version] message r1')
     self.assertEqual(gitutils.get_revision(self.repo), 1)
Exemplo n.º 7
0
 def _get_commit(repo, branch, revision):
     cur = repo.refs['origin/' + branch].commit
     todo = [cur]
     while todo:
         cur = todo.pop()
         rev = gitutils.get_revision(repo, cur)
         if rev > revision:
             todo.extend(cur.parents)
         elif rev == revision:
             return cur
         else:
             raise ValueError('Impossible revision')
Exemplo n.º 8
0
def _make_wrap(workdir, name: str, repo: git.Repo, branch: str) -> wrap.Wrap:
    revision_commit_sha = repo.head.commit.hexsha
    revision_id = gitutils.get_revision(repo, repo.head.commit)
    upstream_file = os.path.join(workdir, 'upstream.wrap')
    wrapfile = ini.WrapFile.from_file(upstream_file)
    _check_wrapfile(wrapfile)
    with io.BytesIO() as zipf:
        _make_zip(zipf, workdir, wrapfile.directory)
        zip_contents = zipf.getvalue()
    wrapfile.patch_url = _OUT_URL_BASE_DEFAULT.format(name, branch,
                                                      revision_id)
    wrapfile.patch_filename = wrap.zip_name(name, branch, revision_id)
    wrapfile.patch_hash = hashlib.sha256(zip_contents).hexdigest()
    return wrap.Wrap(name=name,
                     version=branch,
                     revision=revision_id,
                     wrapfile_content=wrapfile.write_string(),
                     zip=zip_contents,
                     commit_sha=revision_commit_sha)
Exemplo n.º 9
0
 def _get_revision(repo):
     return gitutils.get_revision(repo, repo.head.commit)
Exemplo n.º 10
0
 def test_empty(self):
     with self.open('hello.txt', 'w') as f:
         f.write('foo')
     self.commit('first commit')
     self.assertEqual(gitutils.get_revision(self.repo), 0)