Example #1
0
def step_impl_given(context):
    context.test_git_repo_dir = tempfile.mkdtemp(
        "paasta_tools_deployments_json_itest")
    context.test_git_repo = Repo.init(context.test_git_repo_dir)
    print("Temp repo in %s" % context.test_git_repo_dir)

    blob = Blob.from_string(b"My file content\n")
    tree = Tree()
    tree.add(b"spam", 0o0100644, blob.id)

    commit = Commit()
    commit.author = commit.committer = b"itest author"
    commit.commit_time = commit.author_time = int(time())
    commit.commit_timezone = commit.author_timezone = parse_timezone(
        b"-0200")[0]
    commit.message = b"Initial commit"
    commit.tree = tree.id

    object_store = context.test_git_repo.object_store
    object_store.add_object(blob)
    object_store.add_object(tree)
    object_store.add_object(commit)

    context.test_git_repo.refs[b"refs/heads/master"] = commit.id
    context.expected_commit_as_bytes = commit.id
    context.expected_commit = context.expected_commit_as_bytes.decode()

    context.image_version = None
    def commit(self,
               name,
               email='*****@*****.**',
               message='wip',
               parents=None):
        if not self.is_head:
            return False

        # initial-commit
        if not self.snapshot_commit:
            parents = []
        elif not parents:
            parents = [self.snapshot_commit.id]

        if not self.snapshot_commit or self.root_node.git_object.id != self.snapshot_commit.tree:
            c = Commit()
            c.tree = self.root_node.git_object.id
            c.parents = parents
            c.author = c.committer = '%s <%s>' % (name.encode('utf-8'),
                                                  email.encode('utf-8'))
            c.commit_time = c.author_time = int(time())
            c.commit_timezone = c.author_timezone = 0
            c.encoding = "UTF-8"
            c.message = message
            self.repo.object_store.add_object(c)
            self.repo.refs[self.ref] = c.id
            return c
        return False
Example #3
0
    def delete_file(self, subdir, filename, commit_msg):
        try:
            subdir_tree = _walk_git_repo_tree(self.repo, self.current_tree,
                                              subdir)
        except KeyError:
            raise FileNotFoundException('No subdir named %r' % subdir)
        if not filename in subdir_tree:
            raise FileNotFoundException('%r not in %s' % (filename, subdir))
        del subdir_tree[filename]

        # create new root tree
        tree = self.current_tree
        tree.add(stat.S_IFDIR, subdir, subdir_tree.id)

        # create commit
        # FIXME: factor this out!
        commit = Commit()
        commit.parents = [self.current_commit.id]
        commit.tree = tree.id
        commit.author = commit.committer = self.wiki_user
        commit.commit_time = commit.author_time = int(time.time())
        commit.commit_timezone = commit.author_timezone = parse_timezone(
            time.timezone)[0]
        commit.encoding = 'UTF-8'
        commit.message = commit_msg.encode('utf-8')

        # store all objects
        self.repo.object_store.add_object(subdir_tree)
        self.repo.object_store.add_object(tree)
        self.repo.object_store.add_object(commit)

        # update the branch
        self.repo.refs[self.head] = commit.id
def create_commit(data, marker=b"Default", blob=None):
    if not blob:
        blob = Blob.from_string(b"The blob content " + marker)
    tree = Tree()
    tree.add(b"thefile_" + marker, 0o100644, blob.id)
    cmt = Commit()
    if data:
        assert isinstance(data[-1], Commit)
        cmt.parents = [data[-1].id]
    cmt.tree = tree.id
    author = b"John Doe " + marker + b" <*****@*****.**>"
    cmt.author = cmt.committer = author
    tz = parse_timezone(b"-0200")[0]
    cmt.commit_time = cmt.author_time = int(time())
    cmt.commit_timezone = cmt.author_timezone = tz
    cmt.encoding = b"UTF-8"
    cmt.message = b"The commit message " + marker
    tag = Tag()
    tag.tagger = b"*****@*****.**"
    tag.message = b"Annotated tag"
    tag.tag_timezone = parse_timezone(b"-0200")[0]
    tag.tag_time = cmt.author_time
    tag.object = (Commit, cmt.id)
    tag.name = b"v_" + marker + b"_0.1"
    return blob, tree, tag, cmt
