rerere: move code related to "forget" together
"rerere forget" is the only user of handle_cache() helper, which in turn is the only user of rerere_io that reads from an in-core buffer whose getline method is implemented as rerere_mem_getline(). Gather them together. Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
1be1e85115
commit
3d730ed9b2
194
rerere.c
194
rerere.c
@ -516,103 +516,6 @@ static int handle_file(const char *path, unsigned char *sha1, const char *output
|
|||||||
return hunk_no;
|
return hunk_no;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Subclass of rerere_io that reads from an in-core buffer that is a
|
|
||||||
* strbuf
|
|
||||||
*/
|
|
||||||
struct rerere_io_mem {
|
|
||||||
struct rerere_io io;
|
|
||||||
struct strbuf input;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* ... and its getline() method implementation
|
|
||||||
*/
|
|
||||||
static int rerere_mem_getline(struct strbuf *sb, struct rerere_io *io_)
|
|
||||||
{
|
|
||||||
struct rerere_io_mem *io = (struct rerere_io_mem *)io_;
|
|
||||||
char *ep;
|
|
||||||
size_t len;
|
|
||||||
|
|
||||||
strbuf_release(sb);
|
|
||||||
if (!io->input.len)
|
|
||||||
return -1;
|
|
||||||
ep = memchr(io->input.buf, '\n', io->input.len);
|
|
||||||
if (!ep)
|
|
||||||
ep = io->input.buf + io->input.len;
|
|
||||||
else if (*ep == '\n')
|
|
||||||
ep++;
|
|
||||||
len = ep - io->input.buf;
|
|
||||||
strbuf_add(sb, io->input.buf, len);
|
|
||||||
strbuf_remove(&io->input, 0, len);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int handle_cache(const char *path, unsigned char *sha1, const char *output)
|
|
||||||
{
|
|
||||||
mmfile_t mmfile[3] = {{NULL}};
|
|
||||||
mmbuffer_t result = {NULL, 0};
|
|
||||||
const struct cache_entry *ce;
|
|
||||||
int pos, len, i, hunk_no;
|
|
||||||
struct rerere_io_mem io;
|
|
||||||
int marker_size = ll_merge_marker_size(path);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Reproduce the conflicted merge in-core
|
|
||||||
*/
|
|
||||||
len = strlen(path);
|
|
||||||
pos = cache_name_pos(path, len);
|
|
||||||
if (0 <= pos)
|
|
||||||
return -1;
|
|
||||||
pos = -pos - 1;
|
|
||||||
|
|
||||||
while (pos < active_nr) {
|
|
||||||
enum object_type type;
|
|
||||||
unsigned long size;
|
|
||||||
|
|
||||||
ce = active_cache[pos++];
|
|
||||||
if (ce_namelen(ce) != len || memcmp(ce->name, path, len))
|
|
||||||
break;
|
|
||||||
i = ce_stage(ce) - 1;
|
|
||||||
if (!mmfile[i].ptr) {
|
|
||||||
mmfile[i].ptr = read_sha1_file(ce->sha1, &type, &size);
|
|
||||||
mmfile[i].size = size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (i = 0; i < 3; i++)
|
|
||||||
if (!mmfile[i].ptr && !mmfile[i].size)
|
|
||||||
mmfile[i].ptr = xstrdup("");
|
|
||||||
|
|
||||||
/*
|
|
||||||
* NEEDSWORK: handle conflicts from merges with
|
|
||||||
* merge.renormalize set, too
|
|
||||||
*/
|
|
||||||
ll_merge(&result, path, &mmfile[0], NULL,
|
|
||||||
&mmfile[1], "ours",
|
|
||||||
&mmfile[2], "theirs", NULL);
|
|
||||||
for (i = 0; i < 3; i++)
|
|
||||||
free(mmfile[i].ptr);
|
|
||||||
|
|
||||||
memset(&io, 0, sizeof(io));
|
|
||||||
io.io.getline = rerere_mem_getline;
|
|
||||||
if (output)
|
|
||||||
io.io.output = fopen(output, "w");
|
|
||||||
else
|
|
||||||
io.io.output = NULL;
|
|
||||||
strbuf_init(&io.input, 0);
|
|
||||||
strbuf_attach(&io.input, result.ptr, result.size, result.size);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Grab the conflict ID and optionally write the original
|
|
||||||
* contents with conflict markers out.
|
|
||||||
*/
|
|
||||||
hunk_no = handle_path(sha1, (struct rerere_io *)&io, marker_size);
|
|
||||||
strbuf_release(&io.input);
|
|
||||||
if (io.io.output)
|
|
||||||
fclose(io.io.output);
|
|
||||||
return hunk_no;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Look at a cache entry at "i" and see if it is not conflicting,
|
* Look at a cache entry at "i" and see if it is not conflicting,
|
||||||
* conflicting and we are willing to handle, or conflicting and
|
* conflicting and we are willing to handle, or conflicting and
|
||||||
@ -1005,6 +908,103 @@ int rerere(int flags)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Subclass of rerere_io that reads from an in-core buffer that is a
|
||||||
|
* strbuf
|
||||||
|
*/
|
||||||
|
struct rerere_io_mem {
|
||||||
|
struct rerere_io io;
|
||||||
|
struct strbuf input;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ... and its getline() method implementation
|
||||||
|
*/
|
||||||
|
static int rerere_mem_getline(struct strbuf *sb, struct rerere_io *io_)
|
||||||
|
{
|
||||||
|
struct rerere_io_mem *io = (struct rerere_io_mem *)io_;
|
||||||
|
char *ep;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
strbuf_release(sb);
|
||||||
|
if (!io->input.len)
|
||||||
|
return -1;
|
||||||
|
ep = memchr(io->input.buf, '\n', io->input.len);
|
||||||
|
if (!ep)
|
||||||
|
ep = io->input.buf + io->input.len;
|
||||||
|
else if (*ep == '\n')
|
||||||
|
ep++;
|
||||||
|
len = ep - io->input.buf;
|
||||||
|
strbuf_add(sb, io->input.buf, len);
|
||||||
|
strbuf_remove(&io->input, 0, len);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int handle_cache(const char *path, unsigned char *sha1, const char *output)
|
||||||
|
{
|
||||||
|
mmfile_t mmfile[3] = {{NULL}};
|
||||||
|
mmbuffer_t result = {NULL, 0};
|
||||||
|
const struct cache_entry *ce;
|
||||||
|
int pos, len, i, hunk_no;
|
||||||
|
struct rerere_io_mem io;
|
||||||
|
int marker_size = ll_merge_marker_size(path);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Reproduce the conflicted merge in-core
|
||||||
|
*/
|
||||||
|
len = strlen(path);
|
||||||
|
pos = cache_name_pos(path, len);
|
||||||
|
if (0 <= pos)
|
||||||
|
return -1;
|
||||||
|
pos = -pos - 1;
|
||||||
|
|
||||||
|
while (pos < active_nr) {
|
||||||
|
enum object_type type;
|
||||||
|
unsigned long size;
|
||||||
|
|
||||||
|
ce = active_cache[pos++];
|
||||||
|
if (ce_namelen(ce) != len || memcmp(ce->name, path, len))
|
||||||
|
break;
|
||||||
|
i = ce_stage(ce) - 1;
|
||||||
|
if (!mmfile[i].ptr) {
|
||||||
|
mmfile[i].ptr = read_sha1_file(ce->sha1, &type, &size);
|
||||||
|
mmfile[i].size = size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (i = 0; i < 3; i++)
|
||||||
|
if (!mmfile[i].ptr && !mmfile[i].size)
|
||||||
|
mmfile[i].ptr = xstrdup("");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NEEDSWORK: handle conflicts from merges with
|
||||||
|
* merge.renormalize set, too?
|
||||||
|
*/
|
||||||
|
ll_merge(&result, path, &mmfile[0], NULL,
|
||||||
|
&mmfile[1], "ours",
|
||||||
|
&mmfile[2], "theirs", NULL);
|
||||||
|
for (i = 0; i < 3; i++)
|
||||||
|
free(mmfile[i].ptr);
|
||||||
|
|
||||||
|
memset(&io, 0, sizeof(io));
|
||||||
|
io.io.getline = rerere_mem_getline;
|
||||||
|
if (output)
|
||||||
|
io.io.output = fopen(output, "w");
|
||||||
|
else
|
||||||
|
io.io.output = NULL;
|
||||||
|
strbuf_init(&io.input, 0);
|
||||||
|
strbuf_attach(&io.input, result.ptr, result.size, result.size);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Grab the conflict ID and optionally write the original
|
||||||
|
* contents with conflict markers out.
|
||||||
|
*/
|
||||||
|
hunk_no = handle_path(sha1, (struct rerere_io *)&io, marker_size);
|
||||||
|
strbuf_release(&io.input);
|
||||||
|
if (io.io.output)
|
||||||
|
fclose(io.io.output);
|
||||||
|
return hunk_no;
|
||||||
|
}
|
||||||
|
|
||||||
static int rerere_forget_one_path(const char *path, struct string_list *rr)
|
static int rerere_forget_one_path(const char *path, struct string_list *rr)
|
||||||
{
|
{
|
||||||
const char *filename;
|
const char *filename;
|
||||||
|
Loading…
Reference in New Issue
Block a user