Rewrite convert_to_{git,working_tree} to use strbuf's.

* Now, those functions take an "out" strbuf argument, where they store their
  result if any. In that case, it also returns 1, else it returns 0.
* those functions support "in place" editing, in the sense that it's OK to
  call them this way:
    convert_to_git(path, sb->buf, sb->len, sb);
  When doable, conversions are done in place for real, else the strbuf
  content is just replaced with the new one, transparentely for the caller.

If you want to create a new filter working this way, being the accumulation
of filter1, filter2, ... filtern, then your meta_filter would be:

    int meta_filter(..., const char *src, size_t len, struct strbuf *sb)
    {
        int ret = 0;
        ret |= filter1(...., src, len, sb);
        if (ret) {
            src = sb->buf;
            len = sb->len;
        }
        ret |= filter2(...., src, len, sb);
        if (ret) {
            src = sb->buf;
            len = sb->len;
        }
        ....
        return ret | filtern(..., src, len, sb);
    }

That's why subfilters the convert_to_* functions called were also rewritten
to work this way.

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Pierre Habouzit
2007-09-16 15:51:04 +02:00
committed by Junio C Hamano
parent 917c9a7133
commit 5ecd293d14
7 changed files with 235 additions and 312 deletions

10
entry.c
View File

@ -104,7 +104,8 @@ static int write_entry(struct cache_entry *ce, char *path, const struct checkout
long wrote;
switch (ntohl(ce->ce_mode) & S_IFMT) {
char *buf, *new;
char *new;
struct strbuf buf;
unsigned long size;
case S_IFREG:
@ -116,10 +117,11 @@ static int write_entry(struct cache_entry *ce, char *path, const struct checkout
/*
* Convert from git internal format to working tree format
*/
buf = convert_to_working_tree(ce->name, new, &size);
if (buf) {
strbuf_init(&buf, 0);
if (convert_to_working_tree(ce->name, new, size, &buf)) {
free(new);
new = buf;
new = buf.buf;
size = buf.len;
}
if (to_tempfile) {