]> git.ipfire.org Git - thirdparty/git.git/blobdiff - parse-options-cb.c
Merge branch 'nd/diff-parseopt'
[thirdparty/git.git] / parse-options-cb.c
index 02293493b01a5a9e91c54da9833a583ea1c643b3..a3de795c581a3aab084efac75ed2d6edc2535a15 100644 (file)
@@ -25,8 +25,8 @@ int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset)
                                     opt->long_name);
                if (v && v < MINIMUM_ABBREV)
                        v = MINIMUM_ABBREV;
-               else if (v > 40)
-                       v = 40;
+               else if (v > the_hash_algo->hexsz)
+                       v = the_hash_algo->hexsz;
        }
        *(int *)(opt->value) = v;
        return 0;
@@ -99,6 +99,23 @@ int parse_opt_commits(const struct option *opt, const char *arg, int unset)
        return 0;
 }
 
+int parse_opt_commit(const struct option *opt, const char *arg, int unset)
+{
+       struct object_id oid;
+       struct commit *commit;
+       struct commit **target = opt->value;
+
+       if (!arg)
+               return -1;
+       if (get_oid(arg, &oid))
+               return error("malformed object name %s", arg);
+       commit = lookup_commit_reference(the_repository, &oid);
+       if (!commit)
+               return error("no such commit %s", arg);
+       *target = commit;
+       return 0;
+}
+
 int parse_opt_object_name(const struct option *opt, const char *arg, int unset)
 {
        struct object_id oid;
@@ -115,6 +132,23 @@ int parse_opt_object_name(const struct option *opt, const char *arg, int unset)
        return 0;
 }
 
+int parse_opt_object_id(const struct option *opt, const char *arg, int unset)
+{
+       struct object_id oid;
+       struct object_id *target = opt->value;
+
+       if (unset) {
+               *target = null_oid;
+               return 0;
+       }
+       if (!arg)
+               return -1;
+       if (get_oid(arg, &oid))
+               return error(_("malformed object name '%s'"), arg);
+       *target = oid;
+       return 0;
+}
+
 int parse_opt_tertiary(const struct option *opt, const char *arg, int unset)
 {
        int *target = opt->value;