summaryrefslogtreecommitdiff
path: root/src/buffer.c
diff options
context:
space:
mode:
authorVicent Martí <tanoku@gmail.com>2012-05-16 09:57:45 -0700
committerVicent Martí <tanoku@gmail.com>2012-05-16 09:57:45 -0700
commitc261c272af7fa26af36bca71e56b0342631b3eea (patch)
tree4b4e6efe8871844b40c8c4ec82321ada515f594d /src/buffer.c
parentb206d74ccaca2bca33e5db85fb6c1e4b8fc54541 (diff)
parent2c8339172878cd935eee0d9eb6db747cebd70a72 (diff)
downloadlibgit2-c261c272af7fa26af36bca71e56b0342631b3eea.tar.gz
Merge pull request #702 from arrbee/fix-status-file
Update git_status_file and add ranged iterators
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 2ecb088f8..ef95839f6 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -415,3 +415,33 @@ int git_buf_cmp(const git_buf *a, const git_buf *b)
return (result != 0) ? result :
(a->size < b->size) ? -1 : (a->size > b->size) ? 1 : 0;
}
+
+int git_buf_common_prefix(git_buf *buf, const git_strarray *strings)
+{
+ size_t i;
+ const char *str, *pfx;
+
+ git_buf_clear(buf);
+
+ if (!strings || !strings->count)
+ return 0;
+
+ /* initialize common prefix to first string */
+ if (git_buf_sets(buf, strings->strings[0]) < 0)
+ return -1;
+
+ /* go through the rest of the strings, truncating to shared prefix */
+ for (i = 1; i < strings->count; ++i) {
+
+ for (str = strings->strings[i], pfx = buf->ptr;
+ *str && *str == *pfx; str++, pfx++)
+ /* scanning */;
+
+ git_buf_truncate(buf, pfx - buf->ptr);
+
+ if (!buf->size)
+ break;
+ }
+
+ return 0;
+}