aboutsummaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorPierre Habouzit <madcoder@debian.org>2007-09-16 15:51:04 +0200
committerJunio C Hamano <gitster@pobox.com>2007-09-16 17:30:03 -0700
commit5ecd293d1420bf641a927a015877950f4d79c067 (patch)
treeae217d6915a5c858f7173ed0c99730a4ce62d2f4 /diff.c
parent917c9a713397b16671ed5b1f1c159515bcfa389e (diff)
downloadgit-5ecd293d1420bf641a927a015877950f4d79c067.tar.gz
git-5ecd293d1420bf641a927a015877950f4d79c067.tar.xz
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>
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/diff.c b/diff.c
index 7290309ea..f41bcd94a 100644
--- a/diff.c
+++ b/diff.c
@@ -1600,10 +1600,9 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
if (!s->sha1_valid ||
reuse_worktree_file(s->path, s->sha1, 0)) {
+ struct strbuf buf;
struct stat st;
int fd;
- char *buf;
- unsigned long size;
if (!strcmp(s->path, "-"))
return populate_from_stdin(s);
@@ -1644,13 +1643,12 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
/*
* Convert from working tree format to canonical git format
*/
- size = s->size;
- buf = convert_to_git(s->path, s->data, &size);
- if (buf) {
+ strbuf_init(&buf, 0);
+ if (convert_to_git(s->path, s->data, s->size, &buf)) {
munmap(s->data, s->size);
s->should_munmap = 0;
- s->data = buf;
- s->size = size;
+ s->data = buf.buf;
+ s->size = buf.len;
s->should_free = 1;
}
}