puts(arg);
}
+/* Like show(), but with a negation prefix according to type */
+static void show_with_type(int type, const char *arg)
+{
+ if (type != show_type)
+ putchar('^');
+ show(arg);
+}
+
/* Output a revision, only if filter allows it */
static void show_rev(int type, const unsigned char *sha1, const char *name)
{
return;
def = NULL;
- if (type != show_type)
- putchar('^');
if (symbolic && name) {
if (symbolic == SHOW_SYMBOLIC_FULL) {
unsigned char discard[20];
*/
break;
case 1: /* happy */
- show(full);
+ show_with_type(type, full);
break;
default: /* ambiguous */
error("refname '%s' is ambiguous", name);
break;
}
} else {
- show(name);
+ show_with_type(type, name);
}
}
else if (abbrev)
- show(find_unique_abbrev(sha1, abbrev));
+ show_with_type(type, find_unique_abbrev(sha1, abbrev));
else
- show(sha1_to_hex(sha1));
+ show_with_type(type, sha1_to_hex(sha1));
}
/* Output a flag, only if filter allows it. */
return 0;
}
+static int try_parent_shorthands(const char *arg)
+{
+ char *dotdot;
+ unsigned char sha1[20];
+ struct commit *commit;
+ struct commit_list *parents;
+ int parents_only;
+
+ if ((dotdot = strstr(arg, "^!")))
+ parents_only = 0;
+ else if ((dotdot = strstr(arg, "^@")))
+ parents_only = 1;
+
+ if (!dotdot || dotdot[2])
+ return 0;
+
+ *dotdot = 0;
+ if (get_sha1(arg, sha1))
+ return 0;
+
+ if (!parents_only)
+ show_rev(NORMAL, sha1, arg);
+ commit = lookup_commit_reference(sha1);
+ for (parents = commit->parents; parents; parents = parents->next)
+ show_rev(parents_only ? NORMAL : REVERSED,
+ parents->item->object.sha1, arg);
+
+ return 1;
+}
+
static int parseopt_dump(const struct option *o, const char *arg, int unset)
{
struct strbuf *parsed = o->value;
{
static int keep_dashdash = 0;
static char const * const parseopt_usage[] = {
- "git-rev-parse --parseopt [options] -- [<args>...]",
+ "git rev-parse --parseopt [options] -- [<args>...]",
NULL
};
static struct option parseopt_opts[] = {
return cmd_parseopt(argc - 1, argv + 1, prefix);
prefix = setup_git_directory();
- git_config(git_default_config);
+ git_config(git_default_config, NULL);
for (i = 1; i < argc; i++) {
const char *arg = argv[i];
/* Not a flag argument */
if (try_difference(arg))
continue;
+ if (try_parent_shorthands(arg))
+ continue;
name = arg;
type = NORMAL;
if (*arg == '^') {