Exemplo n.º 1
0
static int parse_picture_entry(git_repository *repo, const git_tree_entry *entry, const char *name)
{
	git_blob *blob;
	struct picture *pic;
	int hh, mm, ss, offset;
	char sign;

	/*
	 * The format of the picture name files is just the offset
	 * within the dive in form [[+-]hh:mm:ss, possibly followed
	 * by a hash to make the filename unique (which we can just
	 * ignore).
	 */
	if (sscanf(name, "%c%d:%d:%d", &sign, &hh, &mm, &ss) != 4)
		return report_error("Unknown file name %s", name);
	offset = ss + 60*(mm + 60*hh);
	if (sign == '-')
		offset = -offset;

	blob = git_tree_entry_blob(repo, entry);
	if (!blob)
		return report_error("Unable to read trip file");

	pic = alloc_picture();
	pic->offset.seconds = offset;
	dive_add_picture(active_dive, pic);

	for_each_line(blob, picture_parser, pic);
	git_blob_free(blob);
	return 0;
}
Exemplo n.º 2
0
static int parse_trip_entry(git_repository *repo, const git_tree_entry *entry)
{
	git_blob *blob = git_tree_entry_blob(repo, entry);
	if (!blob)
		return report_error("Unable to read trip file");
	for_each_line(blob, trip_parser, active_trip);
	git_blob_free(blob);
	return 0;
}
Exemplo n.º 3
0
static int parse_settings_entry(git_repository *repo, const git_tree_entry *entry)
{
	git_blob *blob = git_tree_entry_blob(repo, entry);
	if (!blob)
		return report_error("Unable to read settings file");
	set_save_userid_local(false);
	for_each_line(blob, settings_parser, NULL);
	git_blob_free(blob);
	return 0;
}
Exemplo n.º 4
0
static int parse_dive_entry(git_repository *repo, const git_tree_entry *entry, const char *suffix)
{
	struct dive *dive = active_dive;
	git_blob *blob = git_tree_entry_blob(repo, entry);
	if (!blob)
		return report_error("Unable to read dive file");
	if (*suffix)
		dive->number = atoi(suffix+1);
	cylinder_index = weightsystem_index = 0;
	for_each_line(blob, dive_parser, active_dive);
	git_blob_free(blob);
	return 0;
}
Exemplo n.º 5
0
/*
 * We should *really* try to delay the dive computer data parsing
 * until necessary, in order to reduce load-time. The parsing is
 * cheap, but the loading of the git blob into memory can be pretty
 * costly.
 */
static int parse_divecomputer_entry(git_repository *repo, const git_tree_entry *entry, const char *suffix)
{
	git_blob *blob = git_tree_entry_blob(repo, entry);

	if (!blob)
		return report_error("Unable to read divecomputer file");

	active_dc = create_new_dc(active_dive);
	for_each_line(blob, divecomputer_parser, active_dc);
	git_blob_free(blob);
	active_dc = NULL;
	return 0;
}
Exemplo n.º 6
0
static int parse_site_entry(git_repository *repo, const git_tree_entry *entry, const char *suffix)
{
	if (*suffix == '\0')
		return report_error("Dive site without uuid");
	uint32_t uuid = strtoul(suffix, NULL, 16);
	struct dive_site *ds = alloc_or_get_dive_site(uuid);
	git_blob *blob = git_tree_entry_blob(repo, entry);
	if (!blob)
		return report_error("Unable to read dive site file");
	for_each_line(blob, site_parser, ds);
	git_blob_free(blob);
	return 0;
}
Exemplo n.º 7
0
static int parse_picture_file(git_repository *repo, const git_tree_entry *entry, const char *name)
{
	/* remember the picture data so we can handle it when all dive data has been loaded
	 * the name of the git file is PIC-<hash> */
	git_blob *blob = git_tree_entry_blob(repo, entry);
	const void *rawdata = git_blob_rawcontent(blob);
	int len = git_blob_rawsize(blob);
	struct picture_entry_list *new_pel = malloc(sizeof(struct picture_entry_list));
	new_pel->next = pel;
	pel = new_pel;
	pel->data = malloc(len);
	memcpy(pel->data, rawdata, len);
	pel->len = len;
	pel->hash = strdup(name + 4);
	git_blob_free(blob);
	return 0;
}