Example #5
0
def git_repo_init(gitdir):
    os.mkdir(gitdir)
    repo = Repo.init_bare(gitdir)
    blob = Blob.from_string("""Why, Hello there!

This is your friendly Legislation tracker, Billy here.

This is a git repo full of everything I write to the DB. This isn't super
useful unless you're debugging production issues.

Fondly,
   Bill, your local Billy instance.""")
    tree = Tree()
    tree.add("README", 0100644, blob.id)
    commit = Commit()
    commit.tree = tree.id
    author = "Billy <billy@localhost>"
    commit.author = commit.committer = author
    commit.commit_time = commit.author_time = int(time())
    tz = parse_timezone('-0400')[0]
    commit.commit_timezone = commit.author_timezone = tz
    commit.encoding = "UTF-8"
    commit.message = "Initial commit"
    repo.object_store.add_object(blob)
    repo.object_store.add_object(tree)
    repo.object_store.add_object(commit)
    repo.refs['refs/heads/master'] = commit.id
Example #6
0
 def test_simple_bytesio(self):
     f = BytesIO()
     c = Commit()
     c.committer = c.author = b"Jelmer <*****@*****.**>"
     c.commit_time = c.author_time = 1271350201
     c.commit_timezone = c.author_timezone = 0
     c.message = b"This is the first line\nAnd this is the second line.\n"
     c.tree = Tree().id
     write_commit_patch(f, c, b"CONTENTS", (1, 1), version="custom")
     f.seek(0)
     lines = f.readlines()
     self.assertTrue(lines[0].startswith(
                 b"From 0b0d34d1b5b596c928adc9a727a4b9e03d025298"))
     self.assertEqual(lines[1], b"From: Jelmer <*****@*****.**>\n")
     self.assertTrue(lines[2].startswith(b"Date: "))
     self.assertEqual([
         b"Subject: [PATCH 1/1] This is the first line\n",
         b"And this is the second line.\n",
         b"\n",
         b"\n",
         b"---\n"], lines[3:8])
     self.assertEqual([
         b"CONTENTS-- \n",
         b"custom\n"], lines[-2:])
     if len(lines) >= 12:
         # diffstat may not be present
         self.assertEqual(lines[8], b" 0 files changed\n")
Example #7
0
 def commit_handler(self, cmd):
     """Process a CommitCommand."""
     commit = Commit()
     if cmd.author is not None:
         author = cmd.author
     else:
         author = cmd.committer
     (author_name, author_email, author_timestamp, author_timezone) = author
     (committer_name, committer_email, commit_timestamp,
      commit_timezone) = cmd.committer
     commit.author = author_name + b" <" + author_email + b">"
     commit.author_timezone = author_timezone
     commit.author_time = int(author_timestamp)
     commit.committer = committer_name + b" <" + committer_email + b">"
     commit.commit_timezone = commit_timezone
     commit.commit_time = int(commit_timestamp)
     commit.message = cmd.message
     commit.parents = []
     if cmd.from_:
         self._reset_base(cmd.from_)
     for filecmd in cmd.iter_files():
         if filecmd.name == b"filemodify":
             if filecmd.data is not None:
                 blob = Blob.from_string(filecmd.data)
                 self.repo.object_store.add(blob)
                 blob_id = blob.id
             else:
                 assert filecmd.dataref.startswith(b":"), \
                        ("non-marker refs not supported yet (%r)" %
                         filecmd.dataref)
                 blob_id = self.markers[filecmd.dataref[1:]]
             self._contents[filecmd.path] = (filecmd.mode, blob_id)
         elif filecmd.name == b"filedelete":
             del self._contents[filecmd.path]
         elif filecmd.name == b"filecopy":
             self._contents[filecmd.dest_path] = self._contents[
                 filecmd.src_path]
         elif filecmd.name == b"filerename":
             self._contents[filecmd.new_path] = self._contents[
                 filecmd.old_path]
             del self._contents[filecmd.old_path]
         elif filecmd.name == b"filedeleteall":
             self._contents = {}
         else:
             raise Exception("Command %s not supported" % filecmd.name)
     commit.tree = commit_tree(
         self.repo.object_store,
         ((path, hexsha, mode)
          for (path, (mode, hexsha)) in self._contents.items()))
     if self.last_commit != ZERO_SHA:
         commit.parents.append(self.last_commit)
     for merge in cmd.merges:
         if merge.startswith(b':'):
             merge = self.markers[merge[1:]]
         commit.parents.append(merge)
     self.repo.object_store.add_object(commit)
     self.repo[cmd.ref] = commit.id
     self.last_commit = commit.id
     if cmd.mark:
         self.markers[cmd.mark] = commit.id
