Merge branch 'ew/abbrev' into next
* ew/abbrev: ls-files: add --abbrev[=<n>] option ls-tree: add --abbrev[=<n>] option blame: Fix git-blame <directory> blame: Nicer outputmaint
commit
35a9f5d91e
|
@ -14,9 +14,9 @@ SYNOPSIS
|
||||||
(-[c|d|o|i|s|u|k|m])\*
|
(-[c|d|o|i|s|u|k|m])\*
|
||||||
[-x <pattern>|--exclude=<pattern>]
|
[-x <pattern>|--exclude=<pattern>]
|
||||||
[-X <file>|--exclude-from=<file>]
|
[-X <file>|--exclude-from=<file>]
|
||||||
[--exclude-per-directory=<file>]
|
[--exclude-per-directory=<file>]
|
||||||
[--error-unmatch]
|
[--error-unmatch]
|
||||||
[--full-name] [--] [<file>]\*
|
[--full-name] [--abbrev] [--] [<file>]\*
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
-----------
|
-----------
|
||||||
|
@ -98,6 +98,11 @@ OPTIONS
|
||||||
option forces paths to be output relative to the project
|
option forces paths to be output relative to the project
|
||||||
top directory.
|
top directory.
|
||||||
|
|
||||||
|
--abbrev[=<n>]::
|
||||||
|
Instead of showing the full 40-byte hexadecimal object
|
||||||
|
lines, show only handful hexdigits prefix.
|
||||||
|
Non default number of digits can be specified with --abbrev=<n>.
|
||||||
|
|
||||||
--::
|
--::
|
||||||
Do not interpret any more arguments as options.
|
Do not interpret any more arguments as options.
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,9 @@ git-ls-tree - Lists the contents of a tree object
|
||||||
|
|
||||||
SYNOPSIS
|
SYNOPSIS
|
||||||
--------
|
--------
|
||||||
'git-ls-tree' [-d] [-r] [-t] [-z] [--name-only] [--name-status] <tree-ish> [paths...]
|
'git-ls-tree' [-d] [-r] [-t] [-z]
|
||||||
|
[--name-only] [--name-status] [--full-name] [--abbrev=[<n>]]
|
||||||
|
<tree-ish> [paths...]
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
-----------
|
-----------
|
||||||
|
@ -40,6 +42,11 @@ OPTIONS
|
||||||
--name-status::
|
--name-status::
|
||||||
List only filenames (instead of the "long" output), one per line.
|
List only filenames (instead of the "long" output), one per line.
|
||||||
|
|
||||||
|
--abbrev[=<n>]::
|
||||||
|
Instead of showing the full 40-byte hexadecimal object
|
||||||
|
lines, show only handful hexdigits prefix.
|
||||||
|
Non default number of digits can be specified with --abbrev=<n>.
|
||||||
|
|
||||||
paths::
|
paths::
|
||||||
When paths are given, show them (note that this isn't really raw
|
When paths are given, show them (note that this isn't really raw
|
||||||
pathnames, but rather a list of patterns to match). Otherwise
|
pathnames, but rather a list of patterns to match). Otherwise
|
||||||
|
|
41
blame.c
41
blame.c
|
@ -180,11 +180,13 @@ static int get_blob_sha1_internal(unsigned char *sha1, const char *base,
|
||||||
unsigned mode, int stage);
|
unsigned mode, int stage);
|
||||||
|
|
||||||
static unsigned char blob_sha1[20];
|
static unsigned char blob_sha1[20];
|
||||||
|
static const char* blame_file;
|
||||||
static int get_blob_sha1(struct tree *t, const char *pathname,
|
static int get_blob_sha1(struct tree *t, const char *pathname,
|
||||||
unsigned char *sha1)
|
unsigned char *sha1)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
const char *pathspec[2];
|
const char *pathspec[2];
|
||||||
|
blame_file = pathname;
|
||||||
pathspec[0] = pathname;
|
pathspec[0] = pathname;
|
||||||
pathspec[1] = NULL;
|
pathspec[1] = NULL;
|
||||||
memset(blob_sha1, 0, sizeof(blob_sha1));
|
memset(blob_sha1, 0, sizeof(blob_sha1));
|
||||||
|
@ -209,6 +211,10 @@ static int get_blob_sha1_internal(unsigned char *sha1, const char *base,
|
||||||
if (S_ISDIR(mode))
|
if (S_ISDIR(mode))
|
||||||
return READ_TREE_RECURSIVE;
|
return READ_TREE_RECURSIVE;
|
||||||
|
|
||||||
|
if (strncmp(blame_file, base, baselen) ||
|
||||||
|
strcmp(blame_file + baselen, pathname))
|
||||||
|
return -1;
|
||||||
|
|
||||||
memcpy(blob_sha1, sha1, 20);
|
memcpy(blob_sha1, sha1, 20);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -742,6 +748,8 @@ int main(int argc, const char **argv)
|
||||||
struct commit_info ci;
|
struct commit_info ci;
|
||||||
const char *buf;
|
const char *buf;
|
||||||
int max_digits;
|
int max_digits;
|
||||||
|
size_t longest_file, longest_author;
|
||||||
|
int found_rename;
|
||||||
|
|
||||||
const char* prefix = setup_git_directory();
|
const char* prefix = setup_git_directory();
|
||||||
|
|
||||||
|
@ -818,6 +826,25 @@ int main(int argc, const char **argv)
|
||||||
for (max_digits = 1, i = 10; i <= num_blame_lines + 1; max_digits++)
|
for (max_digits = 1, i = 10; i <= num_blame_lines + 1; max_digits++)
|
||||||
i *= 10;
|
i *= 10;
|
||||||
|
|
||||||
|
longest_file = 0;
|
||||||
|
longest_author = 0;
|
||||||
|
found_rename = 0;
|
||||||
|
for (i = 0; i < num_blame_lines; i++) {
|
||||||
|
struct commit *c = blame_lines[i];
|
||||||
|
struct util_info* u;
|
||||||
|
if (!c)
|
||||||
|
c = initial;
|
||||||
|
u = c->object.util;
|
||||||
|
|
||||||
|
if (!found_rename && strcmp(filename, u->pathname))
|
||||||
|
found_rename = 1;
|
||||||
|
if (longest_file < strlen(u->pathname))
|
||||||
|
longest_file = strlen(u->pathname);
|
||||||
|
get_commit_info(c, &ci);
|
||||||
|
if (longest_author < strlen(ci.author))
|
||||||
|
longest_author = strlen(ci.author);
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < num_blame_lines; i++) {
|
for (i = 0; i < num_blame_lines; i++) {
|
||||||
struct commit *c = blame_lines[i];
|
struct commit *c = blame_lines[i];
|
||||||
struct util_info* u;
|
struct util_info* u;
|
||||||
|
@ -828,14 +855,18 @@ int main(int argc, const char **argv)
|
||||||
u = c->object.util;
|
u = c->object.util;
|
||||||
get_commit_info(c, &ci);
|
get_commit_info(c, &ci);
|
||||||
fwrite(sha1_to_hex(c->object.sha1), sha1_len, 1, stdout);
|
fwrite(sha1_to_hex(c->object.sha1), sha1_len, 1, stdout);
|
||||||
if(compability)
|
if(compability) {
|
||||||
printf("\t(%10s\t%10s\t%d)", ci.author,
|
printf("\t(%10s\t%10s\t%d)", ci.author,
|
||||||
format_time(ci.author_time, ci.author_tz), i+1);
|
format_time(ci.author_time, ci.author_tz), i+1);
|
||||||
else
|
} else {
|
||||||
printf(" %s (%-15.15s %10s %*d) ", u->pathname,
|
if (found_rename)
|
||||||
ci.author, format_time(ci.author_time,
|
printf(" %-*.*s", longest_file, longest_file,
|
||||||
ci.author_tz),
|
u->pathname);
|
||||||
|
printf(" (%-*.*s %10s %*d) ",
|
||||||
|
longest_author, longest_author, ci.author,
|
||||||
|
format_time(ci.author_time, ci.author_tz),
|
||||||
max_digits, i+1);
|
max_digits, i+1);
|
||||||
|
}
|
||||||
|
|
||||||
if(i == num_blame_lines - 1) {
|
if(i == num_blame_lines - 1) {
|
||||||
fwrite(buf, blame_len - (buf - blame_contents),
|
fwrite(buf, blame_len - (buf - blame_contents),
|
||||||
|
|
19
ls-files.c
19
ls-files.c
|
@ -11,6 +11,7 @@
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
#include "quote.h"
|
#include "quote.h"
|
||||||
|
|
||||||
|
static int abbrev = 0;
|
||||||
static int show_deleted = 0;
|
static int show_deleted = 0;
|
||||||
static int show_cached = 0;
|
static int show_cached = 0;
|
||||||
static int show_others = 0;
|
static int show_others = 0;
|
||||||
|
@ -488,7 +489,8 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce)
|
||||||
printf("%s%06o %s %d\t",
|
printf("%s%06o %s %d\t",
|
||||||
tag,
|
tag,
|
||||||
ntohl(ce->ce_mode),
|
ntohl(ce->ce_mode),
|
||||||
sha1_to_hex(ce->sha1),
|
abbrev ? find_unique_abbrev(ce->sha1,abbrev)
|
||||||
|
: sha1_to_hex(ce->sha1),
|
||||||
ce_stage(ce));
|
ce_stage(ce));
|
||||||
write_name_quoted("", 0, ce->name + offset,
|
write_name_quoted("", 0, ce->name + offset,
|
||||||
line_terminator, stdout);
|
line_terminator, stdout);
|
||||||
|
@ -629,7 +631,8 @@ static void verify_pathspec(void)
|
||||||
static const char ls_files_usage[] =
|
static const char ls_files_usage[] =
|
||||||
"git-ls-files [-z] [-t] [-v] (--[cached|deleted|others|stage|unmerged|killed|modified])* "
|
"git-ls-files [-z] [-t] [-v] (--[cached|deleted|others|stage|unmerged|killed|modified])* "
|
||||||
"[ --ignored ] [--exclude=<pattern>] [--exclude-from=<file>] "
|
"[ --ignored ] [--exclude=<pattern>] [--exclude-from=<file>] "
|
||||||
"[ --exclude-per-directory=<filename> ] [--full-name] [--] [<file>]*";
|
"[ --exclude-per-directory=<filename> ] [--full-name] [--abbrev] "
|
||||||
|
"[--] [<file>]*";
|
||||||
|
|
||||||
int main(int argc, const char **argv)
|
int main(int argc, const char **argv)
|
||||||
{
|
{
|
||||||
|
@ -736,6 +739,18 @@ int main(int argc, const char **argv)
|
||||||
error_unmatch = 1;
|
error_unmatch = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (!strncmp(arg, "--abbrev=", 9)) {
|
||||||
|
abbrev = strtoul(arg+9, NULL, 10);
|
||||||
|
if (abbrev && abbrev < MINIMUM_ABBREV)
|
||||||
|
abbrev = MINIMUM_ABBREV;
|
||||||
|
else if (abbrev > 40)
|
||||||
|
abbrev = 40;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!strcmp(arg, "--abbrev")) {
|
||||||
|
abbrev = DEFAULT_ABBREV;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (*arg == '-')
|
if (*arg == '-')
|
||||||
usage(ls_files_usage);
|
usage(ls_files_usage);
|
||||||
break;
|
break;
|
||||||
|
|
19
ls-tree.c
19
ls-tree.c
|
@ -13,13 +13,14 @@ static int line_termination = '\n';
|
||||||
#define LS_TREE_ONLY 2
|
#define LS_TREE_ONLY 2
|
||||||
#define LS_SHOW_TREES 4
|
#define LS_SHOW_TREES 4
|
||||||
#define LS_NAME_ONLY 8
|
#define LS_NAME_ONLY 8
|
||||||
|
static int abbrev = 0;
|
||||||
static int ls_options = 0;
|
static int ls_options = 0;
|
||||||
const char **pathspec;
|
const char **pathspec;
|
||||||
static int chomp_prefix = 0;
|
static int chomp_prefix = 0;
|
||||||
static const char *prefix;
|
static const char *prefix;
|
||||||
|
|
||||||
static const char ls_tree_usage[] =
|
static const char ls_tree_usage[] =
|
||||||
"git-ls-tree [-d] [-r] [-t] [-z] [--name-only] [--name-status] [--full-name] <tree-ish> [path...]";
|
"git-ls-tree [-d] [-r] [-t] [-z] [--name-only] [--name-status] [--full-name] [--abbrev[=<n>]] <tree-ish> [path...]";
|
||||||
|
|
||||||
static int show_recursive(const char *base, int baselen, const char *pathname)
|
static int show_recursive(const char *base, int baselen, const char *pathname)
|
||||||
{
|
{
|
||||||
|
@ -73,7 +74,9 @@ static int show_tree(unsigned char *sha1, const char *base, int baselen,
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!(ls_options & LS_NAME_ONLY))
|
if (!(ls_options & LS_NAME_ONLY))
|
||||||
printf("%06o %s %s\t", mode, type, sha1_to_hex(sha1));
|
printf("%06o %s %s\t", mode, type,
|
||||||
|
abbrev ? find_unique_abbrev(sha1,abbrev)
|
||||||
|
: sha1_to_hex(sha1));
|
||||||
write_name_quoted(base + chomp_prefix, baselen - chomp_prefix,
|
write_name_quoted(base + chomp_prefix, baselen - chomp_prefix,
|
||||||
pathname,
|
pathname,
|
||||||
line_termination, stdout);
|
line_termination, stdout);
|
||||||
|
@ -113,6 +116,18 @@ int main(int argc, const char **argv)
|
||||||
chomp_prefix = 0;
|
chomp_prefix = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (!strncmp(argv[1]+2, "abbrev=",7)) {
|
||||||
|
abbrev = strtoul(argv[1]+9, NULL, 10);
|
||||||
|
if (abbrev && abbrev < MINIMUM_ABBREV)
|
||||||
|
abbrev = MINIMUM_ABBREV;
|
||||||
|
else if (abbrev > 40)
|
||||||
|
abbrev = 40;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!strcmp(argv[1]+2, "abbrev")) {
|
||||||
|
abbrev = DEFAULT_ABBREV;
|
||||||
|
break;
|
||||||
|
}
|
||||||
/* otherwise fallthru */
|
/* otherwise fallthru */
|
||||||
default:
|
default:
|
||||||
usage(ls_tree_usage);
|
usage(ls_tree_usage);
|
||||||
|
|
Loading…
Reference in New Issue