How to use the gitdb.IStream function in gitdb

To help you get started, we’ve selected a few gitdb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gitpython-developers / GitPython / test / performance / test_commit.py View on Github external
commits = list()
		nc = 5000
		st = time()
		for i in xrange(nc):
			cm = Commit(	rwrepo, Commit.NULL_BIN_SHA, hc.tree, 
							hc.author, hc.authored_date, hc.author_tz_offset, 
							hc.committer, hc.committed_date, hc.committer_tz_offset, 
							str(i), parents=hc.parents, encoding=hc.encoding)
			
			stream = StringIO()
			cm._serialize(stream)
			slen = stream.tell()
			stream.seek(0)
			
			cm.binsha = make_object(IStream(Commit.type, slen, stream)).binsha
		# END commit creation
		elapsed = time() - st
		
		print >> sys.stderr, "Serialized %i commits to loose objects in %f s ( %f commits / s )" % (nc, elapsed, nc / elapsed)
github florath / rmtoo / rmtoo / contrib / GitPython-0.3.2.RC1 / git / objects / commit.py View on Github external
if isinstance(tree, str):
			tree = repo.tree(tree)
		# END tree conversion
		
		# CREATE NEW COMMIT
		new_commit = cls(repo, cls.NULL_BIN_SHA, tree, 
						author, author_time, author_offset, 
						committer, committer_time, committer_offset,
						message, parent_commits, conf_encoding)
		
		stream = StringIO()
		new_commit._serialize(stream)
		streamlen = stream.tell()
		stream.seek(0)
		
		istream = repo.odb.store(IStream(cls.type, streamlen, stream))
		new_commit.binsha = istream.binsha
		
		if head:
			# need late import here, importing git at the very beginning throws
			# as well ... 
			import git.refs
			try:
				repo.head.set_commit(new_commit, logmsg="commit: %s" % message)
			except ValueError:
				# head is not yet set to the ref our HEAD points to
				# Happens on first commit
				import git.refs
				master = git.refs.Head.create(repo, repo.head.ref, new_commit, logmsg="commit (initial): %s" % message)
				repo.head.set_reference(master, logmsg='commit: Switching to %s' % master)
			# END handle empty repositories
		# END advance head handling 
github gitpython-developers / GitPython / git / objects / commit.py View on Github external
if isinstance(tree, str):
            tree = repo.tree(tree)
        # END tree conversion

        # CREATE NEW COMMIT
        new_commit = cls(repo, cls.NULL_BIN_SHA, tree,
                         author, author_time, author_offset,
                         committer, committer_time, committer_offset,
                         message, parent_commits, conf_encoding)

        stream = BytesIO()
        new_commit._serialize(stream)
        streamlen = stream.tell()
        stream.seek(0)

        istream = repo.odb.store(IStream(cls.type, streamlen, stream))
        new_commit.binsha = istream.binsha

        if head:
            # need late import here, importing git at the very beginning throws
            # as well ...
            import git.refs
            try:
                repo.head.set_commit(new_commit, logmsg=message)
            except ValueError:
                # head is not yet set to the ref our HEAD points to
                # Happens on first commit
                master = git.refs.Head.create(repo, repo.head.ref, new_commit, logmsg="commit (initial): %s" % message)
                repo.head.set_reference(master, logmsg='commit: Switching to %s' % master)
            # END handle empty repositories
        # END advance head handling
github h3llrais3r / Auto-Subliminal / lib / git / objects / commit.py View on Github external
if isinstance(tree, str):
            tree = repo.tree(tree)
        # END tree conversion

        # CREATE NEW COMMIT
        new_commit = cls(repo, cls.NULL_BIN_SHA, tree,
                         author, author_time, author_offset,
                         committer, committer_time, committer_offset,
                         message, parent_commits, conf_encoding)

        stream = BytesIO()
        new_commit._serialize(stream)
        streamlen = stream.tell()
        stream.seek(0)

        istream = repo.odb.store(IStream(cls.type, streamlen, stream))
        new_commit.binsha = istream.binsha

        if head:
            # need late import here, importing git at the very beginning throws
            # as well ...
            import git.refs
            try:
                repo.head.set_commit(new_commit, logmsg=message)
            except ValueError:
                # head is not yet set to the ref our HEAD points to
                # Happens on first commit
                master = git.refs.Head.create(repo, repo.head.ref, new_commit, logmsg="commit (initial): %s" % message)
                repo.head.set_reference(master, logmsg='commit: Switching to %s' % master)
            # END handle empty repositories
        # END advance head handling
github jsirois / sapling / saplib / split.py View on Github external
index.add(item,)
        else:
          index.add(item.traverse(lambda item, depth: item.type is "blob"))
      synthetic_tree = index.write_tree()
      parent = git.Commit(self._repo, git.Commit.NULL_BIN_SHA, synthetic_tree, commit.author,
                          commit.authored_date, commit.author_tz_offset, commit.committer,
                          commit.committed_date, commit.committer_tz_offset,
                          "%s\n(sapling split of %s)" % (commit.message, commit.hexsha),
                          [] if parent is None else [ parent ], commit.encoding)

      stream = StringIO.StringIO()
      parent._serialize(stream)
      stream_len = stream.tell()
      stream.seek(0)

      istream = self._repo.odb.store(gitdb.IStream(git.Commit.type, stream_len, stream))
      parent.binsha = istream.binsha

      if (on_commit):
        on_commit(i, commit, parent)

    branch.commit = parent
    return parent
github mgaitan / waliki_flask / extensions / Git.py View on Github external
def _create_blob_for(self, path):
        repo = self.repository
        page_abspath = os.path.join(os.path.split(self.repository.working_dir)[0], path)
        data = open(page_abspath, 'r').read()
        istream = IStream('blob', len(data), StringIO(data))
        repo.odb.store(istream)
        blob_path = self._get_blob_path(path)
        blob = Blob(repo, istream.binsha, 0100644, blob_path)
        return blob
github jsirois / sapling / saplib / split.py View on Github external
def _write_commit(self, commit):
    stream = StringIO.StringIO()
    commit._serialize(stream)

    stream_len = stream.tell()
    stream.seek(0)

    istream = self._repo.odb.store(gitdb.IStream(git.Commit.type, stream_len, stream))
    commit.binsha = istream.binsha
    return commit