Example #8
0
File: start.py Project: Swizec/OS2
def init_the_git(config):
    path = config.get('Local', 'path')

    repo = Repo.init(path)
    blob = Blob.from_string(
        open(os.path.join(path, '.git-dropbox.cnf')).read())

    tree = Tree()
    tree.add(".git-dropbox.cnf", 0100644, blob.id)

    commit = Commit()
    commit.tree = tree.id
    commit.author = config.get('Local', 'user')
    commit.committer = 'Git-dropbox'
    commit.commit_time = int(time())
    commit.author_time = os.path.getctime(
        os.path.join(path, '.git-dropbox.cnf'))
    commit.commit_timezone = commit.author_timezone = parse_timezone(
        '-0200')[0]
    commit.encoding = 'UTF-8'
    commit.message = 'Initial commit'

    object_store = repo.object_store
    object_store.add_object(blob)
    object_store.add_object(tree)
    object_store.add_object(commit)

    repo.refs['refs/heads/master'] = commit.id
Example #9
0
    def test_emit_commit(self):
        b = Blob()
        b.data = "FOO"
        t = Tree()
        t.add("foo", stat.S_IFREG | 0o644, b.id)
        c = Commit()
        c.committer = c.author = "Jelmer <jelmer@host>"
        c.author_time = c.commit_time = 1271345553
        c.author_timezone = c.commit_timezone = 0
        c.message = "msg"
        c.tree = t.id
        self.store.add_objects([(b, None), (t, None), (c, None)])
        self.fastexporter.emit_commit(c, "refs/heads/master")
        self.assertEqual(
            """blob
mark :1
data 3
FOO
commit refs/heads/master
mark :2
author Jelmer <jelmer@host> 1271345553 +0000
committer Jelmer <jelmer@host> 1271345553 +0000
data 3
msg
M 644 1 foo
""", self.stream.getvalue())
Example #10
0
File: git.py Project: raony/gitdb
 def __create_commit__(self, message, author):
     commit = Commit()
     commit.author = commit.committer = author.encode(ENCODING)
     commit.author_time = commit.commit_time = int(time.time())
     commit.author_timezone = commit.commit_timezone = 0
     commit.message = message.encode(ENCODING)
     return commit
Example #11
0
    def test_send_pack_no_sideband64k_with_update_ref_error(self):
        # No side-bank-64k reported by server shouldn't try to parse
        # side band data
        pkts = [b'55dcc6bf963f922e1ed5c4bbaaefcfacef57b1d7 capabilities^{}'
                b'\x00 report-status delete-refs ofs-delta\n',
                b'',
                b"unpack ok",
                b"ng refs/foo/bar pre-receive hook declined",
                b'']
        for pkt in pkts:
            if pkt == b'':
                self.rin.write(b"0000")
            else:
                self.rin.write(("%04x" % (len(pkt)+4)).encode('ascii') + pkt)
        self.rin.seek(0)

        tree = Tree()
        commit = Commit()
        commit.tree = tree
        commit.parents = []
        commit.author = commit.committer = b'test user'
        commit.commit_time = commit.author_time = 1174773719
        commit.commit_timezone = commit.author_timezone = 0
        commit.encoding = b'UTF-8'
        commit.message = b'test message'

        def determine_wants(refs):
            return {b'refs/foo/bar': commit.id, }

        def generate_pack_contents(have, want):
            return [(commit, None), (tree, ''), ]

        self.assertRaises(UpdateRefsError,
                          self.client.send_pack, "blah",
                          determine_wants, generate_pack_contents)
