Both single range clone and deeply clone are supported. Signed-off-by: Bo Yang <struggleyb.nku@xxxxxxxxx> --- line.c | 35 +++++++++++++++++++++++++++++++++++ line.h | 4 ++++ 2 files changed, 39 insertions(+), 0 deletions(-) diff --git a/line.c b/line.c index 7b7f3f3..f765a03 100644 --- a/line.c +++ b/line.c @@ -370,6 +370,41 @@ void diff_line_range_append(struct diff_line_range *r, const char *arg) r->ranges[r->nr - 1].arg = arg; } +struct diff_line_range *diff_line_range_clone(struct diff_line_range *r) +{ + struct diff_line_range *ret = xmalloc(sizeof(*ret)); + + DIFF_LINE_RANGE_INIT(ret); + ret->ranges = xcalloc(sizeof(struct range), r->nr); + memcpy(ret->ranges, r->ranges, sizeof(struct range) * r->nr); + + ret->alloc = ret->nr = r->nr; + + ret->spec = r->spec; + assert(ret->spec); + ret->spec->count++; + + return ret; +} + +struct diff_line_range *diff_line_range_clone_deeply(struct diff_line_range *r) +{ + struct diff_line_range *ret = NULL; + struct diff_line_range *tmp = NULL, *prev = NULL; + + assert(r); + ret = tmp = prev = diff_line_range_clone(r); + r = r->next; + while (r) { + tmp = diff_line_range_clone(r); + prev->next = tmp; + prev = tmp; + r = r->next; + } + + return ret; +} + struct diff_line_range *diff_line_range_merge(struct diff_line_range *out, struct diff_line_range *other) { diff --git a/line.h b/line.h index a2f8545..b6f328c 100644 --- a/line.h +++ b/line.h @@ -110,6 +110,10 @@ extern void diff_line_range_append(struct diff_line_range *r, const char *arg); extern void diff_line_range_clear(struct diff_line_range *r); +extern struct diff_line_range *diff_line_range_clone(struct diff_line_range *r); + +extern struct diff_line_range *diff_line_range_clone_deeply(struct diff_line_range *r); + extern struct diff_line_range *diff_line_range_merge(struct diff_line_range *out, struct diff_line_range *other); -- 1.7.1.577.g36cf0.dirty -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html