#define REVERSED 1
static int show_type = NORMAL;
static int symbolic = 0;
+static int abbrev = 0;
static int output_sq = 0;
static int revs_count = 0;
static const char *rev_args[] = {
"--all",
"--bisect",
+ "--dense",
"--header",
"--max-age=",
"--max-count=",
- "--merge-order",
"--min-age=",
"--no-merges",
"--objects",
+ "--objects-edge",
"--parents",
"--pretty",
- "--show-breaks",
+ "--sparse",
"--topo-order",
+ "--date-order",
"--unpacked",
NULL
};
const char **p = rev_args;
+ /* accept -<digit>, like traditional "head" */
+ if ((*arg == '-') && isdigit(arg[1]))
+ return 1;
+
for (;;) {
const char *str = *p++;
int len;
putchar('^');
if (symbolic && name)
show(name);
+ else if (abbrev)
+ show(find_unique_abbrev(sha1, abbrev));
else
show(sha1_to_hex(sha1));
}
/* Output a flag, only if filter allows it. */
-static void show_flag(char *arg)
+static int show_flag(char *arg)
{
if (!(filter & DO_FLAGS))
- return;
- if (filter & (is_rev_argument(arg) ? DO_REVS : DO_NOREV))
+ return 0;
+ if (filter & (is_rev_argument(arg) ? DO_REVS : DO_NOREV)) {
show(arg);
+ return 1;
+ }
+ return 0;
}
static void show_default(void)
static void show_datestring(const char *flag, const char *datestr)
{
- FILE *date;
static char buffer[100];
- static char cmd[1000];
- int len;
/* date handling requires both flags and revs */
if ((filter & (DO_FLAGS | DO_REVS)) != (DO_FLAGS | DO_REVS))
return;
- len = strlen(flag);
- memcpy(buffer, flag, len);
-
- snprintf(cmd, sizeof(cmd), "date --date=%s +%%s", sq_quote(datestr));
- date = popen(cmd, "r");
- if (!date || !fgets(buffer + len, sizeof(buffer) - len, date))
- die("git-rev-list: bad date string");
- pclose(date);
- len = strlen(buffer);
- if (buffer[len-1] == '\n')
- buffer[--len] = 0;
+ snprintf(buffer, sizeof(buffer), "%s%lu", flag, approxidate(datestr));
show(buffer);
}
-static void show_file(const char *arg)
+static int show_file(const char *arg)
{
show_default();
- if ((filter & (DO_NONFLAGS|DO_NOREV)) == (DO_NONFLAGS|DO_NOREV))
+ if ((filter & (DO_NONFLAGS|DO_NOREV)) == (DO_NONFLAGS|DO_NOREV)) {
show(arg);
+ return 1;
+ }
+ return 0;
}
int main(int argc, char **argv)
unsigned char sha1[20];
const char *prefix = setup_git_directory();
+ git_config(git_default_config);
+
for (i = 1; i < argc; i++) {
char *arg = argv[i];
char *dotdot;
-
+
if (as_is) {
- show_file(arg);
+ if (show_file(arg) && as_is < 2)
+ verify_filename(prefix, arg);
continue;
}
+ if (!strcmp(arg,"-n")) {
+ if (++i >= argc)
+ die("-n requires an argument");
+ if ((filter & DO_FLAGS) && (filter & DO_REVS)) {
+ show(arg);
+ show(argv[i]);
+ }
+ continue;
+ }
+ if (!strncmp(arg,"-n",2)) {
+ if ((filter & DO_FLAGS) && (filter & DO_REVS))
+ show(arg);
+ continue;
+ }
+
if (*arg == '-') {
if (!strcmp(arg, "--")) {
- as_is = 1;
+ as_is = 2;
/* Pass on the "--" if we show anything but files.. */
if (filter & (DO_FLAGS | DO_REVS))
show_file(arg);
verify = 1;
continue;
}
+ if (!strcmp(arg, "--short") ||
+ !strncmp(arg, "--short=", 8)) {
+ filter &= ~(DO_FLAGS|DO_NOREV);
+ verify = 1;
+ abbrev = DEFAULT_ABBREV;
+ if (arg[7] == '=')
+ abbrev = strtoul(arg + 8, NULL, 10);
+ if (abbrev < MINIMUM_ABBREV)
+ abbrev = MINIMUM_ABBREV;
+ else if (40 <= abbrev)
+ abbrev = 40;
+ continue;
+ }
if (!strcmp(arg, "--sq")) {
output_sq = 1;
continue;
puts(prefix);
continue;
}
+ if (!strcmp(arg, "--show-cdup")) {
+ const char *pfx = prefix;
+ while (pfx) {
+ pfx = strchr(pfx, '/');
+ if (pfx) {
+ pfx++;
+ printf("../");
+ }
+ }
+ putchar('\n');
+ continue;
+ }
if (!strcmp(arg, "--git-dir")) {
const char *gitdir = getenv(GIT_DIR_ENVIRONMENT);
static char cwd[PATH_MAX];
show_datestring("--min-age=", arg+8);
continue;
}
- if (verify)
+ if (show_flag(arg) && verify)
die("Needed a single revision");
- show_flag(arg);
continue;
}
dotdot = strstr(arg, "..");
if (dotdot) {
unsigned char end[20];
- char *n = dotdot+2;
+ char *next = dotdot + 2;
+ char *this = arg;
*dotdot = 0;
- if (!get_sha1(arg, sha1)) {
- if (!*n)
- n = "HEAD";
- if (!get_sha1(n, end)) {
- show_rev(NORMAL, end, n);
- show_rev(REVERSED, sha1, arg);
- continue;
- }
+ if (!*next)
+ next = "HEAD";
+ if (dotdot == arg)
+ this = "HEAD";
+ if (!get_sha1(this, sha1) && !get_sha1(next, end)) {
+ show_rev(NORMAL, end, next);
+ show_rev(REVERSED, sha1, this);
+ continue;
}
*dotdot = '.';
}
show_rev(REVERSED, sha1, arg+1);
continue;
}
+ as_is = 1;
+ if (!show_file(arg))
+ continue;
if (verify)
die("Needed a single revision");
- show_file(arg);
+ verify_filename(prefix, arg);
}
show_default();
if (verify && revs_count != 1)