Merge branch 'maint'

* maint:
  Documentation/git-am.txt: Pass -r in the example invocation of rm -f .dotest
  timezone_names[]: fixed the tz offset for New Zealand.
  filter-branch documentation: non-zero exit status in command abort the filter
  rev-parse: fix potential bus error with --parseopt option spec handling
  Use a single implementation and API for copy_file()
  Documentation/git-filter-branch: add a new msg-filter example
  Correct fast-export file mode strings to match fast-import standard
This commit is contained in:
Junio C Hamano 2008-02-26 00:14:22 -08:00
commit 2db511fdbd
11 changed files with 89 additions and 51 deletions

View File

@ -138,7 +138,7 @@ aborts in the middle,. You can recover from this in one of two ways:
The command refuses to process new mailboxes while `.dotest` The command refuses to process new mailboxes while `.dotest`
directory exists, so if you decide to start over from scratch, directory exists, so if you decide to start over from scratch,
run `rm -f .dotest` before running the command with mailbox run `rm -f -r .dotest` before running the command with mailbox
names. names.

View File

@ -56,7 +56,9 @@ notable exception of the commit filter, for technical reasons).
Prior to that, the $GIT_COMMIT environment variable will be set to contain Prior to that, the $GIT_COMMIT environment variable will be set to contain
the id of the commit being rewritten. Also, GIT_AUTHOR_NAME, the id of the commit being rewritten. Also, GIT_AUTHOR_NAME,
GIT_AUTHOR_EMAIL, GIT_AUTHOR_DATE, GIT_COMMITTER_NAME, GIT_COMMITTER_EMAIL, GIT_AUTHOR_EMAIL, GIT_AUTHOR_DATE, GIT_COMMITTER_NAME, GIT_COMMITTER_EMAIL,
and GIT_COMMITTER_DATE are set according to the current commit. and GIT_COMMITTER_DATE are set according to the current commit. If any
evaluation of <command> returns a non-zero exit status, the whole operation
will be aborted.
A 'map' function is available that takes an "original sha1 id" argument A 'map' function is available that takes an "original sha1 id" argument
and outputs a "rewritten sha1 id" if the commit has been already and outputs a "rewritten sha1 id" if the commit has been already
@ -197,7 +199,7 @@ happened). If this is not the case, use:
-------------------------------------------------------------------------- --------------------------------------------------------------------------
git filter-branch --parent-filter \ git filter-branch --parent-filter \
'cat; test $GIT_COMMIT = <commit-id> && echo "-p <graft-id>"' HEAD 'test $GIT_COMMIT = <commit-id> && echo "-p <graft-id>" || cat' HEAD
-------------------------------------------------------------------------- --------------------------------------------------------------------------
or even simpler: or even simpler:
@ -240,6 +242,15 @@ committed a merge between P1 and P2, it will be propagated properly
and all children of the merge will become merge commits with P1,P2 and all children of the merge will become merge commits with P1,P2
as their parents instead of the merge commit. as their parents instead of the merge commit.
You can rewrite the commit log messages using `--message-filter`. For
example, `git-svn-id` strings in a repository created by `git-svn` can
be removed this way:
-------------------------------------------------------
git filter-branch --message-filter '
sed -e "/^git-svn-id:/d"
'
-------------------------------------------------------
To restrict rewriting to only part of the history, specify a revision To restrict rewriting to only part of the history, specify a revision
range in addition to the new branch name. The new branch name will range in addition to the new branch name. The new branch name will

View File

@ -123,7 +123,7 @@ static void show_filemodify(struct diff_queue_struct *q,
printf("D %s\n", spec->path); printf("D %s\n", spec->path);
else { else {
struct object *object = lookup_object(spec->sha1); struct object *object = lookup_object(spec->sha1);
printf("M 0%06o :%d %s\n", spec->mode, printf("M %06o :%d %s\n", spec->mode,
get_object_mark(object), spec->path); get_object_mark(object), spec->path);
} }
} }

View File

@ -29,27 +29,6 @@ static void safe_create_dir(const char *dir, int share)
die("Could not make %s writable by group\n", dir); die("Could not make %s writable by group\n", dir);
} }
static int copy_file(const char *dst, const char *src, int mode)
{
int fdi, fdo, status;
mode = (mode & 0111) ? 0777 : 0666;
if ((fdi = open(src, O_RDONLY)) < 0)
return fdi;
if ((fdo = open(dst, O_WRONLY | O_CREAT | O_EXCL, mode)) < 0) {
close(fdi);
return fdo;
}
status = copy_fd(fdi, fdo);
if (close(fdo) != 0)
return error("%s: write error: %s", dst, strerror(errno));
if (!status && adjust_shared_perm(dst))
return -1;
return status;
}
static void copy_templates_1(char *path, int baselen, static void copy_templates_1(char *path, int baselen,
char *template, int template_baselen, char *template, int template_baselen,
DIR *dir) DIR *dir)

View File

