Merge branch 'jc/clean' into next

* jc/clean:
  Teach git-clean optional <paths>... parameters.
  Separate object name errors from usage errors
  Documentation: {caret} fixes (git-rev-list.txt)
  Fix "git diff --stat" with long filenames
  Fix repo-config set-multivar error return path.
This commit is contained in:
Junio C Hamano
2006-05-08 16:43:23 -07:00
18 changed files with 64 additions and 46 deletions

View File

@ -8,7 +8,7 @@ git-clean - Remove untracked files from the working tree
SYNOPSIS SYNOPSIS
-------- --------
[verse] [verse]
'git-clean' [-d] [-n] [-q] [-x | -X] 'git-clean' [-d] [-n] [-q] [-x | -X] [--] <paths>...
DESCRIPTION DESCRIPTION
----------- -----------
@ -16,6 +16,9 @@ Removes files unknown to git. This allows to clean the working tree
from files that are not under version control. If the '-x' option is from files that are not under version control. If the '-x' option is
specified, ignored files are also removed, allowing to remove all specified, ignored files are also removed, allowing to remove all
build products. build products.
When optional `<paths>...` arguments are given, the paths
affected are further limited to those that match them.
OPTIONS OPTIONS
------- -------

View File

@ -68,9 +68,10 @@ OPTIONS
--bisect:: --bisect::
Limit output to the one commit object which is roughly halfway Limit output to the one commit object which is roughly halfway
between the included and excluded commits. Thus, if 'git-rev-list between the included and excluded commits. Thus, if 'git-rev-list
--bisect foo ^bar ^baz' outputs 'midpoint', the output --bisect foo {caret}bar {caret}baz' outputs 'midpoint', the output
of 'git-rev-list foo ^midpoint' and 'git-rev-list midpoint of 'git-rev-list foo {caret}midpoint' and 'git-rev-list midpoint
^bar ^baz' would be of roughly the same length. Finding the change {caret}bar {caret}baz' would be of roughly the same length.
Finding the change
which introduces a regression is thus reduced to a binary search: which introduces a regression is thus reduced to a binary search:
repeatedly generate and test new 'midpoint's until the commit chain repeatedly generate and test new 'midpoint's until the commit chain
is of length one. is of length one.

View File

