Re: [PATCH 1/2] Have a filter_start/filter_end API.

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Alex Riesen
Date: Sunday, October 7, 2007 - 2:50 pm

Pierre Habouzit, Sun, Oct 07, 2007 18:52:18 +0200:

Why do you have to play these games with src being inside/outside?
Don't you know where src already is? AFAICS in convert.c crlf_to_git -
you do. And everywhere else you know this fact too.


in convert.c it is never "inside". It is _exactly_ the ->buf.
No need for generic "inside" check. Just test if src == ->buf.

And AFAICS, there is no other users of the function.


src is outside of strbuf scope. It is not internal to struct strbuf.
The caller must already know if it is inside of the given strbuf
instance.

need_realloc is covered by make_room, isn't it?

I'd suggest just fix the caller, it is simple in convert.c: just use
ret, which contains exactly this information. If you insist on editing
in-place, which makes your routines really need the in-placeability
informaion. Just give it to them, better explicitely. All of this
makes the routines very convert.c specific, which is the reason why I
argument to have them just there and nowhere else.

Alternatively, one can memdup ->buf (as it is the input for next
filter) every time a filter modifies it (which is safe, but simple,
slow, requires memory, and may fragment heap):

/* simplified */
int convert_to_git(const char *path, const char *src, size_t len, struct strbuf *dst)
{
	int crlf = CRLF_GUESS;
	int ident = 0, ret = 0;
	char *filter = NULL;
	const char *tmp = src;

	ret |= apply_filter(path, tmp, len, dst, filter);
	if (ret) {
		tmp = xmemdupz(dst->buf, dst->len);
		len = dst->len;
	}

	if (crlf_to_git(path, tmp, len, dst, crlf)) {
		ret |= 1;
		if (tmp != src)
			free((void*)tmp);
		tmp = xmemdupz(dst->buf, dst->len);
		len = dst->len;
	}

	ret |= ident_to_git(path, tmp, len, dst, ident);
	if (tmp != src)
		free((void*)tmp);
	return ret;
}

It is just to show that nothing like strbuf_start_filter is _needed_
at all.


-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
strbuf `filter' API, Pierre Habouzit, (Fri Oct 5, 1:19 pm)
[PATCH 1/2] Have a filter_start/filter_end API., Pierre Habouzit, (Fri Oct 5, 1:19 pm)
Re: [PATCH 1/2] Have a filter_start/filter_end API., Alex Riesen, (Sat Oct 6, 2:06 am)
Re: [PATCH 1/2] Have a filter_start/filter_end API., Pierre Habouzit, (Sun Oct 7, 7:53 am)
Re: [PATCH 1/2] Have a filter_start/filter_end API., Alex Riesen, (Sun Oct 7, 9:07 am)
Re: [PATCH 1/2] Have a filter_start/filter_end API., Pierre Habouzit, (Sun Oct 7, 9:52 am)
Re: [PATCH 1/2] Have a filter_start/filter_end API., Alex Riesen, (Sun Oct 7, 2:50 pm)
Re: [PATCH 1/2] Have a filter_start/filter_end API., Pierre Habouzit, (Mon Oct 8, 12:29 am)
Re: [PATCH 1/2] Have a filter_start/filter_end API., Alex Riesen, (Mon Oct 8, 11:48 am)