Merge branch 'maint'

* maint:
  Cosmetical command name fix
  Start conforming code to "git subcmd" style part 3
  t9700/test.pl: remove File::Temp requirement
  t9700/test.pl: avoid bareword 'STDERR' in 3-argument open()
This commit is contained in:
Junio C Hamano 2008-09-16 01:24:58 -07:00
commit 97d7fee2cb
10 changed files with 34 additions and 31 deletions

View File

@ -37,7 +37,7 @@ static void copy_templates_1(char *path, int baselen,
/* Note: if ".git/hooks" file exists in the repository being /* Note: if ".git/hooks" file exists in the repository being
* re-initialized, /etc/core-git/templates/hooks/update would * re-initialized, /etc/core-git/templates/hooks/update would
* cause git-init to fail here. I think this is sane but * cause "git init" to fail here. I think this is sane but
* it means that the set of templates we ship by default, along * it means that the set of templates we ship by default, along
* with the way the namespace under .git/ is organized, should * with the way the namespace under .git/ is organized, should
* be really carefully chosen. * be really carefully chosen.

View File

@ -23,7 +23,7 @@
#endif #endif
static const char pack_usage[] = "\ static const char pack_usage[] = "\
git-pack-objects [{ -q | --progress | --all-progress }] \n\ git pack-objects [{ -q | --progress | --all-progress }] \n\
[--max-pack-size=N] [--local] [--incremental] \n\ [--max-pack-size=N] [--local] [--incremental] \n\
[--window=N] [--window-memory=N] [--depth=N] \n\ [--window=N] [--window-memory=N] [--depth=N] \n\
[--no-reuse-delta] [--no-reuse-object] [--delta-base-offset] \n\ [--no-reuse-delta] [--no-reuse-object] [--delta-base-offset] \n\
@ -1872,7 +1872,7 @@ static void mark_in_pack_object(struct object *object, struct packed_git *p, str
/* /*
* Compare the objects in the offset order, in order to emulate the * Compare the objects in the offset order, in order to emulate the
* "git-rev-list --objects" output that produced the pack originally. * "git rev-list --objects" output that produced the pack originally.
*/ */
static int ofscmp(const void *a_, const void *b_) static int ofscmp(const void *a_, const void *b_)
{ {

View File

@ -64,7 +64,7 @@ static void prime_cache_tree(void)
} }
static const char read_tree_usage[] = "git-read-tree (<sha> | [[-m [--trivial] [--aggressive] | --reset | --prefix=<prefix>] [-u | -i]] [--exclude-per-directory=<gitignore>] [--index-output=<file>] <sha1> [<sha2> [<sha3>]])"; static const char read_tree_usage[] = "git read-tree (<sha> | [[-m [--trivial] [--aggressive] | --reset | --prefix=<prefix>] [-u | -i]] [--exclude-per-directory=<gitignore>] [--index-output=<file>] <sha1> [<sha2> [<sha3>]])";
static struct lock_file lock_file; static struct lock_file lock_file;

View File

@ -178,7 +178,7 @@ static void finish_object(struct object_array_entry *p)
static void show_object(struct object_array_entry *p) static void show_object(struct object_array_entry *p)
{ {
/* An object with name "foo\n0000000..." can be used to /* An object with name "foo\n0000000..." can be used to
* confuse downstream git-pack-objects very badly. * confuse downstream "git pack-objects" very badly.
*/ */
const char *ep = strchr(p->name, '\n'); const char *ep = strchr(p->name, '\n');

View File

@ -104,7 +104,7 @@ static int check_local_mod(unsigned char *head, int index_only)
"from both the file and the HEAD\n" "from both the file and the HEAD\n"
"(use -f to force removal)", name); "(use -f to force removal)", name);
else if (!index_only) { else if (!index_only) {
/* It's not dangerous to git-rm --cached a /* It's not dangerous to "git rm --cached" a
* file if the index matches the file or the * file if the index matches the file or the
* HEAD, since it means the deleted content is * HEAD, since it means the deleted content is
* still available somewhere. * still available somewhere.

View File

@ -43,7 +43,7 @@ static int pack_objects(int fd, struct ref *refs)
po.out = fd; po.out = fd;
po.git_cmd = 1; po.git_cmd = 1;
if (start_command(&po)) if (start_command(&po))
die("git-pack-objects failed (%s)", strerror(errno)); die("git pack-objects failed (%s)", strerror(errno));
/* /*
* We feed the pack-objects we just spawned with revision * We feed the pack-objects we just spawned with revision

View File

@ -9,26 +9,26 @@
static const char tar_tree_usage[] = static const char tar_tree_usage[] =
"git tar-tree [--remote=<repo>] <tree-ish> [basedir]\n" "git tar-tree [--remote=<repo>] <tree-ish> [basedir]\n"
"*** Note that this command is now deprecated; use git-archive instead."; "*** Note that this command is now deprecated; use \"git archive\" instead.";
int cmd_tar_tree(int argc, const char **argv, const char *prefix) int cmd_tar_tree(int argc, const char **argv, const char *prefix)
{ {
/* /*
* git-tar-tree is now a wrapper around git-archive --format=tar * "git tar-tree" is now a wrapper around "git archive --format=tar"
* *
* $0 --remote=<repo> arg... ==> * $0 --remote=<repo> arg... ==>
* git-archive --format=tar --remote=<repo> arg... * git archive --format=tar --remote=<repo> arg...
* $0 tree-ish ==> * $0 tree-ish ==>
* git-archive --format=tar tree-ish * git archive --format=tar tree-ish
* $0 tree-ish basedir ==> * $0 tree-ish basedir ==>
* git-archive --format-tar --prefix=basedir tree-ish * git archive --format-tar --prefix=basedir tree-ish
*/ */
int i; int i;
const char **nargv = xcalloc(sizeof(*nargv), argc + 2); const char **nargv = xcalloc(sizeof(*nargv), argc + 2);
char *basedir_arg; char *basedir_arg;
int nargc = 0; int nargc = 0;
nargv[nargc++] = "git-archive"; nargv[nargc++] = "archive";
nargv[nargc++] = "--format=tar"; nargv[nargc++] = "--format=tar";
if (2 <= argc && !prefixcmp(argv[1], "--remote=")) { if (2 <= argc && !prefixcmp(argv[1], "--remote=")) {
@ -53,8 +53,8 @@ int cmd_tar_tree(int argc, const char **argv, const char *prefix)
nargv[nargc] = NULL; nargv[nargc] = NULL;
fprintf(stderr, fprintf(stderr,
"*** git-tar-tree is now deprecated.\n" "*** \"git tar-tree\" is now deprecated.\n"
"*** Running git-archive instead.\n***"); "*** Running \"git archive\" instead.\n***");
for (i = 0; i < nargc; i++) { for (i = 0; i < nargc; i++) {
fputc(' ', stderr); fputc(' ', stderr);
sq_quote_print(stderr, nargv[i]); sq_quote_print(stderr, nargv[i]);

View File

@ -13,7 +13,7 @@
#include "fsck.h" #include "fsck.h"
static int dry_run, quiet, recover, has_errors, strict; static int dry_run, quiet, recover, has_errors, strict;
static const char unpack_usage[] = "git-unpack-objects [-n] [-q] [-r] [--strict] < pack-file"; static const char unpack_usage[] = "git unpack-objects [-n] [-q] [-r] [--strict] < pack-file";
/* We always read in 4kB chunks. */ /* We always read in 4kB chunks. */
static unsigned char buffer[4096]; static unsigned char buffer[4096];

View File

@ -14,7 +14,7 @@
* Default to not allowing changes to the list of files. The * Default to not allowing changes to the list of files. The
* tool doesn't actually care, but this makes it harder to add * tool doesn't actually care, but this makes it harder to add
* files to the revision control by mistake by doing something * files to the revision control by mistake by doing something
* like "git-update-index *" and suddenly having all the object * like "git update-index *" and suddenly having all the object
* files be revision controlled. * files be revision controlled.
*/ */
static int allow_add; static int allow_add;
@ -313,18 +313,18 @@ static void read_index_info(int line_termination)
/* This reads lines formatted in one of three formats: /* This reads lines formatted in one of three formats:
* *
* (1) mode SP sha1 TAB path * (1) mode SP sha1 TAB path
* The first format is what "git-apply --index-info" * The first format is what "git apply --index-info"
* reports, and used to reconstruct a partial tree * reports, and used to reconstruct a partial tree
* that is used for phony merge base tree when falling * that is used for phony merge base tree when falling
* back on 3-way merge. * back on 3-way merge.
* *
* (2) mode SP type SP sha1 TAB path * (2) mode SP type SP sha1 TAB path
* The second format is to stuff git-ls-tree output * The second format is to stuff "git ls-tree" output
* into the index file. * into the index file.
* *
* (3) mode SP sha1 SP stage TAB path * (3) mode SP sha1 SP stage TAB path
* This format is to put higher order stages into the * This format is to put higher order stages into the
* index file and matches git-ls-files --stage output. * index file and matches "git ls-files --stage" output.
*/ */
errno = 0; errno = 0;
ul = strtoul(buf.buf, &ptr, 8); ul = strtoul(buf.buf, &ptr, 8);

View File

@ -9,7 +9,6 @@ use Test::More qw(no_plan);
use Cwd; use Cwd;
use File::Basename; use File::Basename;
use File::Temp;
BEGIN { use_ok('Git') } BEGIN { use_ok('Git') }
@ -35,7 +34,7 @@ is($r->get_color("color.test.slot1", "red"), $ansi_green, "get_color");
# Failure cases for config: # Failure cases for config:
# Save and restore STDERR; we will probably extract this into a # Save and restore STDERR; we will probably extract this into a
# "dies_ok" method and possibly move the STDERR handling to Git.pm. # "dies_ok" method and possibly move the STDERR handling to Git.pm.
open our $tmpstderr, ">&", STDERR or die "cannot save STDERR"; close STDERR; open our $tmpstderr, ">&STDERR" or die "cannot save STDERR"; close STDERR;
eval { $r->config("test.dupstring") }; eval { $r->config("test.dupstring") };
ok($@, "config: duplicate entry in scalar context fails"); ok($@, "config: duplicate entry in scalar context fails");
eval { $r->config_bool("test.boolother") }; eval { $r->config_bool("test.boolother") };
@ -66,21 +65,25 @@ is($r->ident_person("Name", "email", "123 +0000"), "Name <email>",
# objects and hashes # objects and hashes
ok(our $file1hash = $r->command_oneline('rev-parse', "HEAD:file1"), "(get file hash)"); ok(our $file1hash = $r->command_oneline('rev-parse', "HEAD:file1"), "(get file hash)");
our $tmpfile = File::Temp->new; my $tmpfile = "file.tmp";
is($r->cat_blob($file1hash, $tmpfile), 15, "cat_blob: size"); open TEMPFILE, "+>$tmpfile" or die "Can't open $tmpfile: $!";
is($r->cat_blob($file1hash, \*TEMPFILE), 15, "cat_blob: size");
our $blobcontents; our $blobcontents;
{ local $/; seek $tmpfile, 0, 0; $blobcontents = <$tmpfile>; } { local $/; seek TEMPFILE, 0, 0; $blobcontents = <TEMPFILE>; }
is($blobcontents, "changed file 1\n", "cat_blob: data"); is($blobcontents, "changed file 1\n", "cat_blob: data");
seek $tmpfile, 0, 0; close TEMPFILE or die "Failed writing to $tmpfile: $!";
is(Git::hash_object("blob", $tmpfile), $file1hash, "hash_object: roundtrip"); is(Git::hash_object("blob", $tmpfile), $file1hash, "hash_object: roundtrip");
$tmpfile = File::Temp->new(); open TEMPFILE, ">$tmpfile" or die "Can't open $tmpfile: $!";
print $tmpfile my $test_text = "test blob, to be inserted\n"; print TEMPFILE my $test_text = "test blob, to be inserted\n";
close TEMPFILE or die "Failed writing to $tmpfile: $!";
like(our $newhash = $r->hash_and_insert_object($tmpfile), qr/[0-9a-fA-F]{40}/, like(our $newhash = $r->hash_and_insert_object($tmpfile), qr/[0-9a-fA-F]{40}/,
"hash_and_insert_object: returns hash"); "hash_and_insert_object: returns hash");
$tmpfile = File::Temp->new; open TEMPFILE, "+>$tmpfile" or die "Can't open $tmpfile: $!";
is($r->cat_blob($newhash, $tmpfile), length $test_text, "cat_blob: roundtrip size"); is($r->cat_blob($newhash, \*TEMPFILE), length $test_text, "cat_blob: roundtrip size");
{ local $/; seek $tmpfile, 0, 0; $blobcontents = <$tmpfile>; } { local $/; seek TEMPFILE, 0, 0; $blobcontents = <TEMPFILE>; }
is($blobcontents, $test_text, "cat_blob: roundtrip data"); is($blobcontents, $test_text, "cat_blob: roundtrip data");
close TEMPFILE;
unlink $tmpfile;
# paths # paths
is($r->repo_path, "./.git", "repo_path"); is($r->repo_path, "./.git", "repo_path");