@ -103,8 +103,10 @@ int main(int argc, char **argv)
setup_git_directory(); setup_git_directory();
git_config(git_default_config); git_config(git_default_config);
if (argc != 3 || get_sha1(argv[2], sha1)) if (argc != 3)
usage("git-cat-file [-t|-s|-e|-p|<type>] <sha1>"); usage("git-cat-file [-t|-s|-e|-p|<type>] <sha1>");
if (get_sha1(argv[2], sha1))
die("Not a valid object name %s", argv[2]);
opt = 0; opt = 0;
if ( argv[1][0] == '-' ) { if ( argv[1][0] == '-' ) {
@ -133,8 +135,7 @@ int main(int argc, char **argv)
return !has_sha1_file(sha1); return !has_sha1_file(sha1);
case 'p': case 'p':
if (get_sha1(argv[2], sha1) || if (sha1_object_info(sha1, type, NULL))
sha1_object_info(sha1, type, NULL))
die("Not a valid object name %s", argv[2]); die("Not a valid object name %s", argv[2]);
/* custom pretty-print here */ /* custom pretty-print here */

View File

@ -91,15 +91,19 @@ int main(int argc, char **argv)
git_config(git_default_config); git_config(git_default_config);
if (argc < 2 || get_sha1(argv[1], tree_sha1) < 0) if (argc < 2)
usage(commit_tree_usage); usage(commit_tree_usage);
if (get_sha1(argv[1], tree_sha1))
die("Not a valid object name %s", argv[1]);
check_valid(tree_sha1, tree_type); check_valid(tree_sha1, tree_type);
for (i = 2; i < argc; i += 2) { for (i = 2; i < argc; i += 2) {
char *a, *b; char *a, *b;
a = argv[i]; b = argv[i+1]; a = argv[i]; b = argv[i+1];
if (!b || strcmp(a, "-p") || get_sha1(b, parent_sha1[parents])) if (!b || strcmp(a, "-p"))
usage(commit_tree_usage); usage(commit_tree_usage);
if (get_sha1(b, parent_sha1[parents]))
die("Not a valid object name %s", b);
check_valid(parent_sha1[parents], commit_type); check_valid(parent_sha1[parents], commit_type);
if (new_parent(parents)) if (new_parent(parents))
parents++; parents++;

View File

@ -422,7 +422,7 @@ int git_config_set_multivar(const char* key, const char* value,
const char* value_regex, int multi_replace) const char* value_regex, int multi_replace)
{ {
int i; int i;
int fd, in_fd; int fd = -1, in_fd;
int ret; int ret;
char* config_filename = strdup(git_path("config")); char* config_filename = strdup(git_path("config"));
char* lock_file = strdup(git_path("config.lock")); char* lock_file = strdup(git_path("config.lock"));
@ -480,15 +480,11 @@ int git_config_set_multivar(const char* key, const char* value,
if ( ENOENT != errno ) { if ( ENOENT != errno ) {
error("opening %s: %s", config_filename, error("opening %s: %s", config_filename,
strerror(errno)); strerror(errno));
close(fd);
unlink(lock_file);
ret = 3; /* same as "invalid config file" */ ret = 3; /* same as "invalid config file" */
goto out_free; goto out_free;
} }
/* if nothing to unset, error out */ /* if nothing to unset, error out */
if (value == NULL) { if (value == NULL) {
close(fd);
unlink(lock_file);
ret = 5; ret = 5;
goto out_free; goto out_free;
} }
@ -516,8 +512,6 @@ int git_config_set_multivar(const char* key, const char* value,
fprintf(stderr, "Invalid pattern: %s\n", fprintf(stderr, "Invalid pattern: %s\n",
value_regex); value_regex);
free(store.value_regex); free(store.value_regex);
close(fd);
unlink(lock_file);
ret = 6; ret = 6;
goto out_free; goto out_free;
} }
@ -553,8 +547,6 @@ int git_config_set_multivar(const char* key, const char* value,
/* if nothing to unset, or too many matches, error out */ /* if nothing to unset, or too many matches, error out */
if ((store.seen == 0 && value == NULL) || if ((store.seen == 0 && value == NULL) ||
(store.seen > 1 && multi_replace == 0)) { (store.seen > 1 && multi_replace == 0)) {
close(fd);
unlink(lock_file);
ret = 5; ret = 5;
goto out_free; goto out_free;
} }
@ -603,8 +595,6 @@ int git_config_set_multivar(const char* key, const char* value,
unlink(config_filename); unlink(config_filename);
} }
close(fd);
if (rename(lock_file, config_filename) < 0) { if (rename(lock_file, config_filename) < 0) {
fprintf(stderr, "Could not rename the lock file?\n"); fprintf(stderr, "Could not rename the lock file?\n");
ret = 4; ret = 4;
@ -614,10 +604,14 @@ int git_config_set_multivar(const char* key, const char* value,
ret = 0; ret = 0;
out_free: out_free:
if (0 <= fd)
close(fd);
if (config_filename) if (config_filename)
free(config_filename); free(config_filename);
if (lock_file) if (lock_file) {
unlink(lock_file);
free(lock_file); free(lock_file);
}
return ret; return ret;
} }

View File

@ -321,8 +321,10 @@ int main(int argc, char **argv)
setup_git_directory(); setup_git_directory();
if (argc != 2 || get_sha1(argv[1], sha1)) if (argc != 2)
usage("git-convert-objects <sha1>"); usage("git-convert-objects <sha1>");
if (get_sha1(argv[1], sha1))
die("Not a valid object name %s", argv[1]);
entry = convert_entry(sha1); entry = convert_entry(sha1);
printf("new sha1: %s\n", sha1_to_hex(entry->new_sha1)); printf("new sha1: %s\n", sha1_to_hex(entry->new_sha1));

View File

@ -105,11 +105,11 @@ static void describe(char *arg, int last_one)
static int initialized = 0; static int initialized = 0;
struct commit_name *n; struct commit_name *n;
if (get_sha1(arg, sha1) < 0) if (get_sha1(arg, sha1))
usage(describe_usage); die("Not a valid object name %s", arg);
cmit = lookup_commit_reference(sha1); cmit = lookup_commit_reference(sha1);
if (!cmit) if (!cmit)
usage(describe_usage); die("%s is not a valid '%s' object", arg, commit_type);
if (!initialized) { if (!initialized) {
initialized = 1; initialized = 1;

2
diff.c
View File

@ -297,7 +297,6 @@ static const char minuses[]= "--------------------------------------------------
static void show_stats(struct diffstat_t* data) static void show_stats(struct diffstat_t* data)
{ {
char *prefix = "";
int i, len, add, del, total, adds = 0, dels = 0; int i, len, add, del, total, adds = 0, dels = 0;
int max, max_change = 0, max_len = 0; int max, max_change = 0, max_len = 0;
int total_files = data->nr; int total_files = data->nr;
@ -319,6 +318,7 @@ static void show_stats(struct diffstat_t* data)
} }
for (i = 0; i < data->nr; i++) { for (i = 0; i < data->nr; i++) {
char *prefix = "";
char *name = data->files[i]->name; char *name = data->files[i]->name;
int added = data->files[i]->added; int added = data->files[i]->added;
int deleted = data->files[i]->deleted; int deleted = data->files[i]->deleted;

View File

@ -3,13 +3,15 @@
# Copyright (c) 2005-2006 Pavel Roskin # Copyright (c) 2005-2006 Pavel Roskin
# #
USAGE="[-d] [-n] [-q] [-x | -X]" USAGE="[-d] [-n] [-q] [-x | -X] [--] <paths>..."
LONG_USAGE='Clean untracked files from the working directory LONG_USAGE='Clean untracked files from the working directory
-d remove directories as well -d remove directories as well
-n don'\''t remove anything, just show what would be done -n don'\''t remove anything, just show what would be done
-q be quiet, only report errors -q be quiet, only report errors
-x remove ignored files as well -x remove ignored files as well
-X remove only ignored files as well' -X remove only ignored files
When optional <paths>... arguments are given, the paths
affected are further limited to those that match them.'
SUBDIRECTORY_OK=Yes SUBDIRECTORY_OK=Yes
. git-sh-setup . git-sh-setup
@ -44,8 +46,15 @@ do
-X) -X)
ignoredonly=1 ignoredonly=1
;; ;;
*) --)
shift
break
;;
-*)
usage usage
;;
*)
break
esac esac
shift shift
done done
@ -64,7 +73,7 @@ if [ -z "$ignored" ]; then
fi fi
fi fi
git-ls-files --others --directory $excl ${excl_info:+"$excl_info"} | git-ls-files --others --directory $excl ${excl_info:+"$excl_info"} -- "$@" |
while read -r file; do while read -r file; do
if [ -d "$file" -a ! -L "$file" ]; then if [ -d "$file" -a ! -L "$file" ]; then
if [ -z "$cleandir" ]; then if [ -z "$cleandir" ]; then

View File

@ -142,8 +142,8 @@ int main(int argc, const char **argv)
if (argc < 2) if (argc < 2)
usage(ls_tree_usage); usage(ls_tree_usage);
if (get_sha1(argv[1], sha1) < 0) if (get_sha1(argv[1], sha1))
usage(ls_tree_usage); die("Not a valid object name %s", argv[1]);
pathspec = get_pathspec(prefix, argv + 2); pathspec = get_pathspec(prefix, argv + 2);
tree = parse_tree_indirect(sha1); tree = parse_tree_indirect(sha1);

View File

@ -247,10 +247,12 @@ int main(int argc, char **argv)
usage(merge_base_usage); usage(merge_base_usage);
argc--; argv++; argc--; argv++;
} }
if (argc != 3 || if (argc != 3)
get_sha1(argv[1], rev1key) ||
get_sha1(argv[2], rev2key))
usage(merge_base_usage); usage(merge_base_usage);
if (get_sha1(argv[1], rev1key))
die("Not a valid object name %s", argv[1]);
if (get_sha1(argv[2], rev2key))
die("Not a valid object name %s", argv[2]);
rev1 = lookup_commit_reference(rev1key); rev1 = lookup_commit_reference(rev1key);
rev2 = lookup_commit_reference(rev2key); rev2 = lookup_commit_reference(rev2key);
if (!rev1 || !rev2) if (!rev1 || !rev2)

View File

@ -149,7 +149,7 @@ static void *get_tree_descriptor(struct tree_desc *desc, const char *rev)
unsigned char sha1[20]; unsigned char sha1[20];
void *buf; void *buf;
if (get_sha1(rev, sha1) < 0) if (get_sha1(rev, sha1))
die("unknown rev %s", rev); die("unknown rev %s", rev);
buf = fill_tree_descriptor(desc, sha1); buf = fill_tree_descriptor(desc, sha1);
if (!buf) if (!buf)

View File

@ -880,8 +880,8 @@ int main(int argc, char **argv)
if (1 < index_only + update) if (1 < index_only + update)
usage(read_tree_usage); usage(read_tree_usage);
if (get_sha1(arg, sha1) < 0) if (get_sha1(arg, sha1))
usage(read_tree_usage); die("Not a valid object name %s", arg);
if (list_tree(sha1) < 0) if (list_tree(sha1) < 0)
die("failed to unpack tree object %s", arg); die("failed to unpack tree object %s", arg);
stage++; stage++;

View File

@ -794,7 +794,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
local_flags = UNINTERESTING; local_flags = UNINTERESTING;
arg++; arg++;
} }
if (get_sha1(arg, sha1) < 0) { if (get_sha1(arg, sha1)) {
int j; int j;
if (seen_dashdash || local_flags) if (seen_dashdash || local_flags)
@ -820,7 +820,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
if (def && !revs->pending_objects) { if (def && !revs->pending_objects) {
unsigned char sha1[20]; unsigned char sha1[20];
struct object *object; struct object *object;
if (get_sha1(def, sha1) < 0) if (get_sha1(def, sha1))
die("bad default revision '%s'", def); die("bad default revision '%s'", def);
object = get_reference(revs, def, sha1, 0); object = get_reference(revs, def, sha1, 0);
add_pending_object(revs, object, def); add_pending_object(revs, object, def);

View File

@ -134,7 +134,7 @@ int main(int argc, char **argv)
commit_id = argv[arg]; commit_id = argv[arg];
url = argv[arg + 1]; url = argv[arg + 1];
if (get_sha1(commit_id, sha1)) if (get_sha1(commit_id, sha1))
usage(ssh_push_usage); die("Not a valid object name %s", commit_id);
memcpy(hex, sha1_to_hex(sha1), sizeof(hex)); memcpy(hex, sha1_to_hex(sha1), sizeof(hex));
argv[arg] = hex; argv[arg] = hex;

View File

@ -321,8 +321,8 @@ int main(int argc, char **argv)
strbuf_append_string(&current_path, "/"); strbuf_append_string(&current_path, "/");
/* FALLTHROUGH */ /* FALLTHROUGH */
case 2: case 2:
if (get_sha1(argv[1], sha1) < 0) if (get_sha1(argv[1], sha1))
usage(tar_tree_usage); die("Not a valid object name %s", argv[1]);
break; break;
default: default:
usage(tar_tree_usage); usage(tar_tree_usage);

View File

@ -27,8 +27,10 @@ int main(int argc, char **argv)
{ {
unsigned char sha1[20]; unsigned char sha1[20];
if (argc != 2 || get_sha1(argv[1], sha1)) if (argc != 2)
usage("git-unpack-file <sha1>"); usage("git-unpack-file <sha1>");
if (get_sha1(argv[1], sha1))
die("Not a valid object name %s", argv[1]);
setup_git_directory(); setup_git_directory();
git_config(git_default_config); git_config(git_default_config);

View File

@ -32,10 +32,10 @@ int main(int argc, char **argv)
refname = argv[1]; refname = argv[1];
value = argv[2]; value = argv[2];
oldval = argv[3]; oldval = argv[3];
if (get_sha1(value, sha1) < 0) if (get_sha1(value, sha1))
die("%s: not a valid SHA1", value); die("%s: not a valid SHA1", value);
memset(oldsha1, 0, 20); memset(oldsha1, 0, 20);
if (oldval && get_sha1(oldval, oldsha1) < 0) if (oldval && get_sha1(oldval, oldsha1))
die("%s: not a valid old SHA1", oldval); die("%s: not a valid old SHA1", oldval);
path = resolve_ref(git_path("%s", refname), currsha1, !!oldval); path = resolve_ref(git_path("%s", refname), currsha1, !!oldval);