Example #12
0
def create_commit(repo,
                  files=None,
                  tree=None,
                  parent=None,
                  author=AUTHOR,
                  message="No message given"):
    object_store = repo.object_store
    if not tree:
        tree = Tree()
    for f in files:
        blob = Blob.from_string(f[2])
        object_store.add_object(blob)
        tree.add(f[0], f[1], blob.id)
    commit = Commit()
    if parent:
        commit.parents = [parent]
    else:
        commit.parents = []
    # Check that we have really updated the tree
    if parent:
        parent_commit = repo.get_object(parent)
        if parent_commit.tree == tree.id:
            raise NoChangesException()
    commit.tree = tree.id
    commit.author = commit.committer = author
    commit.commit_time = commit.author_time = get_ts()
    tz = parse_timezone('+0100')[0]
    commit.commit_timezone = commit.author_timezone = tz
    commit.encoding = "UTF-8"
    commit.message = message

    object_store.add_object(tree)
    object_store.add_object(commit)
    return commit
Example #13
0
 def _create_commit(self):
     commit = Commit()
     commit.author = commit.committer = self._author
     commit.commit_time = commit.author_time = int(time())
     commit.commit_timezone = commit.author_timezone = self._time_zone
     commit.encoding = self._encoding
     return commit
Example #14
0
def step_impl_given(context):
    context.test_git_repo_dir = tempfile.mkdtemp(
        'paasta_tools_deployments_json_itest')
    context.test_git_repo = Repo.init(context.test_git_repo_dir)
    print 'Temp repo in %s' % context.test_git_repo_dir

    blob = Blob.from_string("My file content\n")
    tree = Tree()
    tree.add("spam", 0100644, blob.id)

    commit = Commit()
    commit.author = commit.committer = "itest author"
    commit.commit_time = commit.author_time = int(time())
    commit.commit_timezone = commit.author_timezone = parse_timezone(
        '-0200')[0]
    commit.message = "Initial commit"
    commit.tree = tree.id

    object_store = context.test_git_repo.object_store
    object_store.add_object(blob)
    object_store.add_object(tree)
    object_store.add_object(commit)

    context.test_git_repo.refs['refs/heads/master'] = commit.id
    context.expected_commit = commit.id
Example #15
0
def create_commit(metadata, parents, tree_id):
    """Create a new Git commit object, and add it to the object store.

	Args:
	  metadata: Dictionary containing metadata to construct the commit,
	      including commit message and author data.
	  parents: The parents of this commit.
	  tree: The tree of files to use for this commit.
	Returns:
	  New commit object.
	"""
    commit = Commit()
    commit.tree = tree_id
    commit.author = "%s <%s>" % (metadata["GIT_AUTHOR_NAME"],
                                 metadata["GIT_AUTHOR_EMAIL"])
    commit.author_time = \
        utc_time_from_string(metadata["GIT_AUTHOR_DATE"])
    commit.author_timezone = 0

    commit.committer = "%s <%s>" % (metadata["GIT_COMMITTER_NAME"],
                                    metadata["GIT_COMMITTER_EMAIL"])
    commit.commit_time = \
        utc_time_from_string(metadata["GIT_COMMITTER_DATE"])
    commit.commit_timezone = 0

    commit.encoding = "UTF-8"
    commit.message = metadata["MESSAGE"]
    commit.parents = parents
    gitrepo.object_store.add_object(commit)

    return commit
