Merge branch 'js/git-gui-commit-gpgsign'
[gitweb.git] / t / helper / test-config.c
index 6a775522105d9bfc5c1c60f36944bc43e64badef..3c6d08cd095152cab9abeb038c1b4f82440c55cd 100644 (file)
@@ -25,6 +25,9 @@
  *                             ascending order of priority from a config_set
  *                             constructed from files entered as arguments.
  *
+ * iterate -> iterate over all values using git_config(), and print some
+ *            data for each
+ *
  * Examples:
  *
  * To print the value with highest priority for key "foo.bAr Baz.rock":
  *
  */
 
+static const char *scope_name(enum config_scope scope)
+{
+       switch (scope) {
+       case CONFIG_SCOPE_SYSTEM:
+               return "system";
+       case CONFIG_SCOPE_GLOBAL:
+               return "global";
+       case CONFIG_SCOPE_REPO:
+               return "repo";
+       case CONFIG_SCOPE_CMDLINE:
+               return "cmdline";
+       default:
+               return "unknown";
+       }
+}
+static int iterate_cb(const char *var, const char *value, void *data)
+{
+       static int nr;
+
+       if (nr++)
+               putchar('\n');
+
+       printf("key=%s\n", var);
+       printf("value=%s\n", value ? value : "(null)");
+       printf("origin=%s\n", current_config_origin_type());
+       printf("name=%s\n", current_config_name());
+       printf("scope=%s\n", scope_name(current_config_scope()));
+
+       return 0;
+}
 
-int main(int argc, char **argv)
+int cmd_main(int argc, const char **argv)
 {
        int i, val;
        const char *v;
@@ -134,6 +167,9 @@ int main(int argc, char **argv)
                        printf("Value not found for \"%s\"\n", argv[2]);
                        goto exit1;
                }
+       } else if (!strcmp(argv[1], "iterate")) {
+               git_config(iterate_cb, NULL);
+               goto exit0;
        }
 
        die("%s: Please check the syntax and the function name", argv[0]);