summaryrefslogtreecommitdiff
path: root/builtin-rerere.c
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2007-10-16 00:15:25 -0400
committerShawn O. Pearce <spearce@spearce.org>2007-10-16 00:15:25 -0400
commit2e13e5d89252ceef606a0a7be32dbf5bea7e5aca (patch)
tree91f34e2fa799880e917238a7794b3dde35536c09 /builtin-rerere.c
parentccfc02a30057a5fa7376e1fc8e8c3fe5478556f4 (diff)
parentd55e7c3acf72413563e695a19f7f66efac442064 (diff)
downloadgit-2e13e5d89252ceef606a0a7be32dbf5bea7e5aca.tar.gz
Merge branch 'master' into db/fetch-pack
There's a number of tricky conflicts between master and this topic right now due to the rewrite of builtin-push. Junio must have handled these via rerere; I'd rather not deal with them again so I'm pre-merging master into the topic. Besides this topic somehow started to depend on the strbuf series that was in next, but is now in master. It no longer compiles on its own without the strbuf API. * master: (184 commits) Whip post 1.5.3.4 maintenance series into shape. Minor usage update in setgitperms.perl manual: use 'URL' instead of 'url'. manual: add some markup. manual: Fix example finding commits referencing given content. Fix wording in push definition. Fix some typos, punctuation, missing words, minor markup. manual: Fix or remove em dashes. Add a --dry-run option to git-push. Add a --dry-run option to git-send-pack. Fix in-place editing functions in convert.c instaweb: support for Ruby's WEBrick server instaweb: allow for use of auto-generated scripts Add 'git-p4 commit' as an alias for 'git-p4 submit' hg-to-git speedup through selectable repack intervals git-svn: respect Subversion's [auth] section configuration values gtksourceview2 support for gitview fix contrib/hooks/post-receive-email hooks.recipients error message Support cvs via git-shell rebase -i: use diff plumbing instead of porcelain ... Conflicts: Makefile builtin-push.c rsh.c
Diffstat (limited to 'builtin-rerere.c')
-rw-r--r--builtin-rerere.c66
1 files changed, 20 insertions, 46 deletions
diff --git a/builtin-rerere.c b/builtin-rerere.c
index 29d057c98c..b8206744c1 100644
--- a/builtin-rerere.c
+++ b/builtin-rerere.c
@@ -66,40 +66,15 @@ static int write_rr(struct path_list *rr, int out_fd)
return commit_lock_file(&write_lock);
}
-struct buffer {
- char *ptr;
- int nr, alloc;
-};
-
-static void append_line(struct buffer *buffer, const char *line)
-{
- int len = strlen(line);
-
- if (buffer->nr + len > buffer->alloc) {
- buffer->alloc = alloc_nr(buffer->nr + len);
- buffer->ptr = xrealloc(buffer->ptr, buffer->alloc);
- }
- memcpy(buffer->ptr + buffer->nr, line, len);
- buffer->nr += len;
-}
-
-static void clear_buffer(struct buffer *buffer)
-{
- free(buffer->ptr);
- buffer->ptr = NULL;
- buffer->nr = buffer->alloc = 0;
-}
-
static int handle_file(const char *path,
unsigned char *sha1, const char *output)
{
SHA_CTX ctx;
char buf[1024];
int hunk = 0, hunk_no = 0;
- struct buffer minus = { NULL, 0, 0 }, plus = { NULL, 0, 0 };
- struct buffer *one = &minus, *two = &plus;
+ struct strbuf one, two;
FILE *f = fopen(path, "r");
- FILE *out;
+ FILE *out = NULL;
if (!f)
return error("Could not open %s", path);
@@ -110,51 +85,50 @@ static int handle_file(const char *path,
fclose(f);
return error("Could not write %s", output);
}
- } else
- out = NULL;
+ }
if (sha1)
SHA1_Init(&ctx);
+ strbuf_init(&one, 0);
+ strbuf_init(&two, 0);
while (fgets(buf, sizeof(buf), f)) {
if (!prefixcmp(buf, "<<<<<<< "))
hunk = 1;
else if (!prefixcmp(buf, "======="))
hunk = 2;
else if (!prefixcmp(buf, ">>>>>>> ")) {
- int one_is_longer = (one->nr > two->nr);
- int common_len = one_is_longer ? two->nr : one->nr;
- int cmp = memcmp(one->ptr, two->ptr, common_len);
+ int cmp = strbuf_cmp(&one, &two);
hunk_no++;
hunk = 0;
- if ((cmp > 0) || ((cmp == 0) && one_is_longer)) {
- struct buffer *swap = one;
- one = two;
- two = swap;
+ if (cmp > 0) {
+ strbuf_swap(&one, &two);
}
if (out) {
fputs("<<<<<<<\n", out);
- fwrite(one->ptr, one->nr, 1, out);
+ fwrite(one.buf, one.len, 1, out);
fputs("=======\n", out);
- fwrite(two->ptr, two->nr, 1, out);
+ fwrite(two.buf, two.len, 1, out);
fputs(">>>>>>>\n", out);
}
if (sha1) {
- SHA1_Update(&ctx, one->ptr, one->nr);
- SHA1_Update(&ctx, "\0", 1);
- SHA1_Update(&ctx, two->ptr, two->nr);
- SHA1_Update(&ctx, "\0", 1);
+ SHA1_Update(&ctx, one.buf ? one.buf : "",
+ one.len + 1);
+ SHA1_Update(&ctx, two.buf ? two.buf : "",
+ two.len + 1);
}
- clear_buffer(one);
- clear_buffer(two);
+ strbuf_reset(&one);
+ strbuf_reset(&two);
} else if (hunk == 1)
- append_line(one, buf);
+ strbuf_addstr(&one, buf);
else if (hunk == 2)
- append_line(two, buf);
+ strbuf_addstr(&two, buf);
else if (out)
fputs(buf, out);
}
+ strbuf_release(&one);
+ strbuf_release(&two);
fclose(f);
if (out)