Example #16
0
    def oldcreate(self, name):
        """
		create a new repo
		
		:param name: the name to give the new repo
		:type name: string
		"""
        repo = Repo.init_bare(name)

        from dulwich.objects import Tree
        tree = Tree()

        from dulwich.objects import Commit, parse_timezone
        from time import time
        commit = Commit()
        commit.tree = tree.id  #is the tree.id the sha1 of the files contained in tree
        author = "New Project Wizard <wizard@host>"
        commit.author = commit.committer = author
        commit.commit_time = commit.author_time = int(time())
        tz = parse_timezone('+1000')[0]
        commit.commit_timezone = commit.author_timezone = tz
        commit.encoding = "UTF-8"
        commit.message = "New Project."

        object_store = repo.object_store

        #then add the tree
        object_store.add_object(tree)
        #then add the commit
        object_store.add_object(commit)

        repo.refs['refs/heads/master'] = commit.id

        return {"success": "%s.git created" % name}
Example #17
0
def create_commit(data, marker='Default', blob=None):
    if not blob:
        blob = Blob.from_string('The blob content %s' % marker)
    tree = Tree()
    tree.add("thefile_%s" % marker, 0o100644, blob.id)
    cmt = Commit()
    if data:
        assert isinstance(data[-1], Commit)
        cmt.parents = [data[-1].id]
    cmt.tree = tree.id
    author = "John Doe %s <*****@*****.**>" % marker
    cmt.author = cmt.committer = author
    tz = parse_timezone('-0200')[0]
    cmt.commit_time = cmt.author_time = int(time())
    cmt.commit_timezone = cmt.author_timezone = tz
    cmt.encoding = "UTF-8"
    cmt.message = "The commit message %s" % marker
    tag = Tag()
    tag.tagger = "*****@*****.**"
    tag.message = "Annotated tag"
    tag.tag_timezone = parse_timezone('-0200')[0]
    tag.tag_time = cmt.author_time
    tag.object = (Commit, cmt.id)
    tag.name = "v_%s_0.1" % marker
    return blob, tree, tag, cmt
Example #18
0
 def _do_commit(self, index, author, message, ctime, parent_rev=None):
     committer = b'%s <>' % author.encode('utf8')
     commit = Commit()
     commit.tree = index.commit(self.repo.object_store)
     commit.author = commit.committer = committer
     commit.commit_time = commit.author_time = ctime
     commit.encoding = b'UTF-8'
     commit.commit_timezone = commit.author_timezone = 0
     commit.message = message.encode('utf8')
     try:
         curr_head = self.repo.head()
         commit.parents = [curr_head]
         # if parent_rev and len(parent_rev) == 40:
         #     commit.parents.append(parent_rev.encode('ascii'))
     except KeyError:
         curr_head = None
     self.repo.object_store.add_object(commit)
     self.repo.refs.set_if_equals(b'HEAD',
                                  curr_head,
                                  commit.id,
                                  message=b"commit: " + commit.message,
                                  committer=commit.committer,
                                  timestamp=ctime,
                                  timezone=0)
     index.write()
Example #19
0
def _create_commit(tree, reason='', branch=False, parents=None, request=None):
    """ Creates a new commit based on the provided information. """

    commit = Commit()

    if request and 'flatpages.git.author_name' in request.registry.settings:
        author = request.registry.settings['flatpages.git.author_name']
    else:
        author = 'Anonymous'

    if request and 'flatpages.git.author_email' in request.registry.settings:
        author_email = request.registry.settings['flatpages.git.author_email']
        author = '{0} <{1}>'.format(author, author_email)

    else:
        if request:
            author = '{0} <anonymous@{0}>'.format(request.host)
        else:
            author = '{0} <anonymous@{0}example.com>'

    # TODO: Right now, all times are in UTC time. Even though everything should
    # use UTC time in a perfect world - this isn't the case in the real world.
    commit.commit_timezone = commit.author_timezone = parse_timezone('0000')[0]
    commit.commit_time = commit.author_time = int(time.time())

    commit.author = commit.committer = author

    commit.tree = tree.id
    commit.encoding = 'UTF-8'
    commit.message = reason

    if parents:
        commit.parents = parents

    return commit
 def test_simple(self):
     c = Commit()
     c.committer = c.author = b"Jelmer <*****@*****.**>"
     c.commit_time = c.author_time = 1271350201
     c.commit_timezone = c.author_timezone = 0
     c.message = b"This is the first line\nAnd this is the second line.\n"
     c.tree = Tree().id
     self.assertEqual("This-is-the-first-line", get_summary(c))
