From 9b28a8b9c2051bf85f71cdec85c142a0ab561f10 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Mon, 26 Feb 2007 11:17:11 -0500 Subject: [PATCH 01/69] git-gui: Relocate the menu/transport menu code. This code doesn't belong down in the main window UI creation, its really part of the menu system and probably should be located with it. I'm moving it because I could not find the code when I was looking for it earlier today, as it was not where I expected it to be found. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 50 ++++++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index f84ba3382b..48097ea5e8 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -5330,6 +5330,34 @@ if {[is_enabled multicommit] || [is_enabled singlecommit]} { [list .mbar.commit entryconf [.mbar.commit index last] -state] } +# -- Merge Menu +# +if {[is_enabled branch]} { + menu .mbar.merge + .mbar.merge add command -label {Local Merge...} \ + -command do_local_merge \ + -font font_ui + lappend disable_on_lock \ + [list .mbar.merge entryconf [.mbar.merge index last] -state] + .mbar.merge add command -label {Abort Merge...} \ + -command do_reset_hard \ + -font font_ui + lappend disable_on_lock \ + [list .mbar.merge entryconf [.mbar.merge index last] -state] + +} + +# -- Transport Menu +# +if {[is_enabled transport]} { + menu .mbar.fetch + + menu .mbar.push + .mbar.push add command -label {Push...} \ + -command do_push_anywhere \ + -font font_ui +} + if {[is_MacOSX]} { # -- Apple Menu (Mac OS X only) # @@ -5502,28 +5530,6 @@ pack .branch.l1 -side left pack .branch.cb -side left -fill x pack .branch -side top -fill x -if {[is_enabled branch]} { - menu .mbar.merge - .mbar.merge add command -label {Local Merge...} \ - -command do_local_merge \ - -font font_ui - lappend disable_on_lock \ - [list .mbar.merge entryconf [.mbar.merge index last] -state] - .mbar.merge add command -label {Abort Merge...} \ - -command do_reset_hard \ - -font font_ui - lappend disable_on_lock \ - [list .mbar.merge entryconf [.mbar.merge index last] -state] - - - menu .mbar.fetch - - menu .mbar.push - .mbar.push add command -label {Push...} \ - -command do_push_anywhere \ - -font font_ui -} - # -- Main Window Layout # panedwindow .vpane -orient vertical From fd234dfdb7ee1955922ded27ed18df59259193d9 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Mon, 26 Feb 2007 11:22:10 -0500 Subject: [PATCH 02/69] git-gui: Add Reset to the Branch menu. cehteh on #git noticed that there was no way to perform a reset --hard from within git-gui. When I pointed out this was Merge->Abort Merge cehteh said this is not very understandable, and that most users would never guess to try that option unless they were actually in a merge. So Branch->Reset is now also a way to cause a reset --hard from within the UI. Right now the confirmation dialog is the same as the one used in Merge->Abort Merge. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/git-gui.sh b/git-gui.sh index 48097ea5e8..36155bb8ea 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -5256,6 +5256,12 @@ if {[is_enabled branch]} { -font font_ui lappend disable_on_lock [list .mbar.branch entryconf \ [.mbar.branch index last] -state] + + .mbar.branch add command -label {Reset...} \ + -command do_reset_hard \ + -font font_ui + lappend disable_on_lock [list .mbar.branch entryconf \ + [.mbar.branch index last] -state] } # -- Commit Menu From 51bd9d7b8cf29e0e441531fb0a671cc7093f278b Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Mon, 26 Feb 2007 11:47:14 -0500 Subject: [PATCH 03/69] git-gui: Don't create empty (same tree as parent) commits. Mark Levedahl noticed that git-gui will let you create an empty normal (non-merge) commit if the file state in the index is out of whack. The case Mark was looking at was with the new autoCRLF feature in git enabled and is actually somewhat difficult to create. I found a different way to create an empty commit: turn on the Trust File Modifications flag, touch a file, rescan, then move the file into the "Changes To Be Committed" list without looking at the file's diff. This makes git-gui think there are files staged for commit, yet the update-index call did nothing other than refresh the stat information for the affected file. In this case git-gui allowed the user to make a commit that did not actually change anything in the repository. Creating empty commits is usually a pointless operation; rarely does it record useful information. More often than not an empty commit is actually an indication that the user did not properly update their index prior to commit. We should help the user out by detecting this possible mistake and guiding them through it, rather than blindly recording it. After we get the new tree name back from write-tree we compare it to the parent commit's tree; if they are the same string and this is a normal (non-merge, non-amend) commit then something fishy is going on. The user is making an empty commit, but they most likely don't want to do that. We now pop an informational dialog and start a rescan, aborting the commit. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/git-gui.sh b/git-gui.sh index 36155bb8ea..743099c573 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -1267,6 +1267,24 @@ proc commit_committree {fd_wt curHEAD msg} { return } + # -- Verify this wasn't an empty change. + # + if {$commit_type eq {normal}} { + set old_tree [git rev-parse "$PARENT^{tree}"] + if {$tree_id eq $old_tree} { + info_popup {No changes to commit. + +No files were modified by this commit and it +was not a merge commit. + +A rescan will be automatically started now. +} + unlock_index + rescan {set ui_status_value {No changes to commit.}} + return + } + } + # -- Build the message. # set msg_p [gitdir COMMIT_EDITMSG] From c3e8a0a4ddb7d32970c49117e0386a3b1c182413 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Thu, 1 Mar 2007 14:37:34 -0500 Subject: [PATCH 04/69] git-gui: Remove unnecessary /dev/null redirection. Git 1.5.0 and later no longer output useless messages to standard error when making the initial (or what looks to be) commit of a repository. Since /dev/null does not exist on Windows in the MinGW environment we can't redirect there anyway. Since Git does not output anymore, I'm removing the redirection. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index 743099c573..1981827a8e 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -1299,14 +1299,8 @@ A rescan will be automatically started now. # -- Create the commit. # set cmd [list git commit-tree $tree_id] - set parents [concat $PARENT $MERGE_HEAD] - if {[llength $parents] > 0} { - foreach p $parents { - lappend cmd -p $p - } - } else { - # git commit-tree writes to stderr during initial commit. - lappend cmd 2>/dev/null + foreach p [concat $PARENT $MERGE_HEAD] { + lappend cmd -p $p } lappend cmd <$msg_p if {[catch {set cmt_id [eval exec $cmd]} err]} { From 118f8b241355b38cd21e644e8620d81f10190627 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Fri, 2 Mar 2007 21:53:33 +0100 Subject: [PATCH 05/69] git-config: document --rename-section, provide --remove-section This patch documents the previously undocumented option --rename-section and adds a new option to zap an entire section. Signed-off-by: Paolo Bonzini Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- Documentation/git-config.txt | 8 +++++ builtin-config.c | 15 ++++++++- config.c | 60 +++++++++++++++++++++--------------- t/t1300-repo-config.sh | 16 ++++++++++ 4 files changed, 74 insertions(+), 25 deletions(-) diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt index 6624484fe1..68de5881bd 100644 --- a/Documentation/git-config.txt +++ b/Documentation/git-config.txt @@ -16,6 +16,8 @@ SYNOPSIS 'git-config' [--global] [type] --get-all name [value_regex] 'git-config' [--global] [type] --unset name [value_regex] 'git-config' [--global] [type] --unset-all name [value_regex] +'git-config' [--global] [type] --rename-section old_name new_name +'git-config' [--global] [type] --remove-section name 'git-config' [--global] -l | --list DESCRIPTION @@ -74,6 +76,12 @@ OPTIONS --global:: Use global ~/.gitconfig file rather than the repository .git/config. +--remove-section:: + Remove the given section from the configuration file. + +--rename-section:: + Rename the given section to a new name. + --unset:: Remove the line matching the key from config file. diff --git a/builtin-config.c b/builtin-config.c index f1433a4ab6..dfa403b94b 100644 --- a/builtin-config.c +++ b/builtin-config.c @@ -2,7 +2,7 @@ #include "cache.h" static const char git_config_set_usage[] = -"git-config [ --global ] [ --bool | --int ] [--get | --get-all | --get-regexp | --replace-all | --add | --unset | --unset-all] name [value [value_regex]] | --rename-section old_name new_name | --list"; +"git-config [ --global ] [ --bool | --int ] [--get | --get-all | --get-regexp | --replace-all | --add | --unset | --unset-all] name [value [value_regex]] | --rename-section old_name new_name | --remove-section name | --list"; static char *key; static regex_t *key_regexp; @@ -168,6 +168,19 @@ int cmd_config(int argc, const char **argv, const char *prefix) } return 0; } + else if (!strcmp(argv[1], "--remove-section")) { + int ret; + if (argc != 3) + usage(git_config_set_usage); + ret = git_config_rename_section(argv[2], NULL); + if (ret < 0) + return ret; + if (ret == 0) { + fprintf(stderr, "No such section!\n"); + return 1; + } + return 0; + } else break; argc--; diff --git a/config.c b/config.c index 0ff413b804..5611d7a6a6 100644 --- a/config.c +++ b/config.c @@ -854,9 +854,37 @@ write_err_out: } +static int section_name_match (const char *buf, const char *name) +{ + int i = 0, j = 0, dot = 0; + for (; buf[i] && buf[i] != ']'; i++) { + if (!dot && isspace(buf[i])) { + dot = 1; + if (name[j++] != '.') + break; + for (i++; isspace(buf[i]); i++) + ; /* do nothing */ + if (buf[i] != '"') + break; + continue; + } + if (buf[i] == '\\' && dot) + i++; + else if (buf[i] == '"' && dot) { + for (i++; isspace(buf[i]); i++) + ; /* do_nothing */ + break; + } + if (buf[i] != name[j++]) + break; + } + return (buf[i] == ']' && name[j] == 0); +} + +/* if new_name == NULL, the section is removed instead */ int git_config_rename_section(const char *old_name, const char *new_name) { - int ret = 0; + int ret = 0, remove = 0; char *config_filename; struct lock_file *lock = xcalloc(sizeof(struct lock_file), 1); int out_fd; @@ -887,31 +915,12 @@ int git_config_rename_section(const char *old_name, const char *new_name) ; /* do nothing */ if (buf[i] == '[') { /* it's a section */ - int j = 0, dot = 0; - for (i++; buf[i] && buf[i] != ']'; i++) { - if (!dot && isspace(buf[i])) { - dot = 1; - if (old_name[j++] != '.') - break; - for (i++; isspace(buf[i]); i++) - ; /* do nothing */ - if (buf[i] != '"') - break; + if (section_name_match (&buf[i+1], old_name)) { + ret++; + if (new_name == NULL) { + remove = 1; continue; } - if (buf[i] == '\\' && dot) - i++; - else if (buf[i] == '"' && dot) { - for (i++; isspace(buf[i]); i++) - ; /* do_nothing */ - break; - } - if (buf[i] != old_name[j++]) - break; - } - if (buf[i] == ']' && old_name[j] == 0) { - /* old_name matches */ - ret++; store.baselen = strlen(new_name); if (!store_write_section(out_fd, new_name)) { ret = write_error(); @@ -919,7 +928,10 @@ int git_config_rename_section(const char *old_name, const char *new_name) } continue; } + remove = 0; } + if (remove) + continue; length = strlen(buf); if (write_in_full(out_fd, buf, length) != length) { ret = write_error(); diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh index 49b5666b33..ee386cfbf3 100755 --- a/t/t1300-repo-config.sh +++ b/t/t1300-repo-config.sh @@ -391,6 +391,22 @@ EOF test_expect_success "rename succeeded" "diff -u expect .git/config" +cat >> .git/config << EOF + [branch "zwei"] a = 1 [branch "vier"] +EOF + +test_expect_success "remove section" "git config --remove-section branch.zwei" + +cat > expect << EOF +# Hallo + #Bello +[branch "drei"] +weird +EOF + +test_expect_success "section was removed properly" \ + "diff -u expect .git/config" + test_expect_success numbers ' git-config kilo.gram 1k && From 9509af686bffdbd7c3f17faf3c07d2034d480ffc Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 1 Mar 2007 05:26:30 +0100 Subject: [PATCH 06/69] Make git-revert & git-cherry-pick a builtin Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- Makefile | 11 +- builtin-revert.c | 406 +++++++++++++++++++++++++++++++++++++++++++++++ builtin.h | 2 + git-revert.sh | 197 ----------------------- git.c | 2 + 5 files changed, 414 insertions(+), 204 deletions(-) create mode 100644 builtin-revert.c delete mode 100755 git-revert.sh diff --git a/Makefile b/Makefile index a221bdc027..061864843f 100644 --- a/Makefile +++ b/Makefile @@ -180,7 +180,7 @@ SCRIPT_SH = \ git-merge-one-file.sh git-parse-remote.sh \ git-pull.sh git-rebase.sh \ git-repack.sh git-request-pull.sh git-reset.sh \ - git-revert.sh git-sh-setup.sh \ + git-sh-setup.sh \ git-tag.sh git-verify-tag.sh \ git-applymbox.sh git-applypatch.sh git-am.sh \ git-merge.sh git-merge-stupid.sh git-merge-octopus.sh \ @@ -196,7 +196,7 @@ SCRIPT_PERL = \ SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)) \ $(patsubst %.perl,%,$(SCRIPT_PERL)) \ - git-cherry-pick git-status git-instaweb + git-status git-instaweb # ... and all the rest that could be moved out of bindir to gitexecdir PROGRAMS = \ @@ -223,7 +223,7 @@ EXTRA_PROGRAMS = BUILT_INS = \ git-format-patch$X git-show$X git-whatchanged$X git-cherry$X \ git-get-tar-commit-id$X git-init$X git-repo-config$X \ - git-fsck-objects$X \ + git-fsck-objects$X git-cherry-pick$X \ $(patsubst builtin-%.o,git-%$X,$(BUILTIN_OBJS)) # what 'all' will build and 'install' will install, in gitexecdir @@ -315,6 +315,7 @@ BUILTIN_OBJS = \ builtin-rerere.o \ builtin-rev-list.o \ builtin-rev-parse.o \ + builtin-revert.o \ builtin-rm.o \ builtin-runstatus.o \ builtin-shortlog.o \ @@ -689,10 +690,6 @@ $(patsubst %.perl,%,$(SCRIPT_PERL)): % : %.perl chmod +x $@+ mv $@+ $@ -git-cherry-pick: git-revert - cp $< $@+ - mv $@+ $@ - git-status: git-commit cp $< $@+ mv $@+ $@ diff --git a/builtin-revert.c b/builtin-revert.c new file mode 100644 index 0000000000..bc3cfcba07 --- /dev/null +++ b/builtin-revert.c @@ -0,0 +1,406 @@ +#include "cache.h" +#include "builtin.h" +#include "object.h" +#include "commit.h" +#include "tag.h" +#include "wt-status.h" +#include "run-command.h" +#include "exec_cmd.h" +#include "utf8.h" + +/* + * This implements the builtins revert and cherry-pick. + * + * Copyright (c) 2007 Johannes E. Schindelin + * + * Based on git-revert.sh, which is + * + * Copyright (c) 2005 Linus Torvalds + * Copyright (c) 2005 Junio C Hamano + */ + +static const char *revert_usage = "git-revert [--edit | --no-edit] [-n] "; + +static const char *cherry_pick_usage = "git-cherry-pick [--edit] [-n] [-r] [-x] "; + +static int edit; +static int replay; +enum { REVERT, CHERRY_PICK } action; +static int no_commit; +static struct commit *commit; +static int needed_deref; + +static const char *me; + +#define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION" + +static void parse_options(int argc, const char **argv) +{ + const char *usage_str = action == REVERT ? + revert_usage : cherry_pick_usage; + unsigned char sha1[20]; + const char *arg; + int i; + + if (argc < 2) + usage(usage_str); + + for (i = 1; i < argc - 1; i++) { + arg = argv[i]; + if (!strcmp(arg, "-n") || !strcmp(arg, "--no-commit")) + no_commit = 1; + else if (!strcmp(arg, "-e") || !strcmp(arg, "--edit")) + edit = 1; + else if (!strcmp(arg, "--no-edit")) + edit = 0; + else if (!strcmp(arg, "-x") || !strcmp(arg, "--i-really-want-" + "to-expose-my-private-commit-object-name")) + replay = 0; + else if (strcmp(arg, "-r")) + usage(usage_str); + } + + arg = argv[argc - 1]; + if (get_sha1(arg, sha1)) + die ("Cannot find '%s'", arg); + commit = (struct commit *)parse_object(sha1); + if (!commit) + die ("Could not find %s", sha1_to_hex(sha1)); + if (commit->object.type == OBJ_TAG) { + commit = (struct commit *) + deref_tag((struct object *)commit, arg, strlen(arg)); + needed_deref = 1; + } + if (commit->object.type != OBJ_COMMIT) + die ("'%s' does not point to a commit", arg); +} + +static char *get_oneline(const char *message) +{ + char *result; + const char *p = message, *abbrev, *eol; + int abbrev_len, oneline_len; + + if (!p) + die ("Could not read commit message of %s", + sha1_to_hex(commit->object.sha1)); + while (*p && (*p != '\n' || p[1] != '\n')) + p++; + + if (*p) { + p += 2; + for (eol = p + 1; *eol && *eol != '\n'; eol++) + ; /* do nothing */ + } else + eol = p; + abbrev = find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV); + abbrev_len = strlen(abbrev); + oneline_len = eol - p; + result = xmalloc(abbrev_len + 5 + oneline_len); + memcpy(result, abbrev, abbrev_len); + memcpy(result + abbrev_len, "... ", 4); + memcpy(result + abbrev_len + 4, p, oneline_len); + result[abbrev_len + 4 + oneline_len] = '\0'; + return result; +} + +char *get_encoding(const char *message) +{ + const char *p = message, *eol; + + if (!p) + die ("Could not read commit message of %s", + sha1_to_hex(commit->object.sha1)); + while (*p && *p != '\n') { + for (eol = p + 1; *eol && *eol != '\n'; eol++) + ; /* do nothing */ + if (!prefixcmp(p, "encoding ")) { + char *result = xmalloc(eol - 8 - p); + strlcpy(result, p + 9, eol - 8 - p); + return result; + } + p = eol; + if (*p == '\n') + p++; + } + return NULL; +} + +struct lock_file msg_file; +static int msg_fd; + +static void add_to_msg(const char *string) +{ + int len = strlen(string); + if (write_in_full(msg_fd, string, len) < 0) + die ("Could not write to .msg"); +} + +static void add_message_to_msg(const char *message) +{ + const char *p = message; + while (*p && (*p != '\n' || p[1] != '\n')) + p++; + + if (!*p) + add_to_msg(sha1_to_hex(commit->object.sha1)); + + p += 2; + add_to_msg(p); + return; +} + +static void set_author_ident_env(const char *message) +{ + const char *p = message; + if (!p) + die ("Could not read commit message of %s", + sha1_to_hex(commit->object.sha1)); + while (*p && *p != '\n') { + const char *eol; + + for (eol = p; *eol && *eol != '\n'; eol++) + ; /* do nothing */ + if (!prefixcmp(p, "author ")) { + char *line, *pend, *email, *timestamp; + + p += 7; + line = xmalloc(eol + 1 - p); + memcpy(line, p, eol - p); + line[eol - p] = '\0'; + email = strchr(line, '<'); + if (!email) + die ("Could not extract author email from %s", + sha1_to_hex(commit->object.sha1)); + if (email == line) + pend = line; + else + for (pend = email; pend != line + 1 && + isspace(pend[-1]); pend--); + ; /* do nothing */ + *pend = '\0'; + email++; + timestamp = strchr(email, '>'); + if (!timestamp) + die ("Could not extract author email from %s", + sha1_to_hex(commit->object.sha1)); + *timestamp = '\0'; + for (timestamp++; *timestamp && isspace(*timestamp); + timestamp++) + ; /* do nothing */ + setenv("GIT_AUTHOR_NAME", line, 1); + setenv("GIT_AUTHOR_EMAIL", email, 1); + setenv("GIT_AUTHOR_DATE", timestamp, 1); + free(line); + return; + } + p = eol; + if (*p == '\n') + p++; + } + die ("No author information found in %s", + sha1_to_hex(commit->object.sha1)); +} + +static int merge_recursive(const char *base_sha1, + const char *head_sha1, const char *head_name, + const char *next_sha1, const char *next_name) +{ + char buffer[256]; + + sprintf(buffer, "GITHEAD_%s", head_sha1); + setenv(buffer, head_name, 1); + sprintf(buffer, "GITHEAD_%s", next_sha1); + setenv(buffer, next_name, 1); + + /* + * This three way merge is an interesting one. We are at + * $head, and would want to apply the change between $commit + * and $prev on top of us (when reverting), or the change between + * $prev and $commit on top of us (when cherry-picking or replaying). + */ + + return run_command_opt(RUN_COMMAND_NO_STDIN | RUN_GIT_CMD, + "merge-recursive", base_sha1, "--", + head_sha1, next_sha1, NULL); +} + +static int revert_or_cherry_pick(int argc, const char **argv) +{ + unsigned char head[20]; + struct commit *base, *next; + int i; + char *oneline, *encoding, *reencoded_message = NULL; + const char *message; + + git_config(git_default_config); + me = action == REVERT ? "revert" : "cherry-pick"; + setenv(GIT_REFLOG_ACTION, me, 0); + parse_options(argc, argv); + + /* this is copied from the shell script, but it's never triggered... */ + if (action == REVERT && replay) + die("revert is incompatible with replay"); + + if (no_commit) { + /* + * We do not intend to commit immediately. We just want to + * merge the differences in. + */ + if (write_tree(head, 0, NULL)) + die ("Your index file is unmerged."); + } else { + struct wt_status s; + + if (get_sha1("HEAD", head)) + die ("You do not have a valid HEAD"); + wt_status_prepare(&s); + if (s.commitable || s.workdir_dirty) + die ("Dirty index: cannot %s", me); + discard_cache(); + } + + if (!commit->parents) + die ("Cannot %s a root commit", me); + if (commit->parents->next) + die ("Cannot %s a multi-parent commit.", me); + if (!(message = commit->buffer)) + die ("Cannot get commit message for %s", + sha1_to_hex(commit->object.sha1)); + + /* + * "commit" is an existing commit. We would want to apply + * the difference it introduces since its first parent "prev" + * on top of the current HEAD if we are cherry-pick. Or the + * reverse of it if we are revert. + */ + + msg_fd = hold_lock_file_for_update(&msg_file, ".msg", 1); + + encoding = get_encoding(message); + if (!encoding) + encoding = "utf-8"; + if (!git_commit_encoding) + git_commit_encoding = "utf-8"; + if ((reencoded_message = reencode_string(message, + git_commit_encoding, encoding))) + message = reencoded_message; + + oneline = get_oneline(message); + + if (action == REVERT) { + base = commit; + next = commit->parents->item; + add_to_msg("Revert "); + add_to_msg(find_unique_abbrev(commit->object.sha1, + DEFAULT_ABBREV)); + add_to_msg(oneline); + add_to_msg("\nThis reverts commit "); + add_to_msg(sha1_to_hex(commit->object.sha1)); + add_to_msg(".\n"); + } else { + base = commit->parents->item; + next = commit; + set_author_ident_env(message); + add_message_to_msg(message); + if (replay) { + add_to_msg("\n(cherry picked from commit "); + add_to_msg(sha1_to_hex(commit->object.sha1)); + add_to_msg(")\n"); + } + } + if (needed_deref) { + add_to_msg("(original 'git "); + add_to_msg(me); + add_to_msg("' arguments: "); + for (i = 0; i < argc; i++) { + if (i) + add_to_msg(" "); + add_to_msg(argv[i]); + } + add_to_msg(")\n"); + } + + if (merge_recursive(sha1_to_hex(base->object.sha1), + sha1_to_hex(head), "HEAD", + sha1_to_hex(next->object.sha1), oneline)) + exit(1); + if (write_tree(head, 0, NULL)) { + const char *target = git_path("MERGE_MSG"); + add_to_msg("\nConflicts:\n\n"); + read_cache(); + for (i = 0; i < active_nr;) { + struct cache_entry *ce = active_cache[i++]; + if (ce_stage(ce)) { + add_to_msg("\t"); + add_to_msg(ce->name); + add_to_msg("\n"); + while (i < active_nr && !strcmp(ce->name, + active_cache[i]->name)) + i++; + } + } + if (close(msg_fd) || commit_lock_file(&msg_file) < 0) + die ("Error wrapping up .msg"); + unlink(target); + if (rename(".msg", target)) + die ("Could not move .msg to %s", target); + fprintf(stderr, "Automatic %s failed. " + "After resolving the conflicts,\n" + "mark the corrected paths with 'git-add '\n" + "and commit the result.\n", me); + if (action == CHERRY_PICK) { + fprintf(stderr, "You may choose to use the following " + "when making the commit:\n" + "GIT_AUTHOR_NAME=\"%s\"\n", + getenv("GIT_AUTHOR_NAME")); + fprintf(stderr, "GIT_AUTHOR_EMAIL=\"%s\"\n", + getenv("GIT_AUTHOR_EMAIL")); + fprintf(stderr, "GIT_AUTHOR_DATE=\"%s\"\n" + "export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL " + "GIT_AUTHOR_DATE\n", + getenv("GIT_AUTHOR_DATE")); + } + exit(1); + } + if (close(msg_fd) || commit_lock_file(&msg_file) < 0) + die ("Error wrapping up .msg"); + fprintf(stderr, "Finished one %s.\n", me); + + /* + * + * If we are cherry-pick, and if the merge did not result in + * hand-editing, we will hit this commit and inherit the original + * author date and name. + * If we are revert, or if our cherry-pick results in a hand merge, + * we had better say that the current user is responsible for that. + */ + + if (!no_commit) { + if (edit) + return execl_git_cmd("commit", "-n", "-F", ".msg", + "-e", NULL); + else + return execl_git_cmd("commit", "-n", "-F", ".msg", + NULL); + } + if (reencoded_message) + free(reencoded_message); + + return 0; +} + +int cmd_revert(int argc, const char **argv, const char *prefix) +{ + if (isatty(0)) + edit = 1; + action = REVERT; + return revert_or_cherry_pick(argc, argv); +} + +int cmd_cherry_pick(int argc, const char **argv, const char *prefix) +{ + replay = 1; + action = CHERRY_PICK; + return revert_or_cherry_pick(argc, argv); +} diff --git a/builtin.h b/builtin.h index 528074b615..c58d3e3445 100644 --- a/builtin.h +++ b/builtin.h @@ -24,6 +24,7 @@ extern int cmd_cat_file(int argc, const char **argv, const char *prefix); extern int cmd_checkout_index(int argc, const char **argv, const char *prefix); extern int cmd_check_ref_format(int argc, const char **argv, const char *prefix); extern int cmd_cherry(int argc, const char **argv, const char *prefix); +extern int cmd_cherry_pick(int argc, const char **argv, const char *prefix); extern int cmd_commit_tree(int argc, const char **argv, const char *prefix); extern int cmd_count_objects(int argc, const char **argv, const char *prefix); extern int cmd_describe(int argc, const char **argv, const char *prefix); @@ -60,6 +61,7 @@ extern int cmd_config(int argc, const char **argv, const char *prefix); extern int cmd_rerere(int argc, const char **argv, const char *prefix); extern int cmd_rev_list(int argc, const char **argv, const char *prefix); extern int cmd_rev_parse(int argc, const char **argv, const char *prefix); +extern int cmd_revert(int argc, const char **argv, const char *prefix); extern int cmd_rm(int argc, const char **argv, const char *prefix); extern int cmd_runstatus(int argc, const char **argv, const char *prefix); extern int cmd_shortlog(int argc, const char **argv, const char *prefix); diff --git a/git-revert.sh b/git-revert.sh deleted file mode 100755 index 49f00321b2..0000000000 --- a/git-revert.sh +++ /dev/null @@ -1,197 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2005 Linus Torvalds -# Copyright (c) 2005 Junio C Hamano -# - -case "$0" in -*-revert* ) - test -t 0 && edit=-e - replay= - me=revert - USAGE='[--edit | --no-edit] [-n] ' ;; -*-cherry-pick* ) - replay=t - edit= - me=cherry-pick - USAGE='[--edit] [-n] [-r] [-x] ' ;; -* ) - echo >&2 "What are you talking about?" - exit 1 ;; -esac - -SUBDIRECTORY_OK=Yes ;# we will cd up -. git-sh-setup -require_work_tree -cd_to_toplevel - -no_commit= -while case "$#" in 0) break ;; esac -do - case "$1" in - -n|--n|--no|--no-|--no-c|--no-co|--no-com|--no-comm|\ - --no-commi|--no-commit) - no_commit=t - ;; - -e|--e|--ed|--edi|--edit) - edit=-e - ;; - --n|--no|--no-|--no-e|--no-ed|--no-edi|--no-edit) - edit= - ;; - -r) - : no-op ;; - -x|--i-really-want-to-expose-my-private-commit-object-name) - replay= - ;; - -*) - usage - ;; - *) - break - ;; - esac - shift -done - -set_reflog_action "$me" - -test "$me,$replay" = "revert,t" && usage - -case "$no_commit" in -t) - # We do not intend to commit immediately. We just want to - # merge the differences in. - head=$(git-write-tree) || - die "Your index file is unmerged." - ;; -*) - head=$(git-rev-parse --verify HEAD) || - die "You do not have a valid HEAD" - files=$(git-diff-index --cached --name-only $head) || exit - if [ "$files" ]; then - die "Dirty index: cannot $me (dirty: $files)" - fi - ;; -esac - -rev=$(git-rev-parse --verify "$@") && -commit=$(git-rev-parse --verify "$rev^0") || - die "Not a single commit $@" -prev=$(git-rev-parse --verify "$commit^1" 2>/dev/null) || - die "Cannot run $me a root commit" -git-rev-parse --verify "$commit^2" >/dev/null 2>&1 && - die "Cannot run $me a multi-parent commit." - -encoding=$(git config i18n.commitencoding || echo UTF-8) - -# "commit" is an existing commit. We would want to apply -# the difference it introduces since its first parent "prev" -# on top of the current HEAD if we are cherry-pick. Or the -# reverse of it if we are revert. - -case "$me" in -revert) - git show -s --pretty=oneline --encoding="$encoding" $commit | - sed -e ' - s/^[^ ]* /Revert "/ - s/$/"/ - ' - echo - echo "This reverts commit $commit." - test "$rev" = "$commit" || - echo "(original 'git revert' arguments: $@)" - base=$commit next=$prev - ;; - -cherry-pick) - pick_author_script=' - /^author /{ - s/'\''/'\''\\'\'\''/g - h - s/^author \([^<]*\) <[^>]*> .*$/\1/ - s/'\''/'\''\'\'\''/g - s/.*/GIT_AUTHOR_NAME='\''&'\''/p - - g - s/^author [^<]* <\([^>]*\)> .*$/\1/ - s/'\''/'\''\'\'\''/g - s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p - - g - s/^author [^<]* <[^>]*> \(.*\)$/\1/ - s/'\''/'\''\'\'\''/g - s/.*/GIT_AUTHOR_DATE='\''&'\''/p - - q - }' - - logmsg=`git show -s --pretty=raw --encoding="$encoding" "$commit"` - set_author_env=`echo "$logmsg" | - LANG=C LC_ALL=C sed -ne "$pick_author_script"` - eval "$set_author_env" - export GIT_AUTHOR_NAME - export GIT_AUTHOR_EMAIL - export GIT_AUTHOR_DATE - - echo "$logmsg" | - sed -e '1,/^$/d' -e 's/^ //' - case "$replay" in - '') - echo "(cherry picked from commit $commit)" - test "$rev" = "$commit" || - echo "(original 'git cherry-pick' arguments: $@)" - ;; - esac - base=$prev next=$commit - ;; - -esac >.msg - -eval GITHEAD_$head=HEAD -eval GITHEAD_$next='`git show -s \ - --pretty=oneline --encoding="$encoding" "$commit" | - sed -e "s/^[^ ]* //"`' -export GITHEAD_$head GITHEAD_$next - -# This three way merge is an interesting one. We are at -# $head, and would want to apply the change between $commit -# and $prev on top of us (when reverting), or the change between -# $prev and $commit on top of us (when cherry-picking or replaying). - -git-merge-recursive $base -- $head $next && -result=$(git-write-tree 2>/dev/null) || { - mv -f .msg "$GIT_DIR/MERGE_MSG" - { - echo ' -Conflicts: -' - git ls-files --unmerged | - sed -e 's/^[^ ]* / /' | - uniq - } >>"$GIT_DIR/MERGE_MSG" - echo >&2 "Automatic $me failed. After resolving the conflicts," - echo >&2 "mark the corrected paths with 'git-add '" - echo >&2 "and commit the result." - case "$me" in - cherry-pick) - echo >&2 "You may choose to use the following when making" - echo >&2 "the commit:" - echo >&2 "$set_author_env" - esac - exit 1 -} -echo >&2 "Finished one $me." - -# If we are cherry-pick, and if the merge did not result in -# hand-editing, we will hit this commit and inherit the original -# author date and name. -# If we are revert, or if our cherry-pick results in a hand merge, -# we had better say that the current user is responsible for that. - -case "$no_commit" in -'') - git-commit -n -F .msg $edit - rm -f .msg - ;; -esac diff --git a/git.c b/git.c index 04fc99a3dd..fe2b74ab79 100644 --- a/git.c +++ b/git.c @@ -234,6 +234,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp) { "checkout-index", cmd_checkout_index, RUN_SETUP }, { "check-ref-format", cmd_check_ref_format }, { "cherry", cmd_cherry, RUN_SETUP }, + { "cherry-pick", cmd_cherry_pick, RUN_SETUP | NOT_BARE }, { "commit-tree", cmd_commit_tree, RUN_SETUP }, { "config", cmd_config }, { "count-objects", cmd_count_objects, RUN_SETUP }, @@ -272,6 +273,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp) { "rerere", cmd_rerere, RUN_SETUP }, { "rev-list", cmd_rev_list, RUN_SETUP }, { "rev-parse", cmd_rev_parse, RUN_SETUP }, + { "revert", cmd_revert, RUN_SETUP | NOT_BARE }, { "rm", cmd_rm, RUN_SETUP | NOT_BARE }, { "runstatus", cmd_runstatus, RUN_SETUP | NOT_BARE }, { "shortlog", cmd_shortlog, RUN_SETUP | USE_PAGER }, From 5332b2af104180b8135e0b3528ace7596cb9ba09 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 25 Feb 2007 23:36:10 +0100 Subject: [PATCH 07/69] diff: support reading a file from stdin via "-" This allows you to say echo Hello World | git diff x - to compare the contents of file "x" with the line "Hello World". This automatically switches to --no-index mode. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- diff-lib.c | 16 +++++++++++----- diff.c | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/diff-lib.c b/diff-lib.c index 88e59b5794..226f09c72b 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -37,14 +37,20 @@ static int queue_diff(struct diff_options *o, int mode1 = 0, mode2 = 0; if (name1) { - if (stat(name1, &st)) + if (!strcmp(name1, "-")) + mode1 = 0644; + else if (stat(name1, &st)) return error("Could not access '%s'", name1); - mode1 = st.st_mode; + else + mode1 = st.st_mode; } if (name2) { - if (stat(name2, &st)) + if (!strcmp(name2, "-")) + mode2 = 0644; + else if (stat(name2, &st)) return error("Could not access '%s'", name2); - mode2 = st.st_mode; + else + mode2 = st.st_mode; } if (mode1 && mode2 && S_ISDIR(mode1) != S_ISDIR(mode2)) @@ -224,7 +230,7 @@ int setup_diff_no_index(struct rev_info *revs, { int i; for (i = 1; i < argc; i++) - if (argv[i][0] != '-') + if (argv[i][0] != '-' || argv[i][1] == '\0') break; else if (!strcmp(argv[i], "--")) { i++; diff --git a/diff.c b/diff.c index e225de2305..81be6adca3 100644 --- a/diff.c +++ b/diff.c @@ -1389,6 +1389,22 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only) char *buf; unsigned long size; + if (!strcmp(s->path, "-")) { +#define INCREMENT 1024 + int i = INCREMENT; + size = 0; + buf = NULL; + while (i == INCREMENT) { + buf = xrealloc(buf, size + INCREMENT); + i = xread(0, buf + size, INCREMENT); + size += i; + } + s->should_munmap = 0; + s->data = buf; + s->size = size; + s->should_free = 1; + return 0; + } if (lstat(s->path, &st) < 0) { if (errno == ENOENT) { err_empty: @@ -1689,6 +1705,10 @@ static void diff_fill_sha1_info(struct diff_filespec *one) if (DIFF_FILE_VALID(one)) { if (!one->sha1_valid) { struct stat st; + if (!strcmp(one->path, "-")) { + hashcpy(one->sha1, null_sha1); + return; + } if (lstat(one->path, &st) < 0) die("stat %s", one->path); if (index_path(one->sha1, one->path, &st, 0)) From 3afaa72d7d4e52d5fa1bc19abb68301f2b09aca6 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 4 Mar 2007 00:17:27 -0800 Subject: [PATCH 08/69] diff-ni: fix the diff with standard input The earlier commit to read from stdin was full of problems, and this corrects them. - The mode bits should have been set to satisify S_ISREG(); we forgot to the S_IFREG bits and hardcoded 0644; - We did not give escape hatch to name a path whose name is really "-". Allow users to say "./-" for that; - Use of xread() was not prepared to see short read (e.g. reading from tty) nor handing read errors. Signed-off-by: Junio C Hamano --- diff-lib.c | 16 +++++++++++----- diff.c | 45 +++++++++++++++++++++++++++++---------------- 2 files changed, 40 insertions(+), 21 deletions(-) diff --git a/diff-lib.c b/diff-lib.c index 226f09c72b..470ad656a8 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -38,7 +38,7 @@ static int queue_diff(struct diff_options *o, if (name1) { if (!strcmp(name1, "-")) - mode1 = 0644; + mode1 = ntohl(create_ce_mode(0666)); else if (stat(name1, &st)) return error("Could not access '%s'", name1); else @@ -46,7 +46,7 @@ static int queue_diff(struct diff_options *o, } if (name2) { if (!strcmp(name2, "-")) - mode2 = 0644; + mode2 = ntohl(create_ce_mode(0666)); else if (stat(name2, &st)) return error("Could not access '%s'", name2); else @@ -260,9 +260,15 @@ int setup_diff_no_index(struct rev_info *revs, revs->diffopt.paths = xcalloc(2, sizeof(char*)); for (i = 0; i < 2; i++) { - const char *p; - p = prefix_filename(prefix, len, argv[argc - 2 + i]); - revs->diffopt.paths[i] = xstrdup(p); + const char *p = argv[argc - 2 + i]; + /* + * stdin should be spelled as '-'; if you have + * path that is '-', spell it as ./-. + */ + p = (strcmp(p, "-") + ? xstrdup(prefix_filename(prefix, len, p)) + : p); + revs->diffopt.paths[i] = p; } } else diff --git a/diff.c b/diff.c index 81be6adca3..9e276e5848 100644 --- a/diff.c +++ b/diff.c @@ -1364,6 +1364,32 @@ static struct sha1_size_cache *locate_size_cache(unsigned char *sha1, return e; } +static int populate_from_stdin(struct diff_filespec *s) +{ +#define INCREMENT 1024 + char *buf; + unsigned long size; + int got; + + size = 0; + buf = NULL; + while (1) { + buf = xrealloc(buf, size + INCREMENT); + got = xread(0, buf + size, INCREMENT); + if (!got) + break; /* EOF */ + if (got < 0) + return error("error while reading from stdin %s", + strerror(errno)); + size += got; + } + s->should_munmap = 0; + s->data = buf; + s->size = size; + s->should_free = 1; + return 0; +} + /* * While doing rename detection and pickaxe operation, we may need to * grab the data for the blob (or file) for our own in-core comparison. @@ -1389,22 +1415,9 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only) char *buf; unsigned long size; - if (!strcmp(s->path, "-")) { -#define INCREMENT 1024 - int i = INCREMENT; - size = 0; - buf = NULL; - while (i == INCREMENT) { - buf = xrealloc(buf, size + INCREMENT); - i = xread(0, buf + size, INCREMENT); - size += i; - } - s->should_munmap = 0; - s->data = buf; - s->size = size; - s->should_free = 1; - return 0; - } + if (!strcmp(s->path, "-")) + return populate_from_stdin(s); + if (lstat(s->path, &st) < 0) { if (errno == ENOENT) { err_empty: From 0c725f1bd938fa2b626e910773e622a385daced2 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 25 Feb 2007 23:36:31 +0100 Subject: [PATCH 09/69] diff --no-index: support /dev/null as filename This allows us to create "new file" and "delete file" patches. It also cleans up the code. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- diff-lib.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/diff-lib.c b/diff-lib.c index 470ad656a8..5e6bca5906 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -30,28 +30,28 @@ static int read_directory(const char *path, struct path_list *list) return 0; } +static int get_mode(const char *path, int *mode) +{ + struct stat st; + + if (!path || !strcmp(path, "/dev/null")) + *mode = 0; + else if (!strcmp(path, "-")) + *mode = ntohl(create_ce_mode(0666)); + else if (stat(path, &st)) + return error("Could not access '%s'", path); + else + *mode = st.st_mode; + return 0; +} + static int queue_diff(struct diff_options *o, const char *name1, const char *name2) { - struct stat st; int mode1 = 0, mode2 = 0; - if (name1) { - if (!strcmp(name1, "-")) - mode1 = ntohl(create_ce_mode(0666)); - else if (stat(name1, &st)) - return error("Could not access '%s'", name1); - else - mode1 = st.st_mode; - } - if (name2) { - if (!strcmp(name2, "-")) - mode2 = ntohl(create_ce_mode(0666)); - else if (stat(name2, &st)) - return error("Could not access '%s'", name2); - else - mode2 = st.st_mode; - } + if (get_mode(name1, &mode1) || get_mode(name2, &mode2)) + return -1; if (mode1 && mode2 && S_ISDIR(mode1) != S_ISDIR(mode2)) return error("file/directory conflict: %s, %s", name1, name2); From 5bd74506cd30e897d1493639b7438c6cc80dea8e Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 25 Feb 2007 23:36:53 +0100 Subject: [PATCH 10/69] Get rid of the dependency to GNU diff in the tests Now that "git diff" handles stdin and relative paths outside the working tree correctly, we can convert all instances of "diff -u" to "git diff". This commit is really the result of $ perl -pi.bak -e 's/diff -u/git diff/' $(git grep -l "diff -u" t/) Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano (cherry picked from commit c699a40d68215c7e44a5b26117a35c8a56fbd387) --- t/diff-lib.sh | 6 +++--- t/t1000-read-tree-m-3way.sh | 2 +- t/t1001-read-tree-m-2way.sh | 26 +++++++++++++------------- t/t1002-read-tree-m-u-2way.sh | 2 +- t/t1300-repo-config.sh | 6 +++--- t/t3001-ls-files-others-exclude.sh | 4 ++-- t/t3002-ls-files-dashpath.sh | 10 +++++----- t/t3100-ls-tree-restrict.sh | 2 +- t/t3101-ls-tree-dirname.sh | 2 +- t/t3300-funny-names.sh | 30 +++++++++++++++--------------- t/t3900-i18n-commit.sh | 2 +- t/t4006-diff-mode.sh | 2 +- t/t4013-diff-various.sh | 2 +- t/t4015-diff-whitespace.sh | 12 ++++++------ t/t4016-diff-quote.sh | 4 ++-- t/t4100-apply-stat.sh | 14 +++++++------- t/t4104-apply-boundary.sh | 4 ++-- t/t4115-apply-symlink.sh | 4 ++-- t/t4116-apply-reverse.sh | 2 +- t/t4117-apply-reject.sh | 12 ++++++------ t/t4118-apply-empty-context.sh | 6 +++--- t/t4200-rerere.sh | 6 +++--- t/t5400-send-pack.sh | 2 +- t/t5401-update-hooks.sh | 4 ++-- t/t6023-merge-file.sh | 8 ++++---- t/t6024-recursive-merge.sh | 4 ++-- t/t6200-fmt-merge-msg.sh | 10 +++++----- t/t9100-git-svn-basic.sh | 6 +++--- t/t9300-fast-import.sh | 26 +++++++++++++------------- 29 files changed, 110 insertions(+), 110 deletions(-) diff --git a/t/diff-lib.sh b/t/diff-lib.sh index 745a1b0311..4624fe654c 100755 --- a/t/diff-lib.sh +++ b/t/diff-lib.sh @@ -11,7 +11,7 @@ compare_diff_raw () { sed -e "$sanitize_diff_raw" <"$1" >.tmp-1 sed -e "$sanitize_diff_raw" <"$2" >.tmp-2 - diff -u .tmp-1 .tmp-2 && rm -f .tmp-1 .tmp-2 + git diff .tmp-1 .tmp-2 && rm -f .tmp-1 .tmp-2 } sanitize_diff_raw_z='/^:/s/ '"$_x40"' '"$_x40"' \([A-Z]\)[0-9]*$/ X X \1#/' @@ -23,7 +23,7 @@ compare_diff_raw_z () { tr '\0' '\012' <"$1" | sed -e "$sanitize_diff_raw_z" >.tmp-1 tr '\0' '\012' <"$2" | sed -e "$sanitize_diff_raw_z" >.tmp-2 - diff -u .tmp-1 .tmp-2 && rm -f .tmp-1 .tmp-2 + git diff .tmp-1 .tmp-2 && rm -f .tmp-1 .tmp-2 } compare_diff_patch () { @@ -37,5 +37,5 @@ compare_diff_patch () { /^[dis]*imilarity index [0-9]*%$/d /^index [0-9a-f]*\.\.[0-9a-f]/d ' <"$2" >.tmp-2 - diff -u .tmp-1 .tmp-2 && rm -f .tmp-1 .tmp-2 + git diff .tmp-1 .tmp-2 && rm -f .tmp-1 .tmp-2 } diff --git a/t/t1000-read-tree-m-3way.sh b/t/t1000-read-tree-m-3way.sh index d0af8c3d52..e26a36cf0f 100755 --- a/t/t1000-read-tree-m-3way.sh +++ b/t/t1000-read-tree-m-3way.sh @@ -131,7 +131,7 @@ _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40" check_result () { git-ls-files --stage | sed -e 's/ '"$_x40"' / X /' >current && - diff -u expected current + git diff expected current } # This is done on an empty work directory, which is the normal diff --git a/t/t1001-read-tree-m-2way.sh b/t/t1001-read-tree-m-2way.sh index 75e4c9a886..030226bbfb 100755 --- a/t/t1001-read-tree-m-2way.sh +++ b/t/t1001-read-tree-m-2way.sh @@ -33,7 +33,7 @@ compare_change () { -e '/^--- /d; /^+++ /d; /^@@ /d;' \ -e 's/^\([-+][0-7][0-7][0-7][0-7][0-7][0-7]\) '"$_x40"' /\1 X /p' \ "$1" - diff -u expected current + git diff expected current } check_cache_at () { @@ -86,7 +86,7 @@ test_expect_success \ 'rm -f .git/index && read_tree_twoway $treeH $treeM && git-ls-files --stage >1-3.out && - diff -u M.out 1-3.out && + git diff M.out 1-3.out && check_cache_at bozbar dirty && check_cache_at frotz dirty && check_cache_at nitfol dirty' @@ -101,7 +101,7 @@ test_expect_success \ git-update-index --add yomin && read_tree_twoway $treeH $treeM && git-ls-files --stage >4.out || return 1 - diff -u M.out 4.out >4diff.out + git diff M.out 4.out >4diff.out compare_change 4diff.out expected && check_cache_at yomin clean' @@ -115,7 +115,7 @@ test_expect_success \ echo yomin yomin >yomin && read_tree_twoway $treeH $treeM && git-ls-files --stage >5.out || return 1 - diff -u M.out 5.out >5diff.out + git diff M.out 5.out >5diff.out compare_change 5diff.out expected && check_cache_at yomin dirty' @@ -127,7 +127,7 @@ test_expect_success \ git-update-index --add frotz && read_tree_twoway $treeH $treeM && git-ls-files --stage >6.out && - diff -u M.out 6.out && + git diff M.out 6.out && check_cache_at frotz clean' test_expect_success \ @@ -140,7 +140,7 @@ test_expect_success \ echo frotz frotz >frotz && read_tree_twoway $treeH $treeM && git-ls-files --stage >7.out && - diff -u M.out 7.out && + git diff M.out 7.out && check_cache_at frotz dirty' test_expect_success \ @@ -171,7 +171,7 @@ test_expect_success \ git-update-index --add rezrov && read_tree_twoway $treeH $treeM && git-ls-files --stage >10.out && - diff -u M.out 10.out' + git diff M.out 10.out' test_expect_success \ '11 - dirty path removed.' \ @@ -216,7 +216,7 @@ test_expect_success \ git-update-index --add nitfol && read_tree_twoway $treeH $treeM && git-ls-files --stage >14.out || return 1 - diff -u M.out 14.out >14diff.out + git diff M.out 14.out >14diff.out compare_change 14diff.out expected && check_cache_at nitfol clean' @@ -230,7 +230,7 @@ test_expect_success \ echo nitfol nitfol nitfol >nitfol && read_tree_twoway $treeH $treeM && git-ls-files --stage >15.out || return 1 - diff -u M.out 15.out >15diff.out + git diff M.out 15.out >15diff.out compare_change 15diff.out expected && check_cache_at nitfol dirty' @@ -262,7 +262,7 @@ test_expect_success \ git-update-index --add bozbar && read_tree_twoway $treeH $treeM && git-ls-files --stage >18.out && - diff -u M.out 18.out && + git diff M.out 18.out && check_cache_at bozbar clean' test_expect_success \ @@ -275,7 +275,7 @@ test_expect_success \ echo gnusto gnusto >bozbar && read_tree_twoway $treeH $treeM && git-ls-files --stage >19.out && - diff -u M.out 19.out && + git diff M.out 19.out && check_cache_at bozbar dirty' test_expect_success \ @@ -287,7 +287,7 @@ test_expect_success \ git-update-index --add bozbar && read_tree_twoway $treeH $treeM && git-ls-files --stage >20.out && - diff -u M.out 20.out && + git diff M.out 20.out && check_cache_at bozbar dirty' test_expect_success \ @@ -337,7 +337,7 @@ test_expect_success \ git-update-index --add DF && read_tree_twoway $treeDF $treeDFDF && git-ls-files --stage >DFDFcheck.out && - diff -u DFDF.out DFDFcheck.out && + git diff DFDF.out DFDFcheck.out && check_cache_at DF/DF dirty && :' diff --git a/t/t1002-read-tree-m-u-2way.sh b/t/t1002-read-tree-m-u-2way.sh index da3c81357b..87fe993f59 100755 --- a/t/t1002-read-tree-m-u-2way.sh +++ b/t/t1002-read-tree-m-u-2way.sh @@ -16,7 +16,7 @@ compare_change () { sed >current \ -e '/^--- /d; /^+++ /d; /^@@ /d;' \ -e 's/^\(.[0-7][0-7][0-7][0-7][0-7][0-7]\) '"$_x40"' /\1 X /' "$1" - diff -u expected current + git diff expected current } check_cache_at () { diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh index 49b5666b33..84a59397b2 100755 --- a/t/t1300-repo-config.sh +++ b/t/t1300-repo-config.sh @@ -368,12 +368,12 @@ cat > expect << EOF weird EOF -test_expect_success "rename succeeded" "diff -u expect .git/config" +test_expect_success "rename succeeded" "git diff expect .git/config" test_expect_failure "rename non-existing section" \ 'git-config --rename-section branch."world domination" branch.drei' -test_expect_success "rename succeeded" "diff -u expect .git/config" +test_expect_success "rename succeeded" "git diff expect .git/config" test_expect_success "rename another section" \ 'git-config --rename-section branch."1 234 blabl/a" branch.drei' @@ -389,7 +389,7 @@ cat > expect << EOF weird EOF -test_expect_success "rename succeeded" "diff -u expect .git/config" +test_expect_success "rename succeeded" "git diff expect .git/config" test_expect_success numbers ' diff --git a/t/t3001-ls-files-others-exclude.sh b/t/t3001-ls-files-others-exclude.sh index 6979b7c1c0..db7a847a5d 100755 --- a/t/t3001-ls-files-others-exclude.sh +++ b/t/t3001-ls-files-others-exclude.sh @@ -65,7 +65,7 @@ test_expect_success \ --exclude-per-directory=.gitignore \ --exclude-from=.git/ignore \ >output && - diff -u expect output' + git diff expect output' # Test \r\n (MSDOS-like systems) printf '*.1\r\n/*.3\r\n!*.6\r\n' >.gitignore @@ -77,6 +77,6 @@ test_expect_success \ --exclude-per-directory=.gitignore \ --exclude-from=.git/ignore \ >output && - diff -u expect output' + git diff expect output' test_done diff --git a/t/t3002-ls-files-dashpath.sh b/t/t3002-ls-files-dashpath.sh index b42f1382bc..cc8967d76b 100755 --- a/t/t3002-ls-files-dashpath.sh +++ b/t/t3002-ls-files-dashpath.sh @@ -23,7 +23,7 @@ test_expect_success \ test_expect_success \ 'git-ls-files without path restriction.' \ 'git-ls-files --others >output && - diff -u output - <output && - diff -u output - <output && - diff -u output - <output && - diff -u output - <output && - diff -u output - <check - diff -u expected check + git diff expected check } test_expect_success \ diff --git a/t/t3101-ls-tree-dirname.sh b/t/t3101-ls-tree-dirname.sh index d78deb1e71..087929a4bf 100755 --- a/t/t3101-ls-tree-dirname.sh +++ b/t/t3101-ls-tree-dirname.sh @@ -43,7 +43,7 @@ _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]' _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40" test_output () { sed -e "s/ $_x40 / X /" check - diff -u expected check + git diff expected check } test_expect_success \ diff --git a/t/t3300-funny-names.sh b/t/t3300-funny-names.sh index c12270efab..b5a1400e18 100755 --- a/t/t3300-funny-names.sh +++ b/t/t3300-funny-names.sh @@ -35,7 +35,7 @@ no-funny' >expected test_expect_success 'git-ls-files no-funny' \ 'git-update-index --add "$p0" "$p2" && git-ls-files >current && - diff -u expected current' + git diff expected current' t0=`git-write-tree` echo "$t0" >t0 @@ -48,14 +48,14 @@ EOF test_expect_success 'git-ls-files with-funny' \ 'git-update-index --add "$p1" && git-ls-files >current && - diff -u expected current' + git diff expected current' echo 'just space no-funny tabs ," (dq) and spaces' >expected test_expect_success 'git-ls-files -z with-funny' \ 'git-ls-files -z | tr \\0 \\012 >current && - diff -u expected current' + git diff expected current' t1=`git-write-tree` echo "$t1" >t1 @@ -67,28 +67,28 @@ no-funny EOF test_expect_success 'git-ls-tree with funny' \ 'git-ls-tree -r $t1 | sed -e "s/^[^ ]* //" >current && - diff -u expected current' + git diff expected current' cat > expected <<\EOF A "tabs\t,\" (dq) and spaces" EOF test_expect_success 'git-diff-index with-funny' \ 'git-diff-index --name-status $t0 >current && - diff -u expected current' + git diff expected current' test_expect_success 'git-diff-tree with-funny' \ 'git-diff-tree --name-status $t0 $t1 >current && - diff -u expected current' + git diff expected current' echo 'A tabs ," (dq) and spaces' >expected test_expect_success 'git-diff-index -z with-funny' \ 'git-diff-index -z --name-status $t0 | tr \\0 \\012 >current && - diff -u expected current' + git diff expected current' test_expect_success 'git-diff-tree -z with-funny' \ 'git-diff-tree -z --name-status $t0 $t1 | tr \\0 \\012 >current && - diff -u expected current' + git diff expected current' cat > expected <<\EOF CNUM no-funny "tabs\t,\" (dq) and spaces" @@ -96,7 +96,7 @@ EOF test_expect_success 'git-diff-tree -C with-funny' \ 'git-diff-tree -C --find-copies-harder --name-status \ $t0 $t1 | sed -e 's/^C[0-9]*/CNUM/' >current && - diff -u expected current' + git diff expected current' cat > expected <<\EOF RNUM no-funny "tabs\t,\" (dq) and spaces" @@ -105,7 +105,7 @@ test_expect_success 'git-diff-tree delete with-funny' \ 'git-update-index --force-remove "$p0" && git-diff-index -M --name-status \ $t0 | sed -e 's/^R[0-9]*/RNUM/' >current && - diff -u expected current' + git diff expected current' cat > expected <<\EOF diff --git a/no-funny "b/tabs\t,\" (dq) and spaces" @@ -116,7 +116,7 @@ EOF test_expect_success 'git-diff-tree delete with-funny' \ 'git-diff-index -M -p $t0 | sed -e "s/index [0-9]*%/index NUM%/" >current && - diff -u expected current' + git diff expected current' chmod +x "$p1" cat > expected <<\EOF @@ -130,7 +130,7 @@ EOF test_expect_success 'git-diff-tree delete with-funny' \ 'git-diff-index -M -p $t0 | sed -e "s/index [0-9]*%/index NUM%/" >current && - diff -u expected current' + git diff expected current' cat >expected <<\EOF "tabs\t,\" (dq) and spaces" @@ -139,7 +139,7 @@ EOF test_expect_success 'git-diff-tree rename with-funny applied' \ 'git-diff-index -M -p $t0 | git-apply --stat | sed -e "s/|.*//" -e "s/ *\$//" >current && - diff -u expected current' + git diff expected current' cat > expected <<\EOF no-funny @@ -149,12 +149,12 @@ EOF test_expect_success 'git-diff-tree delete with-funny applied' \ 'git-diff-index -p $t0 | git-apply --stat | sed -e "s/|.*//" -e "s/ *\$//" >current && - diff -u expected current' + git diff expected current' test_expect_success 'git-apply non-git diff' \ 'git-diff-index -p $t0 | sed -ne "/^[-+@]/p" | git-apply --stat | sed -e "s/|.*//" -e "s/ *\$//" >current && - diff -u expected current' + git diff expected current' test_done diff --git a/t/t3900-i18n-commit.sh b/t/t3900-i18n-commit.sh index e54fe0f401..ffddb68db3 100755 --- a/t/t3900-i18n-commit.sh +++ b/t/t3900-i18n-commit.sh @@ -9,7 +9,7 @@ test_description='commit and log output encodings' compare_with () { git-show -s $1 | sed -e '1,/^$/d' -e 's/^ //' -e '$d' >current && - diff -u current "$2" + git diff current "$2" } test_expect_success setup ' diff --git a/t/t4006-diff-mode.sh b/t/t4006-diff-mode.sh index ca342f48a1..e72c6fd1b4 100755 --- a/t/t4006-diff-mode.sh +++ b/t/t4006-diff-mode.sh @@ -38,7 +38,7 @@ echo ":100644 100755 X X M rezrov" >expected test_expect_success \ 'verify' \ - 'diff -u expected check' + 'git diff expected check' test_done diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh index 3d85ceaae9..9f54af5a1b 100755 --- a/t/t4013-diff-various.sh +++ b/t/t4013-diff-various.sh @@ -111,7 +111,7 @@ do } >"$actual" && if test -f "$expect" then - diff -u "$expect" "$actual" && + git diff "$expect" "$actual" && rm -f "$actual" else # this is to help developing new tests. diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh index adf4993bac..930e209d31 100755 --- a/t/t4015-diff-whitespace.sh +++ b/t/t4015-diff-whitespace.sh @@ -43,13 +43,13 @@ index adf3937..6edc172 100644 EOF git-diff > out -test_expect_success "Ray's example without options" 'diff -u expect out' +test_expect_success "Ray's example without options" 'git diff expect out' git-diff -w > out -test_expect_success "Ray's example with -w" 'diff -u expect out' +test_expect_success "Ray's example with -w" 'git diff expect out' git-diff -b > out -test_expect_success "Ray's example with -b" 'diff -u expect out' +test_expect_success "Ray's example with -b" 'git diff expect out' tr 'Q' '\015' << EOF > x whitespace at beginning @@ -90,14 +90,14 @@ index d99af23..8b32fb5 100644 +CR at end EOF git-diff > out -test_expect_success 'another test, without options' 'diff -u expect out' +test_expect_success 'another test, without options' 'git diff expect out' cat << EOF > expect diff --git a/x b/x index d99af23..8b32fb5 100644 EOF git-diff -w > out -test_expect_success 'another test, with -w' 'diff -u expect out' +test_expect_success 'another test, with -w' 'git diff expect out' tr 'Q' '\015' << EOF > expect diff --git a/x b/x @@ -115,6 +115,6 @@ index d99af23..8b32fb5 100644 CR at endQ EOF git-diff -b > out -test_expect_success 'another test, with -b' 'diff -u expect out' +test_expect_success 'another test, with -b' 'git diff expect out' test_done diff --git a/t/t4016-diff-quote.sh b/t/t4016-diff-quote.sh index 2e7cd5f255..5dbdc0c9fa 100755 --- a/t/t4016-diff-quote.sh +++ b/t/t4016-diff-quote.sh @@ -49,7 +49,7 @@ cat >expect <<\EOF EOF test_expect_success 'git diff --summary -M HEAD' ' git diff --summary -M HEAD >actual && - diff -u expect actual + git diff expect actual ' cat >expect <<\EOF @@ -64,7 +64,7 @@ cat >expect <<\EOF EOF test_expect_success 'git diff --stat -M HEAD' ' git diff --stat -M HEAD >actual && - diff -u expect actual + git diff expect actual ' test_done diff --git a/t/t4100-apply-stat.sh b/t/t4100-apply-stat.sh index 6579f06b05..7b81c32e57 100755 --- a/t/t4100-apply-stat.sh +++ b/t/t4100-apply-stat.sh @@ -11,37 +11,37 @@ test_description='git-apply --stat --summary test. test_expect_success \ 'rename' \ 'git-apply --stat --summary <../t4100/t-apply-1.patch >current && - diff -u ../t4100/t-apply-1.expect current' + git diff ../t4100/t-apply-1.expect current' test_expect_success \ 'copy' \ 'git-apply --stat --summary <../t4100/t-apply-2.patch >current && - diff -u ../t4100/t-apply-2.expect current' + git diff ../t4100/t-apply-2.expect current' test_expect_success \ 'rewrite' \ 'git-apply --stat --summary <../t4100/t-apply-3.patch >current && - diff -u ../t4100/t-apply-3.expect current' + git diff ../t4100/t-apply-3.expect current' test_expect_success \ 'mode' \ 'git-apply --stat --summary <../t4100/t-apply-4.patch >current && - diff -u ../t4100/t-apply-4.expect current' + git diff ../t4100/t-apply-4.expect current' test_expect_success \ 'non git' \ 'git-apply --stat --summary <../t4100/t-apply-5.patch >current && - diff -u ../t4100/t-apply-5.expect current' + git diff ../t4100/t-apply-5.expect current' test_expect_success \ 'non git' \ 'git-apply --stat --summary <../t4100/t-apply-6.patch >current && - diff -u ../t4100/t-apply-6.expect current' + git diff ../t4100/t-apply-6.expect current' test_expect_success \ 'non git' \ 'git-apply --stat --summary <../t4100/t-apply-7.patch >current && - diff -u ../t4100/t-apply-7.expect current' + git diff ../t4100/t-apply-7.expect current' test_done diff --git a/t/t4104-apply-boundary.sh b/t/t4104-apply-boundary.sh index 2ff800c23f..a5fb3ea40e 100755 --- a/t/t4104-apply-boundary.sh +++ b/t/t4104-apply-boundary.sh @@ -90,7 +90,7 @@ do cat '"$kind-patch.$with"' (exit 1) } && - diff -u '"$kind"'-expect victim + git diff '"$kind"'-expect victim ' done done @@ -108,7 +108,7 @@ do cat '"$kind-ng.without"' (exit 1) } && - diff -u '"$kind"'-expect victim + git diff '"$kind"'-expect victim ' done diff --git a/t/t4115-apply-symlink.sh b/t/t4115-apply-symlink.sh index d5f2cfb186..b947ed83bb 100755 --- a/t/t4115-apply-symlink.sh +++ b/t/t4115-apply-symlink.sh @@ -33,7 +33,7 @@ test_expect_success 'apply symlink patch' ' git checkout side && git apply patch && git diff-files -p >patched && - diff -u patch patched + git diff patch patched ' @@ -42,7 +42,7 @@ test_expect_success 'apply --index symlink patch' ' git checkout -f side && git apply --index patch && git diff-index --cached -p HEAD >patched && - diff -u patch patched + git diff patch patched ' diff --git a/t/t4116-apply-reverse.sh b/t/t4116-apply-reverse.sh index aa2c869e0e..2685b22630 100755 --- a/t/t4116-apply-reverse.sh +++ b/t/t4116-apply-reverse.sh @@ -42,7 +42,7 @@ test_expect_success 'apply in reverse' ' git reset --hard second && git apply --reverse --binary --index patch && git diff >diff && - diff -u /dev/null diff + git diff /dev/null diff ' diff --git a/t/t4117-apply-reject.sh b/t/t4117-apply-reject.sh index b4de075a3e..91931f0e3f 100755 --- a/t/t4117-apply-reject.sh +++ b/t/t4117-apply-reject.sh @@ -54,7 +54,7 @@ test_expect_success 'apply without --reject should fail' ' exit 1 fi - diff -u file1 saved.file1 + git diff file1 saved.file1 ' test_expect_success 'apply without --reject should fail' ' @@ -65,7 +65,7 @@ test_expect_success 'apply without --reject should fail' ' exit 1 fi - diff -u file1 saved.file1 + git diff file1 saved.file1 ' test_expect_success 'apply with --reject should fail but update the file' ' @@ -79,7 +79,7 @@ test_expect_success 'apply with --reject should fail but update the file' ' exit 1 fi - diff -u file1 expected && + git diff file1 expected && cat file1.rej && @@ -105,7 +105,7 @@ test_expect_success 'apply with --reject should fail but update the file' ' echo "file1 still exists?" exit 1 } - diff -u file2 expected && + git diff file2 expected && cat file2.rej && @@ -132,7 +132,7 @@ test_expect_success 'the same test with --verbose' ' echo "file1 still exists?" exit 1 } - diff -u file2 expected && + git diff file2 expected && cat file2.rej && @@ -151,7 +151,7 @@ test_expect_success 'apply cleanly with --verbose' ' git apply --verbose patch.1 && - diff -u file1 clean + git diff file1 clean ' test_done diff --git a/t/t4118-apply-empty-context.sh b/t/t4118-apply-empty-context.sh index 7309422fe5..690a182003 100755 --- a/t/t4118-apply-empty-context.sh +++ b/t/t4118-apply-empty-context.sh @@ -37,7 +37,7 @@ test_expect_success 'apply --numstat' ' echo "0 1 file1" && echo "0 1 file2" } >expect && - diff -u expect actual + git diff expect actual ' @@ -47,8 +47,8 @@ test_expect_success 'apply --apply' ' cat file2.orig >file2 && git update-index file1 file2 && git apply --index diff.output && - diff -u file1.mods file1 && - diff -u file2.mods file2 + git diff file1.mods file1 && + git diff file2.mods file2 ' test_done diff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh index 639d45fcec..e081b32aff 100755 --- a/t/t4200-rerere.sh +++ b/t/t4200-rerere.sh @@ -70,7 +70,7 @@ EOF git rerere diff > out -test_expect_success 'rerere diff' 'diff -u expect out' +test_expect_success 'rerere diff' 'git diff expect out' cat > expect << EOF a1 @@ -78,7 +78,7 @@ EOF git rerere status > out -test_expect_success 'rerere status' 'diff -u expect out' +test_expect_success 'rerere status' 'git diff expect out' test_expect_success 'commit succeeds' \ "git commit -q -a -m 'prefer first over second'" @@ -94,7 +94,7 @@ test_expect_failure 'another conflicting merge' 'git pull . first' git show first:a1 | sed 's/To die: t/To die! T/' > expect test_expect_success 'rerere kicked in' "! grep ======= a1" -test_expect_success 'rerere prefers first change' 'diff -u a1 expect' +test_expect_success 'rerere prefers first change' 'git diff a1 expect' rm $rr/postimage echo "$sha1 a1" | tr '\012' '\0' > .git/rr-cache/MERGE_RR diff --git a/t/t5400-send-pack.sh b/t/t5400-send-pack.sh index 7d93d0d7c9..fc4a126407 100755 --- a/t/t5400-send-pack.sh +++ b/t/t5400-send-pack.sh @@ -110,7 +110,7 @@ test_expect_success \ cd .. && git-update-ref refs/heads/master master^ && git-send-pack --force ./victim/.git/ master && - ! diff -u .git/refs/heads/master victim/.git/refs/heads/master + ! git diff .git/refs/heads/master victim/.git/refs/heads/master ' test_done diff --git a/t/t5401-update-hooks.sh b/t/t5401-update-hooks.sh index 0514056ca6..460c9fd7fe 100755 --- a/t/t5401-update-hooks.sh +++ b/t/t5401-update-hooks.sh @@ -51,12 +51,12 @@ test_expect_success 'hooks ran' ' test_expect_success 'update hook arguments' ' echo refs/heads/master $commit0 $commit1 | - diff -u - victim/.git/update.args + git diff - victim/.git/update.args ' test_expect_success 'post-update hook arguments' ' echo refs/heads/master | - diff -u - victim/.git/post-update.args + git diff - victim/.git/post-update.args ' test_expect_failure 'update hook stdin is /dev/null' ' diff --git a/t/t6023-merge-file.sh b/t/t6023-merge-file.sh index f3cd3dba4d..c76fccfb5a 100644 --- a/t/t6023-merge-file.sh +++ b/t/t6023-merge-file.sh @@ -63,7 +63,7 @@ test_expect_success "merge without conflict (missing LF at EOF)" \ "git-merge-file test2.txt orig.txt new2.txt" test_expect_success "merge result added missing LF" \ - "diff -u test.txt test2.txt" + "git diff test.txt test2.txt" cp test.txt backup.txt test_expect_failure "merge with conflicts" \ @@ -86,7 +86,7 @@ non timebo mala, quoniam tu mecum es: virga tua et baculus tuus ipsa me consolata sunt. EOF -test_expect_success "expected conflict markers" "diff -u test.txt expect.txt" +test_expect_success "expected conflict markers" "git diff test.txt expect.txt" cp backup.txt test.txt test_expect_failure "merge with conflicts, using -L" \ @@ -110,7 +110,7 @@ virga tua et baculus tuus ipsa me consolata sunt. EOF test_expect_success "expected conflict markers, with -L" \ - "diff -u test.txt expect.txt" + "git diff test.txt expect.txt" sed "s/ tu / TU /" < new1.txt > new5.txt test_expect_failure "conflict in removed tail" \ @@ -132,7 +132,7 @@ virga tua et baculus tuus ipsa me consolata sunt. >>>>>>> new5.txt EOF -test_expect_success "expected conflict markers" "diff -u expect out" +test_expect_success "expected conflict markers" "git diff expect out" test_done diff --git a/t/t6024-recursive-merge.sh b/t/t6024-recursive-merge.sh index 31b96257b4..a398556137 100644 --- a/t/t6024-recursive-merge.sh +++ b/t/t6024-recursive-merge.sh @@ -70,7 +70,7 @@ G >>>>>>> G:a1 EOF -test_expect_success "result contains a conflict" "diff -u expect a1" +test_expect_success "result contains a conflict" "git diff expect a1" git ls-files --stage > out cat > expect << EOF @@ -79,6 +79,6 @@ cat > expect << EOF 100644 fd7923529855d0b274795ae3349c5e0438333979 3 a1 EOF -test_expect_success "virtual trees were processed" "diff -u expect out" +test_expect_success "virtual trees were processed" "git diff expect out" test_done diff --git a/t/t6200-fmt-merge-msg.sh b/t/t6200-fmt-merge-msg.sh index ea14023616..526d7d1c44 100755 --- a/t/t6200-fmt-merge-msg.sh +++ b/t/t6200-fmt-merge-msg.sh @@ -79,7 +79,7 @@ test_expect_success 'merge-msg test #1' ' git fetch . left && git fmt-merge-msg <.git/FETCH_HEAD >actual && - diff -u actual expected + git diff actual expected ' cat >expected <<\EOF @@ -92,7 +92,7 @@ test_expect_success 'merge-msg test #2' ' git fetch ../trash left && git fmt-merge-msg <.git/FETCH_HEAD >actual && - diff -u actual expected + git diff actual expected ' cat >expected <<\EOF @@ -115,7 +115,7 @@ test_expect_success 'merge-msg test #3' ' git fetch . left && git fmt-merge-msg <.git/FETCH_HEAD >actual && - diff -u actual expected + git diff actual expected ' cat >expected <<\EOF @@ -145,7 +145,7 @@ test_expect_success 'merge-msg test #4' ' git fetch . left right && git fmt-merge-msg <.git/FETCH_HEAD >actual && - diff -u actual expected + git diff actual expected ' test_expect_success 'merge-msg test #5' ' @@ -157,7 +157,7 @@ test_expect_success 'merge-msg test #5' ' git fetch . left right && git fmt-merge-msg <.git/FETCH_HEAD >actual && - diff -u actual expected + git diff actual expected ' test_done diff --git a/t/t9100-git-svn-basic.sh b/t/t9100-git-svn-basic.sh index 7dcfc7e7db..eb628fe075 100755 --- a/t/t9100-git-svn-basic.sh +++ b/t/t9100-git-svn-basic.sh @@ -169,7 +169,7 @@ test_expect_success "$name" " svn up '$SVN_TREE' && test -f '$SVN_TREE'/exec-2.sh && test ! -L '$SVN_TREE'/exec-2.sh && - diff -u help $SVN_TREE/exec-2.sh" + git diff help $SVN_TREE/exec-2.sh" if test "$have_utf8" = t then @@ -193,7 +193,7 @@ test_expect_success "$name" \ "git-svn init $svnrepo && git-svn fetch && git-rev-list --pretty=raw remotes/git-svn | grep ^tree | uniq > a && git-rev-list --pretty=raw remotes/alt | grep ^tree | uniq > b && - diff -u a b" + git diff a b" name='check imported tree checksums expected tree checksums' rm -f expected @@ -211,7 +211,7 @@ tree d667270a1f7b109f5eb3aaea21ede14b56bfdd6e tree 8f51f74cf0163afc9ad68a4b1537288c4558b5a4 EOF -test_expect_success "$name" "diff -u a expected" +test_expect_success "$name" "git diff a expected" test_expect_failure 'exit if remote refs are ambigious' " git-config --add svn-remote.svn.fetch \ diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh index 970d683650..2337d83d35 100755 --- a/t/t9300-fast-import.sh +++ b/t/t9300-fast-import.sh @@ -74,7 +74,7 @@ EOF test_expect_success \ 'A: verify commit' \ 'git-cat-file commit master | sed 1d >actual && - diff -u expect actual' + git diff expect actual' cat >expect <actual && - diff -u expect actual' + git diff expect actual' echo "$file2_data" >expect test_expect_success \ 'A: verify file2' \ - 'git-cat-file blob master:file2 >actual && diff -u expect actual' + 'git-cat-file blob master:file2 >actual && git diff expect actual' echo "$file3_data" >expect test_expect_success \ 'A: verify file3' \ - 'git-cat-file blob master:file3 >actual && diff -u expect actual' + 'git-cat-file blob master:file3 >actual && git diff expect actual' printf "$file4_data" >expect test_expect_success \ 'A: verify file4' \ - 'git-cat-file blob master:file4 >actual && diff -u expect actual' + 'git-cat-file blob master:file4 >actual && git diff expect actual' cat >expect <expect <actual && - diff -u expect actual' + git diff expect actual' cat >expect <expect test_expect_success \ 'D: verify file5' \ 'git-cat-file blob branch:newdir/interesting >actual && - diff -u expect actual' + git diff expect actual' echo "$file6_data" >expect test_expect_success \ 'D: verify file6' \ 'git-cat-file blob branch:newdir/exec.sh >actual && - diff -u expect actual' + git diff expect actual' ### ### series E @@ -274,7 +274,7 @@ EOF test_expect_success \ 'E: verify commit' \ 'git-cat-file commit branch | sed 1,2d >actual && - diff -u expect actual' + git diff expect actual' ### ### series F @@ -327,7 +327,7 @@ EOF test_expect_success \ 'F: verify other commit' \ 'git-cat-file commit other >actual && - diff -u expect actual' + git diff expect actual' ### ### series G @@ -405,7 +405,7 @@ echo "$file5_data" >expect test_expect_success \ 'H: verify file' \ 'git-cat-file blob H:h/e/l/lo >actual && - diff -u expect actual' + git diff expect actual' ### ### series I @@ -431,7 +431,7 @@ EOF test_expect_success \ 'I: verify edge list' \ 'sed -e s/pack-.*pack/pack-.pack/ edges.list >actual && - diff -u expect actual' + git diff expect actual' ### ### series J From f52463a58275c8dd12b26b02bc0388d015547fcc Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 4 Mar 2007 14:26:05 +0100 Subject: [PATCH 11/69] cherry-pick: Suggest a better method to retain authorship When a cherry-pick failed, we used to recommend setting environment variables to retain the authorship. It is much easier, though, to use the "-c" flag of git-commit. Print this message also when merge-recursive fails (the code used to exit(1) in that case, never reaching the proper failure path). Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- builtin-revert.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/builtin-revert.c b/builtin-revert.c index bc3cfcba07..382fe0c6a1 100644 --- a/builtin-revert.c +++ b/builtin-revert.c @@ -323,9 +323,8 @@ static int revert_or_cherry_pick(int argc, const char **argv) if (merge_recursive(sha1_to_hex(base->object.sha1), sha1_to_hex(head), "HEAD", - sha1_to_hex(next->object.sha1), oneline)) - exit(1); - if (write_tree(head, 0, NULL)) { + sha1_to_hex(next->object.sha1), oneline) || + write_tree(head, 0, NULL)) { const char *target = git_path("MERGE_MSG"); add_to_msg("\nConflicts:\n\n"); read_cache(); @@ -350,16 +349,10 @@ static int revert_or_cherry_pick(int argc, const char **argv) "mark the corrected paths with 'git-add '\n" "and commit the result.\n", me); if (action == CHERRY_PICK) { - fprintf(stderr, "You may choose to use the following " - "when making the commit:\n" - "GIT_AUTHOR_NAME=\"%s\"\n", - getenv("GIT_AUTHOR_NAME")); - fprintf(stderr, "GIT_AUTHOR_EMAIL=\"%s\"\n", - getenv("GIT_AUTHOR_EMAIL")); - fprintf(stderr, "GIT_AUTHOR_DATE=\"%s\"\n" - "export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL " - "GIT_AUTHOR_DATE\n", - getenv("GIT_AUTHOR_DATE")); + fprintf(stderr, "When commiting, use the option " + "'-c %s' to retain authorship and message.\n", + find_unique_abbrev(commit->object.sha1, + DEFAULT_ABBREV)); } exit(1); } From c112f689c2c4dfbf2e4dca0e91aa527dd96ab333 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 4 Mar 2007 00:12:06 +0100 Subject: [PATCH 12/69] format-patch: add --inline option and make --attach a true attachment The existing --attach option did not create a true "attachment" but multipart/mixed with Content-Disposition: inline. It should have been with Content-Disposition: attachment. Introduce --inline to add multipart/mixed that is inlined, and make --attach to create an attachement. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- Documentation/git-format-patch.txt | 14 +- builtin-log.c | 16 +- log-tree.c | 6 +- revision.h | 1 + t/t4013-diff-various.sh | 3 + ...at-patch_--attach_--stdout_initial..master | 6 +- ...t-patch_--attach_--stdout_initial..master^ | 4 +- ...rmat-patch_--attach_--stdout_initial..side | 2 +- ...at-patch_--inline_--stdout_initial..master | 173 ++++++++++++++++++ ...t-patch_--inline_--stdout_initial..master^ | 112 ++++++++++++ ...rmat-patch_--inline_--stdout_initial..side | 62 +++++++ 11 files changed, 386 insertions(+), 13 deletions(-) create mode 100644 t/t4013/diff.format-patch_--inline_--stdout_initial..master create mode 100644 t/t4013/diff.format-patch_--inline_--stdout_initial..master^ create mode 100644 t/t4013/diff.format-patch_--inline_--stdout_initial..side diff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt index 59f34b9f0d..dfdb65290f 100644 --- a/Documentation/git-format-patch.txt +++ b/Documentation/git-format-patch.txt @@ -9,7 +9,8 @@ git-format-patch - Prepare patches for e-mail submission SYNOPSIS -------- [verse] -'git-format-patch' [-n | -k] [-o | --stdout] [--attach] [--thread] +'git-format-patch' [-n | -k] [-o | --stdout] [--thread] + [--attach[=] | --inline[=]] [-s | --signoff] [--diff-options] [--start-number ] [--in-reply-to=Message-Id] [--suffix=.] [--ignore-if-in-upstream] @@ -68,8 +69,15 @@ OPTIONS Print all commits to the standard output in mbox format, instead of creating a file for each one. ---attach:: - Create attachments instead of inlining patches. +--attach[=]:: + Create multipart/mixed attachment, the first part of + which is the commit message and the patch itself in the + second part, with "Content-Disposition: attachment". + +--inline[=]:: + Create multipart/mixed attachment, the first part of + which is the commit message and the patch itself in the + second part, with "Content-Disposition: inline". --thread:: Add In-Reply-To and References headers to make the second and diff --git a/builtin-log.c b/builtin-log.c index 1c9f7d02a8..865832c85e 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -482,10 +482,22 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) memcpy(add_signoff, committer, endpos - committer + 1); add_signoff[endpos - committer + 1] = 0; } - else if (!strcmp(argv[i], "--attach")) + else if (!strcmp(argv[i], "--attach")) { rev.mime_boundary = git_version_string; - else if (!prefixcmp(argv[i], "--attach=")) + rev.no_inline = 1; + } + else if (!prefixcmp(argv[i], "--attach=")) { rev.mime_boundary = argv[i] + 9; + rev.no_inline = 1; + } + else if (!strcmp(argv[i], "--inline")) { + rev.mime_boundary = git_version_string; + rev.no_inline = 0; + } + else if (!prefixcmp(argv[i], "--inline=")) { + rev.mime_boundary = argv[i] + 9; + rev.no_inline = 0; + } else if (!strcmp(argv[i], "--ignore-if-in-upstream")) ignore_if_in_upstream = 1; else if (!strcmp(argv[i], "--thread")) diff --git a/log-tree.c b/log-tree.c index 6ce239d8f9..7b3ad7d5f0 100644 --- a/log-tree.c +++ b/log-tree.c @@ -205,10 +205,12 @@ void show_log(struct rev_info *opt, const char *sep) "Content-Type: text/x-patch;\n" " name=\"%s.diff\"\n" "Content-Transfer-Encoding: 8bit\n" - "Content-Disposition: inline;\n" + "Content-Disposition: %s;\n" " filename=\"%s.diff\"\n\n", mime_boundary_leader, opt->mime_boundary, - sha1, sha1); + sha1, + opt->no_inline ? "attachment" : "inline", + sha1); opt->diffopt.stat_sep = buffer; } } else if (opt->commit_format != CMIT_FMT_USERFORMAT) { diff --git a/revision.h b/revision.h index 5fec1846f3..cf33713608 100644 --- a/revision.h +++ b/revision.h @@ -74,6 +74,7 @@ struct rev_info { const char *add_signoff; const char *extra_headers; const char *log_reencode; + int no_inline; /* Filter by commit log message */ struct grep_opt *grep_filter; diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh index 3d85ceaae9..28787a11f7 100755 --- a/t/t4013-diff-various.sh +++ b/t/t4013-diff-various.sh @@ -238,6 +238,9 @@ format-patch --stdout initial..master format-patch --attach --stdout initial..side format-patch --attach --stdout initial..master^ format-patch --attach --stdout initial..master +format-patch --inline --stdout initial..side +format-patch --inline --stdout initial..master^ +format-patch --inline --stdout initial..master diff --abbrev initial..side diff -r initial..side diff --git a/t/t4013/diff.format-patch_--attach_--stdout_initial..master b/t/t4013/diff.format-patch_--attach_--stdout_initial..master index e5ddd6fcbb..33ce92d457 100644 --- a/t/t4013/diff.format-patch_--attach_--stdout_initial..master +++ b/t/t4013/diff.format-patch_--attach_--stdout_initial..master @@ -24,7 +24,7 @@ This is the second commit. Content-Type: text/x-patch; name="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff" Content-Transfer-Encoding: 8bit -Content-Disposition: inline; +Content-Disposition: attachment; filename="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff" diff --git a/dir/sub b/dir/sub @@ -83,7 +83,7 @@ Content-Transfer-Encoding: 8bit Content-Type: text/x-patch; name="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff" Content-Transfer-Encoding: 8bit -Content-Disposition: inline; +Content-Disposition: attachment; filename="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff" diff --git a/dir/sub b/dir/sub @@ -133,7 +133,7 @@ Content-Transfer-Encoding: 8bit Content-Type: text/x-patch; name="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff" Content-Transfer-Encoding: 8bit -Content-Disposition: inline; +Content-Disposition: attachment; filename="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff" diff --git a/dir/sub b/dir/sub diff --git a/t/t4013/diff.format-patch_--attach_--stdout_initial..master^ b/t/t4013/diff.format-patch_--attach_--stdout_initial..master^ index d0dd19b623..d97625a50c 100644 --- a/t/t4013/diff.format-patch_--attach_--stdout_initial..master^ +++ b/t/t4013/diff.format-patch_--attach_--stdout_initial..master^ @@ -24,7 +24,7 @@ This is the second commit. Content-Type: text/x-patch; name="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff" Content-Transfer-Encoding: 8bit -Content-Disposition: inline; +Content-Disposition: attachment; filename="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff" diff --git a/dir/sub b/dir/sub @@ -83,7 +83,7 @@ Content-Transfer-Encoding: 8bit Content-Type: text/x-patch; name="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff" Content-Transfer-Encoding: 8bit -Content-Disposition: inline; +Content-Disposition: attachment; filename="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff" diff --git a/dir/sub b/dir/sub diff --git a/t/t4013/diff.format-patch_--attach_--stdout_initial..side b/t/t4013/diff.format-patch_--attach_--stdout_initial..side index 67a95c5cba..0b6853d929 100644 --- a/t/t4013/diff.format-patch_--attach_--stdout_initial..side +++ b/t/t4013/diff.format-patch_--attach_--stdout_initial..side @@ -22,7 +22,7 @@ Content-Transfer-Encoding: 8bit Content-Type: text/x-patch; name="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff" Content-Transfer-Encoding: 8bit -Content-Disposition: inline; +Content-Disposition: attachment; filename="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff" diff --git a/dir/sub b/dir/sub diff --git a/t/t4013/diff.format-patch_--inline_--stdout_initial..master b/t/t4013/diff.format-patch_--inline_--stdout_initial..master new file mode 100644 index 0000000000..68c98842d6 --- /dev/null +++ b/t/t4013/diff.format-patch_--inline_--stdout_initial..master @@ -0,0 +1,173 @@ +$ git format-patch --inline --stdout initial..master +From 1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44 Mon Sep 17 00:00:00 2001 +From: A U Thor +Date: Mon, 26 Jun 2006 00:01:00 +0000 +Subject: [PATCH] Second +MIME-Version: 1.0 +Content-Type: multipart/mixed; + boundary="------------g-i-t--v-e-r-s-i-o-n" + +This is a multi-part message in MIME format. +--------------g-i-t--v-e-r-s-i-o-n +Content-Type: text/plain; charset=UTF-8; format=fixed +Content-Transfer-Encoding: 8bit + + +This is the second commit. +--- + dir/sub | 2 ++ + file0 | 3 +++ + file2 | 3 --- + 3 files changed, 5 insertions(+), 3 deletions(-) + delete mode 100644 file2 +--------------g-i-t--v-e-r-s-i-o-n +Content-Type: text/x-patch; + name="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff" +Content-Transfer-Encoding: 8bit +Content-Disposition: inline; + filename="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff" + +diff --git a/dir/sub b/dir/sub +index 35d242b..8422d40 100644 +--- a/dir/sub ++++ b/dir/sub +@@ -1,2 +1,4 @@ + A + B ++C ++D +diff --git a/file0 b/file0 +index 01e79c3..b414108 100644 +--- a/file0 ++++ b/file0 +@@ -1,3 +1,6 @@ + 1 + 2 + 3 ++4 ++5 ++6 +diff --git a/file2 b/file2 +deleted file mode 100644 +index 01e79c3..0000000 +--- a/file2 ++++ /dev/null +@@ -1,3 +0,0 @@ +-1 +-2 +-3 + +--------------g-i-t--v-e-r-s-i-o-n-- + + + +From 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 Mon Sep 17 00:00:00 2001 +From: A U Thor +Date: Mon, 26 Jun 2006 00:02:00 +0000 +Subject: [PATCH] Third +MIME-Version: 1.0 +Content-Type: multipart/mixed; + boundary="------------g-i-t--v-e-r-s-i-o-n" + +This is a multi-part message in MIME format. +--------------g-i-t--v-e-r-s-i-o-n +Content-Type: text/plain; charset=UTF-8; format=fixed +Content-Transfer-Encoding: 8bit + +--- + dir/sub | 2 ++ + file1 | 3 +++ + 2 files changed, 5 insertions(+), 0 deletions(-) + create mode 100644 file1 +--------------g-i-t--v-e-r-s-i-o-n +Content-Type: text/x-patch; + name="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff" +Content-Transfer-Encoding: 8bit +Content-Disposition: inline; + filename="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff" + +diff --git a/dir/sub b/dir/sub +index 8422d40..cead32e 100644 +--- a/dir/sub ++++ b/dir/sub +@@ -2,3 +2,5 @@ A + B + C + D ++E ++F +diff --git a/file1 b/file1 +new file mode 100644 +index 0000000..b1e6722 +--- /dev/null ++++ b/file1 +@@ -0,0 +1,3 @@ ++A ++B ++C + +--------------g-i-t--v-e-r-s-i-o-n-- + + + +From c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Mon Sep 17 00:00:00 2001 +From: A U Thor +Date: Mon, 26 Jun 2006 00:03:00 +0000 +Subject: [PATCH] Side +MIME-Version: 1.0 +Content-Type: multipart/mixed; + boundary="------------g-i-t--v-e-r-s-i-o-n" + +This is a multi-part message in MIME format. +--------------g-i-t--v-e-r-s-i-o-n +Content-Type: text/plain; charset=UTF-8; format=fixed +Content-Transfer-Encoding: 8bit + +--- + dir/sub | 2 ++ + file0 | 3 +++ + file3 | 4 ++++ + 3 files changed, 9 insertions(+), 0 deletions(-) + create mode 100644 file3 +--------------g-i-t--v-e-r-s-i-o-n +Content-Type: text/x-patch; + name="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff" +Content-Transfer-Encoding: 8bit +Content-Disposition: inline; + filename="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff" + +diff --git a/dir/sub b/dir/sub +index 35d242b..7289e35 100644 +--- a/dir/sub ++++ b/dir/sub +@@ -1,2 +1,4 @@ + A + B ++1 ++2 +diff --git a/file0 b/file0 +index 01e79c3..f4615da 100644 +--- a/file0 ++++ b/file0 +@@ -1,3 +1,6 @@ + 1 + 2 + 3 ++A ++B ++C +diff --git a/file3 b/file3 +new file mode 100644 +index 0000000..7289e35 +--- /dev/null ++++ b/file3 +@@ -0,0 +1,4 @@ ++A ++B ++1 ++2 + +--------------g-i-t--v-e-r-s-i-o-n-- + + +$ diff --git a/t/t4013/diff.format-patch_--inline_--stdout_initial..master^ b/t/t4013/diff.format-patch_--inline_--stdout_initial..master^ new file mode 100644 index 0000000000..6008e7779a --- /dev/null +++ b/t/t4013/diff.format-patch_--inline_--stdout_initial..master^ @@ -0,0 +1,112 @@ +$ git format-patch --inline --stdout initial..master^ +From 1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44 Mon Sep 17 00:00:00 2001 +From: A U Thor +Date: Mon, 26 Jun 2006 00:01:00 +0000 +Subject: [PATCH] Second +MIME-Version: 1.0 +Content-Type: multipart/mixed; + boundary="------------g-i-t--v-e-r-s-i-o-n" + +This is a multi-part message in MIME format. +--------------g-i-t--v-e-r-s-i-o-n +Content-Type: text/plain; charset=UTF-8; format=fixed +Content-Transfer-Encoding: 8bit + + +This is the second commit. +--- + dir/sub | 2 ++ + file0 | 3 +++ + file2 | 3 --- + 3 files changed, 5 insertions(+), 3 deletions(-) + delete mode 100644 file2 +--------------g-i-t--v-e-r-s-i-o-n +Content-Type: text/x-patch; + name="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff" +Content-Transfer-Encoding: 8bit +Content-Disposition: inline; + filename="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff" + +diff --git a/dir/sub b/dir/sub +index 35d242b..8422d40 100644 +--- a/dir/sub ++++ b/dir/sub +@@ -1,2 +1,4 @@ + A + B ++C ++D +diff --git a/file0 b/file0 +index 01e79c3..b414108 100644 +--- a/file0 ++++ b/file0 +@@ -1,3 +1,6 @@ + 1 + 2 + 3 ++4 ++5 ++6 +diff --git a/file2 b/file2 +deleted file mode 100644 +index 01e79c3..0000000 +--- a/file2 ++++ /dev/null +@@ -1,3 +0,0 @@ +-1 +-2 +-3 + +--------------g-i-t--v-e-r-s-i-o-n-- + + + +From 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 Mon Sep 17 00:00:00 2001 +From: A U Thor +Date: Mon, 26 Jun 2006 00:02:00 +0000 +Subject: [PATCH] Third +MIME-Version: 1.0 +Content-Type: multipart/mixed; + boundary="------------g-i-t--v-e-r-s-i-o-n" + +This is a multi-part message in MIME format. +--------------g-i-t--v-e-r-s-i-o-n +Content-Type: text/plain; charset=UTF-8; format=fixed +Content-Transfer-Encoding: 8bit + +--- + dir/sub | 2 ++ + file1 | 3 +++ + 2 files changed, 5 insertions(+), 0 deletions(-) + create mode 100644 file1 +--------------g-i-t--v-e-r-s-i-o-n +Content-Type: text/x-patch; + name="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff" +Content-Transfer-Encoding: 8bit +Content-Disposition: inline; + filename="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff" + +diff --git a/dir/sub b/dir/sub +index 8422d40..cead32e 100644 +--- a/dir/sub ++++ b/dir/sub +@@ -2,3 +2,5 @@ A + B + C + D ++E ++F +diff --git a/file1 b/file1 +new file mode 100644 +index 0000000..b1e6722 +--- /dev/null ++++ b/file1 +@@ -0,0 +1,3 @@ ++A ++B ++C + +--------------g-i-t--v-e-r-s-i-o-n-- + + +$ diff --git a/t/t4013/diff.format-patch_--inline_--stdout_initial..side b/t/t4013/diff.format-patch_--inline_--stdout_initial..side new file mode 100644 index 0000000000..c4d3da941d --- /dev/null +++ b/t/t4013/diff.format-patch_--inline_--stdout_initial..side @@ -0,0 +1,62 @@ +$ git format-patch --inline --stdout initial..side +From c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Mon Sep 17 00:00:00 2001 +From: A U Thor +Date: Mon, 26 Jun 2006 00:03:00 +0000 +Subject: [PATCH] Side +MIME-Version: 1.0 +Content-Type: multipart/mixed; + boundary="------------g-i-t--v-e-r-s-i-o-n" + +This is a multi-part message in MIME format. +--------------g-i-t--v-e-r-s-i-o-n +Content-Type: text/plain; charset=UTF-8; format=fixed +Content-Transfer-Encoding: 8bit + +--- + dir/sub | 2 ++ + file0 | 3 +++ + file3 | 4 ++++ + 3 files changed, 9 insertions(+), 0 deletions(-) + create mode 100644 file3 +--------------g-i-t--v-e-r-s-i-o-n +Content-Type: text/x-patch; + name="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff" +Content-Transfer-Encoding: 8bit +Content-Disposition: inline; + filename="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff" + +diff --git a/dir/sub b/dir/sub +index 35d242b..7289e35 100644 +--- a/dir/sub ++++ b/dir/sub +@@ -1,2 +1,4 @@ + A + B ++1 ++2 +diff --git a/file0 b/file0 +index 01e79c3..f4615da 100644 +--- a/file0 ++++ b/file0 +@@ -1,3 +1,6 @@ + 1 + 2 + 3 ++A ++B ++C +diff --git a/file3 b/file3 +new file mode 100644 +index 0000000..7289e35 +--- /dev/null ++++ b/file3 +@@ -0,0 +1,4 @@ ++A ++B ++1 ++2 + +--------------g-i-t--v-e-r-s-i-o-n-- + + +$ From 33ee4cfb6929c77307887bc2124eaeaf011892dc Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 4 Mar 2007 16:08:04 -0800 Subject: [PATCH 13/69] format-patch --attach: not folding some long headers. Panagiotis Issaris reports that some MUAs seem not to like folded "content-type" and "content-disposition" headers, so this makes format-patch --attach output to avoid them. Signed-off-by: Junio C Hamano --- log-tree.c | 6 ++--- t/t4013-diff-various.sh | 2 +- ...at-patch_--attach_--stdout_initial..master | 27 +++++++------------ ...t-patch_--attach_--stdout_initial..master^ | 18 +++++-------- ...rmat-patch_--attach_--stdout_initial..side | 9 +++---- ...at-patch_--inline_--stdout_initial..master | 27 +++++++------------ ...t-patch_--inline_--stdout_initial..master^ | 18 +++++-------- ...rmat-patch_--inline_--stdout_initial..side | 9 +++---- 8 files changed, 40 insertions(+), 76 deletions(-) diff --git a/log-tree.c b/log-tree.c index 7b3ad7d5f0..8797aa14c4 100644 --- a/log-tree.c +++ b/log-tree.c @@ -186,7 +186,7 @@ void show_log(struct rev_info *opt, const char *sep) snprintf(subject_buffer, sizeof(subject_buffer) - 1, "%s" "MIME-Version: 1.0\n" - "Content-Type: multipart/mixed;\n" + "Content-Type: multipart/mixed;" " boundary=\"%s%s\"\n" "\n" "This is a multi-part message in MIME " @@ -202,10 +202,10 @@ void show_log(struct rev_info *opt, const char *sep) snprintf(buffer, sizeof(buffer) - 1, "--%s%s\n" - "Content-Type: text/x-patch;\n" + "Content-Type: text/x-patch;" " name=\"%s.diff\"\n" "Content-Transfer-Encoding: 8bit\n" - "Content-Disposition: %s;\n" + "Content-Disposition: %s;" " filename=\"%s.diff\"\n\n", mime_boundary_leader, opt->mime_boundary, sha1, diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh index 28787a11f7..8345ef5bf7 100755 --- a/t/t4013-diff-various.sh +++ b/t/t4013-diff-various.sh @@ -106,7 +106,7 @@ do echo "\$ git $cmd" git $cmd | sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \ - -e "s/^\\( *boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/" + -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/" echo "\$" } >"$actual" && if test -f "$expect" diff --git a/t/t4013/diff.format-patch_--attach_--stdout_initial..master b/t/t4013/diff.format-patch_--attach_--stdout_initial..master index 33ce92d457..cf6891f748 100644 --- a/t/t4013/diff.format-patch_--attach_--stdout_initial..master +++ b/t/t4013/diff.format-patch_--attach_--stdout_initial..master @@ -4,8 +4,7 @@ From: A U Thor Date: Mon, 26 Jun 2006 00:01:00 +0000 Subject: [PATCH] Second MIME-Version: 1.0 -Content-Type: multipart/mixed; - boundary="------------g-i-t--v-e-r-s-i-o-n" +Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n" This is a multi-part message in MIME format. --------------g-i-t--v-e-r-s-i-o-n @@ -21,11 +20,9 @@ This is the second commit. 3 files changed, 5 insertions(+), 3 deletions(-) delete mode 100644 file2 --------------g-i-t--v-e-r-s-i-o-n -Content-Type: text/x-patch; - name="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff" +Content-Type: text/x-patch; name="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff" Content-Transfer-Encoding: 8bit -Content-Disposition: attachment; - filename="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff" +Content-Disposition: attachment; filename="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff" diff --git a/dir/sub b/dir/sub index 35d242b..8422d40 100644 @@ -66,8 +63,7 @@ From: A U Thor Date: Mon, 26 Jun 2006 00:02:00 +0000 Subject: [PATCH] Third MIME-Version: 1.0 -Content-Type: multipart/mixed; - boundary="------------g-i-t--v-e-r-s-i-o-n" +Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n" This is a multi-part message in MIME format. --------------g-i-t--v-e-r-s-i-o-n @@ -80,11 +76,9 @@ Content-Transfer-Encoding: 8bit 2 files changed, 5 insertions(+), 0 deletions(-) create mode 100644 file1 --------------g-i-t--v-e-r-s-i-o-n -Content-Type: text/x-patch; - name="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff" +Content-Type: text/x-patch; name="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff" Content-Transfer-Encoding: 8bit -Content-Disposition: attachment; - filename="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff" +Content-Disposition: attachment; filename="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff" diff --git a/dir/sub b/dir/sub index 8422d40..cead32e 100644 @@ -115,8 +109,7 @@ From: A U Thor Date: Mon, 26 Jun 2006 00:03:00 +0000 Subject: [PATCH] Side MIME-Version: 1.0 -Content-Type: multipart/mixed; - boundary="------------g-i-t--v-e-r-s-i-o-n" +Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n" This is a multi-part message in MIME format. --------------g-i-t--v-e-r-s-i-o-n @@ -130,11 +123,9 @@ Content-Transfer-Encoding: 8bit 3 files changed, 9 insertions(+), 0 deletions(-) create mode 100644 file3 --------------g-i-t--v-e-r-s-i-o-n -Content-Type: text/x-patch; - name="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff" +Content-Type: text/x-patch; name="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff" Content-Transfer-Encoding: 8bit -Content-Disposition: attachment; - filename="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff" +Content-Disposition: attachment; filename="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff" diff --git a/dir/sub b/dir/sub index 35d242b..7289e35 100644 diff --git a/t/t4013/diff.format-patch_--attach_--stdout_initial..master^ b/t/t4013/diff.format-patch_--attach_--stdout_initial..master^ index d97625a50c..fe0258720c 100644 --- a/t/t4013/diff.format-patch_--attach_--stdout_initial..master^ +++ b/t/t4013/diff.format-patch_--attach_--stdout_initial..master^ @@ -4,8 +4,7 @@ From: A U Thor Date: Mon, 26 Jun 2006 00:01:00 +0000 Subject: [PATCH] Second MIME-Version: 1.0 -Content-Type: multipart/mixed; - boundary="------------g-i-t--v-e-r-s-i-o-n" +Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n" This is a multi-part message in MIME format. --------------g-i-t--v-e-r-s-i-o-n @@ -21,11 +20,9 @@ This is the second commit. 3 files changed, 5 insertions(+), 3 deletions(-) delete mode 100644 file2 --------------g-i-t--v-e-r-s-i-o-n -Content-Type: text/x-patch; - name="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff" +Content-Type: text/x-patch; name="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff" Content-Transfer-Encoding: 8bit -Content-Disposition: attachment; - filename="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff" +Content-Disposition: attachment; filename="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff" diff --git a/dir/sub b/dir/sub index 35d242b..8422d40 100644 @@ -66,8 +63,7 @@ From: A U Thor Date: Mon, 26 Jun 2006 00:02:00 +0000 Subject: [PATCH] Third MIME-Version: 1.0 -Content-Type: multipart/mixed; - boundary="------------g-i-t--v-e-r-s-i-o-n" +Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n" This is a multi-part message in MIME format. --------------g-i-t--v-e-r-s-i-o-n @@ -80,11 +76,9 @@ Content-Transfer-Encoding: 8bit 2 files changed, 5 insertions(+), 0 deletions(-) create mode 100644 file1 --------------g-i-t--v-e-r-s-i-o-n -Content-Type: text/x-patch; - name="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff" +Content-Type: text/x-patch; name="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff" Content-Transfer-Encoding: 8bit -Content-Disposition: attachment; - filename="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff" +Content-Disposition: attachment; filename="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff" diff --git a/dir/sub b/dir/sub index 8422d40..cead32e 100644 diff --git a/t/t4013/diff.format-patch_--attach_--stdout_initial..side b/t/t4013/diff.format-patch_--attach_--stdout_initial..side index 0b6853d929..9ff828ee9d 100644 --- a/t/t4013/diff.format-patch_--attach_--stdout_initial..side +++ b/t/t4013/diff.format-patch_--attach_--stdout_initial..side @@ -4,8 +4,7 @@ From: A U Thor Date: Mon, 26 Jun 2006 00:03:00 +0000 Subject: [PATCH] Side MIME-Version: 1.0 -Content-Type: multipart/mixed; - boundary="------------g-i-t--v-e-r-s-i-o-n" +Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n" This is a multi-part message in MIME format. --------------g-i-t--v-e-r-s-i-o-n @@ -19,11 +18,9 @@ Content-Transfer-Encoding: 8bit 3 files changed, 9 insertions(+), 0 deletions(-) create mode 100644 file3 --------------g-i-t--v-e-r-s-i-o-n -Content-Type: text/x-patch; - name="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff" +Content-Type: text/x-patch; name="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff" Content-Transfer-Encoding: 8bit -Content-Disposition: attachment; - filename="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff" +Content-Disposition: attachment; filename="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff" diff --git a/dir/sub b/dir/sub index 35d242b..7289e35 100644 diff --git a/t/t4013/diff.format-patch_--inline_--stdout_initial..master b/t/t4013/diff.format-patch_--inline_--stdout_initial..master index 68c98842d6..aa110c0e7f 100644 --- a/t/t4013/diff.format-patch_--inline_--stdout_initial..master +++ b/t/t4013/diff.format-patch_--inline_--stdout_initial..master @@ -4,8 +4,7 @@ From: A U Thor Date: Mon, 26 Jun 2006 00:01:00 +0000 Subject: [PATCH] Second MIME-Version: 1.0 -Content-Type: multipart/mixed; - boundary="------------g-i-t--v-e-r-s-i-o-n" +Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n" This is a multi-part message in MIME format. --------------g-i-t--v-e-r-s-i-o-n @@ -21,11 +20,9 @@ This is the second commit. 3 files changed, 5 insertions(+), 3 deletions(-) delete mode 100644 file2 --------------g-i-t--v-e-r-s-i-o-n -Content-Type: text/x-patch; - name="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff" +Content-Type: text/x-patch; name="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff" Content-Transfer-Encoding: 8bit -Content-Disposition: inline; - filename="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff" +Content-Disposition: inline; filename="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff" diff --git a/dir/sub b/dir/sub index 35d242b..8422d40 100644 @@ -66,8 +63,7 @@ From: A U Thor Date: Mon, 26 Jun 2006 00:02:00 +0000 Subject: [PATCH] Third MIME-Version: 1.0 -Content-Type: multipart/mixed; - boundary="------------g-i-t--v-e-r-s-i-o-n" +Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n" This is a multi-part message in MIME format. --------------g-i-t--v-e-r-s-i-o-n @@ -80,11 +76,9 @@ Content-Transfer-Encoding: 8bit 2 files changed, 5 insertions(+), 0 deletions(-) create mode 100644 file1 --------------g-i-t--v-e-r-s-i-o-n -Content-Type: text/x-patch; - name="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff" +Content-Type: text/x-patch; name="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff" Content-Transfer-Encoding: 8bit -Content-Disposition: inline; - filename="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff" +Content-Disposition: inline; filename="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff" diff --git a/dir/sub b/dir/sub index 8422d40..cead32e 100644 @@ -115,8 +109,7 @@ From: A U Thor Date: Mon, 26 Jun 2006 00:03:00 +0000 Subject: [PATCH] Side MIME-Version: 1.0 -Content-Type: multipart/mixed; - boundary="------------g-i-t--v-e-r-s-i-o-n" +Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n" This is a multi-part message in MIME format. --------------g-i-t--v-e-r-s-i-o-n @@ -130,11 +123,9 @@ Content-Transfer-Encoding: 8bit 3 files changed, 9 insertions(+), 0 deletions(-) create mode 100644 file3 --------------g-i-t--v-e-r-s-i-o-n -Content-Type: text/x-patch; - name="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff" +Content-Type: text/x-patch; name="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff" Content-Transfer-Encoding: 8bit -Content-Disposition: inline; - filename="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff" +Content-Disposition: inline; filename="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff" diff --git a/dir/sub b/dir/sub index 35d242b..7289e35 100644 diff --git a/t/t4013/diff.format-patch_--inline_--stdout_initial..master^ b/t/t4013/diff.format-patch_--inline_--stdout_initial..master^ index 6008e7779a..95e9ea4c59 100644 --- a/t/t4013/diff.format-patch_--inline_--stdout_initial..master^ +++ b/t/t4013/diff.format-patch_--inline_--stdout_initial..master^ @@ -4,8 +4,7 @@ From: A U Thor Date: Mon, 26 Jun 2006 00:01:00 +0000 Subject: [PATCH] Second MIME-Version: 1.0 -Content-Type: multipart/mixed; - boundary="------------g-i-t--v-e-r-s-i-o-n" +Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n" This is a multi-part message in MIME format. --------------g-i-t--v-e-r-s-i-o-n @@ -21,11 +20,9 @@ This is the second commit. 3 files changed, 5 insertions(+), 3 deletions(-) delete mode 100644 file2 --------------g-i-t--v-e-r-s-i-o-n -Content-Type: text/x-patch; - name="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff" +Content-Type: text/x-patch; name="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff" Content-Transfer-Encoding: 8bit -Content-Disposition: inline; - filename="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff" +Content-Disposition: inline; filename="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff" diff --git a/dir/sub b/dir/sub index 35d242b..8422d40 100644 @@ -66,8 +63,7 @@ From: A U Thor Date: Mon, 26 Jun 2006 00:02:00 +0000 Subject: [PATCH] Third MIME-Version: 1.0 -Content-Type: multipart/mixed; - boundary="------------g-i-t--v-e-r-s-i-o-n" +Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n" This is a multi-part message in MIME format. --------------g-i-t--v-e-r-s-i-o-n @@ -80,11 +76,9 @@ Content-Transfer-Encoding: 8bit 2 files changed, 5 insertions(+), 0 deletions(-) create mode 100644 file1 --------------g-i-t--v-e-r-s-i-o-n -Content-Type: text/x-patch; - name="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff" +Content-Type: text/x-patch; name="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff" Content-Transfer-Encoding: 8bit -Content-Disposition: inline; - filename="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff" +Content-Disposition: inline; filename="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff" diff --git a/dir/sub b/dir/sub index 8422d40..cead32e 100644 diff --git a/t/t4013/diff.format-patch_--inline_--stdout_initial..side b/t/t4013/diff.format-patch_--inline_--stdout_initial..side index c4d3da941d..86ae923d71 100644 --- a/t/t4013/diff.format-patch_--inline_--stdout_initial..side +++ b/t/t4013/diff.format-patch_--inline_--stdout_initial..side @@ -4,8 +4,7 @@ From: A U Thor Date: Mon, 26 Jun 2006 00:03:00 +0000 Subject: [PATCH] Side MIME-Version: 1.0 -Content-Type: multipart/mixed; - boundary="------------g-i-t--v-e-r-s-i-o-n" +Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n" This is a multi-part message in MIME format. --------------g-i-t--v-e-r-s-i-o-n @@ -19,11 +18,9 @@ Content-Transfer-Encoding: 8bit 3 files changed, 9 insertions(+), 0 deletions(-) create mode 100644 file3 --------------g-i-t--v-e-r-s-i-o-n -Content-Type: text/x-patch; - name="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff" +Content-Type: text/x-patch; name="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff" Content-Transfer-Encoding: 8bit -Content-Disposition: inline; - filename="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff" +Content-Disposition: inline; filename="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff" diff --git a/dir/sub b/dir/sub index 35d242b..7289e35 100644 From efec43c028c52bc252afdaa586b46f83186d3eaa Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 5 Mar 2007 00:21:24 -0800 Subject: [PATCH 14/69] fsck: fix broken loose object check. When "git fsck" without --full found a loose object missing because it was broken, it mistakenly thought it was not parsed because we found it in one of the packs. Back when this code was written, we did not have a way to explicitly check if we have the object in pack, but we do now. Signed-off-by: Junio C Hamano --- builtin-fsck.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin-fsck.c b/builtin-fsck.c index 6abf498d2b..abdd0f2c18 100644 --- a/builtin-fsck.c +++ b/builtin-fsck.c @@ -67,7 +67,7 @@ static void check_reachable_object(struct object *obj) * do a full fsck */ if (!obj->parsed) { - if (has_sha1_file(obj->sha1)) + if (has_sha1_pack(obj->sha1, NULL)) return; /* it is in pack - forget about it */ printf("missing %s %s\n", typename(obj->type), sha1_to_hex(obj->sha1)); return; From 7efbff7531af4281487d54c1dc1401308d988e33 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 5 Mar 2007 00:21:37 -0800 Subject: [PATCH 15/69] unpack_sha1_file(): detect corrupt loose object files. We did not detect broken loose object files, either when underlying inflate() signalled the breakage, nor inflate() finished and we had garbage trailing at the end. We do better now. We also make unpack_sha1_file() a static function to sha1_file.c, since it is not used by anybody outside. Signed-off-by: Junio C Hamano --- cache.h | 1 - sha1_file.c | 27 +++++++++++++++++++-------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/cache.h b/cache.h index c291163e6d..4b5a7541a8 100644 --- a/cache.h +++ b/cache.h @@ -281,7 +281,6 @@ char *enter_repo(char *path, int strict); /* Read and unpack a sha1 file into memory, write memory to a sha1 file */ extern int sha1_object_info(const unsigned char *, unsigned long *); -extern void * unpack_sha1_file(void *map, unsigned long mapsize, enum object_type *type, unsigned long *size); extern void * read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size); extern int hash_sha1_file(void *buf, unsigned long len, const char *type, unsigned char *sha1); extern int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned char *return_sha1); diff --git a/sha1_file.c b/sha1_file.c index 6d0a72ed09..ac6b5e00b6 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -956,11 +956,12 @@ static int unpack_sha1_header(z_stream *stream, unsigned char *map, unsigned lon return 0; } -static void *unpack_sha1_rest(z_stream *stream, void *buffer, unsigned long size) +static void *unpack_sha1_rest(z_stream *stream, void *buffer, unsigned long size, const unsigned char *sha1) { int bytes = strlen(buffer) + 1; unsigned char *buf = xmalloc(1+size); unsigned long n; + int status = Z_OK; n = stream->total_out - bytes; if (n > size) @@ -970,12 +971,22 @@ static void *unpack_sha1_rest(z_stream *stream, void *buffer, unsigned long size if (bytes < size) { stream->next_out = buf + bytes; stream->avail_out = size - bytes; - while (inflate(stream, Z_FINISH) == Z_OK) - /* nothing */; + while (status == Z_OK) + status = inflate(stream, Z_FINISH); } buf[size] = 0; - inflateEnd(stream); - return buf; + if ((status == Z_OK || status == Z_STREAM_END) && !stream->avail_in) { + inflateEnd(stream); + return buf; + } + + if (status < 0) + error("corrupt loose object '%s'", sha1_to_hex(sha1)); + else if (stream->avail_in) + error("garbage at end of loose object '%s'", + sha1_to_hex(sha1)); + free(buf); + return NULL; } /* @@ -1029,7 +1040,7 @@ static int parse_sha1_header(const char *hdr, unsigned long *sizep) return *hdr ? -1 : type_from_string(type); } -void * unpack_sha1_file(void *map, unsigned long mapsize, enum object_type *type, unsigned long *size) +static void *unpack_sha1_file(void *map, unsigned long mapsize, enum object_type *type, unsigned long *size, const unsigned char *sha1) { int ret; z_stream stream; @@ -1039,7 +1050,7 @@ void * unpack_sha1_file(void *map, unsigned long mapsize, enum object_type *type if (ret < Z_OK || (*type = parse_sha1_header(hdr, size)) < 0) return NULL; - return unpack_sha1_rest(&stream, hdr, *size); + return unpack_sha1_rest(&stream, hdr, *size, sha1); } static unsigned long get_delta_base(struct packed_git *p, @@ -1555,7 +1566,7 @@ void *read_sha1_file(const unsigned char *sha1, enum object_type *type, return buf; map = map_sha1_file(sha1, &mapsize); if (map) { - buf = unpack_sha1_file(map, mapsize, type, size); + buf = unpack_sha1_file(map, mapsize, type, size, sha1); munmap(map, mapsize); return buf; } From e2b4f63512357d83f1f11bafadb22063e5d56621 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 5 Mar 2007 00:22:06 -0800 Subject: [PATCH 16/69] fsck: exit with non-zero status upon errors git-fsck always exited with status 0, which was a bit sloppy. This makes it exit with a non-zero status when errors are found. The error code is an OR'ed result of: 1 if corrupted objects are found. 2 if objects that are ought to be reachable are missing or corrupt. For example, it would exit with 1 in a repository with an unreachable corrupt object. If a tree object of the HEAD commit is corrupt, you would get 3. Signed-off-by: Junio C Hamano --- builtin-fsck.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/builtin-fsck.c b/builtin-fsck.c index abdd0f2c18..4d03378c1b 100644 --- a/builtin-fsck.c +++ b/builtin-fsck.c @@ -18,6 +18,9 @@ static int check_full; static int check_strict; static int keep_cache_objects; static unsigned char head_sha1[20]; +static int errors_found; +#define ERROR_OBJECT 01 +#define ERROR_REACHABLE 02 #ifdef NO_D_INO_IN_DIRENT #define SORT_DIRENT 0 @@ -40,6 +43,7 @@ static int objerror(struct object *obj, const char *err, ...) { va_list params; va_start(params, err); + errors_found |= ERROR_OBJECT; objreport(obj, "error", err, params); va_end(params); return -1; @@ -70,6 +74,7 @@ static void check_reachable_object(struct object *obj) if (has_sha1_pack(obj->sha1, NULL)) return; /* it is in pack - forget about it */ printf("missing %s %s\n", typename(obj->type), sha1_to_hex(obj->sha1)); + errors_found |= ERROR_REACHABLE; return; } @@ -88,6 +93,7 @@ static void check_reachable_object(struct object *obj) typename(obj->type), sha1_to_hex(obj->sha1)); printf(" to %7s %s\n", typename(ref->type), sha1_to_hex(ref->sha1)); + errors_found |= ERROR_REACHABLE; } } } @@ -346,8 +352,11 @@ static int fsck_tag(struct tag *tag) static int fsck_sha1(unsigned char *sha1) { struct object *obj = parse_object(sha1); - if (!obj) - return error("%s: object corrupt or missing", sha1_to_hex(sha1)); + if (!obj) { + errors_found |= ERROR_OBJECT; + return error("%s: object corrupt or missing", + sha1_to_hex(sha1)); + } if (obj->flags & SEEN) return 0; obj->flags |= SEEN; @@ -359,8 +368,10 @@ static int fsck_sha1(unsigned char *sha1) return fsck_commit((struct commit *) obj); if (obj->type == OBJ_TAG) return fsck_tag((struct tag *) obj); + /* By now, parse_object() would've returned NULL instead. */ - return objerror(obj, "unknown type '%d' (internal fsck error)", obj->type); + return objerror(obj, "unknown type '%d' (internal fsck error)", + obj->type); } /* @@ -576,11 +587,16 @@ static int fsck_cache_tree(struct cache_tree *it) return err; } +static const char fsck_usage[] = +"git-fsck [--tags] [--root] [[--unreachable] [--cache] [--full] " +"[--strict] *]"; + int cmd_fsck(int argc, char **argv, const char *prefix) { int i, heads; track_object_refs = 1; + errors_found = 0; for (i = 1; i < argc; i++) { const char *arg = argv[i]; @@ -610,7 +626,7 @@ int cmd_fsck(int argc, char **argv, const char *prefix) continue; } if (*arg == '-') - usage("git-fsck [--tags] [--root] [[--unreachable] [--cache] [--full] [--strict] *]"); + usage(fsck_usage); } fsck_head_link(); @@ -690,5 +706,5 @@ int cmd_fsck(int argc, char **argv, const char *prefix) } check_connectivity(); - return 0; + return errors_found; } From 734c91f9e292cf6ed1401c178bc9fbb902cc82dd Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Mon, 5 Mar 2007 12:31:09 -0500 Subject: [PATCH 17/69] fast-import: Avoid infinite loop after reset Johannes Sixt noticed that a 'reset' command applied to a branch that is already active in the branch LRU cache can cause fast-import to relink the same branch into the LRU cache twice. This will cause the LRU cache to contain a cycle, making unload_one_branch run in an infinite loop as it tries to select the oldest branch for eviction. I have trivially fixed the problem by adding an active bit to each branch object; this bit indicates if the branch is already in the LRU and allows us to avoid trying to add it a second time. Converting the pack_id field into a bitfield makes this change take up no additional memory. Signed-off-by: Shawn O. Pearce --- fast-import.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/fast-import.c b/fast-import.c index 1ae125a040..490f640036 100644 --- a/fast-import.c +++ b/fast-import.c @@ -220,7 +220,8 @@ struct branch const char *name; struct tree_entry branch_tree; uintmax_t last_commit; - unsigned int pack_id; + unsigned active : 1; + unsigned pack_id : PACK_ID_BITS; unsigned char sha1[20]; }; @@ -528,6 +529,7 @@ static struct branch *new_branch(const char *name) b->table_next_branch = branch_table[hc]; b->branch_tree.versions[0].mode = S_IFDIR; b->branch_tree.versions[1].mode = S_IFDIR; + b->active = 0; b->pack_id = MAX_PACK_ID; branch_table[hc] = b; branch_count++; @@ -1547,6 +1549,7 @@ static void unload_one_branch(void) e = active_branches; active_branches = e->active_next_branch; } + e->active = 0; e->active_next_branch = NULL; if (e->branch_tree.tree) { release_tree_content_recursive(e->branch_tree.tree); @@ -1559,10 +1562,13 @@ static void unload_one_branch(void) static void load_branch(struct branch *b) { load_tree(&b->branch_tree); - b->active_next_branch = active_branches; - active_branches = b; - cur_active_branches++; - branch_load_count++; + if (!b->active) { + b->active = 1; + b->active_next_branch = active_branches; + active_branches = b; + cur_active_branches++; + branch_load_count++; + } } static void file_change_m(struct branch *b) From 2f6dc35d2ad0bd2a8648902a692f087f47d1ee86 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Mon, 5 Mar 2007 12:43:14 -0500 Subject: [PATCH 18/69] fast-import: Fail if a non-existant commit is used for merge Johannes Sixt noticed during one of his own imports that fast-import did not fail if a non-existant commit is referenced by SHA-1 value as an argument to the 'merge' command. This allowed the user to unknowingly create commits that would fail in fsck, as the commit contents would not be completely reachable. A side effect of this bug was that a frontend process could mark any SHA-1 object (blob, tree, tag) as a parent of a merge commit. This should also fail in fsck, as the commit is not a valid commit. We now use the same rule as the 'from' command. If a commit is referenced in the 'merge' command by hex formatted SHA-1 then the SHA-1 must be a commit or a tag that can be peeled back to a commit, the commit must already exist, and must be readable by the core Git infrastructure code. This requirement means that the commit must have existed prior to fast-import starting, or the commit must have been flushed out by a prior 'checkpoint' command. Signed-off-by: Shawn O. Pearce --- fast-import.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fast-import.c b/fast-import.c index 490f640036..d9492b9884 100644 --- a/fast-import.c +++ b/fast-import.c @@ -1752,7 +1752,14 @@ static struct hash_list *cmd_merge(unsigned int *count) if (oe->type != OBJ_COMMIT) die("Mark :%" PRIuMAX " not a commit", idnum); hashcpy(n->sha1, oe->sha1); - } else if (get_sha1(from, n->sha1)) + } else if (!get_sha1(from, n->sha1)) { + unsigned long size; + char *buf = read_object_with_reference(n->sha1, + type_names[OBJ_COMMIT], &size, n->sha1); + if (!buf || size < 46) + die("Not a valid commit: %s", from); + free(buf); + } else die("Invalid ref name or SHA1 expression: %s", from); n->next = NULL; From 56333bac66ccdefa3f6d67f78da9f5267119c4a6 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 5 Mar 2007 16:37:54 +0100 Subject: [PATCH 19/69] Begin SubmittingPatches with a check list It seems that some people prefer a short list to a long text. But even for the latter group, a quick reminder list is useful. So, add a check list to Documentation/SubmittingPatches of what to do to get your patch accepted. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- Documentation/SubmittingPatches | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Documentation/SubmittingPatches b/Documentation/SubmittingPatches index 285781d9db..131bcff9b2 100644 --- a/Documentation/SubmittingPatches +++ b/Documentation/SubmittingPatches @@ -1,3 +1,30 @@ +Checklist (and a short version for the impatient): + + - make commits of logical units + - check for unnecessary whitespace with "git diff --check" + before committing + - do not check in commented out code or unneeded files + - provide a meaningful commit message + - the first line of the commit message should be a short + description and should skip the full stop + - if you want your work included in git.git, add a + "Signed-off-by: Your Name " line to the + commit message (or just use the option "-s" when + committing) to confirm that you agree to the Developer's + Certificate of Origin + - do not PGP sign your patch + - use "git format-patch -M" to create the patch + - do not attach your patch, but read in the mail + body, unless you cannot teach your mailer to + leave the formatting of the patch alone. + - be careful doing cut & paste into your mailer, not to + corrupt whitespaces. + - provide additional information (which is unsuitable for + the commit message) between the "---" and the diffstat + - send the patch to the list _and_ the maintainer + +Long version: + I started reading over the SubmittingPatches document for Linux kernel, primarily because I wanted to have a document similar to it for the core GIT to make sure people understand what they are From 043d76050d3136b8684b5a3938e8bc0c1f8483fd Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Mon, 5 Mar 2007 14:46:05 -0500 Subject: [PATCH 20/69] Add definition of to the main git man page. Signed-off-by: "Theodore Ts'o" Signed-off-by: Junio C Hamano --- Documentation/git.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/git.txt b/Documentation/git.txt index c0fa0d4b17..e514588bd3 100644 --- a/Documentation/git.txt +++ b/Documentation/git.txt @@ -231,6 +231,12 @@ Identifier Terminology operate on a object but automatically dereferences and objects that point at a . +:: + Indicates a commit or tag object name. A + command that takes a argument ultimately wants to + operate on a object but automatically dereferences + objects that point at a . + :: Indicates that an object type is required. Currently one of: `blob`, `tree`, `commit`, or `tag`. From b8105375abfeee54e0a34e1c290983fd15e743cf Mon Sep 17 00:00:00 2001 From: Brian Gernhardt Date: Mon, 5 Mar 2007 22:27:44 -0500 Subject: [PATCH 21/69] Fix diff-options references in git-diff and git-format-patch Most of the git-diff-* documentation used [] instead of [--diff-options], so make that change in git-diff and git-format-patch. In addition, git-format-patch didn't include the meanings of the diff options. Signed-off-by: Brian Gernhardt Signed-off-by: Junio C Hamano --- Documentation/git-diff.txt | 2 +- Documentation/git-format-patch.txt | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Documentation/git-diff.txt b/Documentation/git-diff.txt index 6a098df26b..b88764f45f 100644 --- a/Documentation/git-diff.txt +++ b/Documentation/git-diff.txt @@ -8,7 +8,7 @@ git-diff - Show changes between commits, commit and working tree, etc SYNOPSIS -------- -'git-diff' [ --diff-options ] {0,2} [--] [...] +'git-diff' [] {0,2} [--] [...] DESCRIPTION ----------- diff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt index 59f34b9f0d..84eabebe0b 100644 --- a/Documentation/git-format-patch.txt +++ b/Documentation/git-format-patch.txt @@ -9,8 +9,8 @@ git-format-patch - Prepare patches for e-mail submission SYNOPSIS -------- [verse] -'git-format-patch' [-n | -k] [-o | --stdout] [--attach] [--thread] - [-s | --signoff] [--diff-options] [--start-number ] +'git-format-patch' [] [-n | -k] [-o | --stdout] + [--attach] [--thread] [-s | --signoff] [--start-number ] [--in-reply-to=Message-Id] [--suffix=.] [--ignore-if-in-upstream] [..] @@ -46,6 +46,8 @@ reference. OPTIONS ------- +include::diff-options.txt[] + -o|--output-directory :: Use to store the resulting files, instead of the current working directory. From 0e6240447c6e0e75e22c30ece7eedb16e1e8ff0b Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 6 Mar 2007 00:46:00 -0500 Subject: [PATCH 22/69] cherry-pick: Bug fix 'cherry picked from' message. Somewhere along the line (in abd6970a) git-revert.sh learned to omit the private object name from the new commit message *unless* -x was supplied on the command line by the user. The way this was implemented is really non-obvious in the original script. Setting replay=t (the default) means we don't include the the private object name, while setting reply='' (the -x flag) means we should include the private object name. These two settings now relate to the replay=1 and replay=0 cases in the C version, so we need to negate replay to test it is 0. I also noticed the C version was adding an extra LF in the -x case, where the older git-revert.sh was not. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- builtin-revert.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin-revert.c b/builtin-revert.c index 382fe0c6a1..2f2dc1bbaa 100644 --- a/builtin-revert.c +++ b/builtin-revert.c @@ -303,8 +303,8 @@ static int revert_or_cherry_pick(int argc, const char **argv) next = commit; set_author_ident_env(message); add_message_to_msg(message); - if (replay) { - add_to_msg("\n(cherry picked from commit "); + if (!replay) { + add_to_msg("(cherry picked from commit "); add_to_msg(sha1_to_hex(commit->object.sha1)); add_to_msg(")\n"); } From c93d88a574220c00954e3694bd78181b8b95249a Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 5 Mar 2007 12:35:41 -0800 Subject: [PATCH 23/69] git-commit: cd to top before showing the final stat Signed-off-by: Junio C Hamano --- git-commit.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/git-commit.sh b/git-commit.sh index 476f4f18db..cad16a5e86 100755 --- a/git-commit.sh +++ b/git-commit.sh @@ -621,6 +621,9 @@ else fi ret="$?" rm -f "$GIT_DIR/COMMIT_MSG" "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG" + +cd_to_toplevel + if test -d "$GIT_DIR/rr-cache" then git-rerere From 0b5ea163d21163343579cd6eb9274ccc2190a0fe Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 6 Mar 2007 02:13:23 -0500 Subject: [PATCH 24/69] git-gui: Make 'make' quieter by default To fit nicely into the output of the git.git project's own quieter Makefile, we want to make the git-gui Makefile nice and quiet too. Signed-off-by: Shawn O. Pearce --- Makefile | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 66538ba1ad..e486e8f984 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,8 @@ all:: +# Define V=1 to have a more verbose compile. +# + GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE @$(SHELL_PATH) ./GIT-VERSION-GEN -include GIT-VERSION-FILE @@ -19,27 +22,32 @@ ifndef INSTALL INSTALL = install endif +ifndef V + QUIET_GEN = @echo ' ' GEN $@; + QUIET_BUILT_IN = @echo ' ' BUILTIN $@; +endif + DESTDIR_SQ = $(subst ','\'',$(DESTDIR)) gitexecdir_SQ = $(subst ','\'',$(gitexecdir)) SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH)) git-gui: git-gui.sh GIT-VERSION-FILE CREDITS-FILE - rm -f $@ $@+ + $(QUIET_GEN)rm -f $@ $@+ && \ sed -n \ -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \ -e 's/@@GITGUI_VERSION@@/$(GITGUI_VERSION)/g' \ -e '1,/^set gitgui_credits /p' \ - $@.sh >$@+ - cat CREDITS-FILE >>$@+ - sed -e '1,/^set gitgui_credits /d' $@.sh >>$@+ - chmod +x $@+ + $@.sh >$@+ && \ + cat CREDITS-FILE >>$@+ && \ + sed -e '1,/^set gitgui_credits /d' $@.sh >>$@+ && \ + chmod +x $@+ && \ mv $@+ $@ CREDITS-FILE: CREDITS-GEN .FORCE-CREDITS-FILE - $(SHELL_PATH) ./CREDITS-GEN + $(QUIET_GEN)$(SHELL_PATH) ./CREDITS-GEN $(GITGUI_BUILT_INS): git-gui - rm -f $@ && ln git-gui $@ + $(QUIET_BUILT_IN)rm -f $@ && ln git-gui $@ all:: $(ALL_PROGRAMS) From c044aa18f68bcba4f7ec6fd625eb48c2520a1bb1 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 5 Mar 2007 22:48:00 -0800 Subject: [PATCH 25/69] git-bundle: fix pack generation. The handcrafted built-in rev-list lookalike forgot to mark the trees and blobs contained in the boundary commits uninteresting, resulting in unnecessary objects in the pack. Signed-off-by: Junio C Hamano --- builtin-bundle.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/builtin-bundle.c b/builtin-bundle.c index d41a413b58..279b8f8e58 100644 --- a/builtin-bundle.c +++ b/builtin-bundle.c @@ -263,6 +263,11 @@ static void show_object(struct object_array_entry *p) write_or_die(1, "\n", 1); } +static void show_edge(struct commit *commit) +{ + ; /* nothing to do */ +} + static int create_bundle(struct bundle_header *header, const char *path, int argc, const char **argv) { @@ -341,6 +346,7 @@ static int create_bundle(struct bundle_header *header, const char *path, dup2(in, 1); close(in); prepare_revision_walk(&revs); + mark_edges_uninteresting(revs.commits, &revs, show_edge); traverse_commit_list(&revs, show_commit, show_object); close(1); while (waitpid(pid, &status, 0) < 0) From 74f2b2a8d006a49e1be7e30731c2f7365d2741d1 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 6 Mar 2007 01:35:01 -0500 Subject: [PATCH 26/69] Make 'make' quieter while building git I find it difficult to see compiler warnings amongst the massive spewing produced by GNU make as it works through our productions. This is especially true if CFLAGS winds up being rather long, due to a large number of -W options being enabled and due to a number of -D options being configured/required by my platform. By defining QUIET_MAKE (e.g. make QUIET_MAKE=YesPlease) during compilation users will get a less verbose output, such as: ... CC builtin-grep.c builtin-grep.c:187: warning: 'external_grep' defined but not used CC builtin-init-db.c CC builtin-log.c CC builtin-ls-files.c CC builtin-ls-tree.c ... The verbose (normal make) output is still the default. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- Makefile | 86 ++++++++++++++++++++++++++-------------------- perl/Makefile | 8 +++-- templates/Makefile | 10 ++++-- 3 files changed, 62 insertions(+), 42 deletions(-) diff --git a/Makefile b/Makefile index a221bdc027..66ab992442 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,8 @@ # The default target of this Makefile is... all:: +# Define QUIET_MAKE to have a less verbose compile. +# # Define NO_OPENSSL environment variable if you do not have OpenSSL. # This also implies MOZILLA_SHA1. # @@ -602,6 +604,19 @@ endif ifdef NO_PERL_MAKEMAKER export NO_PERL_MAKEMAKER endif +ifdef QUIET_MAKE + QUIET_CC = @echo ' ' CC $<; + QUIET_AR = @echo ' ' AR $@; + QUIET_LINK = @echo ' ' LINK $@; + QUIET_BUILT_IN = @echo ' ' BUILTIN $@; + QUIET_GEN = @echo ' ' GEN $@; + QUIET_SUBDIR0 = @subdir= + QUIET_SUBDIR1 = ;echo ' ' SUBDIR $$subdir; $(MAKE) -C$$subdir + export QUIET_MAKE +else + QUIET_SUBDIR0 = $(MAKE) -C + QUIET_SUBDIR1 = +endif # Shell quote (do not use $(call) to accommodate ancient setups); @@ -637,35 +652,34 @@ ifneq (,$X) endif all:: - $(MAKE) -C git-gui all - $(MAKE) -C perl PERL_PATH='$(PERL_PATH_SQ)' prefix='$(prefix_SQ)' all - $(MAKE) -C templates + $(QUIET_SUBDIR0)git-gui $(QUIET_SUBDIR1) all + $(QUIET_SUBDIR0)perl $(QUIET_SUBDIR1) PERL_PATH='$(PERL_PATH_SQ)' prefix='$(prefix_SQ)' all + $(QUIET_SUBDIR0)templates $(QUIET_SUBDIR1) strip: $(PROGRAMS) git$X $(STRIP) $(STRIP_OPTS) $(PROGRAMS) git$X git$X: git.c common-cmds.h $(BUILTIN_OBJS) $(GITLIBS) GIT-CFLAGS - $(CC) -DGIT_VERSION='"$(GIT_VERSION)"' \ + $(QUIET_LINK)$(CC) -DGIT_VERSION='"$(GIT_VERSION)"' \ $(ALL_CFLAGS) -o $@ $(filter %.c,$^) \ $(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS) help.o: common-cmds.h $(BUILT_INS): git$X - rm -f $@ && ln git$X $@ + $(QUIET_BUILT_IN)rm -f $@ && ln git$X $@ common-cmds.h: Documentation/git-*.txt - ./generate-cmdlist.sh > $@+ - mv $@+ $@ + $(QUIET_GEN)./generate-cmdlist.sh > $@+ && mv $@+ $@ $(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh - rm -f $@ $@+ + $(QUIET_GEN)rm -f $@ $@+ && \ sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \ -e 's|@@PERL@@|$(PERL_PATH_SQ)|g' \ -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \ -e 's/@@NO_CURL@@/$(NO_CURL)/g' \ - $@.sh >$@+ - chmod +x $@+ + $@.sh >$@+ && \ + chmod +x $@+ && \ mv $@+ $@ $(patsubst %.perl,%,$(SCRIPT_PERL)): perl/perl.mak @@ -674,7 +688,7 @@ perl/perl.mak: GIT-CFLAGS $(MAKE) -C perl PERL_PATH='$(PERL_PATH_SQ)' prefix='$(prefix_SQ)' $(@F) $(patsubst %.perl,%,$(SCRIPT_PERL)): % : %.perl - rm -f $@ $@+ + $(QUIET_GEN)rm -f $@ $@+ && \ INSTLIBDIR=`$(MAKE) -C perl -s --no-print-directory instlibdir` && \ sed -e '1{' \ -e ' s|#!.*perl|#!$(PERL_PATH_SQ)|' \ @@ -685,20 +699,18 @@ $(patsubst %.perl,%,$(SCRIPT_PERL)): % : %.perl -e '}' \ -e 's|@@INSTLIBDIR@@|'"$$INSTLIBDIR"'|g' \ -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \ - $@.perl >$@+ - chmod +x $@+ + $@.perl >$@+ && \ + chmod +x $@+ && \ mv $@+ $@ git-cherry-pick: git-revert - cp $< $@+ - mv $@+ $@ + $(QUIET_GEN)cp $< $@+ && mv $@+ $@ git-status: git-commit - cp $< $@+ - mv $@+ $@ + $(QUIET_GEN)cp $< $@+ && mv $@+ $@ gitweb/gitweb.cgi: gitweb/gitweb.perl - rm -f $@ $@+ + $(QUIET_GEN)rm -f $@ $@+ && \ sed -e '1s|#!.*perl|#!$(PERL_PATH_SQ)|' \ -e 's|++GIT_VERSION++|$(GIT_VERSION)|g' \ -e 's|++GIT_BINDIR++|$(bindir)|g' \ @@ -716,12 +728,12 @@ gitweb/gitweb.cgi: gitweb/gitweb.perl -e 's|++GITWEB_FAVICON++|$(GITWEB_FAVICON)|g' \ -e 's|++GITWEB_SITE_HEADER++|$(GITWEB_SITE_HEADER)|g' \ -e 's|++GITWEB_SITE_FOOTER++|$(GITWEB_SITE_FOOTER)|g' \ - $< >$@+ - chmod +x $@+ + $< >$@+ && \ + chmod +x $@+ && \ mv $@+ $@ git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css - rm -f $@ $@+ + $(QUIET_GEN)rm -f $@ $@+ && \ sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \ -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \ -e 's/@@NO_CURL@@/$(NO_CURL)/g' \ @@ -729,15 +741,15 @@ git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css -e '/@@GITWEB_CGI@@/d' \ -e '/@@GITWEB_CSS@@/r gitweb/gitweb.css' \ -e '/@@GITWEB_CSS@@/d' \ - $@.sh > $@+ - chmod +x $@+ + $@.sh > $@+ && \ + chmod +x $@+ && \ mv $@+ $@ configure: configure.ac - rm -f $@ $<+ + $(QUIET_GEN)rm -f $@ $<+ && \ sed -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \ - $< > $<+ - autoconf -o $@ $<+ + $< > $<+ && \ + autoconf -o $@ $<+ && \ rm -f $<+ # These can record GIT_VERSION @@ -747,25 +759,25 @@ git$X git.spec \ : GIT-VERSION-FILE %.o: %.c GIT-CFLAGS - $(CC) -o $*.o -c $(ALL_CFLAGS) $< + $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) $< %.o: %.S - $(CC) -o $*.o -c $(ALL_CFLAGS) $< + $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) $< exec_cmd.o: exec_cmd.c GIT-CFLAGS - $(CC) -o $*.o -c $(ALL_CFLAGS) '-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' $< + $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) '-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' $< builtin-init-db.o: builtin-init-db.c GIT-CFLAGS - $(CC) -o $*.o -c $(ALL_CFLAGS) -DDEFAULT_GIT_TEMPLATE_DIR='"$(template_dir_SQ)"' $< + $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DDEFAULT_GIT_TEMPLATE_DIR='"$(template_dir_SQ)"' $< http.o: http.c GIT-CFLAGS - $(CC) -o $*.o -c $(ALL_CFLAGS) -DGIT_USER_AGENT='"git/$(GIT_VERSION)"' $< + $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DGIT_USER_AGENT='"git/$(GIT_VERSION)"' $< ifdef NO_EXPAT http-fetch.o: http-fetch.c http.h GIT-CFLAGS - $(CC) -o $*.o -c $(ALL_CFLAGS) -DNO_EXPAT $< + $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DNO_EXPAT $< endif git-%$X: %.o $(GITLIBS) - $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) + $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) ssh-pull.o: ssh-fetch.c ssh-push.o: ssh-upload.c @@ -779,11 +791,11 @@ git-imap-send$X: imap-send.o $(LIB_FILE) http.o http-fetch.o http-push.o: http.h git-http-fetch$X: fetch.o http.o http-fetch.o $(GITLIBS) - $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \ + $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \ $(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT) git-http-push$X: revision.o http.o http-push.o $(GITLIBS) - $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \ + $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \ $(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIB_OBJS) $(BUILTIN_OBJS) fetch.o: $(LIB_H) @@ -791,7 +803,7 @@ $(patsubst git-%$X,%.o,$(PROGRAMS)): $(LIB_H) $(wildcard */*.h) $(DIFF_OBJS): diffcore.h $(LIB_FILE): $(LIB_OBJS) - rm -f $@ && $(AR) rcs $@ $(LIB_OBJS) + $(QUIET_AR)rm -f $@ && $(AR) rcs $@ $(LIB_OBJS) XDIFF_OBJS=xdiff/xdiffi.o xdiff/xprepare.o xdiff/xutils.o xdiff/xemit.o \ xdiff/xmerge.o @@ -799,7 +811,7 @@ $(XDIFF_OBJS): xdiff/xinclude.h xdiff/xmacros.h xdiff/xdiff.h xdiff/xtypes.h \ xdiff/xutils.h xdiff/xprepare.h xdiff/xdiffi.h xdiff/xemit.h $(XDIFF_LIB): $(XDIFF_OBJS) - rm -f $@ && $(AR) rcs $@ $(XDIFF_OBJS) + $(QUIET_AR)rm -f $@ && $(AR) rcs $@ $(XDIFF_OBJS) perl/Makefile: perl/Git.pm perl/Makefile.PL GIT-CFLAGS diff --git a/perl/Makefile b/perl/Makefile index 099beda873..2fceff2791 100644 --- a/perl/Makefile +++ b/perl/Makefile @@ -6,11 +6,15 @@ makfile:=perl.mak PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH)) prefix_SQ = $(subst ','\'',$(prefix)) +ifdef QUIET_MAKE + QUIET = @ +endif + all install instlibdir: $(makfile) - $(MAKE) -f $(makfile) $@ + $(QUIET)$(MAKE) -f $(makfile) $@ clean: - test -f $(makfile) && $(MAKE) -f $(makfile) $@ || exit 0 + $(QUIET)test -f $(makfile) && $(MAKE) -f $(makfile) $@ || exit 0 $(RM) ppport.h $(RM) $(makfile) $(RM) $(makfile).old diff --git a/templates/Makefile b/templates/Makefile index 0eeee43feb..81bd86ccf3 100644 --- a/templates/Makefile +++ b/templates/Makefile @@ -1,5 +1,9 @@ # make and install sample templates +ifdef QUIET_MAKE + QUIET = @ +endif + INSTALL ?= install TAR ?= tar prefix ?= $(HOME) @@ -18,7 +22,7 @@ all: boilerplates.made custom bpsrc = $(filter-out %~,$(wildcard *--*)) boilerplates.made : $(bpsrc) - ls *--* 2>/dev/null | \ + $(QUIET)ls *--* 2>/dev/null | \ while read boilerplate; \ do \ case "$$boilerplate" in *~) continue ;; esac && \ @@ -29,13 +33,13 @@ boilerplates.made : $(bpsrc) *--) ;; \ *) cp $$boilerplate blt/$$dst ;; \ esac || exit; \ - done || exit + done && \ date >$@ # If you need build-tailored templates, build them into blt/ # directory yourself here. custom: - : no custom templates yet + $(QUIET): no custom templates yet clean: rm -rf blt boilerplates.made From 2314c947706b9480ddd8c1420efa8da523d99c9f Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 6 Mar 2007 02:09:14 -0500 Subject: [PATCH 27/69] Make 'make' quiet by default Per Junio's suggestion we are setting 'make' to be quiet by default, with `make V=1` available to force GNU make back to its default behavior of showing each command it is running. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- Makefile | 6 +++--- perl/Makefile | 2 +- templates/Makefile | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 66ab992442..72d42917d9 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ # The default target of this Makefile is... all:: -# Define QUIET_MAKE to have a less verbose compile. +# Define V=1 to have a more verbose compile. # # Define NO_OPENSSL environment variable if you do not have OpenSSL. # This also implies MOZILLA_SHA1. @@ -604,7 +604,7 @@ endif ifdef NO_PERL_MAKEMAKER export NO_PERL_MAKEMAKER endif -ifdef QUIET_MAKE +ifndef V QUIET_CC = @echo ' ' CC $<; QUIET_AR = @echo ' ' AR $@; QUIET_LINK = @echo ' ' LINK $@; @@ -612,7 +612,7 @@ ifdef QUIET_MAKE QUIET_GEN = @echo ' ' GEN $@; QUIET_SUBDIR0 = @subdir= QUIET_SUBDIR1 = ;echo ' ' SUBDIR $$subdir; $(MAKE) -C$$subdir - export QUIET_MAKE + export V else QUIET_SUBDIR0 = $(MAKE) -C QUIET_SUBDIR1 = diff --git a/perl/Makefile b/perl/Makefile index 2fceff2791..17d004e5a0 100644 --- a/perl/Makefile +++ b/perl/Makefile @@ -6,7 +6,7 @@ makfile:=perl.mak PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH)) prefix_SQ = $(subst ','\'',$(prefix)) -ifdef QUIET_MAKE +ifndef V QUIET = @ endif diff --git a/templates/Makefile b/templates/Makefile index 81bd86ccf3..b8352e731b 100644 --- a/templates/Makefile +++ b/templates/Makefile @@ -1,6 +1,6 @@ # make and install sample templates -ifdef QUIET_MAKE +ifndef V QUIET = @ endif From c390ae97beb9e8cdab159b593ea9659e8096c4db Mon Sep 17 00:00:00 2001 From: Li Yang Date: Tue, 6 Mar 2007 11:58:56 +0800 Subject: [PATCH 28/69] gitweb: Change to use explicitly function call cgi->escapHTML() Change to use explicitly function call cgi->escapHTML(). This fix the problem on some systems that escapeHTML() is not functioning, as default CGI is not setting 'escape' parameter. Signed-off-by: Li Yang Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 653ca3cc60..3a564d1c48 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -591,7 +591,7 @@ sub esc_html ($;%) { my %opts = @_; $str = to_utf8($str); - $str = escapeHTML($str); + $str = $cgi->escapeHTML($str); if ($opts{'-nbsp'}) { $str =~ s/ / /g; } @@ -605,7 +605,7 @@ sub esc_path { my %opts = @_; $str = to_utf8($str); - $str = escapeHTML($str); + $str = $cgi->escapeHTML($str); if ($opts{'-nbsp'}) { $str =~ s/ / /g; } From 58db64f73c3dedb41467f915b45d305d52d04d2c Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 6 Mar 2007 19:48:59 -0500 Subject: [PATCH 29/69] make t8001 work on Mac OS X again The test was recently broken to expect sed to leave the incomplete line at the end without newline. POSIX says that output of the pattern space is to be followed by a newline, while GNU adds the newline back only when it was stripped when input. GNU behaviour is arguably more intuitive and nicer, but we should not depend on it. Signed-off-by: Johannes Schindelin Acked-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- t/annotate-tests.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/t/annotate-tests.sh b/t/annotate-tests.sh index 87403da780..cacb273aff 100644 --- a/t/annotate-tests.sh +++ b/t/annotate-tests.sh @@ -114,7 +114,8 @@ test_expect_success \ test_expect_success \ 'some edit' \ 'mv file file.orig && - sed -e "s/^3A/99/" -e "/^1A/d" < file.orig > file && + sed -e "s/^3A/99/" -e "/^1A/d" -e "/^incomplete/d" < file.orig > file && + echo "incomplete" | tr -d "\\012" >>file && GIT_AUTHOR_NAME="D" git commit -a -m "edit"' test_expect_success \ From 31d0399c3c310d035cd7ed55c094f0b636ac5e20 Mon Sep 17 00:00:00 2001 From: Alex Riesen Date: Tue, 6 Mar 2007 23:37:18 +0100 Subject: [PATCH 30/69] More build output cleaning up - print output file name for .c files - suppress output of the names of subdirectories when make changes into them - use GEN prefix for makefile generation in perl/ Signed-off-by: Alex Riesen Signed-off-by: Junio C Hamano --- Makefile | 8 +++++--- perl/Makefile | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 72d42917d9..eb6c421acc 100644 --- a/Makefile +++ b/Makefile @@ -605,14 +605,16 @@ ifdef NO_PERL_MAKEMAKER export NO_PERL_MAKEMAKER endif ifndef V - QUIET_CC = @echo ' ' CC $<; + QUIET_CC = @echo ' ' CC $@; QUIET_AR = @echo ' ' AR $@; QUIET_LINK = @echo ' ' LINK $@; QUIET_BUILT_IN = @echo ' ' BUILTIN $@; QUIET_GEN = @echo ' ' GEN $@; QUIET_SUBDIR0 = @subdir= - QUIET_SUBDIR1 = ;echo ' ' SUBDIR $$subdir; $(MAKE) -C$$subdir + QUIET_SUBDIR1 = ;echo ' ' SUBDIR $$subdir; \ + $(MAKE) --no-print-directory -C $$subdir export V + export QUIET_GEN else QUIET_SUBDIR0 = $(MAKE) -C QUIET_SUBDIR1 = @@ -685,7 +687,7 @@ $(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh $(patsubst %.perl,%,$(SCRIPT_PERL)): perl/perl.mak perl/perl.mak: GIT-CFLAGS - $(MAKE) -C perl PERL_PATH='$(PERL_PATH_SQ)' prefix='$(prefix_SQ)' $(@F) + $(QUIET_SUBDIR0)perl $(QUIET_SUBDIR1) PERL_PATH='$(PERL_PATH_SQ)' prefix='$(prefix_SQ)' $(@F) $(patsubst %.perl,%,$(SCRIPT_PERL)): % : %.perl $(QUIET_GEN)rm -f $@ $@+ && \ diff --git a/perl/Makefile b/perl/Makefile index 17d004e5a0..5ec0389883 100644 --- a/perl/Makefile +++ b/perl/Makefile @@ -33,7 +33,7 @@ $(makfile): ../GIT-CFLAGS Makefile echo ' echo $(instdir_SQ)' >> $@ else $(makfile): Makefile.PL ../GIT-CFLAGS - '$(PERL_PATH_SQ)' $< PREFIX='$(prefix_SQ)' + $(QUIET_GEN)'$(PERL_PATH_SQ)' $< PREFIX='$(prefix_SQ)' endif # this is just added comfort for calling make directly in perl dir From b777434383bd2f365be6896d8c89be6c1b62a135 Mon Sep 17 00:00:00 2001 From: Alex Riesen Date: Wed, 7 Mar 2007 00:44:49 +0100 Subject: [PATCH 31/69] Support of "make -s": do not output anything of the build itself Signed-off-by: Junio C Hamano --- Makefile | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index eb6c421acc..983da608d6 100644 --- a/Makefile +++ b/Makefile @@ -604,6 +604,11 @@ endif ifdef NO_PERL_MAKEMAKER export NO_PERL_MAKEMAKER endif + +QUIET_SUBDIR0 = $(MAKE) -C # space to separate -C and subdir +QUIET_SUBDIR1 = + +ifneq ($(findstring $(MAKEFLAGS),s),s) ifndef V QUIET_CC = @echo ' ' CC $@; QUIET_AR = @echo ' ' AR $@; @@ -615,9 +620,8 @@ ifndef V $(MAKE) --no-print-directory -C $$subdir export V export QUIET_GEN -else - QUIET_SUBDIR0 = $(MAKE) -C - QUIET_SUBDIR1 = + export QUIET_BUILT_IN +endif endif # Shell quote (do not use $(call) to accommodate ancient setups); From a6f37099d0fce10b536abc1d1a8111460638bac0 Mon Sep 17 00:00:00 2001 From: Alex Riesen Date: Wed, 7 Mar 2007 00:05:34 +0100 Subject: [PATCH 32/69] Allow "make -w" generate its usual output Signed-off-by: Alex Riesen Signed-off-by: Junio C Hamano --- Makefile | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 983da608d6..bab7565563 100644 --- a/Makefile +++ b/Makefile @@ -608,6 +608,12 @@ endif QUIET_SUBDIR0 = $(MAKE) -C # space to separate -C and subdir QUIET_SUBDIR1 = +ifneq ($(findstring $(MAKEFLAGS),w),w) +PRINT_DIR = --no-print-directory +else # "make -w" +NO_SUBDIR = : +endif + ifneq ($(findstring $(MAKEFLAGS),s),s) ifndef V QUIET_CC = @echo ' ' CC $@; @@ -616,8 +622,8 @@ ifndef V QUIET_BUILT_IN = @echo ' ' BUILTIN $@; QUIET_GEN = @echo ' ' GEN $@; QUIET_SUBDIR0 = @subdir= - QUIET_SUBDIR1 = ;echo ' ' SUBDIR $$subdir; \ - $(MAKE) --no-print-directory -C $$subdir + QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \ + $(MAKE) $(PRINT_DIR) -C $$subdir export V export QUIET_GEN export QUIET_BUILT_IN From edc04e90f5a79b7805f1188ca94f06ef7eed81f5 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Wed, 7 Mar 2007 02:21:25 +0100 Subject: [PATCH 33/69] gitweb: Don't escape attributes in CGI.pm HTML methods There is no need to escape HTML tag's attributes in CGI.pm HTML methods (like CGI::a()), because CGI.pm does attribute escaping automatically. $cgi->a({ ... -attribute => atribute_value }, tag_contents) is translated to tag_contents The rules for escaping attribute values (which are string contents) are different. For example you have to take care about escaping embedded '"' and "'" characters; CGI::a() does that for us automatically. CGI::a() does not HTML escape tag_contents; we would need to write some bold text for example. So we use esc_html (or esc_path) to escape tag_contents as needed. Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 3a564d1c48..27b5970bca 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -1974,17 +1974,17 @@ sub git_print_page_path { $fullname .= ($fullname ? '/' : '') . $dir; print $cgi->a({-href => href(action=>"tree", file_name=>$fullname, hash_base=>$hb), - -title => esc_html($fullname)}, esc_path($dir)); + -title => $fullname}, esc_path($dir)); print " / "; } if (defined $type && $type eq 'blob') { print $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name, hash_base=>$hb), - -title => esc_html($name)}, esc_path($basename)); + -title => $name}, esc_path($basename)); } elsif (defined $type && $type eq 'tree') { print $cgi->a({-href => href(action=>"tree", file_name=>$file_name, hash_base=>$hb), - -title => esc_html($name)}, esc_path($basename)); + -title => $name}, esc_path($basename)); print " / "; } else { print esc_path($basename); From ef203f08564c1c6d267fedf8e0357c56d477892f Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 7 Mar 2007 12:04:24 -0500 Subject: [PATCH 34/69] Catch write_ref_sha1 failure in receive-pack This failure to catch the failure of write_ref_sha1 was noticed by Bill Lear. The ref will not update if the log file could not be appended to (due to file permissions problems). Such a failure should be flagged as a failure to update the ref, so that the client knows the push did not succeed. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- receive-pack.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/receive-pack.c b/receive-pack.c index 7311c822dd..ea6872e46f 100644 --- a/receive-pack.c +++ b/receive-pack.c @@ -158,7 +158,10 @@ static int update(struct command *cmd) cmd->error_string = "failed to lock"; return error("failed to lock %s", name); } - write_ref_sha1(lock, new_sha1, "push"); + if (write_ref_sha1(lock, new_sha1, "push")) { + cmd->error_string = "failed to write"; + return -1; /* error() already called */ + } fprintf(stderr, "%s: %s -> %s\n", name, old_hex, new_hex); } return 0; From e3d842cf12f6ef6d155ef578957cf98d93abe09a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Santi=20B=1B=2CAi=1B=28Bjar?= Date: Wed, 7 Mar 2007 13:18:59 +0100 Subject: [PATCH 35/69] t/t5515-fetch-merge-logic.sh: Add two more tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit They test the behaviour with just a URL in the command line. Signed-off-by: Santi B,Ai(Bjar Signed-off-by: Junio C Hamano --- t/t5515-fetch-merge-logic.sh | 1 + t/t5515/fetch.br-unconfig_.._.git | 2 ++ t/t5515/fetch.master_.._.git | 2 ++ 3 files changed, 5 insertions(+) create mode 100644 t/t5515/fetch.br-unconfig_.._.git create mode 100644 t/t5515/fetch.master_.._.git diff --git a/t/t5515-fetch-merge-logic.sh b/t/t5515-fetch-merge-logic.sh index 765c83fda7..0b600bb429 100755 --- a/t/t5515-fetch-merge-logic.sh +++ b/t/t5515-fetch-merge-logic.sh @@ -114,6 +114,7 @@ done >> tests # neither in the Pull: or .fetch config for branch in master br-unconfig ; do cat < Date: Wed, 7 Mar 2007 10:43:41 +0100 Subject: [PATCH 36/69] git-archimport: allow remapping branch names This patch adds support to archimport for remapping the branch names to match those used in git more closely. This is useful for projects that migrate to git (as opposed to users that want to use git on Arch-based projects). For example, one can choose an Arch branch name and call it "master". The new command-line syntax works even if there is a colon in a branch name, since only the part after the last colon is taken to be the git name (git does not allow colons in branch names). The new feature is implemented so that archives rotated every year can also be remapped into a single git archive. Signed-off-by: Paolo Bonzini Signed-off-by: Junio C Hamano --- Documentation/git-archimport.txt | 19 +++++++- git-archimport.perl | 84 ++++++++++++++++++++++++-------- 2 files changed, 80 insertions(+), 23 deletions(-) diff --git a/Documentation/git-archimport.txt b/Documentation/git-archimport.txt index 5a13187a87..82cb41d279 100644 --- a/Documentation/git-archimport.txt +++ b/Documentation/git-archimport.txt @@ -10,7 +10,7 @@ SYNOPSIS -------- [verse] 'git-archimport' [-h] [-v] [-o] [-a] [-f] [-T] [-D depth] [-t tempdir] - [ ] + [:] ... DESCRIPTION ----------- @@ -39,6 +39,19 @@ directory. To follow the development of a project that uses Arch, rerun `git-archimport` with the same parameters as the initial import to perform incremental imports. +While git-archimport will try to create sensible branch names for the +archives that it imports, it is also possible to specify git branch names +manually. To do so, write a git branch name after each +parameter, separated by a colon. This way, you can shorten the Arch +branch names and convert Arch jargon to git jargon, for example mapping a +"PROJECT--devo--VERSION" branch to "master". + +Associating multiple Arch branches to one git branch is possible; the +result will make the most sense only if no commits are made to the first +branch, after the second branch is created. Still, this is useful to +convert Arch repositories that had been rotated periodically. + + MERGES ------ Patch merge data from Arch is used to mark merges in git as well. git @@ -73,7 +86,9 @@ OPTIONS Use this for compatibility with old-style branch names used by earlier versions of git-archimport. Old-style branch names were category--branch, whereas new-style branch names are - archive,category--branch--version. + archive,category--branch--version. In both cases, names given + on the command-line will override the automatically-generated + ones. -D :: Follow merge ancestry and attempt to import trees that have been diff --git a/git-archimport.perl b/git-archimport.perl index 0fcb156d14..c1e7c1ddcb 100755 --- a/git-archimport.perl +++ b/git-archimport.perl @@ -89,7 +89,11 @@ usage if $opt_h; # values associated with keys: # =1 - Arch version / git 'branch' detected via abrowse on a limit # >1 - Arch version / git 'branch' of an auxiliary branch we've merged -my %arch_branches = map { $_ => 1 } @ARGV; +my %arch_branches = map { my $branch = $_; $branch =~ s/:[^:]*$//; $branch => 1 } @ARGV; + +# $branch_name_map: +# maps arch branches to git branch names +my %branch_name_map = map { m/^(.*):([^:]*)$/; $1 => $2 } grep { m/:/ } @ARGV; $ENV{'TMPDIR'} = $opt_t if $opt_t; # $ENV{TMPDIR} will affect tempdir() calls: my $tmp = tempdir('git-archimport-XXXXXX', TMPDIR => 1, CLEANUP => 1); @@ -104,6 +108,7 @@ unless (-d $git_dir) { # initial import needs empty directory closedir DIR } +my $default_archive; # default Arch archive my %reachable = (); # Arch repositories we can access my %unreachable = (); # Arch repositories we can't access :< my @psets = (); # the collection @@ -303,7 +308,34 @@ sub old_style_branchname { return $ret; } -*git_branchname = $opt_o ? *old_style_branchname : *tree_dirname; +*git_default_branchname = $opt_o ? *old_style_branchname : *tree_dirname; + +# retrieve default archive, since $branch_name_map keys might not include it +sub get_default_archive { + if (!defined $default_archive) { + $default_archive = safe_pipe_capture($TLA,'my-default-archive'); + chomp $default_archive; + } + return $default_archive; +} + +sub git_branchname { + my $revision = shift; + my $name = extract_versionname($revision); + + if (exists $branch_name_map{$name}) { + return $branch_name_map{$name}; + + } elsif ($name =~ m#^([^/]*)/(.*)$# + && $1 eq get_default_archive() + && exists $branch_name_map{$2}) { + # the names given in the command-line lacked the archive. + return $branch_name_map{$2}; + + } else { + return git_default_branchname($revision); + } +} sub process_patchset_accurate { my $ps = shift; @@ -333,19 +365,23 @@ sub process_patchset_accurate { if ($ps->{tag} && (my $branchpoint = eval { ptag($ps->{tag}) })) { # find where we are supposed to branch from - system('git-checkout','-f','-b',$ps->{branch}, - $branchpoint) == 0 or die "$! $?\n"; - + if (! -e "$git_dir/refs/heads/$ps->{branch}") { + system('git-branch',$ps->{branch},$branchpoint) == 0 or die "$! $?\n"; + + # We trust Arch with the fact that this is just a tag, + # and it does not affect the state of the tree, so + # we just tag and move on. If the user really wants us + # to consolidate more branches into one, don't tag because + # the tag name would be already taken. + tag($ps->{id}, $branchpoint); + ptag($ps->{id}, $branchpoint); + print " * Tagged $ps->{id} at $branchpoint\n"; + } + system('git-checkout','-f',$ps->{branch}) == 0 or die "$! $?\n"; + # remove any old stuff that got leftover: my $rm = safe_pipe_capture('git-ls-files','--others','-z'); rmtree(split(/\0/,$rm)) if $rm; - - # If we trust Arch with the fact that this is just - # a tag, and it does not affect the state of the tree - # then we just tag and move on - tag($ps->{id}, $branchpoint); - ptag($ps->{id}, $branchpoint); - print " * Tagged $ps->{id} at $branchpoint\n"; return 0; } else { warn "Tagging from unknown id unsupported\n" if $ps->{tag}; @@ -385,14 +421,19 @@ sub process_patchset_fast { unless $branchpoint; # find where we are supposed to branch from - system('git-checkout','-b',$ps->{branch},$branchpoint); + if (! -e "$git_dir/refs/heads/$ps->{branch}") { + system('git-branch',$ps->{branch},$branchpoint) == 0 or die "$! $?\n"; - # If we trust Arch with the fact that this is just - # a tag, and it does not affect the state of the tree - # then we just tag and move on - tag($ps->{id}, $branchpoint); - ptag($ps->{id}, $branchpoint); - print " * Tagged $ps->{id} at $branchpoint\n"; + # We trust Arch with the fact that this is just a tag, + # and it does not affect the state of the tree, so + # we just tag and move on. If the user really wants us + # to consolidate more branches into one, don't tag because + # the tag name would be already taken. + tag($ps->{id}, $branchpoint); + ptag($ps->{id}, $branchpoint); + print " * Tagged $ps->{id} at $branchpoint\n"; + } + system('git-checkout',$ps->{branch}) == 0 or die "$! $?\n"; return 0; } die $! if $?; @@ -830,8 +871,9 @@ sub tag { if ($opt_o) { $tag =~ s|/|--|g; } else { - # don't use subdirs for tags yet, it could screw up other porcelains - $tag =~ s|/|,|g; + my $patchname = $tag; + $patchname =~ s/.*--//; + $tag = git_branchname ($tag) . '--' . $patchname; } if ($commit) { From 30fee0625d9e7012a3baf92c1315cfde751b8582 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 6 Mar 2007 20:44:08 -0500 Subject: [PATCH 37/69] Display the null SHA-1 as the base for an OBJ_OFS_DELTA. Because we are currently cheating and never supplying the delta base for an OBJ_OFS_DELTA we get a random SHA-1 in the delta base field. Instead lets clear the hash out so its at least all 0's. This is somewhat more obvious that something fishy is going on, like we don't actually have the SHA-1 of the base handy. :) Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- sha1_file.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sha1_file.c b/sha1_file.c index 6d0a72ed09..c13ef6675c 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1200,6 +1200,7 @@ const char *packed_object_info_detail(struct packed_git *p, obj_offset = get_delta_base(p, &w_curs, &curpos, type, obj_offset); if (*delta_chain_length == 0) { /* TODO: find base_sha1 as pointed by curpos */ + hashclr(base_sha1); } break; case OBJ_REF_DELTA: From 2d88451b7a8cdd8bc233c7910c775bbb0ac76457 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 6 Mar 2007 20:44:11 -0500 Subject: [PATCH 38/69] Fix mmap leak caused by reading bad indexes. If an index is corrupt, or is simply too new for us to understand, we were leaking the mmap that held the entire content of the index. This could be a considerable size on large projects, given that the index is at least 24 bytes * nr_objects. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- sha1_file.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/sha1_file.c b/sha1_file.c index c13ef6675c..cfce7acdbd 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -430,8 +430,9 @@ void pack_report() pack_mapped, peak_pack_mapped); } -static int check_packed_git_idx(const char *path, unsigned long *idx_size_, - void **idx_map_) +static int check_packed_git_idx(const char *path, + unsigned long *idx_size_, + void **idx_map_) { void *idx_map; uint32_t *index; @@ -446,6 +447,10 @@ static int check_packed_git_idx(const char *path, unsigned long *idx_size_, return -1; } idx_size = st.st_size; + if (idx_size < 4 * 256 + 20 + 20) { + close(fd); + return error("index file %s is too small", path); + } idx_map = xmmap(NULL, idx_size, PROT_READ, MAP_PRIVATE, fd, 0); close(fd); @@ -453,25 +458,25 @@ static int check_packed_git_idx(const char *path, unsigned long *idx_size_, *idx_map_ = idx_map; *idx_size_ = idx_size; - /* check index map */ - if (idx_size < 4*256 + 20 + 20) - return error("index file %s is too small", path); - /* a future index format would start with this, as older git * binaries would fail the non-monotonic index check below. * give a nicer warning to the user if we can. */ - if (index[0] == htonl(PACK_IDX_SIGNATURE)) + if (index[0] == htonl(PACK_IDX_SIGNATURE)) { + munmap(idx_map, idx_size); return error("index file %s is a newer version" " and is not supported by this binary" " (try upgrading GIT to a newer version)", path); + } nr = 0; for (i = 0; i < 256; i++) { unsigned int n = ntohl(index[i]); - if (n < nr) + if (n < nr) { + munmap(idx_map, idx_size); return error("non-monotonic index %s", path); + } nr = n; } @@ -482,8 +487,10 @@ static int check_packed_git_idx(const char *path, unsigned long *idx_size_, * - 20-byte SHA1 of the packfile * - 20-byte SHA1 file checksum */ - if (idx_size != 4*256 + nr * 24 + 20 + 20) + if (idx_size != 4*256 + nr * 24 + 20 + 20) { + munmap(idx_map, idx_size); return error("wrong index file size in %s", path); + } return 0; } From ff1f99453f1fe2fd9470f6ea268aed5a1839bd09 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 6 Mar 2007 20:44:14 -0500 Subject: [PATCH 39/69] Don't build external_grep if its not used Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- builtin-grep.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builtin-grep.c b/builtin-grep.c index 96b70227cf..e4f06f2b3a 100644 --- a/builtin-grep.c +++ b/builtin-grep.c @@ -150,6 +150,7 @@ static int grep_file(struct grep_opt *opt, const char *filename) return i; } +#ifdef __unix__ static int exec_grep(int argc, const char **argv) { pid_t pid; @@ -298,6 +299,7 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached) } return hit; } +#endif static int grep_cache(struct grep_opt *opt, const char **paths, int cached) { From 3a55602eeca4ac8670e8698a7187e18b95683344 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 6 Mar 2007 20:44:17 -0500 Subject: [PATCH 40/69] General const correctness fixes We shouldn't attempt to assign constant strings into char*, as the string is not writable at runtime. Likewise we should always be treating unsigned values as unsigned values, not as signed values. Most of these are very straightforward. The only exception is the (unnecessary) xstrdup/free in builtin-branch.c for the detached head case. Since this is a user-level interactive type program and that particular code path is executed no more than once, I feel that the extra xstrdup call is well worth the easy elimination of this warning. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- builtin-blame.c | 20 ++++++++++---------- builtin-branch.c | 3 ++- builtin-for-each-ref.c | 6 +++--- builtin-mailinfo.c | 6 +++--- builtin-shortlog.c | 4 ++-- builtin-show-branch.c | 3 ++- cache.h | 2 +- commit.c | 21 +++++++++------------ convert-objects.c | 2 +- environment.c | 2 +- fast-import.c | 2 +- index-pack.c | 2 +- interpolate.c | 2 +- interpolate.h | 2 +- path.c | 2 +- sha1_file.c | 3 +-- 16 files changed, 40 insertions(+), 42 deletions(-) diff --git a/builtin-blame.c b/builtin-blame.c index 9f7dd4e19f..20966b9e02 100644 --- a/builtin-blame.c +++ b/builtin-blame.c @@ -1244,26 +1244,26 @@ static void pass_blame(struct scoreboard *sb, struct origin *origin, int opt) */ struct commit_info { - char *author; - char *author_mail; + const char *author; + const char *author_mail; unsigned long author_time; - char *author_tz; + const char *author_tz; /* filled only when asked for details */ - char *committer; - char *committer_mail; + const char *committer; + const char *committer_mail; unsigned long committer_time; - char *committer_tz; + const char *committer_tz; - char *summary; + const char *summary; }; /* * Parse author/committer line in the commit object buffer */ static void get_ac_line(const char *inbuf, const char *what, - int bufsz, char *person, char **mail, - unsigned long *time, char **tz) + int bufsz, char *person, const char **mail, + unsigned long *time, const char **tz) { int len; char *tmp, *endp; @@ -1280,7 +1280,7 @@ static void get_ac_line(const char *inbuf, const char *what, if (bufsz <= len) { error_out: /* Ugh */ - person = *mail = *tz = "(unknown)"; + *mail = *tz = "(unknown)"; *time = 0; return; } diff --git a/builtin-branch.c b/builtin-branch.c index d371849655..06d8a8ce04 100644 --- a/builtin-branch.c +++ b/builtin-branch.c @@ -289,12 +289,13 @@ static void print_ref_list(int kinds, int detached, int verbose, int abbrev) detached = (detached && (kinds & REF_LOCAL_BRANCH)); if (detached) { struct ref_item item; - item.name = "(no branch)"; + item.name = xstrdup("(no branch)"); item.kind = REF_LOCAL_BRANCH; hashcpy(item.sha1, head_sha1); if (strlen(item.name) > ref_list.maxwidth) ref_list.maxwidth = strlen(item.name); print_ref_item(&item, ref_list.maxwidth, verbose, abbrev, 1); + free(item.name); } for (i = 0; i < ref_list.index; i++) { diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c index b11ca928d6..2b218425aa 100644 --- a/builtin-for-each-ref.c +++ b/builtin-for-each-ref.c @@ -301,7 +301,7 @@ static const char *find_wholine(const char *who, int wholen, const char *buf, un return ""; } -static char *copy_line(const char *buf) +static const char *copy_line(const char *buf) { const char *eol = strchr(buf, '\n'); char *line; @@ -315,7 +315,7 @@ static char *copy_line(const char *buf) return line; } -static char *copy_name(const char *buf) +static const char *copy_name(const char *buf) { const char *eol = strchr(buf, '\n'); const char *eoname = strstr(buf, " <"); @@ -330,7 +330,7 @@ static char *copy_name(const char *buf) return line; } -static char *copy_email(const char *buf) +static const char *copy_email(const char *buf) { const char *email = strchr(buf, '<'); const char *eoemail = strchr(email, '>'); diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c index 766a37ebe2..f54e8752fb 100644 --- a/builtin-mailinfo.c +++ b/builtin-mailinfo.c @@ -545,10 +545,10 @@ static int decode_b_segment(char *in, char *ot, char *ep) return 0; } -static void convert_to_utf8(char *line, char *charset) +static void convert_to_utf8(char *line, const char *charset) { - static char latin_one[] = "latin1"; - char *input_charset = *charset ? charset : latin_one; + static const char latin_one[] = "latin1"; + const char *input_charset = *charset ? charset : latin_one; char *out = reencode_string(line, metainfo_charset, input_charset); if (!out) diff --git a/builtin-shortlog.c b/builtin-shortlog.c index 2f71a2a6e2..2d7726e8b9 100644 --- a/builtin-shortlog.c +++ b/builtin-shortlog.c @@ -217,13 +217,13 @@ static void get_from_rev(struct rev_info *rev, struct path_list *list) prepare_revision_walk(rev); while ((commit = get_revision(rev)) != NULL) { - char *author = NULL, *oneline, *buffer; + const char *author = NULL, *oneline, *buffer; int authorlen = authorlen, onelinelen; /* get author and oneline */ for (buffer = commit->buffer; buffer && *buffer != '\0' && *buffer != '\n'; ) { - char *eol = strchr(buffer, '\n'); + const char *eol = strchr(buffer, '\n'); if (eol == NULL) eol = buffer + strlen(buffer); diff --git a/builtin-show-branch.c b/builtin-show-branch.c index 67ae6bacda..c892f1f7a6 100644 --- a/builtin-show-branch.c +++ b/builtin-show-branch.c @@ -721,7 +721,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) } for (i = 0; i < reflog; i++) { - char *logmsg, *msg, *m; + char *logmsg, *m; + const char *msg; unsigned long timestamp; int tz; diff --git a/cache.h b/cache.h index c291163e6d..f3d7538aab 100644 --- a/cache.h +++ b/cache.h @@ -451,7 +451,7 @@ extern char git_default_email[MAX_GITNAME]; extern char git_default_name[MAX_GITNAME]; extern char *git_commit_encoding; -extern char *git_log_output_encoding; +extern const char *git_log_output_encoding; extern int copy_fd(int ifd, int ofd); extern int read_in_full(int fd, void *buf, size_t count); diff --git a/commit.c b/commit.c index 5552527342..5b9234e12e 100644 --- a/commit.c +++ b/commit.c @@ -651,7 +651,7 @@ static char *get_header(const struct commit *commit, const char *key) } } -static char *replace_encoding_header(char *buf, char *encoding) +static char *replace_encoding_header(char *buf, const char *encoding) { char *encoding_header = strstr(buf, "\nencoding "); char *end_of_encoding_header; @@ -694,29 +694,26 @@ static char *replace_encoding_header(char *buf, char *encoding) } static char *logmsg_reencode(const struct commit *commit, - char *output_encoding) + const char *output_encoding) { + static const char *utf8 = "utf-8"; + const char *use_encoding; char *encoding; char *out; - char *utf8 = "utf-8"; if (!*output_encoding) return NULL; encoding = get_header(commit, "encoding"); - if (!encoding) - encoding = utf8; - if (!strcmp(encoding, output_encoding)) + use_encoding = encoding ? encoding : utf8; + if (!strcmp(use_encoding, output_encoding)) out = strdup(commit->buffer); else out = reencode_string(commit->buffer, - output_encoding, encoding); + output_encoding, use_encoding); if (out) out = replace_encoding_header(out, output_encoding); - if (encoding != utf8) - free(encoding); - if (!out) - return NULL; + free(encoding); return out; } @@ -917,7 +914,7 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt, const char *msg = commit->buffer; int plain_non_ascii = 0; char *reencoded; - char *encoding; + const char *encoding; if (fmt == CMIT_FMT_USERFORMAT) return format_commit_message(commit, msg, buf, space); diff --git a/convert-objects.c b/convert-objects.c index b5f41ae2e3..4809f9199f 100644 --- a/convert-objects.c +++ b/convert-objects.c @@ -132,7 +132,7 @@ static void convert_tree(void *buffer, unsigned long size, unsigned char *result unsigned long orig_size = size; while (size) { - int len = 1+strlen(buffer); + size_t len = 1+strlen(buffer); convert_binary_sha1((char *) buffer + len); diff --git a/environment.c b/environment.c index 49486dd9f1..0151ad0722 100644 --- a/environment.c +++ b/environment.c @@ -21,7 +21,7 @@ int log_all_ref_updates = -1; /* unspecified */ int warn_ambiguous_refs = 1; int repository_format_version; char *git_commit_encoding; -char *git_log_output_encoding; +const char *git_log_output_encoding; int shared_repository = PERM_UMASK; const char *apply_default_whitespace; int zlib_compression_level = Z_DEFAULT_COMPRESSION; diff --git a/fast-import.c b/fast-import.c index cc3347b23d..132dd9c938 100644 --- a/fast-import.c +++ b/fast-import.c @@ -757,7 +757,7 @@ static char *create_index(void) static char *keep_pack(char *curr_index_name) { static char name[PATH_MAX]; - static char *keep_msg = "fast-import"; + static const char *keep_msg = "fast-import"; int keep_fd; chmod(pack_data->pack_name, 0444); diff --git a/index-pack.c b/index-pack.c index cf81a99500..b405864be9 100644 --- a/index-pack.c +++ b/index-pack.c @@ -753,7 +753,7 @@ static void final(const char *final_pack_name, const char *curr_pack_name, const char *keep_name, const char *keep_msg, unsigned char *sha1) { - char *report = "pack"; + const char *report = "pack"; char name[PATH_MAX]; int err; diff --git a/interpolate.c b/interpolate.c index f992ef7753..fb30694f47 100644 --- a/interpolate.c +++ b/interpolate.c @@ -55,7 +55,7 @@ int interpolate(char *result, int reslen, const char *src = orig; char *dest = result; int newlen = 0; - char *name, *value; + const char *name, *value; int namelen, valuelen; int i; char c; diff --git a/interpolate.h b/interpolate.h index 190a180b58..16a26b9986 100644 --- a/interpolate.h +++ b/interpolate.h @@ -12,7 +12,7 @@ */ struct interp { - char *name; + const char *name; char *value; }; diff --git a/path.c b/path.c index c5d25a4b90..6395cf2309 100644 --- a/path.c +++ b/path.c @@ -252,7 +252,7 @@ char *enter_repo(char *path, int strict) if (access("objects", X_OK) == 0 && access("refs", X_OK) == 0 && validate_headref("HEAD") == 0) { - putenv("GIT_DIR=."); + setenv("GIT_DIR", ".", 1); check_repository_format(); return path; } diff --git a/sha1_file.c b/sha1_file.c index cfce7acdbd..b17a828795 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -2065,10 +2065,9 @@ int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, enum object_type type, const char *path) { unsigned long size = st->st_size; - void *buf; + void *buf = NULL; int ret, re_allocated = 0; - buf = ""; if (size) buf = xmmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); close(fd); From 326bf396778bc9ab8f9e253bb514e7f41ef1502b Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 6 Mar 2007 20:44:19 -0500 Subject: [PATCH 41/69] Use uint32_t for all packed object counts. As we permit up to 2^32-1 objects in a single packfile we cannot use a signed int to represent the object offset within a packfile, after 2^31-1 objects we will start seeing negative indexes and error out or compute bad addresses within the mmap'd index. This is a minor cleanup that does not introduce any significant logic changes. It is roach free. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- builtin-fsck.c | 2 +- cache.h | 4 ++-- pack-check.c | 8 ++++---- sha1_file.c | 10 +++++----- sha1_name.c | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/builtin-fsck.c b/builtin-fsck.c index 6abf498d2b..39cfc32818 100644 --- a/builtin-fsck.c +++ b/builtin-fsck.c @@ -632,7 +632,7 @@ int cmd_fsck(int argc, char **argv, const char *prefix) verify_pack(p, 0); for (p = packed_git; p; p = p->next) { - int num = num_packed_objects(p); + uint32_t i, num = num_packed_objects(p); for (i = 0; i < num; i++) { unsigned char sha1[20]; nth_packed_object_sha1(p, i, sha1); diff --git a/cache.h b/cache.h index f3d7538aab..63a093bcfd 100644 --- a/cache.h +++ b/cache.h @@ -425,8 +425,8 @@ extern void pack_report(void); extern unsigned char* use_pack(struct packed_git *, struct pack_window **, unsigned long, unsigned int *); extern void unuse_pack(struct pack_window **); extern struct packed_git *add_packed_git(char *, int, int); -extern int num_packed_objects(const struct packed_git *p); -extern int nth_packed_object_sha1(const struct packed_git *, int, unsigned char*); +extern uint32_t num_packed_objects(const struct packed_git *p); +extern int nth_packed_object_sha1(const struct packed_git *, uint32_t, unsigned char*); extern unsigned long find_pack_entry_one(const unsigned char *, struct packed_git *); extern void *unpack_entry(struct packed_git *, unsigned long, enum object_type *, unsigned long *); extern unsigned long unpack_object_header_gently(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep); diff --git a/pack-check.c b/pack-check.c index f248ac8c7a..7c82f6795e 100644 --- a/pack-check.c +++ b/pack-check.c @@ -9,7 +9,8 @@ static int verify_packfile(struct packed_git *p, SHA_CTX ctx; unsigned char sha1[20]; unsigned long offset = 0, pack_sig = p->pack_size - 20; - int nr_objects, err, i; + uint32_t nr_objects, i; + int err; /* Note that the pack header checks are actually performed by * use_pack when it first opens the pack file. If anything @@ -40,7 +41,7 @@ static int verify_packfile(struct packed_git *p, * we do not do scan-streaming check on the pack file. */ nr_objects = num_packed_objects(p); - for (i = err = 0; i < nr_objects; i++) { + for (i = 0, err = 0; i < nr_objects; i++) { unsigned char sha1[20]; void *data; enum object_type type; @@ -74,8 +75,7 @@ static int verify_packfile(struct packed_git *p, static void show_pack_info(struct packed_git *p) { - int nr_objects, i; - unsigned int chain_histogram[MAX_CHAIN]; + uint32_t nr_objects, i, chain_histogram[MAX_CHAIN]; nr_objects = num_packed_objects(p); memset(chain_histogram, 0, sizeof(chain_histogram)); diff --git a/sha1_file.c b/sha1_file.c index b17a828795..54ffa7c703 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -437,7 +437,7 @@ static int check_packed_git_idx(const char *path, void *idx_map; uint32_t *index; unsigned long idx_size; - int nr, i; + uint32_t nr, i; int fd = open(path, O_RDONLY); struct stat st; if (fd < 0) @@ -472,7 +472,7 @@ static int check_packed_git_idx(const char *path, nr = 0; for (i = 0; i < 256; i++) { - unsigned int n = ntohl(index[i]); + uint32_t n = ntohl(index[i]); if (n < nr) { munmap(idx_map, idx_size); return error("non-monotonic index %s", path); @@ -1339,17 +1339,17 @@ void *unpack_entry(struct packed_git *p, unsigned long obj_offset, return data; } -int num_packed_objects(const struct packed_git *p) +uint32_t num_packed_objects(const struct packed_git *p) { /* See check_packed_git_idx() */ return (p->index_size - 20 - 20 - 4*256) / 24; } -int nth_packed_object_sha1(const struct packed_git *p, int n, +int nth_packed_object_sha1(const struct packed_git *p, uint32_t n, unsigned char* sha1) { void *index = p->index_base + 256; - if (n < 0 || num_packed_objects(p) <= n) + if (num_packed_objects(p) <= n) return -1; hashcpy(sha1, (unsigned char *) index + (24 * n) + 4); return 0; diff --git a/sha1_name.c b/sha1_name.c index 0781477a71..31812d3d26 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -76,10 +76,10 @@ static int find_short_packed_object(int len, const unsigned char *match, unsigne prepare_packed_git(); for (p = packed_git; p && found < 2; p = p->next) { - unsigned num = num_packed_objects(p); - unsigned first = 0, last = num; + uint32_t num = num_packed_objects(p); + uint32_t first = 0, last = num; while (first < last) { - unsigned mid = (first + last) / 2; + uint32_t mid = (first + last) / 2; unsigned char now[20]; int cmp; From 7cadf491c6d7a29e345e1608c23b0d98cee5e848 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 6 Mar 2007 20:44:24 -0500 Subject: [PATCH 42/69] Use uint32_t for pack-objects counters. As we technically try to support up to a maximum of 2**32-1 objects in a single packfile we should act like it and use unsigned 32 bit integers for all of our object counts and progress output. This change does not modify everything in pack-objects that probably needs to change to fully support the maximum of 2**32-1 objects. I'm intentionally breaking the improvements into slightly smaller commits to make them easier to follow. No logic change should be occuring here, with the exception that some comparsions will now work properly when the number of objects exceeds 2**31-1. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- builtin-pack-objects.c | 63 ++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index 8cf24f4079..8d5c3f14ac 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -68,7 +68,7 @@ static int allow_ofs_delta; static struct object_entry **sorted_by_sha, **sorted_by_type; static struct object_entry *objects; -static int nr_objects, nr_alloc, nr_result; +static uint32_t nr_objects, nr_alloc, nr_result; static const char *base_name; static unsigned char pack_file_sha1[20]; static int progress = 1; @@ -114,10 +114,8 @@ static int pack_revindex_hashsz; /* * stats */ -static int written; -static int written_delta; -static int reused; -static int reused_delta; +static uint32_t written, written_delta; +static uint32_t reused, reused_delta; static int pack_revindex_ix(struct packed_git *p) { @@ -518,7 +516,7 @@ static unsigned long write_one(struct sha1file *f, static void write_pack_file(void) { - int i; + uint32_t i; struct sha1file *f; unsigned long offset; struct pack_header hdr; @@ -533,7 +531,7 @@ static void write_pack_file(void) f = sha1create("%s-%s.%s", base_name, sha1_to_hex(object_list_sha1), "pack"); if (do_progress) - fprintf(stderr, "Writing %d objects.\n", nr_result); + fprintf(stderr, "Writing %u objects.\n", nr_result); hdr.hdr_signature = htonl(PACK_SIGNATURE); hdr.hdr_version = htonl(PACK_VERSION); @@ -558,13 +556,13 @@ static void write_pack_file(void) fputc('\n', stderr); done: if (written != nr_result) - die("wrote %d objects while expecting %d", written, nr_result); + die("wrote %u objects while expecting %u", written, nr_result); sha1close(f, pack_file_sha1, 1); } static void write_index_file(void) { - int i; + uint32_t i; struct sha1file *f = sha1create("%s-%s.%s", base_name, sha1_to_hex(object_list_sha1), "idx"); struct object_entry **list = sorted_by_sha; @@ -633,7 +631,7 @@ static struct object_entry *locate_object_entry(const unsigned char *sha1) static void rehash_objects(void) { - int i; + uint32_t i; struct object_entry *oe; object_ix_hashsz = nr_objects * 3; @@ -670,7 +668,7 @@ static unsigned name_hash(const char *name) static int add_object_entry(const unsigned char *sha1, unsigned hash, int exclude) { - unsigned int idx = nr_objects; + uint32_t idx = nr_objects; struct object_entry *entry; struct packed_git *p; unsigned int found_offset = 0; @@ -696,9 +694,8 @@ static int add_object_entry(const unsigned char *sha1, unsigned hash, int exclud goto already_added; if (idx >= nr_alloc) { - unsigned int needed = (idx + 1024) * 3 / 2; - objects = xrealloc(objects, needed * sizeof(*entry)); - nr_alloc = needed; + nr_alloc = (idx + 1024) * 3 / 2; + objects = xrealloc(objects, nr_alloc * sizeof(*entry)); } entry = objects + idx; nr_objects = idx + 1; @@ -718,7 +715,7 @@ static int add_object_entry(const unsigned char *sha1, unsigned hash, int exclud already_added: if (progress_update) { - fprintf(stderr, "Counting objects...%d\r", nr_objects); + fprintf(stderr, "Counting objects...%u\r", nr_objects); progress_update = 0; } if (exclude) @@ -1081,7 +1078,7 @@ static unsigned int check_delta_limit(struct object_entry *me, unsigned int n) static void get_object_details(void) { - int i; + uint32_t i; struct object_entry *entry; prepare_pack_ix(); @@ -1120,7 +1117,7 @@ static int sort_comparator(const void *_a, const void *_b) static struct object_entry **create_sorted_list(entry_sort_t sort) { struct object_entry **list = xmalloc(nr_objects * sizeof(struct object_entry *)); - int i; + uint32_t i; for (i = 0; i < nr_objects; i++) list[i] = objects + i; @@ -1137,7 +1134,7 @@ static int sha1_sort(const struct object_entry *a, const struct object_entry *b) static struct object_entry **create_final_object_list(void) { struct object_entry **list; - int i, j; + uint32_t i, j; for (i = nr_result = 0; i < nr_objects; i++) if (!objects[i].preferred_base) @@ -1279,20 +1276,20 @@ static void progress_interval(int signum) static void find_deltas(struct object_entry **list, int window, int depth) { - int i, idx; + uint32_t i = nr_objects, idx = 0, processed = 0; unsigned int array_size = window * sizeof(struct unpacked); - struct unpacked *array = xmalloc(array_size); - unsigned processed = 0; + struct unpacked *array; unsigned last_percent = 999; + if (!nr_objects) + return; + array = xmalloc(array_size); memset(array, 0, array_size); - i = nr_objects; - idx = 0; if (progress) - fprintf(stderr, "Deltifying %d objects.\n", nr_result); + fprintf(stderr, "Deltifying %u objects.\n", nr_result); - while (--i >= 0) { - struct object_entry *entry = list[i]; + do { + struct object_entry *entry = list[--i]; struct unpacked *n = array + idx; int j; @@ -1325,7 +1322,7 @@ static void find_deltas(struct object_entry **list, int window, int depth) j = window; while (--j > 0) { - unsigned int other_idx = idx + j; + uint32_t other_idx = idx + j; struct unpacked *m; if (other_idx >= window) other_idx -= window; @@ -1345,7 +1342,7 @@ static void find_deltas(struct object_entry **list, int window, int depth) idx++; if (idx >= window) idx = 0; - } + } while (i > 0); if (progress) fputc('\n', stderr); @@ -1386,7 +1383,7 @@ static int reuse_cached_pack(unsigned char *sha1) } if (progress) - fprintf(stderr, "Reusing %d objects pack %s\n", nr_objects, + fprintf(stderr, "Reusing %u objects pack %s\n", nr_objects, sha1_to_hex(sha1)); if (pack_to_stdout) { @@ -1537,7 +1534,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) struct object_entry **list; int use_internal_rev_list = 0; int thin = 0; - int i; + uint32_t i; const char **rp_av; int rp_ac_alloc = 64; int rp_ac; @@ -1670,7 +1667,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) } if (progress) - fprintf(stderr, "Done counting %d objects.\n", nr_objects); + fprintf(stderr, "Done counting %u objects.\n", nr_objects); sorted_by_sha = create_final_object_list(); if (non_empty && !nr_result) return 0; @@ -1683,7 +1680,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) } SHA1_Final(object_list_sha1, &ctx); if (progress && (nr_objects != nr_result)) - fprintf(stderr, "Result has %d objects.\n", nr_result); + fprintf(stderr, "Result has %u objects.\n", nr_result); if (reuse_cached_pack(object_list_sha1)) ; @@ -1704,7 +1701,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) } } if (progress) - fprintf(stderr, "Total %d (delta %d), reused %d (delta %d)\n", + fprintf(stderr, "Total %u (delta %u), reused %u (delta %u)\n", written, written_delta, reused, reused_delta); return 0; } From c4001d92be61766d3494489b15590ca0147ee19d Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 6 Mar 2007 20:44:30 -0500 Subject: [PATCH 43/69] Use off_t when we really mean a file offset. Not all platforms have declared 'unsigned long' to be a 64 bit value, but we want to support a 64 bit packfile (or close enough anyway) in the near future as some projects are getting large enough that their packed size exceeds 4 GiB. By using off_t, the POSIX type that is declared to mean an offset within a file, we support whatever maximum file size the underlying operating system will handle. For most modern systems this is up around 2^60 or higher. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- cache.h | 10 ++++----- fast-import.c | 4 ---- git-compat-util.h | 4 ++++ pack-check.c | 21 ++++++++++-------- pack-redundant.c | 8 +++---- sha1_file.c | 54 +++++++++++++++++++++++++---------------------- 6 files changed, 54 insertions(+), 47 deletions(-) diff --git a/cache.h b/cache.h index 63a093bcfd..ae25759c43 100644 --- a/cache.h +++ b/cache.h @@ -383,7 +383,7 @@ extern struct packed_git { } *packed_git; struct pack_entry { - unsigned int offset; + off_t offset; unsigned char sha1[20]; struct packed_git *p; }; @@ -422,15 +422,15 @@ extern struct packed_git *find_sha1_pack(const unsigned char *sha1, struct packed_git *packs); extern void pack_report(void); -extern unsigned char* use_pack(struct packed_git *, struct pack_window **, unsigned long, unsigned int *); +extern unsigned char* use_pack(struct packed_git *, struct pack_window **, off_t, unsigned int *); extern void unuse_pack(struct pack_window **); extern struct packed_git *add_packed_git(char *, int, int); extern uint32_t num_packed_objects(const struct packed_git *p); extern int nth_packed_object_sha1(const struct packed_git *, uint32_t, unsigned char*); -extern unsigned long find_pack_entry_one(const unsigned char *, struct packed_git *); -extern void *unpack_entry(struct packed_git *, unsigned long, enum object_type *, unsigned long *); +extern off_t find_pack_entry_one(const unsigned char *, struct packed_git *); +extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsigned long *); extern unsigned long unpack_object_header_gently(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep); -extern const char *packed_object_info_detail(struct packed_git *, unsigned long, unsigned long *, unsigned long *, unsigned int *, unsigned char *); +extern const char *packed_object_info_detail(struct packed_git *, off_t, unsigned long *, unsigned long *, unsigned int *, unsigned char *); /* Dumb servers support */ extern int update_server_info(int); diff --git a/fast-import.c b/fast-import.c index 132dd9c938..a418a174d0 100644 --- a/fast-import.c +++ b/fast-import.c @@ -133,10 +133,6 @@ Format of STDIN stream: #define PACK_ID_BITS 16 #define MAX_PACK_ID ((1<index_size; + off_t index_size = p->index_size; void *index_base = p->index_base; SHA_CTX ctx; unsigned char sha1[20]; - unsigned long offset = 0, pack_sig = p->pack_size - 20; + off_t offset = 0, pack_sig = p->pack_size - 20; uint32_t nr_objects, i; int err; @@ -24,7 +24,7 @@ static int verify_packfile(struct packed_git *p, unsigned char *in = use_pack(p, w_curs, offset, &remaining); offset += remaining; if (offset > pack_sig) - remaining -= offset - pack_sig; + remaining -= (unsigned int)(offset - pack_sig); SHA1_Update(&ctx, in, remaining); } SHA1_Final(sha1, &ctx); @@ -45,7 +45,8 @@ static int verify_packfile(struct packed_git *p, unsigned char sha1[20]; void *data; enum object_type type; - unsigned long size, offset; + unsigned long size; + off_t offset; if (nth_packed_object_sha1(p, i, sha1)) die("internal error pack-check nth-packed-object"); @@ -85,7 +86,7 @@ static void show_pack_info(struct packed_git *p) const char *type; unsigned long size; unsigned long store_size; - unsigned long offset; + off_t offset; unsigned int delta_chain_length; if (nth_packed_object_sha1(p, i, sha1)) @@ -99,9 +100,11 @@ static void show_pack_info(struct packed_git *p) base_sha1); printf("%s ", sha1_to_hex(sha1)); if (!delta_chain_length) - printf("%-6s %lu %lu\n", type, size, offset); + printf("%-6s %lu %"PRIuMAX"\n", + type, size, (uintmax_t)offset); else { - printf("%-6s %lu %lu %u %s\n", type, size, offset, + printf("%-6s %lu %"PRIuMAX" %u %s\n", + type, size, (uintmax_t)offset, delta_chain_length, sha1_to_hex(base_sha1)); if (delta_chain_length < MAX_CHAIN) chain_histogram[delta_chain_length]++; @@ -123,7 +126,7 @@ static void show_pack_info(struct packed_git *p) int verify_pack(struct packed_git *p, int verbose) { - unsigned long index_size = p->index_size; + off_t index_size = p->index_size; void *index_base = p->index_base; SHA_CTX ctx; unsigned char sha1[20]; @@ -132,7 +135,7 @@ int verify_pack(struct packed_git *p, int verbose) ret = 0; /* Verify SHA1 sum of the index file */ SHA1_Init(&ctx); - SHA1_Update(&ctx, index_base, index_size - 20); + SHA1_Update(&ctx, index_base, (unsigned int)(index_size - 20)); SHA1_Final(sha1, &ctx); if (hashcmp(sha1, (unsigned char *)index_base + index_size - 20)) ret = error("Packfile index for %s SHA1 mismatch", diff --git a/pack-redundant.c b/pack-redundant.c index edb5524fc4..c8f7d9af7b 100644 --- a/pack-redundant.c +++ b/pack-redundant.c @@ -396,9 +396,9 @@ static size_t get_pack_redundancy(struct pack_list *pl) return ret; } -static inline size_t pack_set_bytecount(struct pack_list *pl) +static inline off_t pack_set_bytecount(struct pack_list *pl) { - size_t ret = 0; + off_t ret = 0; while (pl) { ret += pl->pack->pack_size; ret += pl->pack->index_size; @@ -413,7 +413,7 @@ static void minimize(struct pack_list **min) *non_unique = NULL, *min_perm = NULL; struct pll *perm, *perm_all, *perm_ok = NULL, *new_perm; struct llist *missing; - size_t min_perm_size = (size_t)-1, perm_size; + off_t min_perm_size = 0, perm_size; int n; pl = local_packs; @@ -461,7 +461,7 @@ static void minimize(struct pack_list **min) perm = perm_ok; while (perm) { perm_size = pack_set_bytecount(perm->pl); - if (min_perm_size > perm_size) { + if (!min_perm_size || min_perm_size > perm_size) { min_perm_size = perm_size; min_perm = perm->pl; } diff --git a/sha1_file.c b/sha1_file.c index 54ffa7c703..50d800eea0 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -629,7 +629,7 @@ static int open_packed_git(struct packed_git *p) return -1; } -static int in_window(struct pack_window *win, unsigned long offset) +static int in_window(struct pack_window *win, off_t offset) { /* We must promise at least 20 bytes (one hash) after the * offset is available from this window, otherwise the offset @@ -644,7 +644,7 @@ static int in_window(struct pack_window *win, unsigned long offset) unsigned char* use_pack(struct packed_git *p, struct pack_window **w_cursor, - unsigned long offset, + off_t offset, unsigned int *left) { struct pack_window *win = *w_cursor; @@ -1049,14 +1049,14 @@ void * unpack_sha1_file(void *map, unsigned long mapsize, enum object_type *type return unpack_sha1_rest(&stream, hdr, *size); } -static unsigned long get_delta_base(struct packed_git *p, +static off_t get_delta_base(struct packed_git *p, struct pack_window **w_curs, - unsigned long *curpos, + off_t *curpos, enum object_type type, - unsigned long delta_obj_offset) + off_t delta_obj_offset) { unsigned char *base_info = use_pack(p, w_curs, *curpos, NULL); - unsigned long base_offset; + off_t base_offset; /* use_pack() assured us we have [base_info, base_info + 20) * as a range that we can look at without walking off the @@ -1092,17 +1092,17 @@ static unsigned long get_delta_base(struct packed_git *p, } /* forward declaration for a mutually recursive function */ -static int packed_object_info(struct packed_git *p, unsigned long offset, +static int packed_object_info(struct packed_git *p, off_t offset, unsigned long *sizep); static int packed_delta_info(struct packed_git *p, struct pack_window **w_curs, - unsigned long curpos, + off_t curpos, enum object_type type, - unsigned long obj_offset, + off_t obj_offset, unsigned long *sizep) { - unsigned long base_offset; + off_t base_offset; base_offset = get_delta_base(p, w_curs, &curpos, type, obj_offset); type = packed_object_info(p, base_offset, NULL); @@ -1152,7 +1152,7 @@ static int packed_delta_info(struct packed_git *p, static int unpack_object_header(struct packed_git *p, struct pack_window **w_curs, - unsigned long *curpos, + off_t *curpos, unsigned long *sizep) { unsigned char *base; @@ -1176,14 +1176,15 @@ static int unpack_object_header(struct packed_git *p, } const char *packed_object_info_detail(struct packed_git *p, - unsigned long obj_offset, + off_t obj_offset, unsigned long *size, unsigned long *store_size, unsigned int *delta_chain_length, unsigned char *base_sha1) { struct pack_window *w_curs = NULL; - unsigned long curpos, dummy; + off_t curpos; + unsigned long dummy; unsigned char *next_sha1; enum object_type type; @@ -1223,11 +1224,12 @@ const char *packed_object_info_detail(struct packed_git *p, } } -static int packed_object_info(struct packed_git *p, unsigned long obj_offset, +static int packed_object_info(struct packed_git *p, off_t obj_offset, unsigned long *sizep) { struct pack_window *w_curs = NULL; - unsigned long size, curpos = obj_offset; + unsigned long size; + off_t curpos = obj_offset; enum object_type type; type = unpack_object_header(p, &w_curs, &curpos, &size); @@ -1255,7 +1257,7 @@ static int packed_object_info(struct packed_git *p, unsigned long obj_offset, static void *unpack_compressed_entry(struct packed_git *p, struct pack_window **w_curs, - unsigned long curpos, + off_t curpos, unsigned long size) { int st; @@ -1286,20 +1288,22 @@ static void *unpack_compressed_entry(struct packed_git *p, static void *unpack_delta_entry(struct packed_git *p, struct pack_window **w_curs, - unsigned long curpos, + off_t curpos, unsigned long delta_size, - unsigned long obj_offset, + off_t obj_offset, enum object_type *type, unsigned long *sizep) { void *delta_data, *result, *base; - unsigned long base_size, base_offset; + unsigned long base_size; + off_t base_offset; base_offset = get_delta_base(p, w_curs, &curpos, *type, obj_offset); base = unpack_entry(p, base_offset, type, &base_size); if (!base) - die("failed to read delta base object at %lu from %s", - base_offset, p->pack_name); + die("failed to read delta base object" + " at %"PRIuMAX" from %s", + (uintmax_t)base_offset, p->pack_name); delta_data = unpack_compressed_entry(p, w_curs, curpos, delta_size); result = patch_delta(base, base_size, @@ -1312,11 +1316,11 @@ static void *unpack_delta_entry(struct packed_git *p, return result; } -void *unpack_entry(struct packed_git *p, unsigned long obj_offset, +void *unpack_entry(struct packed_git *p, off_t obj_offset, enum object_type *type, unsigned long *sizep) { struct pack_window *w_curs = NULL; - unsigned long curpos = obj_offset; + off_t curpos = obj_offset; void *data; *type = unpack_object_header(p, &w_curs, &curpos, sizep); @@ -1355,7 +1359,7 @@ int nth_packed_object_sha1(const struct packed_git *p, uint32_t n, return 0; } -unsigned long find_pack_entry_one(const unsigned char *sha1, +off_t find_pack_entry_one(const unsigned char *sha1, struct packed_git *p) { uint32_t *level1_ofs = p->index_base; @@ -1397,7 +1401,7 @@ static int matches_pack_name(struct packed_git *p, const char *ig) static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e, const char **ignore_packed) { struct packed_git *p; - unsigned long offset; + off_t offset; prepare_packed_git(); From 6777a59fcdfd96b9ca5cba49cb265c6c47de3d02 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 6 Mar 2007 20:44:34 -0500 Subject: [PATCH 44/69] Use off_t in pack-objects/fast-import when we mean an offset Always use an off_t value in pack-objects anytime we are dealing with an offset to some data within a packfile. Also fixed a minor uintmax_t that was incorrectly defined before. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- builtin-pack-objects.c | 52 +++++++++++++++++++++--------------------- fast-import.c | 4 ++-- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index 8d5c3f14ac..f8ebad0b2f 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -23,7 +23,7 @@ git-pack-objects [{ -q | --progress | --all-progress }] \n\ struct object_entry { unsigned char sha1[20]; unsigned long size; /* uncompressed size */ - unsigned long offset; /* offset into the final pack file; + off_t offset; /* offset into the final pack file; * nonzero if already written. */ unsigned int depth; /* delta depth */ @@ -35,7 +35,7 @@ struct object_entry { #define in_pack_header_size delta_size /* only when reusing pack data */ struct object_entry *delta; /* delta base object */ struct packed_git *in_pack; /* already in pack */ - unsigned int in_pack_offset; + off_t in_pack_offset; struct object_entry *delta_child; /* deltified objects who bases me */ struct object_entry *delta_sibling; /* other deltified objects who * uses the same base as me @@ -101,7 +101,7 @@ static int object_ix_hashsz; * get the object sha1 from the main index. */ struct revindex_entry { - unsigned int offset; + off_t offset; unsigned int nr; }; struct pack_revindex { @@ -183,7 +183,7 @@ static void prepare_pack_revindex(struct pack_revindex *rix) } static struct revindex_entry * find_packed_object(struct packed_git *p, - unsigned int ofs) + off_t ofs) { int num; int lo, hi; @@ -211,15 +211,14 @@ static struct revindex_entry * find_packed_object(struct packed_git *p, die("internal error: pack revindex corrupt"); } -static unsigned long find_packed_object_size(struct packed_git *p, - unsigned long ofs) +static off_t find_packed_object_size(struct packed_git *p, off_t ofs) { struct revindex_entry *entry = find_packed_object(p, ofs); return entry[1].offset - ofs; } static unsigned char *find_packed_object_name(struct packed_git *p, - unsigned long ofs) + off_t ofs) { struct revindex_entry *entry = find_packed_object(p, ofs); return (unsigned char *)(p->index_base + 256) + 24 * entry->nr + 4; @@ -276,8 +275,8 @@ static int encode_header(enum object_type type, unsigned long size, unsigned cha */ static int check_pack_inflate(struct packed_git *p, struct pack_window **w_curs, - unsigned long offset, - unsigned long len, + off_t offset, + off_t len, unsigned long expect) { z_stream stream; @@ -303,8 +302,8 @@ static int check_pack_inflate(struct packed_git *p, static void copy_pack_data(struct sha1file *f, struct packed_git *p, struct pack_window **w_curs, - unsigned long offset, - unsigned long len) + off_t offset, + off_t len) { unsigned char *in; unsigned int avail; @@ -312,7 +311,7 @@ static void copy_pack_data(struct sha1file *f, while (len) { in = use_pack(p, w_curs, offset, &avail); if (avail > len) - avail = len; + avail = (unsigned int)len; sha1write(f, in, avail); offset += avail; len -= avail; @@ -369,14 +368,15 @@ static int revalidate_loose_object(struct object_entry *entry, return check_loose_inflate(map, mapsize, size); } -static unsigned long write_object(struct sha1file *f, +static off_t write_object(struct sha1file *f, struct object_entry *entry) { unsigned long size; enum object_type type; void *buf; unsigned char header[10]; - unsigned hdrlen, datalen; + unsigned hdrlen; + off_t datalen; enum object_type obj_type; int to_reuse = 0; @@ -439,7 +439,7 @@ static unsigned long write_object(struct sha1file *f, * encoding of the relative offset for the delta * base from this object's position in the pack. */ - unsigned long ofs = entry->offset - entry->delta->offset; + off_t ofs = entry->offset - entry->delta->offset; unsigned pos = sizeof(header) - 1; header[pos] = ofs & 127; while (ofs >>= 7) @@ -460,7 +460,7 @@ static unsigned long write_object(struct sha1file *f, else { struct packed_git *p = entry->in_pack; struct pack_window *w_curs = NULL; - unsigned long offset; + off_t offset; if (entry->delta) { obj_type = (allow_ofs_delta && entry->delta->offset) ? @@ -470,7 +470,7 @@ static unsigned long write_object(struct sha1file *f, hdrlen = encode_header(obj_type, entry->size, header); sha1write(f, header, hdrlen); if (obj_type == OBJ_OFS_DELTA) { - unsigned long ofs = entry->offset - entry->delta->offset; + off_t ofs = entry->offset - entry->delta->offset; unsigned pos = sizeof(header) - 1; header[pos] = ofs & 127; while (ofs >>= 7) @@ -498,9 +498,9 @@ static unsigned long write_object(struct sha1file *f, return hdrlen + datalen; } -static unsigned long write_one(struct sha1file *f, +static off_t write_one(struct sha1file *f, struct object_entry *e, - unsigned long offset) + off_t offset) { if (e->offset || e->preferred_base) /* offset starts from header size and cannot be zero @@ -518,7 +518,7 @@ static void write_pack_file(void) { uint32_t i; struct sha1file *f; - unsigned long offset; + off_t offset; struct pack_header hdr; unsigned last_percent = 999; int do_progress = progress; @@ -671,13 +671,13 @@ static int add_object_entry(const unsigned char *sha1, unsigned hash, int exclud uint32_t idx = nr_objects; struct object_entry *entry; struct packed_git *p; - unsigned int found_offset = 0; + off_t found_offset = 0; struct packed_git *found_pack = NULL; int ix, status = 0; if (!exclude) { for (p = packed_git; p; p = p->next) { - unsigned long offset = find_pack_entry_one(sha1, p); + off_t offset = find_pack_entry_one(sha1, p); if (offset) { if (incremental) return 0; @@ -978,17 +978,17 @@ static void check_object(struct object_entry *entry) if (entry->in_pack && !entry->preferred_base) { struct packed_git *p = entry->in_pack; struct pack_window *w_curs = NULL; - unsigned long left = p->pack_size - entry->in_pack_offset; unsigned long size, used; + unsigned int avail; unsigned char *buf; struct object_entry *base_entry = NULL; - buf = use_pack(p, &w_curs, entry->in_pack_offset, NULL); + buf = use_pack(p, &w_curs, entry->in_pack_offset, &avail); /* We want in_pack_type even if we do not reuse delta. * There is no point not reusing non-delta representations. */ - used = unpack_object_header_gently(buf, left, + used = unpack_object_header_gently(buf, avail, &entry->in_pack_type, &size); /* Check if it is delta, and the base is also an object @@ -997,7 +997,7 @@ static void check_object(struct object_entry *entry) */ if (!no_reuse_delta) { unsigned char c, *base_name; - unsigned long ofs; + off_t ofs; unsigned long used_0; /* there is at least 20 bytes left in the pack */ switch (entry->in_pack_type) { diff --git a/fast-import.c b/fast-import.c index a418a174d0..fda50188ea 100644 --- a/fast-import.c +++ b/fast-import.c @@ -249,7 +249,7 @@ typedef enum { /* Configured limits on output */ static unsigned long max_depth = 10; -static unsigned long max_packsize = (1LL << 32) - 1; +static off_t max_packsize = (1LL << 32) - 1; static int force_update; /* Stats and misc. counters */ @@ -1527,7 +1527,7 @@ static void unload_one_branch(void) { while (cur_active_branches && cur_active_branches >= max_active_branches) { - unsigned long min_commit = ULONG_MAX; + uintmax_t min_commit = ULONG_MAX; struct branch *e, *l = NULL, *p = NULL; for (e = active_branches; e; e = e->active_next_branch) { From dc49cd769b5fa6b7e0114b051c34a849828a7603 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 6 Mar 2007 20:44:37 -0500 Subject: [PATCH 45/69] Cast 64 bit off_t to 32 bit size_t Some systems have sizeof(off_t) == 8 while sizeof(size_t) == 4. This implies that we are able to access and work on files whose maximum length is around 2^63-1 bytes, but we can only malloc or mmap somewhat less than 2^32-1 bytes of memory. On such a system an implicit conversion of off_t to size_t can cause the size_t to wrap, resulting in unexpected and exciting behavior. Right now we are working around all gcc warnings generated by the -Wshorten-64-to-32 option by passing the off_t through xsize_t(). In the future we should make xsize_t on such problematic platforms detect the wrapping and die if such a file is accessed. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- builtin-apply.c | 2 +- builtin-blame.c | 2 +- builtin-count-objects.c | 2 +- builtin-grep.c | 9 ++++++--- combine-diff.c | 4 ++-- config.c | 28 +++++++++++++++------------- diff.c | 9 +++++---- diffcore-break.c | 2 +- diffcore-order.c | 6 ++++-- diffcore-rename.c | 7 ++++--- dir.c | 4 ++-- git-compat-util.h | 5 +++++ read-cache.c | 6 +++--- refs.c | 8 +++++--- sha1_file.c | 40 +++++++++++++++++++++++----------------- xdiff-interface.c | 8 +++++--- 16 files changed, 83 insertions(+), 59 deletions(-) diff --git a/builtin-apply.c b/builtin-apply.c index 53935109a3..dfa1716796 100644 --- a/builtin-apply.c +++ b/builtin-apply.c @@ -1981,7 +1981,7 @@ static int apply_data(struct patch *patch, struct stat *st, struct cache_entry * } } else if (patch->old_name) { - size = st->st_size; + size = xsize_t(st->st_size); alloc = size + 8192; buf = xmalloc(alloc); if (read_old_data(st, patch->old_name, &buf, &alloc, &size)) diff --git a/builtin-blame.c b/builtin-blame.c index 20966b9e02..b51cdc71fa 100644 --- a/builtin-blame.c +++ b/builtin-blame.c @@ -1963,7 +1963,7 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con die("Cannot lstat %s", path); read_from = path; } - fin_size = st.st_size; + fin_size = xsize_t(st.st_size); buf = xmalloc(fin_size+1); mode = canon_mode(st.st_mode); switch (st.st_mode & S_IFMT) { diff --git a/builtin-count-objects.c b/builtin-count-objects.c index f5b22bb80e..6263d8af29 100644 --- a/builtin-count-objects.c +++ b/builtin-count-objects.c @@ -44,7 +44,7 @@ static void count_objects(DIR *d, char *path, int len, int verbose, if (lstat(path, &st) || !S_ISREG(st.st_mode)) bad = 1; else - (*loose_size) += st.st_blocks; + (*loose_size) += xsize_t(st.st_blocks); } if (bad) { if (verbose) { diff --git a/builtin-grep.c b/builtin-grep.c index e4f06f2b3a..694da5ba09 100644 --- a/builtin-grep.c +++ b/builtin-grep.c @@ -122,6 +122,8 @@ static int grep_file(struct grep_opt *opt, const char *filename) struct stat st; int i; char *data; + size_t sz; + if (lstat(filename, &st) < 0) { err_ret: if (errno != ENOENT) @@ -132,11 +134,12 @@ static int grep_file(struct grep_opt *opt, const char *filename) return 0; /* empty file -- no grep hit */ if (!S_ISREG(st.st_mode)) return 0; + sz = xsize_t(st.st_size); i = open(filename, O_RDONLY); if (i < 0) goto err_ret; - data = xmalloc(st.st_size + 1); - if (st.st_size != read_in_full(i, data, st.st_size)) { + data = xmalloc(sz + 1); + if (st.st_size != read_in_full(i, data, sz)) { error("'%s': short read %s", filename, strerror(errno)); close(i); free(data); @@ -145,7 +148,7 @@ static int grep_file(struct grep_opt *opt, const char *filename) close(i); if (opt->relative && opt->prefix_length) filename += opt->prefix_length; - i = grep_buffer(opt, filename, data, st.st_size); + i = grep_buffer(opt, filename, data, sz); free(data); return i; } diff --git a/combine-diff.c b/combine-diff.c index 6d928f282a..3a9b32f6b8 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -684,7 +684,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent, goto deleted_file; if (S_ISLNK(st.st_mode)) { - size_t len = st.st_size; + size_t len = xsize_t(st.st_size); result_size = len; result = xmalloc(len + 1); if (result_size != readlink(elem->path, result, len)) { @@ -697,7 +697,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent, } else if (0 <= (fd = open(elem->path, O_RDONLY)) && !fstat(fd, &st)) { - size_t len = st.st_size; + size_t len = xsize_t(st.st_size); size_t sz = 0; int is_file, i; diff --git a/config.c b/config.c index 7ac3947858..8fc4f11f45 100644 --- a/config.c +++ b/config.c @@ -431,7 +431,7 @@ static struct { int do_not_match; regex_t* value_regex; int multi_replace; - off_t offset[MAX_MATCHES]; + size_t offset[MAX_MATCHES]; enum { START, SECTION_SEEN, SECTION_END_SEEN, KEY_SEEN } state; int seen; } store; @@ -579,11 +579,11 @@ static int store_write_pair(int fd, const char* key, const char* value) return 1; } -static int find_beginning_of_line(const char* contents, int size, - int offset_, int* found_bracket) +static ssize_t find_beginning_of_line(const char* contents, size_t size, + size_t offset_, int* found_bracket) { - int equal_offset = size, bracket_offset = size; - int offset; + size_t equal_offset = size, bracket_offset = size; + ssize_t offset; for (offset = offset_-2; offset > 0 && contents[offset] != '\n'; offset--) @@ -727,7 +727,8 @@ int git_config_set_multivar(const char* key, const char* value, } else { struct stat st; char* contents; - int i, copy_begin, copy_end, new_line = 0; + size_t contents_sz, copy_begin, copy_end; + int i, new_line = 0; if (value_regex == NULL) store.value_regex = NULL; @@ -784,7 +785,8 @@ int git_config_set_multivar(const char* key, const char* value, } fstat(in_fd, &st); - contents = xmmap(NULL, st.st_size, PROT_READ, + contents_sz = xsize_t(st.st_size); + contents = xmmap(NULL, contents_sz, PROT_READ, MAP_PRIVATE, in_fd, 0); close(in_fd); @@ -793,12 +795,12 @@ int git_config_set_multivar(const char* key, const char* value, for (i = 0, copy_begin = 0; i < store.seen; i++) { if (store.offset[i] == 0) { - store.offset[i] = copy_end = st.st_size; + store.offset[i] = copy_end = contents_sz; } else if (store.state != KEY_SEEN) { copy_end = store.offset[i]; } else copy_end = find_beginning_of_line( - contents, st.st_size, + contents, contents_sz, store.offset[i]-2, &new_line); /* write the first part of the config */ @@ -825,13 +827,13 @@ int git_config_set_multivar(const char* key, const char* value, } /* write the rest of the config */ - if (copy_begin < st.st_size) + if (copy_begin < contents_sz) if (write_in_full(fd, contents + copy_begin, - st.st_size - copy_begin) < - st.st_size - copy_begin) + contents_sz - copy_begin) < + contents_sz - copy_begin) goto write_err_out; - munmap(contents, st.st_size); + munmap(contents, contents_sz); unlink(config_filename); } diff --git a/diff.c b/diff.c index e225de2305..8f7a7d1108 100644 --- a/diff.c +++ b/diff.c @@ -1399,7 +1399,7 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only) return err; } } - s->size = st.st_size; + s->size = xsize_t(st.st_size); if (!s->size) goto empty; if (size_only) @@ -1515,12 +1515,13 @@ static void prepare_temp_file(const char *name, if (S_ISLNK(st.st_mode)) { int ret; char buf[PATH_MAX + 1]; /* ought to be SYMLINK_MAX */ + size_t sz = xsize_t(st.st_size); if (sizeof(buf) <= st.st_size) die("symlink too long: %s", name); - ret = readlink(name, buf, st.st_size); + ret = readlink(name, buf, sz); if (ret < 0) die("readlink(%s)", name); - prep_temp_blob(temp, buf, st.st_size, + prep_temp_blob(temp, buf, sz, (one->sha1_valid ? one->sha1 : null_sha1), (one->sha1_valid ? @@ -2138,7 +2139,7 @@ static int parse_num(const char **cp_p) /* user says num divided by scale and we say internally that * is MAX_SCORE * num / scale. */ - return (num >= scale) ? MAX_SCORE : (MAX_SCORE * num / scale); + return (int)((num >= scale) ? MAX_SCORE : (MAX_SCORE * num / scale)); } int diff_scoreopt_parse(const char *opt) diff --git a/diffcore-break.c b/diffcore-break.c index acb18db1db..9c19b8cab7 100644 --- a/diffcore-break.c +++ b/diffcore-break.c @@ -89,7 +89,7 @@ static int should_break(struct diff_filespec *src, * merge the surviving pair together if the score is * less than the minimum, after rename/copy runs. */ - *merge_score_p = src_removed * MAX_SCORE / src->size; + *merge_score_p = (int)(src_removed * MAX_SCORE / src->size); /* Extent of damage, which counts both inserts and * deletes. diff --git a/diffcore-order.c b/diffcore-order.c index 7ad0946185..2a4bd8232e 100644 --- a/diffcore-order.c +++ b/diffcore-order.c @@ -14,6 +14,7 @@ static void prepare_order(const char *orderfile) void *map; char *cp, *endp; struct stat st; + size_t sz; if (order) return; @@ -25,11 +26,12 @@ static void prepare_order(const char *orderfile) close(fd); return; } - map = mmap(NULL, st.st_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); + sz = xsize_t(st.st_size); + map = mmap(NULL, sz, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); close(fd); if (map == MAP_FAILED) return; - endp = (char *) map + st.st_size; + endp = (char *) map + sz; for (pass = 0; pass < 2; pass++) { cnt = 0; cp = map; diff --git a/diffcore-rename.c b/diffcore-rename.c index 91fa2bea51..79030412db 100644 --- a/diffcore-rename.c +++ b/diffcore-rename.c @@ -172,7 +172,8 @@ static int estimate_similarity(struct diff_filespec *src, return 0; /* error but caught downstream */ - delta_limit = base_size * (MAX_SCORE-minimum_score) / MAX_SCORE; + delta_limit = (unsigned long) + (base_size * (MAX_SCORE-minimum_score) / MAX_SCORE); if (diffcore_count_changes(src->data, src->size, dst->data, dst->size, &src->cnt_data, &dst->cnt_data, @@ -186,7 +187,7 @@ static int estimate_similarity(struct diff_filespec *src, if (!dst->size) score = 0; /* should not happen */ else - score = src_copied * MAX_SCORE / max_size; + score = (int)(src_copied * MAX_SCORE / max_size); return score; } @@ -297,7 +298,7 @@ void diffcore_rename(struct diff_options *options) struct diff_filespec *one = rename_src[j].one; if (!is_exact_match(one, two, contents_too)) continue; - record_rename_pair(i, j, MAX_SCORE); + record_rename_pair(i, j, (int)MAX_SCORE); rename_count++; break; /* we are done with this entry */ } diff --git a/dir.c b/dir.c index 32b57f0125..b48e19dc09 100644 --- a/dir.c +++ b/dir.c @@ -130,13 +130,13 @@ static int add_excludes_from_file_1(const char *fname, { struct stat st; int fd, i; - long size; + size_t size; char *buf, *entry; fd = open(fname, O_RDONLY); if (fd < 0 || fstat(fd, &st) < 0) goto err; - size = st.st_size; + size = xsize_t(st.st_size); if (size == 0) { close(fd); return 0; diff --git a/git-compat-util.h b/git-compat-util.h index 33b68e463c..7534db1267 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -258,6 +258,11 @@ static inline ssize_t xwrite(int fd, const void *buf, size_t len) } } +static inline size_t xsize_t(off_t len) +{ + return (size_t)len; +} + static inline int has_extension(const char *filename, const char *ext) { size_t len = strlen(filename); diff --git a/read-cache.c b/read-cache.c index 4a972b4ab7..6339a278da 100644 --- a/read-cache.c +++ b/read-cache.c @@ -66,7 +66,7 @@ static int ce_compare_data(struct cache_entry *ce, struct stat *st) return match; } -static int ce_compare_link(struct cache_entry *ce, unsigned long expected_size) +static int ce_compare_link(struct cache_entry *ce, size_t expected_size) { int match = -1; char *target; @@ -101,7 +101,7 @@ static int ce_modified_check_fs(struct cache_entry *ce, struct stat *st) return DATA_CHANGED; break; case S_IFLNK: - if (ce_compare_link(ce, st->st_size)) + if (ce_compare_link(ce, xsize_t(st->st_size))) return DATA_CHANGED; break; default: @@ -797,7 +797,7 @@ int read_cache_from(const char *path) } if (!fstat(fd, &st)) { - cache_mmap_size = st.st_size; + cache_mmap_size = xsize_t(st.st_size); errno = EINVAL; if (cache_mmap_size >= sizeof(struct cache_header) + 20) cache_mmap = xmmap(NULL, cache_mmap_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); diff --git a/refs.c b/refs.c index 7a1f89caad..76c08d0360 100644 --- a/refs.c +++ b/refs.c @@ -1075,6 +1075,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char * unsigned long date; unsigned char logged_sha1[20]; void *log_mapped; + size_t mapsz; logfile = git_path("logs/%s", ref); logfd = open(logfile, O_RDONLY, 0); @@ -1083,7 +1084,8 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char * fstat(logfd, &st); if (!st.st_size) die("Log %s is empty.", logfile); - log_mapped = xmmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, logfd, 0); + mapsz = xsize_t(st.st_size); + log_mapped = xmmap(NULL, mapsz, PROT_READ, MAP_PRIVATE, logfd, 0); logdata = log_mapped; close(logfd); @@ -1136,7 +1138,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char * logfile, show_rfc2822_date(date, tz)); } } - munmap(log_mapped, st.st_size); + munmap(log_mapped, mapsz); return 0; } lastrec = rec; @@ -1155,7 +1157,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char * die("Log %s is corrupt.", logfile); if (msg) *msg = ref_msg(logdata, logend); - munmap(log_mapped, st.st_size); + munmap(log_mapped, mapsz); if (cutoff_time) *cutoff_time = date; diff --git a/sha1_file.c b/sha1_file.c index 50d800eea0..219a10f403 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -349,6 +349,7 @@ static void link_alt_odb_entries(const char *alt, const char *ep, int sep, static void read_info_alternates(const char * relative_base, int depth) { char *map; + size_t mapsz; struct stat st; char path[PATH_MAX]; int fd; @@ -361,12 +362,13 @@ static void read_info_alternates(const char * relative_base, int depth) close(fd); return; } - map = xmmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + mapsz = xsize_t(st.st_size); + map = xmmap(NULL, mapsz, PROT_READ, MAP_PRIVATE, fd, 0); close(fd); - link_alt_odb_entries(map, map + st.st_size, '\n', relative_base, depth); + link_alt_odb_entries(map, map + mapsz, '\n', relative_base, depth); - munmap(map, st.st_size); + munmap(map, mapsz); } void prepare_alt_odb(void) @@ -436,7 +438,7 @@ static int check_packed_git_idx(const char *path, { void *idx_map; uint32_t *index; - unsigned long idx_size; + size_t idx_size; uint32_t nr, i; int fd = open(path, O_RDONLY); struct stat st; @@ -446,7 +448,7 @@ static int check_packed_git_idx(const char *path, close(fd); return -1; } - idx_size = st.st_size; + idx_size = xsize_t(st.st_size); if (idx_size < 4 * 256 + 20 + 20) { close(fd); return error("index file %s is too small", path); @@ -669,11 +671,13 @@ unsigned char* use_pack(struct packed_git *p, } if (!win) { size_t window_align = packed_git_window_size / 2; + off_t len; win = xcalloc(1, sizeof(*win)); win->offset = (offset / window_align) * window_align; - win->len = p->pack_size - win->offset; - if (win->len > packed_git_window_size) - win->len = packed_git_window_size; + len = p->pack_size - win->offset; + if (len > packed_git_window_size) + len = packed_git_window_size; + win->len = (size_t)len; pack_mapped += win->len; while (packed_git_limit < pack_mapped && unuse_one_window(p)) @@ -702,7 +706,7 @@ unsigned char* use_pack(struct packed_git *p, } offset -= win->offset; if (left) - *left = win->len - offset; + *left = win->len - xsize_t(offset); return win->base + offset; } @@ -878,9 +882,9 @@ void *map_sha1_file(const unsigned char *sha1, unsigned long *size) */ sha1_file_open_flag = 0; } - map = xmmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + *size = xsize_t(st.st_size); + map = xmmap(NULL, *size, PROT_READ, MAP_PRIVATE, fd, 0); close(fd); - *size = st.st_size; return map; } @@ -1346,7 +1350,7 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset, uint32_t num_packed_objects(const struct packed_git *p) { /* See check_packed_git_idx() */ - return (p->index_size - 20 - 20 - 4*256) / 24; + return (uint32_t)((p->index_size - 20 - 20 - 4*256) / 24); } int nth_packed_object_sha1(const struct packed_git *p, uint32_t n, @@ -2068,7 +2072,7 @@ int index_pipe(unsigned char *sha1, int fd, const char *type, int write_object) int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, enum object_type type, const char *path) { - unsigned long size = st->st_size; + size_t size = xsize_t(st->st_size); void *buf = NULL; int ret, re_allocated = 0; @@ -2111,6 +2115,7 @@ int index_path(unsigned char *sha1, const char *path, struct stat *st, int write { int fd; char *target; + size_t len; switch (st->st_mode & S_IFMT) { case S_IFREG: @@ -2123,16 +2128,17 @@ int index_path(unsigned char *sha1, const char *path, struct stat *st, int write path); break; case S_IFLNK: - target = xmalloc(st->st_size+1); - if (readlink(path, target, st->st_size+1) != st->st_size) { + len = xsize_t(st->st_size); + target = xmalloc(len + 1); + if (readlink(path, target, len + 1) != st->st_size) { char *errstr = strerror(errno); free(target); return error("readlink(\"%s\"): %s", path, errstr); } if (!write_object) - hash_sha1_file(target, st->st_size, blob_type, sha1); - else if (write_sha1_file(target, st->st_size, blob_type, sha1)) + hash_sha1_file(target, len, blob_type, sha1); + else if (write_sha1_file(target, len, blob_type, sha1)) return error("%s: failed to insert into database", path); free(target); diff --git a/xdiff-interface.c b/xdiff-interface.c index 6c1f99b149..10816e95a0 100644 --- a/xdiff-interface.c +++ b/xdiff-interface.c @@ -107,16 +107,18 @@ int read_mmfile(mmfile_t *ptr, const char *filename) { struct stat st; FILE *f; + size_t sz; if (stat(filename, &st)) return error("Could not stat %s", filename); if ((f = fopen(filename, "rb")) == NULL) return error("Could not open %s", filename); - ptr->ptr = xmalloc(st.st_size); - if (fread(ptr->ptr, st.st_size, 1, f) != 1) + sz = xsize_t(st.st_size); + ptr->ptr = xmalloc(sz); + if (fread(ptr->ptr, sz, 1, f) != 1) return error("Could not read %s", filename); fclose(f); - ptr->size = st.st_size; + ptr->size = sz; return 0; } From 93e72d8d8fbfbbf28abee82c3e769337d7b940ec Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 7 Mar 2007 17:09:21 -0500 Subject: [PATCH 46/69] Preallocate memory earlier in fast-import I'm about to teach fast-import how to reload the marks file created by a prior session. The general approach that I want to use is to immediately parse the marks file when the specific argument is found in argv, thereby allowing the caller to supply multiple marks files, as the mark space can be sparsely populated. To make that work out we need to allocate our object tables before we parse the command line options. Since none of these tables depend on the command line options, we can easily relocate them. Signed-off-by: Shawn O. Pearce --- fast-import.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/fast-import.c b/fast-import.c index cc3347b23d..28f5e7c3b1 100644 --- a/fast-import.c +++ b/fast-import.c @@ -1988,6 +1988,12 @@ int main(int argc, const char **argv) int i, show_stats = 1; git_config(git_default_config); + alloc_objects(object_entry_alloc); + strbuf_init(&command_buf); + atom_table = xcalloc(atom_table_sz, sizeof(struct atom_str*)); + branch_table = xcalloc(branch_table_sz, sizeof(struct branch*)); + avail_tree_table = xcalloc(avail_tree_table_sz, sizeof(struct avail_tree_content*)); + marks = pool_calloc(1, sizeof(struct mark_set)); for (i = 1; i < argc; i++) { const char *a = argv[i]; @@ -2031,14 +2037,6 @@ int main(int argc, const char **argv) if (i != argc) usage(fast_import_usage); - alloc_objects(object_entry_alloc); - strbuf_init(&command_buf); - - atom_table = xcalloc(atom_table_sz, sizeof(struct atom_str*)); - branch_table = xcalloc(branch_table_sz, sizeof(struct branch*)); - avail_tree_table = xcalloc(avail_tree_table_sz, sizeof(struct avail_tree_content*)); - marks = pool_calloc(1, sizeof(struct mark_set)); - start_packfile(); for (;;) { read_next_command(); From 8e663d9e90d3d9efc9bb99ad597a6819efe625ce Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 7 Mar 2007 16:50:24 -0500 Subject: [PATCH 47/69] Move post-update hook to after all other activity As the post-update hook is meant to run after we have completed the receipt of the pushed changes, and it might actually try to kick off a `repack -a -d`, we should delay on invoking it until after we have removed the *.keep file on the uploaded pack (if we kept the pack). Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- receive-pack.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/receive-pack.c b/receive-pack.c index dda98549ca..d39aebac1e 100644 --- a/receive-pack.c +++ b/receive-pack.c @@ -206,12 +206,10 @@ static void run_update_post_hook(struct command *cmd) static void execute_commands(void) { struct command *cmd = commands; - while (cmd) { update(cmd); cmd = cmd->next; } - run_update_post_hook(commands); } static void read_head_info(void) @@ -456,6 +454,7 @@ int main(int argc, char **argv) unlink(pack_lockfile); if (report_status) report(unpack_status); + run_update_post_hook(commands); } return 0; } From 3e6e152c7496c1acd298ec2b916d62acb56f11c0 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 7 Mar 2007 16:50:43 -0500 Subject: [PATCH 48/69] Don't run post-update hook unless a ref changed There is little point in executing the post-update hook if all refs had an error and were unable to be updated. In this case nothing new is reachable within the repository, and there is no state change for the post-update hook to be interested in. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- receive-pack.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/receive-pack.c b/receive-pack.c index d39aebac1e..e32e301d47 100644 --- a/receive-pack.c +++ b/receive-pack.c @@ -175,14 +175,14 @@ static void run_update_post_hook(struct command *cmd) int argc; const char **argv; - if (access(update_post_hook, X_OK) < 0) - return; - for (argc = 1, cmd_p = cmd; cmd_p; cmd_p = cmd_p->next) { + for (argc = 0, cmd_p = cmd; cmd_p; cmd_p = cmd_p->next) { if (cmd_p->error_string) continue; argc++; } - argv = xmalloc(sizeof(*argv) * (1 + argc)); + if (!argc || access(update_post_hook, X_OK) < 0) + return; + argv = xmalloc(sizeof(*argv) * (2 + argc)); argv[0] = update_post_hook; for (argc = 1, cmd_p = cmd; cmd_p; cmd_p = cmd_p->next) { From c8dd277109c1cdb9422e474e6bd6e32a382291a0 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 7 Mar 2007 16:51:09 -0500 Subject: [PATCH 49/69] Refactor run_update_hook to be more useful This is a simple refactoring of run_update_hook to allow the function to be passed the name of the hook it runs and also to build the argument list from a list of struct commands, rather than just one struct command. The refactoring is to support new pre-receive and post-receive hooks that will be given the entire list of struct commands, rather than just one struct command. These new hooks will follow in another patch. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- receive-pack.c | 63 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 19 deletions(-) diff --git a/receive-pack.c b/receive-pack.c index e32e301d47..c55d905d5c 100644 --- a/receive-pack.c +++ b/receive-pack.c @@ -67,18 +67,45 @@ struct command { static struct command *commands; -static char update_hook[] = "hooks/update"; +static const char update_hook[] = "hooks/update"; -static int run_update_hook(const char *refname, - char *old_hex, char *new_hex) +static int run_hook(const char *hook_name, + struct command *first_cmd, + int single) { - int code; + struct command *cmd; + int argc, code; + const char **argv; - if (access(update_hook, X_OK) < 0) + for (argc = 0, cmd = first_cmd; cmd; cmd = cmd->next) { + if (!cmd->error_string) + argc += 3; + if (single) + break; + } + + if (!argc || access(hook_name, X_OK) < 0) return 0; - code = run_command_opt(RUN_COMMAND_NO_STDIN - | RUN_COMMAND_STDOUT_TO_STDERR, - update_hook, refname, old_hex, new_hex, NULL); + + argv = xmalloc(sizeof(*argv) * (2 + argc)); + argv[0] = hook_name; + for (argc = 1, cmd = first_cmd; cmd; cmd = cmd->next) { + if (!cmd->error_string) { + argv[argc++] = xstrdup(cmd->ref_name); + argv[argc++] = xstrdup(sha1_to_hex(cmd->old_sha1)); + argv[argc++] = xstrdup(sha1_to_hex(cmd->new_sha1)); + } + if (single) + break; + } + argv[argc] = NULL; + + code = run_command_v_opt(argv, + RUN_COMMAND_NO_STDIN | RUN_COMMAND_STDOUT_TO_STDERR); + while (--argc > 0) + free((char*)argv[argc]); + free(argv); + switch (code) { case 0: return 0; @@ -91,11 +118,11 @@ static int run_update_hook(const char *refname, case -ERR_RUN_COMMAND_WAITPID_WRONG_PID: return error("waitpid is confused"); case -ERR_RUN_COMMAND_WAITPID_SIGNAL: - return error("%s died of signal", update_hook); + return error("%s died of signal", hook_name); case -ERR_RUN_COMMAND_WAITPID_NOEXIT: - return error("%s died strangely", update_hook); + return error("%s died strangely", hook_name); default: - error("%s exited with error code %d", update_hook, -code); + error("%s exited with error code %d", hook_name, -code); return -code; } } @@ -105,7 +132,6 @@ static int update(struct command *cmd) const char *name = cmd->ref_name; unsigned char *old_sha1 = cmd->old_sha1; unsigned char *new_sha1 = cmd->new_sha1; - char new_hex[41], old_hex[41]; struct ref_lock *lock; cmd->error_string = NULL; @@ -115,13 +141,10 @@ static int update(struct command *cmd) name); } - strcpy(new_hex, sha1_to_hex(new_sha1)); - strcpy(old_hex, sha1_to_hex(old_sha1)); - if (!is_null_sha1(new_sha1) && !has_sha1_file(new_sha1)) { cmd->error_string = "bad pack"; return error("unpack should have generated %s, " - "but I can't find it!", new_hex); + "but I can't find it!", sha1_to_hex(new_sha1)); } if (deny_non_fast_forwards && !is_null_sha1(new_sha1) && !is_null_sha1(old_sha1) && @@ -140,7 +163,7 @@ static int update(struct command *cmd) return error("denying non-fast forward;" " you should pull first"); } - if (run_update_hook(name, old_hex, new_hex)) { + if (run_hook(update_hook, cmd, 1)) { cmd->error_string = "hook declined"; return error("hook declined to update %s", name); } @@ -150,7 +173,8 @@ static int update(struct command *cmd) cmd->error_string = "failed to delete"; return error("failed to delete %s", name); } - fprintf(stderr, "%s: %s -> deleted\n", name, old_hex); + fprintf(stderr, "%s: %s -> deleted\n", name, + sha1_to_hex(old_sha1)); } else { lock = lock_any_ref_for_update(name, old_sha1); @@ -162,7 +186,8 @@ static int update(struct command *cmd) cmd->error_string = "failed to write"; return -1; /* error() already called */ } - fprintf(stderr, "%s: %s -> %s\n", name, old_hex, new_hex); + fprintf(stderr, "%s: %s -> %s\n", name, + sha1_to_hex(old_sha1), sha1_to_hex(new_sha1)); } return 0; } From 8aaf7d6410119ee221f5d3ebdc4fc5a57f862665 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 7 Mar 2007 16:51:59 -0500 Subject: [PATCH 50/69] Refactor handling of error_string in receive-pack I discovered we did not send an ng line in the report-status feedback if the ref was not updated because the repository has the config option receive.denyNonFastForwards enabled. I think the reason this happened is that it is simply too easy to forget to set error_string when returning back a failure from update() We now return an ng line for a non-fastforward update, which in turn will cause send-pack to exit with a non-zero exit status. Hence the modified test. This refactoring changes update to return a const char* describing the error, which execute_commands always loads into error_string. The result is what I think is cleaner code, and allows us to initialize the error_string member to NULL when we read_head_info. I want error_string to be NULL in all commands before we call execute_commands, so that we can reuse the run_hook function to execute a new pre-receive hook. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- receive-pack.c | 62 +++++++++++++++++++++++--------------------- t/t5400-send-pack.sh | 6 ++--- 2 files changed, 36 insertions(+), 32 deletions(-) diff --git a/receive-pack.c b/receive-pack.c index c55d905d5c..ff746e7d56 100644 --- a/receive-pack.c +++ b/receive-pack.c @@ -127,24 +127,22 @@ static int run_hook(const char *hook_name, } } -static int update(struct command *cmd) +static const char *update(struct command *cmd) { const char *name = cmd->ref_name; unsigned char *old_sha1 = cmd->old_sha1; unsigned char *new_sha1 = cmd->new_sha1; struct ref_lock *lock; - cmd->error_string = NULL; if (!prefixcmp(name, "refs/") && check_ref_format(name + 5)) { - cmd->error_string = "funny refname"; - return error("refusing to create funny ref '%s' locally", - name); + error("refusing to create funny ref '%s' locally", name); + return "funny refname"; } if (!is_null_sha1(new_sha1) && !has_sha1_file(new_sha1)) { - cmd->error_string = "bad pack"; - return error("unpack should have generated %s, " - "but I can't find it!", sha1_to_hex(new_sha1)); + error("unpack should have generated %s, " + "but I can't find it!", sha1_to_hex(new_sha1)); + return "bad pack"; } if (deny_non_fast_forwards && !is_null_sha1(new_sha1) && !is_null_sha1(old_sha1) && @@ -159,37 +157,39 @@ static int update(struct command *cmd) if (!hashcmp(old_sha1, ent->item->object.sha1)) break; free_commit_list(bases); - if (!ent) - return error("denying non-fast forward;" - " you should pull first"); + if (!ent) { + error("denying non-fast forward %s" + " (you should pull first)", name); + return "non-fast forward"; + } } if (run_hook(update_hook, cmd, 1)) { - cmd->error_string = "hook declined"; - return error("hook declined to update %s", name); + error("hook declined to update %s", name); + return "hook declined"; } if (is_null_sha1(new_sha1)) { if (delete_ref(name, old_sha1)) { - cmd->error_string = "failed to delete"; - return error("failed to delete %s", name); + error("failed to delete %s", name); + return "failed to delete"; } fprintf(stderr, "%s: %s -> deleted\n", name, sha1_to_hex(old_sha1)); + return NULL; /* good */ } else { lock = lock_any_ref_for_update(name, old_sha1); if (!lock) { - cmd->error_string = "failed to lock"; - return error("failed to lock %s", name); + error("failed to lock %s", name); + return "failed to lock"; } if (write_ref_sha1(lock, new_sha1, "push")) { - cmd->error_string = "failed to write"; - return -1; /* error() already called */ + return "failed to write"; /* error() already called */ } fprintf(stderr, "%s: %s -> %s\n", name, sha1_to_hex(old_sha1), sha1_to_hex(new_sha1)); + return NULL; /* good */ } - return 0; } static char update_post_hook[] = "hooks/post-update"; @@ -224,15 +224,20 @@ static void run_update_post_hook(struct command *cmd) | RUN_COMMAND_STDOUT_TO_STDERR); } -/* - * This gets called after(if) we've successfully - * unpacked the data payload. - */ -static void execute_commands(void) +static void execute_commands(const char *unpacker_error) { struct command *cmd = commands; + + if (unpacker_error) { + while (cmd) { + cmd->error_string = "n/a (unpacker error)"; + cmd = cmd->next; + } + return; + } + while (cmd) { - update(cmd); + cmd->error_string = update(cmd); cmd = cmd->next; } } @@ -270,7 +275,7 @@ static void read_head_info(void) hashcpy(cmd->old_sha1, old_sha1); hashcpy(cmd->new_sha1, new_sha1); memcpy(cmd->ref_name, line + 82, len - 81); - cmd->error_string = "n/a (unpacker error)"; + cmd->error_string = NULL; cmd->next = NULL; *p = cmd; p = &cmd->next; @@ -473,8 +478,7 @@ int main(int argc, char **argv) if (!delete_only(commands)) unpack_status = unpack(); - if (!unpack_status) - execute_commands(); + execute_commands(unpack_status); if (pack_lockfile) unlink(pack_lockfile); if (report_status) diff --git a/t/t5400-send-pack.sh b/t/t5400-send-pack.sh index 7d93d0d7c9..b1c97b0dfb 100755 --- a/t/t5400-send-pack.sh +++ b/t/t5400-send-pack.sh @@ -108,9 +108,9 @@ test_expect_success \ cd victim && git-config receive.denyNonFastforwards true && cd .. && - git-update-ref refs/heads/master master^ && - git-send-pack --force ./victim/.git/ master && - ! diff -u .git/refs/heads/master victim/.git/refs/heads/master + git-update-ref refs/heads/master master^ || return 1 + git-send-pack --force ./victim/.git/ master && return 1 + ! diff .git/refs/heads/master victim/.git/refs/heads/master ' test_done From 05ef58ec1f2fb69d6e7ae7fca84163f75bd95050 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 7 Mar 2007 16:52:05 -0500 Subject: [PATCH 51/69] Teach receive-pack to run pre-receive/post-receive hooks Bill Lear pointed out that it is easy to send out notifications of changes with the update hook, but successful execution of the update hook does not necessarily mean that the ref was actually updated. Lock contention on the ref or being unable to append to the reflog may prevent the ref from being changed. Sending out notifications prior to the ref actually changing is very misleading. To help this situation I am introducing two new hooks to the receive-pack flow: pre-receive and post-receive. These new hooks are invoked only once per receive-pack execution and are passed three arguments per ref (refname, old-sha1, new-sha1). The new post-receive hook is ideal for sending out notifications, as it has the complete list of all refnames that were successfully updated as well as the old and new SHA-1 values. This allows more interesting notifications to be sent. Multiple ref updates could be easily summarized into one email, for example. The new pre-receive hook is ideal for logging update attempts, as it is run only once for the entire receive-pack operation. It can also be used to verify multiple updates happen at once, e.g. an update to the `maint` head must also be accompained by a new annotated tag. Lots of documentation improvements for receive-pack are included in this change, as we want to make sure the new hooks are clearly explained. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- Documentation/git-receive-pack.txt | 159 ++++++++++++++++++++--------- receive-pack.c | 11 ++ t/t5401-update-hooks.sh | 93 +++++++++++++---- 3 files changed, 196 insertions(+), 67 deletions(-) diff --git a/Documentation/git-receive-pack.txt b/Documentation/git-receive-pack.txt index 10e8c46c4c..3cf55111cc 100644 --- a/Documentation/git-receive-pack.txt +++ b/Documentation/git-receive-pack.txt @@ -25,62 +25,127 @@ The command allows for creation and fast forwarding of sha1 refs local end receive-pack runs, but to the user who is sitting at the send-pack end, it is updating the remote. Confused?) -Before each ref is updated, if $GIT_DIR/hooks/update file exists -and executable, it is called with three parameters: - - $GIT_DIR/hooks/update refname sha1-old sha1-new - -The refname parameter is relative to $GIT_DIR; e.g. for the -master head this is "refs/heads/master". Two sha1 are the -object names for the refname before and after the update. Note -that the hook is called before the refname is updated, so either -sha1-old is 0{40} (meaning there is no such ref yet), or it -should match what is recorded in refname. - -The hook should exit with non-zero status if it wants to -disallow updating the named ref. Otherwise it should exit with -zero. - -Using this hook, it is easy to generate mails on updates to -the local repository. This example script sends a mail with -the commits pushed to the repository: - - #!/bin/sh - # mail out commit update information. - if expr "$2" : '0*$' >/dev/null - then - echo "Created a new ref, with the following commits:" - git-rev-list --pretty "$2" - else - echo "New commits:" - git-rev-list --pretty "$3" "^$2" - fi | - mail -s "Changes to ref $1" commit-list@mydomain - exit 0 - -Another hook $GIT_DIR/hooks/post-update, if exists and -executable, is called with the list of refs that have been -updated. This can be used to implement repository wide cleanup -task if needed. The exit code from this hook invocation is -ignored; the only thing left for git-receive-pack to do at that -point is to exit itself anyway. This hook can be used, for -example, to run "git-update-server-info" if the repository is -packed and is served via a dumb transport. - - #!/bin/sh - exec git-update-server-info - There are other real-world examples of using update and post-update hooks found in the Documentation/howto directory. -git-receive-pack honours the receive.denyNonFastforwards flag, which -tells it if updates to a ref should be denied if they are not fast-forwards. +git-receive-pack honours the receive.denyNonFastForwards config +option, which tells it if updates to a ref should be denied if they +are not fast-forwards. OPTIONS ------- :: The repository to sync into. +pre-receive Hook +---------------- +Before any ref is updated, if $GIT_DIR/hooks/pre-receive file exists +and is executable, it will be invoked once, with three parameters +per ref to be updated: + + $GIT_DIR/hooks/pre-receive (refname sha1-old sha1-new)+ + +The refname parameter is relative to $GIT_DIR; e.g. for the master +head this is "refs/heads/master". The two sha1 arguments after +each refname are the object names for the refname before and after +the update. Refs to be created will have sha1-old equal to 0{40}, +while refs to be deleted will have sha1-new equal to 0{40}, otherwise +sha1-old and sha1-new should be valid objects in the repository. + +This hook is called before any refname is updated and before any +fast-forward checks are performed. + +If the pre-receive hook exits with a non-zero exit status no updates +will be performed, and the update, post-receive and post-update +hooks will not be invoked either. This can be useful to quickly +bail out if the update is not to be supported. + +update Hook +----------- +Before each ref is updated, if $GIT_DIR/hooks/update file exists +and is executable, it is invoked once per ref, with three parameters: + + $GIT_DIR/hooks/update refname sha1-old sha1-new + +The refname parameter is relative to $GIT_DIR; e.g. for the master +head this is "refs/heads/master". The two sha1 arguments are +the object names for the refname before and after the update. +Note that the hook is called before the refname is updated, +so either sha1-old is 0{40} (meaning there is no such ref yet), +or it should match what is recorded in refname. + +The hook should exit with non-zero status if it wants to disallow +updating the named ref. Otherwise it should exit with zero. + +Successful execution (a zero exit status) of this hook does not +ensure the ref will actully be updated, it is only a prerequisite. +As such it is not a good idea to send notices (e.g. email) from +this hook. Consider using the post-receive hook instead. + +post-receive Hook +----------------- +After all refs were updated (or attempted to be updated), if any +ref update was successful, and if $GIT_DIR/hooks/post-receive +file exists and is executable, it will be invoke once with three +parameters for each successfully updated ref: + + $GIT_DIR/hooks/post-receive (refname sha1-old sha1-new)+ + +The refname parameter is relative to $GIT_DIR; e.g. for the master +head this is "refs/heads/master". The two sha1 arguments after +each refname are the object names for the refname before and after +the update. Refs that were created will have sha1-old equal to +0{40}, while refs that were deleted will have sha1-new equal to +0{40}, otherwise sha1-old and sha1-new should be valid objects in +the repository. + +Using this hook, it is easy to generate mails describing the updates +to the repository. This example script sends one mail message per +ref listing the commits pushed to the repository: + + #!/bin/sh + # mail out commit update information. + while test $# -gt 0 + do + if expr "$2" : '0*$' >/dev/null + then + echo "Created a new ref, with the following commits:" + git-rev-list --pretty "$2" + else + echo "New commits:" + git-rev-list --pretty "$3" "^$2" + fi | + mail -s "Changes to ref $1" commit-list@mydomain + shift; shift; shift; # discard this ref's args + done + exit 0 + +The exit code from this hook invocation is ignored, however a +non-zero exit code will generate an error message. + +Note that it is possible for refname to not have sha1-new when this +hook runs. This can easily occur if another user modifies the ref +after it was updated by receive-pack, but before the hook was able +to evaluate it. It is recommended that hooks rely on sha1-new +rather than the current value of refname. + +post-update Hook +---------------- +After all other processing, if at least one ref was updated, and +if $GIT_DIR/hooks/post-update file exists and is executable, then +post-update will called with the list of refs that have been updated. +This can be used to implement any repository wide cleanup tasks. + +The exit code from this hook invocation is ignored; the only thing +left for git-receive-pack to do at that point is to exit itself +anyway. + +This hook can be used, for example, to run "git-update-server-info" +if the repository is packed and is served via a dumb transport. + + #!/bin/sh + exec git-update-server-info + SEE ALSO -------- diff --git a/receive-pack.c b/receive-pack.c index ff746e7d56..675c88f492 100644 --- a/receive-pack.c +++ b/receive-pack.c @@ -68,6 +68,8 @@ struct command { static struct command *commands; static const char update_hook[] = "hooks/update"; +static const char pre_receive_hook[] = "hooks/pre-receive"; +static const char post_receive_hook[] = "hooks/post-receive"; static int run_hook(const char *hook_name, struct command *first_cmd, @@ -236,6 +238,14 @@ static void execute_commands(const char *unpacker_error) return; } + if (run_hook(pre_receive_hook, commands, 0)) { + while (cmd) { + cmd->error_string = "pre-receive hook declined"; + cmd = cmd->next; + } + return; + } + while (cmd) { cmd->error_string = update(cmd); cmd = cmd->next; @@ -483,6 +493,7 @@ int main(int argc, char **argv) unlink(pack_lockfile); if (report_status) report(unpack_status); + run_hook(post_receive_hook, commands, 0); run_update_post_hook(commands); } return 0; diff --git a/t/t5401-update-hooks.sh b/t/t5401-update-hooks.sh index 0514056ca6..0c0034e34c 100755 --- a/t/t5401-update-hooks.sh +++ b/t/t5401-update-hooks.sh @@ -11,47 +11,91 @@ test_expect_success setup ' git-update-index --add a && tree0=$(git-write-tree) && commit0=$(echo setup | git-commit-tree $tree0) && - git-update-ref HEAD $commit0 && - git-clone ./. victim && echo We hope it works. >a && git-update-index a && tree1=$(git-write-tree) && commit1=$(echo modify | git-commit-tree $tree1 -p $commit0) && - git-update-ref HEAD $commit1 + git-update-ref refs/heads/master $commit0 && + git-update-ref refs/heads/tofail $commit1 && + git-clone ./. victim && + GIT_DIR=victim/.git git-update-ref refs/heads/tofail $commit1 && + git-update-ref refs/heads/master $commit1 && + git-update-ref refs/heads/tofail $commit0 ' +cat >victim/.git/hooks/pre-receive <<'EOF' +#!/bin/sh +echo "$@" >>$GIT_DIR/pre-receive.args +read x; printf "$x" >$GIT_DIR/pre-receive.stdin +echo STDOUT pre-receive +echo STDERR pre-receive >&2 +EOF +chmod u+x victim/.git/hooks/pre-receive + cat >victim/.git/hooks/update <<'EOF' #!/bin/sh -echo "$@" >$GIT_DIR/update.args +echo "$@" >>$GIT_DIR/update.args read x; printf "$x" >$GIT_DIR/update.stdin -echo STDOUT update -echo STDERR update >&2 +echo STDOUT update $1 +echo STDERR update $1 >&2 +test "$1" = refs/heads/master || exit EOF chmod u+x victim/.git/hooks/update +cat >victim/.git/hooks/post-receive <<'EOF' +#!/bin/sh +echo "$@" >>$GIT_DIR/post-receive.args +read x; printf "$x" >$GIT_DIR/post-receive.stdin +echo STDOUT post-receive +echo STDERR post-receive >&2 +EOF +chmod u+x victim/.git/hooks/post-receive + cat >victim/.git/hooks/post-update <<'EOF' #!/bin/sh -echo "$@" >$GIT_DIR/post-update.args +echo "$@" >>$GIT_DIR/post-update.args read x; printf "$x" >$GIT_DIR/post-update.stdin echo STDOUT post-update echo STDERR post-update >&2 EOF chmod u+x victim/.git/hooks/post-update -test_expect_success push ' - git-send-pack ./victim/.git/ master >send.out 2>send.err +test_expect_failure push ' + git-send-pack --force ./victim/.git master tofail >send.out 2>send.err +' + +test_expect_success 'updated as expected' ' + test $(GIT_DIR=victim/.git git-rev-parse master) = $commit1 && + test $(GIT_DIR=victim/.git git-rev-parse tofail) = $commit1 ' test_expect_success 'hooks ran' ' + test -f victim/.git/pre-receive.args && + test -f victim/.git/pre-receive.stdin && test -f victim/.git/update.args && test -f victim/.git/update.stdin && + test -f victim/.git/post-receive.args && + test -f victim/.git/post-receive.stdin && test -f victim/.git/post-update.args && test -f victim/.git/post-update.stdin ' +test_expect_success 'pre-receive hook arguments' ' + echo \ + refs/heads/master $commit0 $commit1 \ + refs/heads/tofail $commit1 $commit0 \ + | diff - victim/.git/pre-receive.args +' + test_expect_success 'update hook arguments' ' + (echo refs/heads/master $commit0 $commit1; + echo refs/heads/tofail $commit1 $commit0 + ) | diff - victim/.git/update.args +' + +test_expect_success 'post-receive hook arguments' ' echo refs/heads/master $commit0 $commit1 | - diff -u - victim/.git/update.args + diff - victim/.git/post-receive.args ' test_expect_success 'post-update hook arguments' ' @@ -59,23 +103,32 @@ test_expect_success 'post-update hook arguments' ' diff -u - victim/.git/post-update.args ' -test_expect_failure 'update hook stdin is /dev/null' ' - test -s victim/.git/update.stdin -' - -test_expect_failure 'post-update hook stdin is /dev/null' ' - test -s victim/.git/post-update.stdin +test_expect_success 'all hook stdin is /dev/null' ' + ! test -s victim/.git/pre-receive.stdin && + ! test -s victim/.git/update.stdin && + ! test -s victim/.git/post-receive.stdin && + ! test -s victim/.git/post-update.stdin ' test_expect_failure 'send-pack produced no output' ' test -s send.out ' +cat <expect +STDOUT pre-receive +STDERR pre-receive +STDOUT update refs/heads/master +STDERR update refs/heads/master +STDOUT update refs/heads/tofail +STDERR update refs/heads/tofail +STDOUT post-receive +STDERR post-receive +STDOUT post-update +STDERR post-update +EOF test_expect_success 'send-pack stderr contains hook messages' ' - grep "STDOUT update" send.err && - grep "STDERR update" send.err && - grep "STDOUT post-update" send.err && - grep "STDERR post-update" send.err + egrep ^STD send.err >actual && + diff - actual Date: Wed, 7 Mar 2007 18:05:38 -0500 Subject: [PATCH 52/69] Use atomic updates to the fast-import mark file When we allow fast-import frontends to reload a mark file from a prior session we want to let them use the same file as they exported the marks to. This makes it very simple for the frontend to save state across incremental imports. But we don't want to lose the old marks table if anything goes wrong while writing our current marks table. So instead of truncating and overwriting the path specified to --export-marks we use the standard lockfile code to write the current marks out to a temporary file, then rename it over the old marks table. Signed-off-by: Shawn O. Pearce --- fast-import.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/fast-import.c b/fast-import.c index 28f5e7c3b1..a09221242e 100644 --- a/fast-import.c +++ b/fast-import.c @@ -1375,16 +1375,33 @@ static void dump_marks_helper(FILE *f, static void dump_marks(void) { - if (mark_file) - { - FILE *f = fopen(mark_file, "w"); - if (f) { - dump_marks_helper(f, 0, marks); - fclose(f); - } else - failure |= error("Unable to write marks file %s: %s", - mark_file, strerror(errno)); + static struct lock_file mark_lock; + int mark_fd; + FILE *f; + + if (!mark_file) + return; + + mark_fd = hold_lock_file_for_update(&mark_lock, mark_file, 0); + if (mark_fd < 0) { + failure |= error("Unable to write marks file %s: %s", + mark_file, strerror(errno)); + return; } + + f = fdopen(mark_fd, "w"); + if (!f) { + rollback_lock_file(&mark_lock); + failure |= error("Unable to write marks file %s: %s", + mark_file, strerror(errno)); + return; + } + + dump_marks_helper(f, 0, marks); + fclose(f); + if (commit_lock_file(&mark_lock)) + failure |= error("Unable to write marks file %s: %s", + mark_file, strerror(errno)); } static void read_next_command(void) From e8438420bb7d368bec3647b90c557b9931582267 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 7 Mar 2007 18:07:26 -0500 Subject: [PATCH 53/69] Allow fast-import frontends to reload the marks table I'm giving fast-import a lesson on how to reload the marks table using the same format it outputs with --export-marks. This way a frontend can reload the marks table from a prior import, making incremental imports less painful. Signed-off-by: Shawn O. Pearce --- Documentation/git-fast-import.txt | 13 ++++++++++- fast-import.c | 36 +++++++++++++++++++++++++++++++ t/t9300-fast-import.sh | 8 +++++++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/Documentation/git-fast-import.txt b/Documentation/git-fast-import.txt index 77a14bb076..7e3d2b1a96 100644 --- a/Documentation/git-fast-import.txt +++ b/Documentation/git-fast-import.txt @@ -62,7 +62,18 @@ OPTIONS Dumps the internal marks table to when complete. Marks are written one per line as `:markid SHA-1`. Frontends can use this file to validate imports after they - have been completed. + have been completed, or to save the marks table across + incremental runs. As is only opened and truncated + at checkpoint (or completion) the same path can also be + safely given to \--import-marks. + +--import-marks=:: + Before processing any input, load the marks specified in + . The input file must exist, must be readable, and + must use the same format as produced by \--export-marks. + Multiple options may be supplied to import more than one + set of marks. If a mark is defined to different values, + the last file wins. --export-pack-edges=:: After creating a packfile, print a line of data to diff --git a/fast-import.c b/fast-import.c index a09221242e..fbed8e4e89 100644 --- a/fast-import.c +++ b/fast-import.c @@ -1997,6 +1997,40 @@ static void cmd_checkpoint(void) read_next_command(); } +static void import_marks(const char *input_file) +{ + char line[512]; + FILE *f = fopen(input_file, "r"); + if (!f) + die("cannot read %s: %s", input_file, strerror(errno)); + while (fgets(line, sizeof(line), f)) { + uintmax_t mark; + char *end; + unsigned char sha1[20]; + struct object_entry *e; + + end = strchr(line, '\n'); + if (line[0] != ':' || !end) + die("corrupt mark line: %s", line); + *end = 0; + mark = strtoumax(line + 1, &end, 10); + if (!mark || end == line + 1 + || *end != ' ' || get_sha1(end + 1, sha1)) + die("corrupt mark line: %s", line); + e = find_object(sha1); + if (!e) { + enum object_type type = sha1_object_info(sha1, NULL); + if (type < 0) + die("object not found: %s", sha1_to_hex(sha1)); + e = insert_object(sha1); + e->type = type; + e->pack_id = MAX_PACK_ID; + } + insert_mark(mark, e); + } + fclose(f); +} + static const char fast_import_usage[] = "git-fast-import [--date-format=f] [--max-pack-size=n] [--depth=n] [--active-branches=n] [--export-marks=marks.file]"; @@ -2034,6 +2068,8 @@ int main(int argc, const char **argv) max_depth = strtoul(a + 8, NULL, 0); else if (!prefixcmp(a, "--active-branches=")) max_active_branches = strtoul(a + 18, NULL, 0); + else if (!prefixcmp(a, "--import-marks=")) + import_marks(a + 15); else if (!prefixcmp(a, "--export-marks=")) mark_file = a + 15; else if (!prefixcmp(a, "--export-pack-edges=")) { diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh index 970d683650..2e1a09ff2d 100755 --- a/t/t9300-fast-import.sh +++ b/t/t9300-fast-import.sh @@ -111,6 +111,14 @@ test_expect_success \ 'A: verify marks output' \ 'diff -u expect marks.out' +test_expect_success \ + 'A: verify marks import' \ + 'git-fast-import \ + --import-marks=marks.out \ + --export-marks=marks.new \ + Date: Mon, 5 Mar 2007 08:57:53 +0100 Subject: [PATCH 54/69] git-commit: add a --interactive option The --interactive option behaves like "git commit", except that "git add --interactive" is executed before committing. It is incompatible with -a and -i. Signed-off-by: Paolo Bonzini Signed-off-by: Junio C Hamano --- Documentation/git-commit.txt | 9 +++++++-- git-commit.sh | 21 ++++++++++++++++----- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt index 2187eee416..53a7bb0895 100644 --- a/Documentation/git-commit.txt +++ b/Documentation/git-commit.txt @@ -8,8 +8,9 @@ git-commit - Record changes to the repository SYNOPSIS -------- [verse] -'git-commit' [-a] [-s] [-v] [(-c | -C) | -F | -m | - --amend] [--no-verify] [-e] [--author ] +'git-commit' [-a | --interactive] [-s] [-v] + [(-c | -C) | -F | -m | --amend] + [--no-verify] [-e] [--author ] [--] [[-i | -o ]...] DESCRIPTION @@ -35,6 +36,10 @@ methods: before, and to automatically "rm" files that have been removed from the working tree, and perform the actual commit. +5. by using the --interactive switch with the 'commit' command to decide one + by one which files should be part of the commit, before finalizing the + operation. Currently, this is done by invoking `git-add --interactive`. + The gitlink:git-status[1] command can be used to obtain a summary of what is included by any of the above for the next commit by giving the same set of parameters you would give to diff --git a/git-commit.sh b/git-commit.sh index b8c00b8236..3656d607d5 100755 --- a/git-commit.sh +++ b/git-commit.sh @@ -3,7 +3,7 @@ # Copyright (c) 2005 Linus Torvalds # Copyright (c) 2006 Junio C Hamano -USAGE='[-a] [-s] [-v] [--no-verify] [-m | -F | (-C|-c) | --amend] [-u] [-e] [--author ] [[-i | -o] ...]' +USAGE='[-a | --interactive] [-s] [-v] [--no-verify] [-m | -F | (-C|-c) | --amend] [-u] [-e] [--author ] [[-i | -o] ...]' SUBDIRECTORY_OK=Yes . git-sh-setup require_work_tree @@ -71,6 +71,7 @@ trap ' all= also= +interactive= only= logfile= use_commit= @@ -131,6 +132,11 @@ do also=t shift ;; + --int|--inte|--inter|--intera|--interac|--interact|--interacti|\ + --interactiv|--interactive) + interactive=t + shift + ;; -o|--o|--on|--onl|--only) only=t shift @@ -304,12 +310,14 @@ case "$#,$also,$only,$amend" in ;; esac unset only -case "$all,$also,$#" in -t,t,*) - die "Cannot use -a and -i at the same time." ;; +case "$all,$interactive,$also,$#" in +*t,*t,*) + die "Cannot use -a, --interactive or -i at the same time." ;; t,,[1-9]*) die "Paths with -a does not make sense." ;; -,t,0) +,t,[1-9]*) + die "Paths with --interactive does not make sense." ;; +,,t,0) die "No paths with -i does not make sense." ;; esac @@ -344,6 +352,9 @@ t,) ) || exit ;; ,) + if test "$interactive" = t; then + git add --interactive || exit + fi case "$#" in 0) ;; # commit as-is From 443b92b6e50462942a8b2ca22a7def87036762ff Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Fri, 9 Mar 2007 23:38:57 +0100 Subject: [PATCH 55/69] Adjust reflog filemode in shared repository Without this, committing in a group-shared repository would not work even though all developers are in the same group. Signed-off-by: Matthias Kestenholz Signed-off-by: Junio C Hamano --- refs.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/refs.c b/refs.c index a9b8c72c6b..131e870149 100644 --- a/refs.c +++ b/refs.c @@ -921,6 +921,8 @@ static int log_ref_write(const char *ref_name, const unsigned char *old_sha1, log_file, strerror(errno)); } + adjust_shared_perm(log_file); + msglen = 0; if (msg) { /* clean up the message and make sure it is a single line */ From c4431d380c20b4c05c373980c600798fc02e79b0 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 9 Mar 2007 15:21:41 -0500 Subject: [PATCH 56/69] Documentation: s/seperator/separator/ Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- Documentation/git-fast-import.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Documentation/git-fast-import.txt b/Documentation/git-fast-import.txt index 77a14bb076..a7d255d39f 100644 --- a/Documentation/git-fast-import.txt +++ b/Documentation/git-fast-import.txt @@ -451,7 +451,7 @@ in octal. Git only supports the following modes: In both formats `` is the complete path of the file to be added (if not already existing) or modified (if already existing). -A `` string must use UNIX-style directory seperators (forward +A `` string must use UNIX-style directory separators (forward slash `/`), may contain any byte other than `LF`, and must not start with double quote (`"`). @@ -461,8 +461,8 @@ quoting should be used, e.g. `"path/with\n and \" in it"`. The value of `` must be in canoncial form. That is it must not: * contain an empty directory component (e.g. `foo//bar` is invalid), -* end with a directory seperator (e.g. `foo/` is invalid), -* start with a directory seperator (e.g. `/foo` is invalid), +* end with a directory separator (e.g. `foo/` is invalid), +* start with a directory separator (e.g. `/foo` is invalid), * contain the special component `.` or `..` (e.g. `foo/./bar` and `foo/../bar` are invalid). From c816eb1784b324fcf3988253affac4d43bce78c9 Mon Sep 17 00:00:00 2001 From: "J. Bruce Fields" Date: Sun, 4 Mar 2007 19:13:09 -0500 Subject: [PATCH 57/69] glossary: fix overoptimistic automatic linking of defined terms The script sort_glossary.pl turns each use of "term" into a link to the definition of "term". To avoid mangling links like gitlink:git-term[1] it doesn't replace any occurence of "term" preceded by "link:git-". This fails for gitlink:git-symbolic-ref[1] when substituting for "ref". So instead just refuse to replace anything preceded by a "-". That could result in missing some opportunities, but that's a less annoying error. Actually I find the automatic substitution a little distracting; some day maybe we should just run it once and commit the result, so it can be hand-tuned. Signed-off-by: "J. Bruce Fields" --- Documentation/sort_glossary.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/sort_glossary.pl b/Documentation/sort_glossary.pl index e0bc552a64..05dc7b2c7b 100644 --- a/Documentation/sort_glossary.pl +++ b/Documentation/sort_glossary.pl @@ -48,7 +48,7 @@ This list is sorted alphabetically: '; @keys=sort {uc($a) cmp uc($b)} keys %terms; -$pattern='(\b(?>";/eg; print '[[ref_'.no_spaces($key).']]'.$key."::\n" From 923642fe1bdf010a1f2bef1507e17b9ee97cbf87 Mon Sep 17 00:00:00 2001 From: "J. Bruce Fields" Date: Sat, 10 Mar 2007 21:45:29 -0500 Subject: [PATCH 58/69] user-manual: fix inconsistent example The configuration file fragment here is inconsistent with the text above. Thanks to Ramsay Jones for the correction. Cc: Ramsay Jones Signed-off-by: "J. Bruce Fields" --- Documentation/user-manual.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt index a5e7b536f2..8b5709ba75 100644 --- a/Documentation/user-manual.txt +++ b/Documentation/user-manual.txt @@ -601,8 +601,8 @@ a new stanza: $ cat .git/config ... [remote "linux-nfs"] - url = git://linux-nfs.org/~bfields/git.git - fetch = +refs/heads/*:refs/remotes/linux-nfs-read/* + url = git://linux-nfs.org/pub/nfs-2.6.git + fetch = +refs/heads/*:refs/remotes/linux-nfs/* ... ------------------------------------------------- From fabbd8f6ca610a570d7bfcbbfc80bb0e03247b2a Mon Sep 17 00:00:00 2001 From: "J. Bruce Fields" Date: Sat, 10 Mar 2007 21:52:39 -0500 Subject: [PATCH 59/69] user-manual: fix inconsistent use of pull and merge I used "git pull ." instead of "git merge" here without any explanation. Stick instead to "git merge" for now (the equivalent pull syntax is still covered in a later chapter). Cc: Ramsay Jones Signed-off-by: "J. Bruce Fields" --- Documentation/user-manual.txt | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt index 8b5709ba75..f4ea967191 100644 --- a/Documentation/user-manual.txt +++ b/Documentation/user-manual.txt @@ -1133,17 +1133,9 @@ modified in two different ways in the remote branch and the local branch--then you are warned; the output may look something like this: ------------------------------------------------- -$ git pull . next -Trying really trivial in-index merge... -fatal: Merge requires file-level merging -Nope. -Merging HEAD with 77976da35a11db4580b80ae27e8d65caf5208086 -Merging: -15e2162 world -77976da goodbye -found 1 common ancestor(s): -d122ed4 initial -Auto-merging file.txt +$ git merge next + 100% (4/4) done +Auto-merged file.txt CONFLICT (content): Merge conflict in file.txt Automatic merge failed; fix conflicts and then commit the result. ------------------------------------------------- From ed4eb0d8f3560c20a3b8eefefdcaae4d864743c6 Mon Sep 17 00:00:00 2001 From: "J. Bruce Fields" Date: Sat, 10 Mar 2007 22:00:12 -0500 Subject: [PATCH 60/69] user-manual: fix missing colon in git-show example There should be a colon in this git-show example. Cc: Ramsay Jones Signed-off-by: "J. Bruce Fields" --- Documentation/user-manual.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt index f4ea967191..1e151b4d29 100644 --- a/Documentation/user-manual.txt +++ b/Documentation/user-manual.txt @@ -1431,7 +1431,7 @@ modifying the working directory, you can do that with gitlink:git-show[1]: ------------------------------------------------- -$ git show HEAD^ path/to/file +$ git show HEAD^:path/to/file ------------------------------------------------- which will display the given version of the file. From 1dc71a9155e209ed4da866eeb7c3064e4568532e Mon Sep 17 00:00:00 2001 From: "J. Bruce Fields" Date: Sat, 10 Mar 2007 22:38:13 -0500 Subject: [PATCH 61/69] user-manual: fix rendering of history diagrams Asciidoc appears to interpret a backslash at the end of a line as escaping the end-of-line character, which screws up the display of history diagrams like o--o--o \ o--... The obvious fix (replacing "\" by "\\") doesn't work. The only workaround I've found is to include all such diagrams in a LiteralBlock. Asciidoc claims that should be equivalent to a literal paragraph, so I don't understand why the difference--perhaps it's an asciidoc bug. Cc: Ramsay Jones Signed-off-by: "J. Bruce Fields" --- Documentation/user-manual.txt | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt index 1e151b4d29..0919574fb4 100644 --- a/Documentation/user-manual.txt +++ b/Documentation/user-manual.txt @@ -437,11 +437,14 @@ We will sometimes represent git history using diagrams like the one below. Commits are shown as "o", and the links between them with lines drawn with - / and \. Time goes left to right: + +................................................ o--o--o <-- Branch A / o--o--o <-- master \ o--o--o <-- Branch B +................................................ If we need to talk about a particular commit, the character "o" may be replaced with another letter or number. @@ -1928,25 +1931,29 @@ $ git commit You have performed no merges into mywork, so it is just a simple linear sequence of patches on top of "origin": - +................................................ o--o--o <-- origin \ o--o--o <-- mywork +................................................ Some more interesting work has been done in the upstream project, and "origin" has advanced: +................................................ o--o--O--o--o--o <-- origin \ a--b--c <-- mywork +................................................ At this point, you could use "pull" to merge your changes back in; the result would create a new merge commit, like this: - +................................................ o--o--O--o--o--o <-- origin \ \ a--b--c--m <-- mywork +................................................ However, if you prefer to keep the history in mywork a simple series of commits without any merges, you may instead choose to use @@ -1963,9 +1970,11 @@ point at the latest version of origin, then apply each of the saved patches to the new mywork. The result will look like: +................................................ o--o--O--o--o--o <-- origin \ a'--b'--c' <-- mywork +................................................ In the process, it may discover conflicts. In that case it will stop and allow you to fix the conflicts; after fixing conflicts, use "git @@ -2073,24 +2082,30 @@ The primary problem with rewriting the history of a branch has to do with merging. Suppose somebody fetches your branch and merges it into their branch, with a result something like this: +................................................ o--o--O--o--o--o <-- origin \ \ t--t--t--m <-- their branch: +................................................ Then suppose you modify the last three commits: +................................................ o--o--o <-- new head of origin / o--o--O--o--o--o <-- old head of origin +................................................ If we examined all this history together in one repository, it will look like: +................................................ o--o--o <-- new head of origin / o--o--O--o--o--o <-- old head of origin \ \ t--t--t--m <-- their branch: +................................................ Git has no way of knowing that the new head is an updated version of the old head; it treats this situation exactly the same as it would if @@ -2151,9 +2166,11 @@ commit. Git calls this process a "fast forward". A fast forward looks something like this: +................................................ o--o--o--o <-- old head of the branch \ o--o--o <-- new head of the branch +................................................ In some cases it is possible that the new head will *not* actually be @@ -2161,11 +2178,11 @@ a descendant of the old head. For example, the developer may have realized she made a serious mistake, and decided to backtrack, resulting in a situation like: +................................................ o--o--o--o--a--b <-- old head of the branch \ o--o--o <-- new head of the branch - - +................................................ In this case, "git fetch" will fail, and print out a warning. From 8ce9d83b78fa95addf61cb911fa052ec4f37f77e Mon Sep 17 00:00:00 2001 From: "J. Bruce Fields" Date: Sat, 10 Mar 2007 22:58:54 -0500 Subject: [PATCH 62/69] user-manual: install user manual stylesheet with other web documents Install the stylesheet needed for the user manual. This should solve the problem of, e.g., http://www.kernel.org/pub/software/scm/git/docs/user-manual.html lacking a lot of formatting. Signed-off-by: "J. Bruce Fields" --- Documentation/install-webdoc.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/install-webdoc.sh b/Documentation/install-webdoc.sh index b3981936e3..cd3a18eb7f 100755 --- a/Documentation/install-webdoc.sh +++ b/Documentation/install-webdoc.sh @@ -2,7 +2,7 @@ T="$1" -for h in *.html *.txt howto/*.txt howto/*.html RelNotes-*.txt +for h in *.html *.txt howto/*.txt howto/*.html RelNotes-*.txt *.css do if test -f "$T/$h" && diff -u -I'Last updated [0-9][0-9]-[A-Z][a-z][a-z]-' "$T/$h" "$h" From 96a5702409e193616ad7e56700dd6051ad324654 Mon Sep 17 00:00:00 2001 From: Matthias Lederhofer Date: Sun, 11 Mar 2007 02:35:00 +0100 Subject: [PATCH 63/69] setup_git_directory_gently: fix off-by-one error don't tell getcwd that the buffer has one spare byte for an extra / Signed-off-by: Matthias Lederhofer Signed-off-by: Junio C Hamano --- setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.c b/setup.c index e9d3f5aab6..76e5e693cc 100644 --- a/setup.c +++ b/setup.c @@ -216,7 +216,7 @@ const char *setup_git_directory_gently(int *nongit_ok) die("Not a git repository: '%s'", gitdirenv); } - if (!getcwd(cwd, sizeof(cwd)) || cwd[0] != '/') + if (!getcwd(cwd, sizeof(cwd)-1) || cwd[0] != '/') die("Unable to read current working directory"); offset = len = strlen(cwd); From 38448147553917c584a353ed6c39ad55b037f694 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Sat, 10 Mar 2007 19:21:25 +0100 Subject: [PATCH 64/69] git.el: Avoid appending a signoff line that is already present. Also avoid inserting an extra newline if other signoff lines are present. Signed-off-by: Alexandre Julliard Signed-off-by: Junio C Hamano --- contrib/emacs/git.el | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el index 13d198229b..427f89b0e1 100644 --- a/contrib/emacs/git.el +++ b/contrib/emacs/git.el @@ -891,6 +891,18 @@ and returns the process output as a string." (with-current-buffer log-edit-parent-buffer (git-get-filenames (git-marked-files-state 'added 'deleted 'modified)))) +(defun git-append-sign-off (name email) + "Append a Signed-off-by entry to the current buffer, avoiding duplicates." + (let ((sign-off (format "Signed-off-by: %s <%s>" name email)) + (case-fold-search t)) + (goto-char (point-min)) + (unless (re-search-forward (concat "^" (regexp-quote sign-off)) nil t) + (goto-char (point-min)) + (unless (re-search-forward "^Signed-off-by: " nil t) + (setq sign-off (concat "\n" sign-off))) + (goto-char (point-max)) + (insert sign-off "\n")))) + (defun git-commit-file () "Commit the marked file(s), asking for a commit message." (interactive) @@ -899,6 +911,8 @@ and returns the process output as a string." (merge-heads (git-get-merge-heads)) (dir default-directory) (coding-system (git-get-commits-coding-system)) + (committer-name (git-get-committer-name)) + (committer-email (git-get-committer-email)) (sign-off git-append-signed-off-by)) (with-current-buffer buffer (when (eq 0 (buffer-size)) @@ -907,7 +921,7 @@ and returns the process output as a string." (insert (propertize (format "Author: %s <%s>\n%s" - (git-get-committer-name) (git-get-committer-email) + committer-name committer-email (if merge-heads (format "Parent: %s\n%s\n" (git-rev-parse "HEAD") @@ -916,11 +930,9 @@ and returns the process output as a string." 'face 'git-header-face) (propertize git-log-msg-separator 'face 'git-separator-face) "\n") - (cond ((file-readable-p ".git/MERGE_MSG") - (insert-file-contents ".git/MERGE_MSG")) - (sign-off - (insert (format "\n\nSigned-off-by: %s <%s>\n" - (git-get-committer-name) (git-get-committer-email))))))) + (when (file-readable-p ".git/MERGE_MSG") + (insert-file-contents ".git/MERGE_MSG")) + (when sign-off (git-append-sign-off committer-name committer-email)))) (log-edit #'git-do-commit nil #'git-log-edit-files buffer) (setq font-lock-keywords (font-lock-compile-keywords git-log-edit-font-lock-keywords)) (setq buffer-file-coding-system coding-system) From 60fa08ed617dd148a9843bfdef2dfecf2ef60123 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Sat, 10 Mar 2007 19:22:26 +0100 Subject: [PATCH 65/69] git.el: Retrieve commit log information from .dotest directory. If a git-am or git-rebase is in progress, fill the commit log buffer from the commit information found in the various files in the .dotest directory. Signed-off-by: Alexandre Julliard Signed-off-by: Junio C Hamano --- contrib/emacs/git.el | 77 ++++++++++++++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 24 deletions(-) diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el index 427f89b0e1..db87a37895 100644 --- a/contrib/emacs/git.el +++ b/contrib/emacs/git.el @@ -903,36 +903,65 @@ and returns the process output as a string." (goto-char (point-max)) (insert sign-off "\n")))) +(defun git-setup-log-buffer (buffer &optional author-name author-email subject date msg) + "Setup the log buffer for a commit." + (unless git-status (error "Not in git-status buffer.")) + (let ((merge-heads (git-get-merge-heads)) + (dir default-directory) + (committer-name (git-get-committer-name)) + (committer-email (git-get-committer-email)) + (sign-off git-append-signed-off-by)) + (with-current-buffer buffer + (cd dir) + (erase-buffer) + (insert + (propertize + (format "Author: %s <%s>\n%s%s" + (or author-name committer-name) + (or author-email committer-email) + (if date (format "Date: %s\n" date) "") + (if merge-heads + (format "Parent: %s\n%s\n" + (git-rev-parse "HEAD") + (mapconcat (lambda (str) (concat "Parent: " str)) merge-heads "\n")) + "")) + 'face 'git-header-face) + (propertize git-log-msg-separator 'face 'git-separator-face) + "\n") + (when subject (insert subject "\n\n")) + (cond (msg (insert msg "\n")) + ((file-readable-p ".dotest/msg") + (insert-file-contents ".dotest/msg")) + ((file-readable-p ".git/MERGE_MSG") + (insert-file-contents ".git/MERGE_MSG"))) + ; delete empty lines at end + (goto-char (point-min)) + (when (re-search-forward "\n+\\'" nil t) + (replace-match "\n" t t)) + (when sign-off (git-append-sign-off committer-name committer-email))))) + (defun git-commit-file () "Commit the marked file(s), asking for a commit message." (interactive) (unless git-status (error "Not in git-status buffer.")) (let ((buffer (get-buffer-create "*git-commit*")) - (merge-heads (git-get-merge-heads)) - (dir default-directory) (coding-system (git-get-commits-coding-system)) - (committer-name (git-get-committer-name)) - (committer-email (git-get-committer-email)) - (sign-off git-append-signed-off-by)) - (with-current-buffer buffer - (when (eq 0 (buffer-size)) - (cd dir) - (erase-buffer) - (insert - (propertize - (format "Author: %s <%s>\n%s" - committer-name committer-email - (if merge-heads - (format "Parent: %s\n%s\n" - (git-rev-parse "HEAD") - (mapconcat (lambda (str) (concat "Parent: " str)) merge-heads "\n")) - "")) - 'face 'git-header-face) - (propertize git-log-msg-separator 'face 'git-separator-face) - "\n") - (when (file-readable-p ".git/MERGE_MSG") - (insert-file-contents ".git/MERGE_MSG")) - (when sign-off (git-append-sign-off committer-name committer-email)))) + author-name author-email subject date) + (when (eq 0 (buffer-size buffer)) + (when (file-readable-p ".dotest/info") + (with-temp-buffer + (insert-file-contents ".dotest/info") + (goto-char (point-min)) + (when (re-search-forward "^Author: \\(.*\\)\nEmail: \\(.*\\)$" nil t) + (setq author-name (match-string 1)) + (setq author-email (match-string 2))) + (goto-char (point-min)) + (when (re-search-forward "^Subject: \\(.*\\)$" nil t) + (setq subject (match-string 1))) + (goto-char (point-min)) + (when (re-search-forward "^Date: \\(.*\\)$" nil t) + (setq date (match-string 1))))) + (git-setup-log-buffer buffer author-name author-email subject date)) (log-edit #'git-do-commit nil #'git-log-edit-files buffer) (setq font-lock-keywords (font-lock-compile-keywords git-log-edit-font-lock-keywords)) (setq buffer-file-coding-system coding-system) From ed8ad7e2e29d4adf342964f6cc15d6b84f62c700 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sun, 11 Mar 2007 19:49:08 +0100 Subject: [PATCH 66/69] I like the idea of the new ':/' notation, and gave it a try, but all I could get was a segfault. It was dereferencing a NULL commit list. Fix below. With it, this example now works: $ mkdir .j; cd .j; touch f $ git-init; git-add f; git-commit -mc f; echo x >f; git-commit -md f $ git-diff -p :/c :/d diff --git a/f b/f index e69de29..587be6b 100644 --- a/f +++ b/f @@ -0,0 +1 @@ +x Signed-off-by: Jim Meyering Signed-off-by: Junio C Hamano --- sha1_name.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sha1_name.c b/sha1_name.c index 31812d3d26..6b8b67b4db 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -605,7 +605,7 @@ static int handle_one_ref(const char *path, int get_sha1_oneline(const char *prefix, unsigned char *sha1) { struct commit_list *list = NULL, *backup = NULL, *l; - struct commit *commit; + struct commit *commit = NULL; if (prefix[0] == '!') { if (prefix[1] != '!') @@ -617,8 +617,12 @@ int get_sha1_oneline(const char *prefix, unsigned char *sha1) for_each_ref(handle_one_ref, &list); for (l = list; l; l = l->next) commit_list_insert(l->item, &backup); - while ((commit = pop_most_recent_commit(&list, ONELINE_SEEN))) { + while (list) { char *p; + + commit = pop_most_recent_commit(&list, ONELINE_SEEN); + if (!commit) + break; parse_object(commit->object.sha1); if (!commit->buffer || !(p = strstr(commit->buffer, "\n\n"))) continue; From 538778469ca267c8888bc659d20680c3a1e077fd Mon Sep 17 00:00:00 2001 From: Frank Lichtenheld Date: Tue, 6 Mar 2007 10:42:24 +0100 Subject: [PATCH 67/69] cvsserver: Use Merged response instead of Update-existing for merged files Using Update-existing leads to the client forgetting about the "locally modified" status of the file which can lead to loss of local changes on later updates. Signed-off-by: Frank Lichtenheld Acked-by: Martin Langhoff Signed-off-by: Junio C Hamano --- git-cvsserver.perl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/git-cvsserver.perl b/git-cvsserver.perl index 1bf892e4c1..65fcc84049 100755 --- a/git-cvsserver.perl +++ b/git-cvsserver.perl @@ -957,12 +957,12 @@ sub req_update { $log->info("Merged successfully"); print "M M $filename\n"; - $log->debug("Update-existing $dirpart"); + $log->debug("Merged $dirpart"); # Don't want to actually _DO_ the update if -n specified unless ( $state->{globaloptions}{-n} ) { - print "Update-existing $dirpart\n"; + print "Merged $dirpart\n"; $log->debug($state->{CVSROOT} . "/$state->{module}/$filename"); print $state->{CVSROOT} . "/$state->{module}/$filename\n"; my $kopts = kopts_from_path($filepart); @@ -978,7 +978,7 @@ sub req_update # Don't want to actually _DO_ the update if -n specified unless ( $state->{globaloptions}{-n} ) { - print "Update-existing $dirpart\n"; + print "Merged $dirpart\n"; print $state->{CVSROOT} . "/$state->{module}/$filename\n"; my $kopts = kopts_from_path($filepart); print "/$filepart/1.$meta->{revision}/+/$kopts/\n"; From 497bdc88d661b3da15fdd5365293381bd66010c9 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sat, 10 Mar 2007 03:27:28 -0500 Subject: [PATCH 68/69] Switch to run_command_v_opt in revert Another change by me is removing the va_list variants of run_command, one of which is used by builtin-revert.c. To avoid compile errors I'm refactoring builtin-revert to use the char** variant instead, as that variant is staying. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- builtin-revert.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/builtin-revert.c b/builtin-revert.c index 2f2dc1bbaa..652eece5ad 100644 --- a/builtin-revert.c +++ b/builtin-revert.c @@ -207,6 +207,7 @@ static int merge_recursive(const char *base_sha1, const char *next_sha1, const char *next_name) { char buffer[256]; + const char *argv[6]; sprintf(buffer, "GITHEAD_%s", head_sha1); setenv(buffer, head_name, 1); @@ -219,10 +220,14 @@ static int merge_recursive(const char *base_sha1, * and $prev on top of us (when reverting), or the change between * $prev and $commit on top of us (when cherry-picking or replaying). */ + argv[0] = "merge-recursive"; + argv[1] = base_sha1; + argv[2] = "--"; + argv[3] = head_sha1; + argv[4] = next_sha1; + argv[5] = NULL; - return run_command_opt(RUN_COMMAND_NO_STDIN | RUN_GIT_CMD, - "merge-recursive", base_sha1, "--", - head_sha1, next_sha1, NULL); + return run_command_v_opt(argv, RUN_COMMAND_NO_STDIN | RUN_GIT_CMD); } static int revert_or_cherry_pick(int argc, const char **argv) From afdb269c76cb965cf8bbb1012c2ec0e2bf7172b1 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sat, 10 Mar 2007 03:27:52 -0500 Subject: [PATCH 69/69] Remove unused run_command variants We don't actually use these va_list based variants of run_command anymore. I'm removing them before I make further improvements. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- builtin-push.c | 2 +- run-command.c | 45 --------------------------------------------- run-command.h | 4 ---- 3 files changed, 1 insertion(+), 50 deletions(-) diff --git a/builtin-push.c b/builtin-push.c index 979efcc45f..6ab9a28e8c 100644 --- a/builtin-push.c +++ b/builtin-push.c @@ -336,7 +336,7 @@ static int do_push(const char *repo) argv[dest_argc] = NULL; if (verbose) fprintf(stderr, "Pushing to %s\n", dest); - err = run_command_v(argv); + err = run_command_v_opt(argv, 0); if (!err) continue; switch (err) { diff --git a/run-command.c b/run-command.c index cfbad74d14..94ace50a25 100644 --- a/run-command.c +++ b/run-command.c @@ -46,48 +46,3 @@ int run_command_v_opt(const char **argv, int flags) return 0; } } - -int run_command_v(const char **argv) -{ - return run_command_v_opt(argv, 0); -} - -static int run_command_va_opt(int opt, const char *cmd, va_list param) -{ - int argc; - const char *argv[MAX_RUN_COMMAND_ARGS]; - const char *arg; - - argv[0] = (char*) cmd; - argc = 1; - while (argc < MAX_RUN_COMMAND_ARGS) { - arg = argv[argc++] = va_arg(param, char *); - if (!arg) - break; - } - if (MAX_RUN_COMMAND_ARGS <= argc) - return error("too many args to run %s", cmd); - return run_command_v_opt(argv, opt); -} - -int run_command_opt(int opt, const char *cmd, ...) -{ - va_list params; - int r; - - va_start(params, cmd); - r = run_command_va_opt(opt, cmd, params); - va_end(params); - return r; -} - -int run_command(const char *cmd, ...) -{ - va_list params; - int r; - - va_start(params, cmd); - r = run_command_va_opt(0, cmd, params); - va_end(params); - return r; -} diff --git a/run-command.h b/run-command.h index 59c4476ced..2646d38ac7 100644 --- a/run-command.h +++ b/run-command.h @@ -1,7 +1,6 @@ #ifndef RUN_COMMAND_H #define RUN_COMMAND_H -#define MAX_RUN_COMMAND_ARGS 256 enum { ERR_RUN_COMMAND_FORK = 10000, ERR_RUN_COMMAND_EXEC, @@ -15,8 +14,5 @@ enum { #define RUN_GIT_CMD 2 /*If this is to be git sub-command */ #define RUN_COMMAND_STDOUT_TO_STDERR 4 int run_command_v_opt(const char **argv, int opt); -int run_command_v(const char **argv); -int run_command_opt(int opt, const char *cmd, ...); -int run_command(const char *cmd, ...); #endif