@ -267,23 +267,6 @@ static int diff_two(const char *file1, const char *label1,
return 0; return 0;
} }
static int copy_file(const char *src, const char *dest)
{
FILE *in, *out;
char buffer[32768];
int count;
if (!(in = fopen(src, "r")))
return error("Could not open %s", src);
if (!(out = fopen(dest, "w")))
return error("Could not open %s", dest);
while ((count = fread(buffer, 1, sizeof(buffer), in)))
fwrite(buffer, 1, count, out);
fclose(in);
fclose(out);
return 0;
}
static int do_plain_rerere(struct path_list *rr, int fd) static int do_plain_rerere(struct path_list *rr, int fd)
{ {
struct path_list conflict = { NULL, 0, 0, 1 }; struct path_list conflict = { NULL, 0, 0, 1 };
@ -343,7 +326,7 @@ static int do_plain_rerere(struct path_list *rr, int fd)
continue; continue;
fprintf(stderr, "Recorded resolution for '%s'.\n", path); fprintf(stderr, "Recorded resolution for '%s'.\n", path);
copy_file(path, rr_path(name, "postimage")); copy_file(rr_path(name, "postimage"), path, 0666);
tail_optimization: tail_optimization:
if (i < rr->nr - 1) if (i < rr->nr - 1)
memmove(rr->items + i, memmove(rr->items + i,

View File

@ -315,7 +315,7 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)
s = strchr(sb.buf, ' '); s = strchr(sb.buf, ' ');
if (!s || *sb.buf == ' ') { if (!s || *sb.buf == ' ') {
o->type = OPTION_GROUP; o->type = OPTION_GROUP;
o->help = xstrdup(skipspaces(s)); o->help = xstrdup(skipspaces(sb.buf));
continue; continue;
} }

View File

@ -698,6 +698,7 @@ extern const char *git_log_output_encoding;
/* IO helper functions */ /* IO helper functions */
extern void maybe_flush_or_die(FILE *, const char *); extern void maybe_flush_or_die(FILE *, const char *);
extern int copy_fd(int ifd, int ofd); extern int copy_fd(int ifd, int ofd);
extern int copy_file(const char *dst, const char *src, int mode);
extern int read_in_full(int fd, void *buf, size_t count); extern int read_in_full(int fd, void *buf, size_t count);
extern int write_in_full(int fd, const void *buf, size_t count); extern int write_in_full(int fd, const void *buf, size_t count);
extern void write_or_die(int fd, const void *buf, size_t count); extern void write_or_die(int fd, const void *buf, size_t count);

21
copy.c
View File

@ -34,3 +34,24 @@ int copy_fd(int ifd, int ofd)
close(ifd); close(ifd);
return 0; return 0;
} }
int copy_file(const char *dst, const char *src, int mode)
{
int fdi, fdo, status;
mode = (mode & 0111) ? 0777 : 0666;
if ((fdi = open(src, O_RDONLY)) < 0)
return fdi;
if ((fdo = open(dst, O_WRONLY | O_CREAT | O_EXCL, mode)) < 0) {
close(fdi);
return fdo;
}
status = copy_fd(fdi, fdo);
if (close(fdo) != 0)
return error("%s: write error: %s", dst, strerror(errno));
if (!status && adjust_shared_perm(dst))
return -1;
return status;
}

6
date.c
View File

@ -213,9 +213,9 @@ static const struct {
{ "EAST", +10, 0, }, /* Eastern Australian Standard */ { "EAST", +10, 0, }, /* Eastern Australian Standard */
{ "EADT", +10, 1, }, /* Eastern Australian Daylight */ { "EADT", +10, 1, }, /* Eastern Australian Daylight */
{ "GST", +10, 0, }, /* Guam Standard, USSR Zone 9 */ { "GST", +10, 0, }, /* Guam Standard, USSR Zone 9 */
{ "NZT", +11, 0, }, /* New Zealand */ { "NZT", +12, 0, }, /* New Zealand */
{ "NZST", +11, 0, }, /* New Zealand Standard */ { "NZST", +12, 0, }, /* New Zealand Standard */
{ "NZDT", +11, 1, }, /* New Zealand Daylight */ { "NZDT", +12, 1, }, /* New Zealand Daylight */
{ "IDLE", +12, 0, }, /* International Date Line East */ { "IDLE", +12, 0, }, /* International Date Line East */
}; };

8
diff.c
View File

@ -272,8 +272,8 @@ static void print_line_count(int count)
} }
} }
static void copy_file(int prefix, const char *data, int size, static void copy_file_with_prefix(int prefix, const char *data, int size,
const char *set, const char *reset) const char *set, const char *reset)
{ {
int ch, nl_just_seen = 1; int ch, nl_just_seen = 1;
while (0 < size--) { while (0 < size--) {
@ -331,9 +331,9 @@ static void emit_rewrite_diff(const char *name_a,
print_line_count(lc_b); print_line_count(lc_b);
printf(" @@%s\n", reset); printf(" @@%s\n", reset);
if (lc_a) if (lc_a)
copy_file('-', one->data, one->size, old, reset); copy_file_with_prefix('-', one->data, one->size, old, reset);
if (lc_b) if (lc_b)
copy_file('+', two->data, two->size, new, reset); copy_file_with_prefix('+', two->data, two->size, new, reset);
} }
static int fill_mmfile(mmfile_t *mf, struct diff_filespec *one) static int fill_mmfile(mmfile_t *mf, struct diff_filespec *one)

43
t/t1502-rev-parse-parseopt.sh Executable file
View File

@ -0,0 +1,43 @@
#!/bin/sh
test_description='test git rev-parse --parseopt'
. ./test-lib.sh
cat > expect.err <<EOF
usage: some-command [options] <args>...
some-command does foo and bar!
-h, --help show the help
--foo some nifty option --foo
--bar ... some cool option --bar with an argument
An option group Header
-C [...] option C with an optional argument
Extras
--extra1 line above used to cause a segfault but no longer does
EOF
test_expect_success 'test --parseopt help output' '
git rev-parse --parseopt -- -h 2> output.err <<EOF
some-command [options] <args>...
some-command does foo and bar!
--
h,help show the help
foo some nifty option --foo
bar= some cool option --bar with an argument
An option group Header
C? option C with an optional argument
Extras
extra1 line above used to cause a segfault but no longer does
EOF
git diff expect.err output.err
'
test_done