Example #21
0
 def test_full_tree(self):
     c = self.make_commit(commit_time=30)
     t = Tree()
     t.add(b'data-x', 0o644, Blob().id)
     c.tree = t
     c1 = Commit()
     c1.set_raw_string(c.as_raw_string())
     self.assertEqual(t.id, c1.tree)
     self.assertEqual(c.as_raw_string(), c1.as_raw_string())
Example #22
0
    def export_hg_commit(self, rev):
        self.ui.note(_("converting revision %s\n") % hex(rev))

        oldenc = self.swap_out_encoding()

        ctx = self.repo.changectx(rev)
        extra = ctx.extra()

        commit = Commit()

        (time, timezone) = ctx.date()
        commit.author = self.get_git_author(ctx)
        commit.author_time = int(time)
        commit.author_timezone = -timezone

        if 'committer' in extra:
            # fixup timezone
            (name, timestamp, timezone) = extra['committer'].rsplit(' ', 2)
            commit.committer = name
            commit.commit_time = timestamp

            # work around a timezone format change
            if int(timezone) % 60 != 0: #pragma: no cover
                timezone = parse_timezone(timezone)
                # Newer versions of Dulwich return a tuple here
                if isinstance(timezone, tuple):
                    timezone, neg_utc = timezone
                    commit._commit_timezone_neg_utc = neg_utc
            else:
                timezone = -int(timezone)
            commit.commit_timezone = timezone
        else:
            commit.committer = commit.author
            commit.commit_time = commit.author_time
            commit.commit_timezone = commit.author_timezone

        commit.parents = []
        for parent in self.get_git_parents(ctx):
            hgsha = hex(parent.node())
            git_sha = self.map_git_get(hgsha)
            if git_sha:
                commit.parents.append(git_sha)

        commit.message = self.get_git_message(ctx)

        if 'encoding' in extra:
            commit.encoding = extra['encoding']

        tree_sha = commit_tree(self.git.object_store, self.iterblobs(ctx))
        commit.tree = tree_sha

        self.git.object_store.add_object(commit)
        self.map_set(commit.id, ctx.hex())

        self.swap_out_encoding(oldenc)
        return commit.id
Example #23
0
 def test_commit_double_negative_timezone(self):
     c = Commit()
     c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
     c.message = b"Some message"
     c.committer = b"Committer <Committer>"
     c.commit_time = 4
     (c.commit_timezone, c._commit_timezone_neg_utc) = parse_timezone(b"--700")
     c.author_time = 5
     c.author_timezone = 60 * 2
     c.author = b"Author <author>"
     self.assertRoundtripCommit(c)
Example #24
0
 def _get_test_commit(self):
     c = Commit()
     c.committer = b"Jelmer <*****@*****.**>"
     c.commit_time = 0
     c.commit_timezone = 0
     c.author = b"Jelmer <*****@*****.**>"
     c.author_time = 0
     c.author_timezone = 0
     c.message = b"Teh foo bar"
     c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
     return c
Example #25
0
 def test_commit(self):
     c = Commit()
     c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
     c.message = b"Some message"
     c.committer = b"Committer <Committer>"
     c.commit_time = 4
     c.commit_timezone = -60 * 3
     c.author_time = 5
     c.author_timezone = 60 * 2
     c.author = b"Author <author>"
     self.assertRoundtripCommit(c)
