From fb39b3a54cfedd1e414dc86f6ff5f9af9190c97b Mon Sep 17 00:00:00 2001 From: nulltoken Date: Tue, 2 Oct 2012 14:36:59 +0200 Subject: [PATCH] refspec: introduce git_refspec__serialize() --- src/refspec.c | 11 +++++++++++ src/refspec.h | 2 ++ src/remote.c | 11 ++++------- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/refspec.c b/src/refspec.c index b1790b32c..8b69e9d8e 100644 --- a/src/refspec.c +++ b/src/refspec.c @@ -225,3 +225,14 @@ int git_refspec_transform_l(git_buf *out, const git_refspec *spec, const char *n return refspec_transform(out, spec->dst, spec->src, name); } +int git_refspec__serialize(git_buf *out, const git_refspec *refspec) +{ + if (refspec->force) + git_buf_putc(out, '+'); + + git_buf_printf(out, "%s:%s", + refspec->src != NULL ? refspec->src : "", + refspec->dst != NULL ? refspec->dst : ""); + + return git_buf_oom(out) == false; +} diff --git a/src/refspec.h b/src/refspec.h index 6e0596a55..40da16afc 100644 --- a/src/refspec.h +++ b/src/refspec.h @@ -51,4 +51,6 @@ int git_refspec_transform_r(git_buf *out, const git_refspec *spec, const char *n */ int git_refspec_transform_l(git_buf *out, const git_refspec *spec, const char *name); +int git_refspec__serialize(git_buf *out, const git_refspec *refspec); + #endif diff --git a/src/remote.c b/src/remote.c index 1e1cc3883..3506d5f08 100644 --- a/src/remote.c +++ b/src/remote.c @@ -237,17 +237,14 @@ static int update_config_refspec( if (refspec->src == NULL || refspec->dst == NULL) return 0; - git_buf_printf( + if (git_buf_printf( &name, "remote.%s.%s", remote_name, - git_direction == GIT_DIR_FETCH ? "fetch" : "push"); + git_direction == GIT_DIR_FETCH ? "fetch" : "push") < 0) + goto cleanup; - if (refspec->force) - git_buf_putc(&value, '+'); - git_buf_printf(&value, "%s:%s", refspec->src, refspec->dst); - - if (git_buf_oom(&name) || git_buf_oom(&value)) + if (git_refspec__serialize(&value, refspec) < 0) goto cleanup; error = git_config_set_string(