Exemple #1
0
/*
 *	call-seq:
 *		Blob.write_file(repository, file_path) -> oid
 *
 *	Write the file specified in +file_path+ to a blob in +repository+.
 *	+file_path+ must be relative to the repository's working folder.
 *
 *		Blob.write_file(repo, 'src/blob.h') #=> '9d09060c850defbc7711d08b57def0d14e742f4e'
 */
static VALUE rb_git_blob_writefile(VALUE self, VALUE rb_repo, VALUE rb_path)
{
	int error;
	git_oid oid;
	git_repository *repo;

	Check_Type(rb_path, T_STRING);
	if (!rb_obj_is_instance_of(rb_repo, rb_cRuggedRepo))
		rb_raise(rb_eTypeError, "Expecting a Rugged Repository");

	Data_Get_Struct(rb_repo, git_repository, repo);

	error = git_blob_create_fromfile(&oid, repo, StringValueCStr(rb_path));
	rugged_exception_check(error);

	return rugged_create_oid(&oid);
}
PyObject *
Repository_create_blob_fromfile(Repository *self, PyObject *args)
{
    git_oid oid;
    const char* path;
    int err;

    if (!PyArg_ParseTuple(args, "s", &path))
      return NULL;

    err = git_blob_create_fromfile(&oid, self->repo, path);

    if (err < 0)
      return Error_set(err);

    return git_oid_to_python(oid.id);
}
Exemple #3
0
static int index_init_entry(git_index_entry *entry, git_index *index, const char *rel_path, int stage)
{
	char full_path[GIT_PATH_MAX];
	struct stat st;
	int error;

	if (index->repository == NULL)
		return git__throw(GIT_EBAREINDEX, "Failed to initialize entry. Repository is bare");

	git_path_join(full_path, index->repository->path_workdir, rel_path);

	if (p_lstat(full_path, &st) < 0)
		return git__throw(GIT_ENOTFOUND, "Failed to initialize entry. '%s' cannot be opened", full_path);

	if (stage < 0 || stage > 3)
		return git__throw(GIT_ERROR, "Failed to initialize entry. Invalid stage %i", stage);

	memset(entry, 0x0, sizeof(git_index_entry));

	entry->ctime.seconds = (git_time_t)st.st_ctime;
	entry->mtime.seconds = (git_time_t)st.st_mtime;
	/* entry.mtime.nanoseconds = st.st_mtimensec; */
	/* entry.ctime.nanoseconds = st.st_ctimensec; */
	entry->dev= st.st_rdev;
	entry->ino = st.st_ino;
	entry->mode = index_create_mode(st.st_mode);
	entry->uid = st.st_uid;
	entry->gid = st.st_gid;
	entry->file_size = st.st_size;

	/* write the blob to disk and get the oid */
	if ((error = git_blob_create_fromfile(&entry->oid, index->repository, rel_path)) < GIT_SUCCESS)
		return git__rethrow(error, "Failed to initialize index entry");

	entry->flags |= (stage << GIT_IDXENTRY_STAGESHIFT);
	entry->path = rel_path; /* do not duplicate; index_insert already does this */
	return GIT_SUCCESS;
}