Example #26
0
 def make_base(self):
     c = Commit()
     c.tree = 'd80c186a03f423a81b39df39dc87fd269736ca86'
     c.parents = ['ab64bbdcc51b170d21588e5c5d391ee5c0c96dfd', '4cffe90e0a41ad3f5190079d7c8f036bde29cbe6']
     c.author = 'James Westby <*****@*****.**>'
     c.committer = 'James Westby <*****@*****.**>'
     c.commit_time = 1174773719
     c.author_time = 1174773719
     c.commit_timezone = 0
     c.author_timezone = 0
     c.message =  'Merge ../b\n'
     return c
Example #27
0
def create_commit(marker=None):
    blob = Blob.from_string(b'The blob content ' + marker)
    tree = Tree()
    tree.add(b"thefile " + marker, 0o100644, blob.id)
    cmt = Commit()
    cmt.tree = tree.id
    cmt.author = cmt.committer = b"John Doe <*****@*****.**>"
    cmt.message = marker
    tz = parse_timezone(b'-0200')[0]
    cmt.commit_time = cmt.author_time = int(time.time())
    cmt.commit_timezone = cmt.author_timezone = tz
    return cmt, tree, blob
Example #28
0
 def test_commit_extra(self):
     c = Commit()
     c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
     c.message = b"Some message"
     c.committer = b"Committer <Committer>"
     c.commit_time = 4
     c.commit_timezone = -60 * 3
     c.author_time = 5
     c.author_timezone = 60 * 2
     c.author = b"Author <author>"
     c._extra = [(b"HG:rename-source", b"hg")]
     self.assertRoundtripCommit(c)
Example #29
0
    def commit(self):
        # XXX: evidence for the rest of
        # this functions is supposed not to exist
        # yes, its that
        # XXX: generate all objects at once and
        #     add them as pack instead of legacy objects
        r = self.repo.repo
        store = r.object_store
        new_objects = []
        names = sorted(self.contents)
        nametree = defaultdict(list)
        for name in names:
            base = name.strip('/')
            while base:
                nbase = os.path.dirname(base)
                nametree[nbase].append(base)
                base = nbase

        if self.base_commit:
            tree = r.tree(self.base_commit.commit.tree)
            tree._ensure_parsed()
            print tree._entries
        else:
            tree = Tree()

        for src, dest in self.renames:
            src = src.strip('/')
            dest = dest.strip('/')
            tree[dest] = tree[src]
            del tree[src]

        for name in names:
            blob = Blob()
            blob.data = self.contents[name]
            new_objects.append((blob, name))
            tree.add(0555, os.path.basename(name), blob.id)

        new_objects.append((tree, ''))
        commit = Commit()
        if self.base_commit:
            commit.parents = [self.base_commit.commit.id]
        commit.tree = tree.id
        commit.message = self.extra['message']
        commit.committer = self.author
        commit.commit_time = int(self.time_unix)
        commit.commit_timezone = self.time_offset
        commit.author = self.author
        commit.author_time = int(self.time_unix)
        commit.author_timezone = self.time_offset
        new_objects.append((commit, ''))
        store.add_objects(new_objects)
        self.repo.repo.refs['HEAD'] = commit.id
Example #30
0
 def add_blob(self, gc, name, contents):
     b = Blob.from_string(contents)
     t = Tree()
     t.add(name.encode('utf-8'), 0o644 | stat.S_IFREG, b.id)
     c = Commit()
     c.tree = t.id
     c.committer = c.author = b'Somebody <*****@*****.**>'
     c.commit_time = c.author_time = 800000
     c.commit_timezone = c.author_timezone = 0
     c.message = b'do something'
     gc.repo.object_store.add_objects([(b, None), (t, None), (c, None)])
     gc.repo[gc.ref] = c.id
     return b.id.decode('ascii')