]> oss.titaniummirror.com Git - repo_shell.git/blobdiff - git_acl.c
gitcreate: add option to set description
[repo_shell.git] / git_acl.c
index 3c740dd10a4ac368fae242b0acf7ce41575486d3..8783874b8472310f923ef85377b96fde0e35ee34 100644 (file)
--- a/git_acl.c
+++ b/git_acl.c
@@ -37,9 +37,7 @@ typedef struct {
   perms_t perms;
 } acl_t;
 
-const char* perm_str[PERMS_COUNT] = {
-  "NOTFOUND", "NONE", "READ", "READ_WRITE"
-};
+const char* perms_str[PERMS_COUNT] = { "", "", "r", "rw" };
 
 const char* lm_none = "<none>";
 static char *lm_repoid = NULL;
@@ -76,7 +74,7 @@ static const char *perms_as_str(perms_t p)
 {
   if (p < PERMS_NOTFOUND || p >= PERMS_COUNT)
     die("perms_as_str: invalid perm %u", p);
-  return perm_str[p];
+  return perms_str[p];
 }
 
 static perms_t perms_from_str(const char *str)
@@ -85,11 +83,11 @@ static perms_t perms_from_str(const char *str)
 
   if (!str)
     return PERMS_NOTFOUND;
-  else if (!*str)
+  else if (!strcmp(str, perms_str[PERMS_NONE]))
     return PERMS_NONE;
-  else if (!strcmp(str, "r"))
+  else if (!strcmp(str, perms_str[PERMS_READ]))
     return PERMS_READ;
-  else if (!strcmp(str, "rw"))
+  else if (!strcmp(str, perms_str[PERMS_READ_WRITE]))
     return PERMS_READ_WRITE;
   else
     die("Invalid perms value '%s'", str);
@@ -109,26 +107,6 @@ static acl_clear(acl_t *acl)
   stra_destroy(&acl->userids);
 }
 
-/* git tools match /path/to/repo against /path/to/repo.git when the former
- * doesn't exist and the latter does.  repo_shell addresses this by stripping
- * the .git prefix off all repopath's read in from .gitacls and the SSH comand
- * line.  This mimics the expected git tool behavior except when /path/to/repo
- * and /path/to/repo.git both exist.  This case shouldn't ever be seen anyway.
- */
-static 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);
-  }
-}
-
 static int acl_handler(void* user, const char* section, const char* name,
     const char* value)
 {
@@ -145,18 +123,15 @@ static int acl_handler(void* user, const char* section, const char* name,
       stra_add(&acl->userids, name);
     }
   } else if (!strcmp(section, "repo_groups")) {
-    char *v = strip_repo(value);
-    if (str_has_word(v, acl->repo)) {
+    if (str_has_repo(value, acl->repo)) {
       //debug("repoids += '%s'", name);
       stra_add(&acl->repoids, name);
     }
-    free(v);
   } else if (!strncmp(section, "repo", 4)) {
     char *_p = xstrdup(section + 4);
     char *p = _p;
     char *repo = strip_repo(my_strtok(&p, " \t\n"));
 
-    debug("repo '%s'", repo);
     if (!repo || my_strtok(&p, " \t\n"))
       die("acl_handler: badly formatted section '%s'", section);
     /* repo is repo name, name is userid, value is permission */