Exemple #1
0
static git_revwalk_commit *commit_to_walkcommit(git_revwalk *walk, git_commit *commit_object)
{
	git_revwalk_commit *commit;

	commit = (git_revwalk_commit *)git_hashtable_lookup(walk->commits, commit_object);

	if (commit != NULL)
		return commit;

	commit = git__malloc(sizeof(git_revwalk_commit));
	if (commit == NULL)
		return NULL;

	memset(commit, 0x0, sizeof(git_revwalk_commit));

	commit->commit_object = commit_object;
	GIT_OBJECT_INCREF(commit_object);

	git_hashtable_insert(walk->commits, commit_object, commit);

	return commit;
}
Exemple #2
0
int git_revwalk_next(git_commit **commit, git_revwalk *walk)
{
	git_revwalk_commit *next;

	assert(walk && commit);

	if (!walk->walking)
		prepare_walk(walk);

	*commit = NULL;

	while ((next = walk->next(&walk->iterator)) != NULL) {
		if (!next->uninteresting) {
			*commit = next->commit_object;
			GIT_OBJECT_INCREF(*commit);
			return GIT_SUCCESS;
		}
	}

	/* No commits left to iterate */
	git_revwalk_reset(walk);
	return GIT_EREVWALKOVER;
}
Exemple #3
0
int git_object_lookup(git_object **object_out, git_repository *repo, const git_oid *id, git_otype type)
{
	git_object *object = NULL;
	git_rawobj obj_file;
	int error = GIT_SUCCESS;

	assert(repo && object_out && id);

	object = git_hashtable_lookup(repo->objects, id);
	if (object != NULL) {
		*object_out = object;
		GIT_OBJECT_INCREF(repo, object);
		return GIT_SUCCESS;
	}

	error = git_odb_read(&obj_file, repo->db, id);
	if (error < GIT_SUCCESS)
		return error;

	if (type != GIT_OBJ_ANY && type != obj_file.type) {
		git_rawobj_close(&obj_file);
		return GIT_EINVALIDTYPE;
	}

	type = obj_file.type;

	if ((error = create_object(&object, type)) < GIT_SUCCESS)
		return error;

	/* Initialize parent object */
	git_oid_cpy(&object->id, id);
	object->repo = repo;
	memcpy(&object->source.raw, &obj_file, sizeof(git_rawobj));
	object->source.open = 1;

	switch (type) {
	case GIT_OBJ_COMMIT:
		error = git_commit__parse((git_commit *)object);
		break;

	case GIT_OBJ_TREE:
		error = git_tree__parse((git_tree *)object);
		break;

	case GIT_OBJ_TAG:
		error = git_tag__parse((git_tag *)object);
		break;

	case GIT_OBJ_BLOB:
		error = git_blob__parse((git_blob *)object);
		break;

	default:
		break;
	}

	if (error < GIT_SUCCESS) {
		git_object__free(object);
		return error;
	}

	git_object__source_close(object);
	git_hashtable_insert(repo->objects, &object->id, object);

	GIT_OBJECT_INCREF(repo, object);
	*object_out = object;
	return GIT_SUCCESS;
}