summaryrefslogtreecommitdiff
path: root/src/buffer.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-09-26 20:20:03 -0400
committerEdward Thomson <ethomson@edwardthomson.com>2021-09-26 20:20:57 -0400
commit7e7cfe8acdc8e506a5e670e7cfb74e43c031ccaf (patch)
treefedcb7be8c2b7c200e2fdbe5f9219ca8f567d649 /src/buffer.c
parent136901086ecfdd2b5cc106782310355a9c0b1a9a (diff)
downloadlibgit2-ethomson/strarray.tar.gz
buf: common_prefix takes a string arrayethomson/strarray
`git_strarray` is a public-facing type. Change `git_buf_text_common_prefix` to not use it, and just take an array of strings instead.
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/buffer.c b/src/buffer.c
index a57df1284..fe087ea11 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1201,25 +1201,26 @@ int git_buf_lf_to_crlf(git_buf *tgt, const git_buf *src)
return git_buf_put(tgt, scan, end - scan);
}
-int git_buf_common_prefix(git_buf *buf, const git_strarray *strings)
+int git_buf_common_prefix(git_buf *buf, char *const *const strings, size_t count)
{
size_t i;
const char *str, *pfx;
git_buf_clear(buf);
- if (!strings || !strings->count)
+ if (!strings || !count)
return 0;
/* initialize common prefix to first string */
- if (git_buf_sets(buf, strings->strings[0]) < 0)
+ if (git_buf_sets(buf, strings[0]) < 0)
return -1;
/* go through the rest of the strings, truncating to shared prefix */
- for (i = 1; i < strings->count; ++i) {
+ for (i = 1; i < count; ++i) {
- for (str = strings->strings[i], pfx = buf->ptr;
- *str && *str == *pfx; str++, pfx++)
+ for (str = strings[i], pfx = buf->ptr;
+ *str && *str == *pfx;
+ str++, pfx++)
/* scanning */;
git_buf_truncate(buf, pfx - buf->ptr);