summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornulltoken <emeric.fermas@gmail.com>2012-09-26 19:15:11 +0200
committernulltoken <emeric.fermas@gmail.com>2012-10-08 00:44:13 +0200
commit3e012fca770944211bd2b32632f64ae07c42e25d (patch)
tree885469efb1434c995292c43670db4b7f5dc2d698
parent70edc1b0fc98c22e6c0f73c7292cb858e444e5c2 (diff)
downloadlibgit2-3e012fca770944211bd2b32632f64ae07c42e25d.tar.gz
refspec: introduce git_refspec_transform_l()
-rw-r--r--src/refspec.c18
-rw-r--r--src/refspec.h11
2 files changed, 25 insertions, 4 deletions
diff --git a/src/refspec.c b/src/refspec.c
index cd3a528bd..b1790b32c 100644
--- a/src/refspec.c
+++ b/src/refspec.c
@@ -194,20 +194,20 @@ int git_refspec_transform(char *out, size_t outlen, const git_refspec *spec, con
return 0;
}
-int git_refspec_transform_r(git_buf *out, const git_refspec *spec, const char *name)
+static int refspec_transform(git_buf *out, const char *from, const char *to, const char *name)
{
- if (git_buf_sets(out, spec->dst) < 0)
+ if (git_buf_sets(out, to) < 0)
return -1;
/*
- * No '*' at the end means that it's mapped to one specific local
+ * No '*' at the end means that it's mapped to one specific
* branch, so no actual transformation is needed.
*/
if (git_buf_len(out) > 0 && out->ptr[git_buf_len(out) - 1] != '*')
return 0;
git_buf_truncate(out, git_buf_len(out) - 1); /* remove trailing '*' */
- git_buf_puts(out, name + strlen(spec->src) - 1);
+ git_buf_puts(out, name + strlen(from) - 1);
if (git_buf_oom(out))
return -1;
@@ -215,3 +215,13 @@ int git_refspec_transform_r(git_buf *out, const git_refspec *spec, const char *n
return 0;
}
+int git_refspec_transform_r(git_buf *out, const git_refspec *spec, const char *name)
+{
+ return refspec_transform(out, spec->src, spec->dst, name);
+}
+
+int git_refspec_transform_l(git_buf *out, const git_refspec *spec, const char *name)
+{
+ return refspec_transform(out, spec->dst, spec->src, name);
+}
+
diff --git a/src/refspec.h b/src/refspec.h
index a5df458c6..6e0596a55 100644
--- a/src/refspec.h
+++ b/src/refspec.h
@@ -40,4 +40,15 @@ void git_refspec__free(git_refspec *refspec);
*/
int git_refspec_transform_r(git_buf *out, const git_refspec *spec, const char *name);
+/**
+ * Transform a reference from its target following the refspec's rules,
+ * and writes the results into a git_buf.
+ *
+ * @param out where to store the source name
+ * @param spec the refspec
+ * @param name the name of the reference to transform
+ * @return 0 or error if buffer allocation fails
+ */
+int git_refspec_transform_l(git_buf *out, const git_refspec *spec, const char *name);
+
#endif