How to use the dulwich.objects.Blob function in dulwich

To help you get started, we’ve selected a few dulwich 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 ties / BeAT / beat / tools / logsave.py View on Github external
def __init_code__():
	# initialize the repo if it doesn't exists, or load it if it does

	if not path.exists(LOGS_PATH):
		print "creating folder "+ LOGS_PATH
		mkdir(LOGS_PATH)
		repo = Repo.init(LOGS_PATH)
		blob = Blob.from_string("data")
		tree =Tree()
		tree.add(0100644, "initfile", blob.id)
		c = Commit()
		c.tree = tree.id
		author = "Writer a@a.com"
		c.author=c.committer=author
		c.commit_time=c.author_time=int(time())
		tz = parse_timezone('+0200')
		c.commit_timezone=c.author_timezone=tz
		c.encoding="UTF-8"
		c.message="initial commit"
		store = repo.object_store
		store.add_object(blob)
		store.add_object(tree)
		store.add_object(c)
		repo.refs['refs/heads/master'] = c.id
github arthaud / git-dumper / git-dumper.py View on Github external
def get_referenced_sha1(obj_file):
    ''' Return all the referenced SHA1 in the given object file '''
    objs = []

    if isinstance(obj_file, dulwich.objects.Commit):
        objs.append(obj_file.tree.decode())

        for parent in obj_file.parents:
            objs.append(parent.decode())
    elif isinstance(obj_file, dulwich.objects.Tree):
        for item in obj_file.iteritems():
            objs.append(item.sha.decode())
    elif isinstance(obj_file, dulwich.objects.Blob):
        pass
    else:
        printf('error: unexpected object type: %r\n' % obj_file, file=sys.stderr)
        sys.exit(1)

    return objs
github facebookexperimental / eden / eden / scm / edenscm / hgext / hggit / git_handler.py View on Github external
CALLBACK_BUFFER = ""
            if not remote_info:
                remote_info = "\n"

            for line in remote_info[:-1].split("\n"):
                self.ui.status(_("remote: %s\n") % line)

        try:
            new_refs = client.send_pack(path, changed, genpack, progress=callback)
            if len(change_totals) > 0:
                self.ui.status(
                    _("added %d commits with %d trees" " and %d blobs\n")
                    % (
                        change_totals.get(Commit, 0),
                        change_totals.get(Tree, 0),
                        change_totals.get(Blob, 0),
                    )
                )
            return old_refs, new_refs
        except (HangupException, GitProtocolError) as e:
            raise error.Abort(_("git remote error: ") + str(e))
github cloudfoundry / python-buildpack / fixtures / mercurial / src / vcs / vcs / backends / git / inmemory.py View on Github external
# put curdir back into dirnames and stops
                    dirnames.insert(0, curdir)
                    break
                else:
                    # If found, updates parent
                    parent = self.repository._repo[dir_id]
                    ancestors.append((curdir, parent))
            # Now parent is deepest existing tree and we need to create subtrees
            # for dirnames (in reverse order) [this only applies for nodes from added]
            new_trees = []

            if not node.is_binary:
                content = node.content.encode(ENCODING)
            else:
                content = node.content
            blob = objects.Blob.from_string(content)

            node_path = node.name.encode(ENCODING)
            if dirnames:
                # If there are trees which should be created we need to build
                # them now (in reverse order)
                reversed_dirnames = list(reversed(dirnames))
                curtree = objects.Tree()
                curtree[node_path] = node.mode, blob.id
                new_trees.append(curtree)
                for dirname in reversed_dirnames[:-1]:
                    newtree = objects.Tree()
                    #newtree.add(DIRMOD, dirname, curtree.id)
                    newtree[dirname] = DIRMOD, curtree.id
                    new_trees.append(newtree)
                    curtree = newtree
                parent[reversed_dirnames[-1]] = DIRMOD, curtree.id
github openstates / billy / billy / importers / bills.py View on Github external
def git_add_bill(data):
    if not hasattr(settings, "ENABLE_GIT") or not settings.ENABLE_GIT:
        return

    global git_active_repo
    global git_active_tree
    global git_active_commit

    bill = json.dumps(data, cls=JSONEncoderPlus, sort_keys=True, indent=4)
    spam = Blob.from_string(bill)
    bid = str(data['_id'])
    git_active_repo.object_store.add_object(spam)
    # 0100644 octal -> 33188 decimal
    git_active_tree[bid] = (33188, spam.id)
    git_active_tree.check()
    print("added %s - %s" % (data['_id'], spam.id))
github jonashaag / klaus / klaus / repo.py View on Github external
"""Return the list of changes introduced by `commit`."""
        from klaus.utils import guess_is_binary

        if commit.parents:
            parent_tree = self[commit.parents[0]].tree
        else:
            parent_tree = None

        summary = {'nfiles': 0, 'nadditions':  0, 'ndeletions':  0}
        file_changes = []  # the changes in detail

        dulwich_changes = self.object_store.tree_changes(parent_tree, commit.tree)
        for (oldpath, newpath), (oldmode, newmode), (oldsha, newsha) in dulwich_changes:
            summary['nfiles'] += 1
            try:
                oldblob = self.object_store[oldsha] if oldsha else Blob.from_string(b'')
                newblob = self.object_store[newsha] if newsha else Blob.from_string(b'')
            except KeyError:
                # newsha/oldsha are probably related to submodules.
                # Dulwich will handle that.
                pass

            # Check for binary files -- can't show diffs for these
            if guess_is_binary(newblob) or \
               guess_is_binary(oldblob):
                file_changes.append({
                    'is_binary': True,
                    'old_filename': oldpath or '/dev/null',
                    'new_filename': newpath or '/dev/null',
                    'chunks': None
                })
                continue
github dulwich / dulwich / dulwich / index.py View on Github external
def blob_from_path_and_stat(fs_path, st):
    """Create a blob from a path and a stat object.

    Args:
      fs_path: Full file system path to file
      st: A stat object
    Returns: A `Blob` object
    """
    assert isinstance(fs_path, bytes)
    blob = Blob()
    if not stat.S_ISLNK(st.st_mode):
        with open(fs_path, 'rb') as f:
            blob.data = f.read()
    else:
        if sys.platform == 'win32' and sys.version_info[0] == 3:
            # os.readlink on Python3 on Windows requires a unicode string.
            # TODO(jelmer): Don't assume tree_encoding == fs_encoding
            tree_encoding = sys.getfilesystemencoding()
            fs_path = fs_path.decode(tree_encoding)
            blob.data = os.readlink(fs_path).encode(tree_encoding)
        else:
            blob.data = os.readlink(fs_path)
    return blob
github FriendCode / gittle / gittle / utils / git.py View on Github external
def blob_from_path(basepath, path):
    """Returns a tuple of (sha_id, mode, blob)
    """
    fullpath = os.path.join(basepath, path)
    with open(fullpath, 'rb') as working_file:
        blob = Blob()
        blob.data = working_file.read()
    return (path, os.stat(fullpath).st_mode, blob)
github mbr / unleash / unleash / git.py View on Github external
def set_path_data(self, path, data, mode=0o0100644):
        blob = Blob.from_string(data)
        self.new_objects[blob.id] = blob

        return self.set_path_id(path, blob.id, mode)
github akbargumbira / qgis_resources_sharing / ext_libs / dulwich / patch.py View on Github external
def content(mode, hexsha):
        if hexsha is None:
            return Blob.from_string(b'')
        elif S_ISGITLINK(mode):
            return Blob.from_string(b"Subproject commit " + hexsha + b"\n")
        else:
            return store[hexsha]