]> oss.titaniummirror.com Git - repo_shell.git/blobdiff - stringutils.c
Fix improper handling of repo_groups sections
[repo_shell.git] / stringutils.c
index 8249d86fea37902ae2ae1a6a6e7f6079c6bbb261..08afc45526d94946124bcb13e1c7ce7a7e25bb8f 100644 (file)
@@ -75,3 +75,40 @@ bool str_has_word(const char* string, const char* word)
   free(_s);
   return false;
 }
+
+char *strip_repo(const char *repo_name)
+{
+  if (!repo_name)
+    return NULL;
+  else {
+    char *dot = rindex(repo_name, '.');
+
+    if (dot && !strcmp(dot, ".git"))
+      return xstrndup(repo_name, dot - repo_name);
+    else
+      return xstrdup(repo_name);
+  }
+}
+
+bool str_has_repo(const char* string, const char* repo)
+{
+  char *_s = xstrdup(string);
+  char *s = _s;
+  char *p = my_strtok(&s, " \t\n");
+  char *r = strip_repo(repo);
+
+  while (p) {
+    char *q = strip_repo(p);
+    if (match(q, r)) {
+      free(q);
+      free(r);
+      free(_s);
+      return true;
+    }
+    free(q);
+    p = my_strtok(&s, " \t\n");
+  }
+  free(r);
+  free(_s);
+  return false;
+}