diff options
165 files changed, 5096 insertions, 1122 deletions
diff --git a/.gitignore b/.gitignore index 87fcc5f6ff..83a5c9df1b 100644 --- a/.gitignore +++ b/.gitignore @@ -92,6 +92,7 @@ /git-name-rev /git-mv /git-notes +/git-p4 /git-pack-redundant /git-pack-objects /git-pack-refs @@ -180,6 +181,7 @@ /test-index-version /test-line-buffer /test-match-trees +/test-mergesort /test-mktemp /test-parse-options /test-path-utils diff --git a/Documentation/Makefile b/Documentation/Makefile index d40e211f22..9fee0b9261 100644 --- a/Documentation/Makefile +++ b/Documentation/Makefile @@ -124,6 +124,16 @@ SHELL_PATH ?= $(SHELL) # Shell quote; SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH)) +ifdef DEFAULT_PAGER +DEFAULT_PAGER_SQ = $(subst ','\'',$(DEFAULT_PAGER)) +ASCIIDOC_EXTRA += -a 'git-default-pager=$(DEFAULT_PAGER_SQ)' +endif + +ifdef DEFAULT_EDITOR +DEFAULT_EDITOR_SQ = $(subst ','\'',$(DEFAULT_EDITOR)) +ASCIIDOC_EXTRA += -a 'git-default-editor=$(DEFAULT_EDITOR_SQ)' +endif + # # Please note that there is a minor bug in asciidoc. # The version after 6.0.3 _will_ include the patch found here: diff --git a/Documentation/RelNotes/1.7.11.txt b/Documentation/RelNotes/1.7.11.txt new file mode 100644 index 0000000000..7694203cad --- /dev/null +++ b/Documentation/RelNotes/1.7.11.txt @@ -0,0 +1,115 @@ +Git v1.7.11 Release Notes +========================= + +Updates since v1.7.10 +--------------------- + +UI, Workflows & Features + + * A third-party tool "git subtree" is distributed in contrib/ + + * Even with "-q"uiet option, "checkout" used to report setting up + tracking. Also "branch" learned the "-q"uiet option to squelch + informational message. + + * The smart-http backend used to always override GIT_COMMITTER_* + variables with REMOTE_USER and REMOTE_ADDR, but these variables are + now preserved when set. + + * "git am" learned the "--include" option, which is an opposite of + existing the "--exclude" option. + + * When "git am -3" needs to fall back to an application to a + synthesized preimage followed by a 3-way merge, the paths that + needed such treatment are now reported to the end user, so that the + result in them can be eyeballed with extra care. + + * The "fmt-merge-msg" command learns to list the primary contributors + involved in the side topic you are merging. + + * The cases "git push" fails due to non-ff can be broken into three + categories; each case is given a separate advise message. + + * A 'snapshot' request to "gitweb" honors If-Modified-Since: header, + based on the commit date. + +Foreign Interface + + +Performance + + +Internal Implementation (please report possible regressions) + + * Minor memory leak during unpack_trees (hence "merge" and "checkout" + to check out another branch) has been plugged. + + * More lower-level commands learned to use the streaming API to read + from the object store without keeping everything in core. + + * Because "sh" on the user's PATH may be utterly broken on some + systems, run-command API now uses SHELL_PATH, not /bin/sh, when + spawning an external command (not applicable to Windows port). + +Also contains minor documentation updates and code clean-ups. + + +Fixes since v1.7.10 +------------------- + +Unless otherwise noted, all the fixes since v1.7.10 in the maintenance +releases are contained in this release (see release notes to them for +details). + + * When PATH contains an unreadable directory, alias expansion code + did not kick in, and failed with an error that said "git-subcmd" + was not found. + (merge 38f865c jk/run-command-eacces later to maint). + + * The 'push to upstream' implementation was broken in some corner + cases. "git push $there" without refspec, when the current branch + is set to push to a remote different from $there, used to push to + $there using the upstream information to a remote unreleated to + $there. + (merge 135dade jc/push-upstream-sanity later to maint). + + * "git clean -d -f" (not "-d -f -f") is supposed to protect nested + working trees of independent git repositories that exist in the + current project working tree from getting removed, but the + protection applied only to such working trees that are at the + top-level of the current project by mistake. + (merge ae2f203 jc/maint-clean-nested-worktree-in-subdir later to maint). + + * Rename detection logic used to match two empty files as renames + during merge-recursive, leading unnatural mismerges. + (merge 4f7cb99 jk/diff-no-rename-empty later to maint). + + * An age-old corner case bug in combine diff (only triggered with -U0 + and the hunk at the beginning of the file needs to be shown) has + been fixed. + (merge e5e9b56 rs/combine-diff-zero-context-at-the-beginning later to maint). + + * When "git commit --template F" errors out because the user did not + touch the message, it claimed that it aborts due to "empty + message", which was utterly wrong. + (merge 1f08c2c jc/commit-unedited-template later to maint). + + * "git add -p" is not designed to deal with unmerged paths but did + not exclude them and tried to apply funny patches only to fail. + (merge 4066bd6 jk/add-p-skip-conflicts later to maint). + + * "git commit --author=$name" did not tell the name that was being + recorded in the resulting commit to hooks, even though it does do + so when the end user overrode the authorship via the + "GIT_AUTHOR_NAME" environment variable. + (merge 7dfe8ad jc/commit-hook-authorship later to maint). + + * The regexp configured with diff.wordregex was incorrectly reused + across files. + (merge 6440d34 tr/maint-word-diff-regex-sticky later to maint). + + * Running "notes merge --commit" failed to perform correctly when run + from any directory inside $GIT_DIR/. When "notes merge" stops with + conflicts, $GIT_DIR/NOTES_MERGE_WORKTREE is the place a user edits + to resolve it. + (merge dabba59 jh/notes-merge-in-git-dir-worktree later to maint). diff --git a/Documentation/config.txt b/Documentation/config.txt index c081657be7..fb386abc51 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -138,8 +138,23 @@ advice.*:: + -- pushNonFastForward:: - Advice shown when linkgit:git-push[1] refuses - non-fast-forward refs. + Set this variable to 'false' if you want to disable + 'pushNonFFCurrent', 'pushNonFFDefault', and + 'pushNonFFMatching' simultaneously. + pushNonFFCurrent:: + Advice shown when linkgit:git-push[1] fails due to a + non-fast-forward update to the current branch. + pushNonFFDefault:: + Advice to set 'push.default' to 'upstream' or 'current' + when you ran linkgit:git-push[1] and pushed 'matching + refs' by default (i.e. you did not provide an explicit + refspec, and no 'push.default' configuration was set) + and it resulted in a non-fast-forward error. + pushNonFFMatching:: + Advice shown when you ran linkgit:git-push[1] and pushed + 'matching refs' explicitly (i.e. you used ':', or + specified a refspec that isn't your current branch) and + it resulted in a non-fast-forward error. statusHints:: Directions on how to stage/unstage/add shown in the output of linkgit:git-status[1] and the template shown diff --git a/Documentation/git-am.txt b/Documentation/git-am.txt index ee6cca2e13..19d57a80f5 100644 --- a/Documentation/git-am.txt +++ b/Documentation/git-am.txt @@ -13,7 +13,7 @@ SYNOPSIS [--3way] [--interactive] [--committer-date-is-author-date] [--ignore-date] [--ignore-space-change | --ignore-whitespace] [--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>] - [--exclude=<path>] [--reject] [-q | --quiet] + [--exclude=<path>] [--include=<path>] [--reject] [-q | --quiet] [--scissors | --no-scissors] [(<mbox> | <Maildir>)...] 'git am' (--continue | --skip | --abort) @@ -92,6 +92,7 @@ default. You can use `--no-utf8` to override this. -p<n>:: --directory=<dir>:: --exclude=<path>:: +--include=<path>:: --reject:: These flags are passed to the 'git apply' (see linkgit:git-apply[1]) program that applies diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt index 6410c3d345..e71370d6b4 100644 --- a/Documentation/git-branch.txt +++ b/Documentation/git-branch.txt @@ -126,6 +126,11 @@ OPTIONS relationship to upstream branch (if any). If given twice, print the name of the upstream branch, as well. +-q:: +--quiet:: + Be more quiet when creating or deleting a branch, suppressing + non-error messages. + --abbrev=<length>:: Alter the sha1's minimum display length in the output listing. The default value is 7 and can be overridden by the `core.abbrev` diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt index 5cc84a1391..68abfcacca 100644 --- a/Documentation/git-commit.txt +++ b/Documentation/git-commit.txt @@ -132,11 +132,14 @@ OPTIONS -t <file>:: --template=<file>:: - Use the contents of the given file as the initial version - of the commit message. The editor is invoked and you can - make subsequent changes. If a message is specified using - the `-m` or `-F` options, this option has no effect. This - overrides the `commit.template` configuration variable. + When editing the commit message, start the editor with the + contents in the given file. The `commit.template` configuration + variable is often used to give this option implicitly to the + command. This mechanism can be used by projects that want to + guide participants with some hints on what to write in the message + in what order. If the user exits the editor without editing the + message, the commit is aborted. This has no effect when a message + is given by other means, e.g. with the `-m` or `-F` options. -s:: --signoff:: diff --git a/Documentation/git-p4.txt b/Documentation/git-p4.txt index b7c7929716..3fac4137e2 100644 --- a/Documentation/git-p4.txt +++ b/Documentation/git-p4.txt @@ -31,13 +31,6 @@ the updated p4 remote branch. EXAMPLE ------- -* Create an alias for 'git p4', using the full path to the 'git-p4' - script if needed: -+ ------------- -$ git config --global alias.p4 '!git-p4' ------------- - * Clone a repository: + ------------ @@ -311,19 +304,19 @@ configuration file. This allows future 'git p4 submit' commands to work properly; the submit command looks only at the variable and does not have a command-line option. -The full syntax for a p4 view is documented in 'p4 help views'. Git-p4 +The full syntax for a p4 view is documented in 'p4 help views'. 'Git p4' knows only a subset of the view syntax. It understands multi-line mappings, overlays with '+', exclusions with '-' and double-quotes -around whitespace. Of the possible wildcards, git-p4 only handles -'...', and only when it is at the end of the path. Git-p4 will complain +around whitespace. Of the possible wildcards, 'git p4' only handles +'...', and only when it is at the end of the path. 'Git p4' will complain if it encounters an unhandled wildcard. Bugs in the implementation of overlap mappings exist. If multiple depot paths map through overlays to the same location in the repository, -git-p4 can choose the wrong one. This is hard to solve without -dedicating a client spec just for git-p4. +'git p4' can choose the wrong one. This is hard to solve without +dedicating a client spec just for 'git p4'. -The name of the client can be given to git-p4 in multiple ways. The +The name of the client can be given to 'git p4' in multiple ways. The variable 'git-p4.client' takes precedence if it exists. Otherwise, normal p4 mechanisms of determining the client are used: environment variable P4CLIENT, a file referenced by P4CONFIG, or the local host name. diff --git a/Documentation/git-var.txt b/Documentation/git-var.txt index 5317cc2474..988a3234f4 100644 --- a/Documentation/git-var.txt +++ b/Documentation/git-var.txt @@ -43,13 +43,21 @@ GIT_EDITOR:: `$SOME_ENVIRONMENT_VARIABLE`, `"C:\Program Files\Vim\gvim.exe" --nofork`. The order of preference is the `$GIT_EDITOR` environment variable, then `core.editor` configuration, then - `$VISUAL`, then `$EDITOR`, and then finally 'vi'. + `$VISUAL`, then `$EDITOR`, and then the default chosen at compile + time, which is usually 'vi'. +ifdef::git-default-editor[] + The build you are using chose '{git-default-editor}' as the default. +endif::git-default-editor[] GIT_PAGER:: Text viewer for use by git commands (e.g., 'less'). The value is meant to be interpreted by the shell. The order of preference is the `$GIT_PAGER` environment variable, then `core.pager` - configuration, then `$PAGER`, and then finally 'less'. + configuration, then `$PAGER`, and then the default chosen at + compile time (usually 'less'). +ifdef::git-default-pager[] + The build you are using chose '{git-default-pager}' as the default. +endif::git-default-pager[] Diagnostics ----------- diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN index 1f55d3e900..b982e33299 100755 --- a/GIT-VERSION-GEN +++ b/GIT-VERSION-GEN @@ -1,7 +1,7 @@ #!/bin/sh GVF=GIT-VERSION-FILE -DEF_VER=v1.7.10 +DEF_VER=v1.7.10.GIT LF=' ' @@ -131,6 +131,9 @@ Issues of note: use English. Under autoconf the configure script will do this automatically if it can't find libintl on the system. + - Python version 2.6 or later is needed to use the git-p4 + interface to Perforce. + - Some platform specific issues are dealt with Makefile rules, but depending on your specific installation, you may not have all the libraries/tools needed, or you may have @@ -440,6 +440,7 @@ SCRIPT_PERL += git-send-email.perl SCRIPT_PERL += git-svn.perl SCRIPT_PYTHON += git-remote-testgit.py +SCRIPT_PYTHON += git-p4.py SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)) \ $(patsubst %.perl,%,$(SCRIPT_PERL)) \ @@ -480,6 +481,7 @@ TEST_PROGRAMS_NEED_X += test-genrandom TEST_PROGRAMS_NEED_X += test-index-version TEST_PROGRAMS_NEED_X += test-line-buffer TEST_PROGRAMS_NEED_X += test-match-trees +TEST_PROGRAMS_NEED_X += test-mergesort TEST_PROGRAMS_NEED_X += test-mktemp TEST_PROGRAMS_NEED_X += test-parse-options TEST_PROGRAMS_NEED_X += test-path-utils @@ -590,6 +592,7 @@ LIB_H += log-tree.h LIB_H += mailmap.h LIB_H += merge-file.h LIB_H += merge-recursive.h +LIB_H += mergesort.h LIB_H += notes.h LIB_H += notes-cache.h LIB_H += notes-merge.h @@ -694,6 +697,7 @@ LIB_OBJS += mailmap.o LIB_OBJS += match-trees.o LIB_OBJS += merge-file.o LIB_OBJS += merge-recursive.o +LIB_OBJS += mergesort.o LIB_OBJS += name-hash.o LIB_OBJS += notes.o LIB_OBJS += notes-cache.o @@ -1849,6 +1853,13 @@ DEFAULT_PAGER_CQ_SQ = $(subst ','\'',$(DEFAULT_PAGER_CQ)) BASIC_CFLAGS += -DDEFAULT_PAGER='$(DEFAULT_PAGER_CQ_SQ)' endif +ifdef SHELL_PATH +SHELL_PATH_CQ = "$(subst ",\",$(subst \,\\,$(SHELL_PATH)))" +SHELL_PATH_CQ_SQ = $(subst ','\'',$(SHELL_PATH_CQ)) + +BASIC_CFLAGS += -DSHELL_PATH='$(SHELL_PATH_CQ_SQ)' +endif + ALL_CFLAGS += $(BASIC_CFLAGS) ALL_LDFLAGS += $(BASIC_LDFLAGS) @@ -2258,6 +2269,8 @@ $(XDIFF_LIB): $(XDIFF_OBJS) $(VCSSVN_LIB): $(VCSSVN_OBJS) $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(VCSSVN_OBJS) +export DEFAULT_EDITOR DEFAULT_PAGER + doc: $(MAKE) -C Documentation all @@ -1 +1 @@ -Documentation/RelNotes/1.7.10.txt
\ No newline at end of file +Documentation/RelNotes/1.7.11.txt
\ No newline at end of file @@ -1,6 +1,9 @@ #include "cache.h" int advice_push_nonfastforward = 1; +int advice_push_non_ff_current = 1; +int advice_push_non_ff_default = 1; +int advice_push_non_ff_matching = 1; int advice_status_hints = 1; int advice_commit_before_merge = 1; int advice_resolve_conflict = 1; @@ -12,6 +15,9 @@ static struct { int *preference; } advice_config[] = { { "pushnonfastforward", &advice_push_nonfastforward }, + { "pushnonffcurrent", &advice_push_non_ff_current }, + { "pushnonffdefault", &advice_push_non_ff_default }, + { "pushnonffmatching", &advice_push_non_ff_matching }, { "statushints", &advice_status_hints }, { "commitbeforemerge", &advice_commit_before_merge }, { "resolveconflict", &advice_resolve_conflict }, @@ -4,6 +4,9 @@ #include "git-compat-util.h" extern int advice_push_nonfastforward; +extern int advice_push_non_ff_current; +extern int advice_push_non_ff_default; +extern int advice_push_non_ff_matching; extern int advice_status_hints; extern int advice_commit_before_merge; extern int advice_resolve_conflict; @@ -101,9 +101,10 @@ void install_branch_config(int flag, const char *local, const char *origin, cons * config. */ static int setup_tracking(const char *new_ref, const char *orig_ref, - enum branch_track track) + enum branch_track track, int quiet) { struct tracking tracking; + int config_flags = quiet ? 0 : BRANCH_CONFIG_VERBOSE; if (strlen(new_ref) > 1024 - 7 - 7 - 1) return error("Tracking not set up: name too long: %s", @@ -128,7 +129,7 @@ static int setup_tracking(const char *new_ref, const char *orig_ref, return error("Not tracking: ambiguous information for ref %s", orig_ref); - install_branch_config(BRANCH_CONFIG_VERBOSE, new_ref, tracking.remote, + install_branch_config(config_flags, new_ref, tracking.remote, tracking.src ? tracking.src : orig_ref); free(tracking.src); @@ -191,7 +192,7 @@ int validate_new_branchname(const char *name, struct strbuf *ref, void create_branch(const char *head, const char *name, const char *start_name, int force, int reflog, int clobber_head, - enum branch_track track) + int quiet, enum branch_track track) { struct ref_lock *lock = NULL; struct commit *commit; @@ -260,7 +261,7 @@ void create_branch(const char *head, start_name); if (real_ref && track) - setup_tracking(ref.buf+11, real_ref, track); + setup_tracking(ref.buf+11, real_ref, track, quiet); if (!dont_change_ref) if (write_ref_sha1(lock, sha1, msg) < 0) @@ -14,7 +14,7 @@ */ void create_branch(const char *head, const char *name, const char *start_name, int force, int reflog, - int clobber_head, enum branch_track track); + int clobber_head, int quiet, enum branch_track track); /* * Validates that the requested branch may be created, returning the diff --git a/builtin/apply.c b/builtin/apply.c index 389898f133..799bb5e906 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -152,9 +152,14 @@ struct fragment { unsigned long leading, trailing; unsigned long oldpos, oldlines; unsigned long newpos, newlines; + /* + * 'patch' is usually borrowed from buf in apply_patch(), + * but some codepaths store an allocated buffer. + */ const char *patch; + unsigned free_patch:1, + rejected:1; int size; - int rejected; int linenr; struct fragment *next; }; @@ -196,6 +201,36 @@ struct patch { struct patch *next; }; +static void free_fragment_list(struct fragment *list) +{ + while (list) { + struct fragment *next = list->next; + if (list->free_patch) + free((char *)list->patch); + free(list); + list = next; + } +} + +static void free_patch(struct patch *patch) +{ + free_fragment_list(patch->fragments); + free(patch->def_name); + free(patch->old_name); + free(patch->new_name); + free(patch->result); + free(patch); +} + +static void free_patch_list(struct patch *list) +{ + while (list) { + struct patch *next = list->next; + free_patch(list); + list = next; + } +} + /* * A line in a file, len-bytes long (includes the terminating LF, * except for an incomplete line at the end if the file ends with @@ -302,6 +337,11 @@ static void add_line_info(struct image *img, const char *bol, size_t len, unsign img->nr++; } +/* + * "buf" has the file contents to be patched (read from various sources). + * attach it to "image" and add line-based index to it. + * "image" now owns the "buf". + */ static void prepare_image(struct image *image, char *buf, size_t len, int prepare_linetable) { @@ -353,7 +393,6 @@ static void say_patch_name(FILE *output, const char *pre, fputs(post, output); } -#define CHUNKSIZE (8192) #define SLOP (16) static void read_patch_file(struct strbuf *sb, int fd) @@ -416,7 +455,7 @@ static char *squash_slash(char *name) return name; } -static char *find_name_gnu(const char *line, char *def, int p_value) +static char *find_name_gnu(const char *line, const char *def, int p_value) { struct strbuf name = STRBUF_INIT; char *cp; @@ -439,11 +478,7 @@ static char *find_name_gnu(const char *line, char *def, int p_value) cp++; } - /* name can later be freed, so we need - * to memmove, not just return cp - */ strbuf_remove(&name, 0, cp - name.buf); - free(def); if (root) strbuf_insert(&name, 0, root, root_len); return squash_slash(strbuf_detach(&name, NULL)); @@ -608,8 +643,13 @@ static size_t diff_timestamp_len(const char *line, size_t len) return line + len - end; } -static char *find_name_common(const char *line, char *def, int p_value, - const char *end, int terminate) +static char *null_strdup(const char *s) +{ + return s ? xstrdup(s) : NULL; +} + +static char *find_name_common(const char *line, const char *def, + int p_value, const char *end, int terminate) { int len; const char *start = NULL; @@ -630,10 +670,10 @@ static char *find_name_common(const char *line, char *def, int p_value, start = line; } if (!start) - return squash_slash(def); + return squash_slash(null_strdup(def)); len = line - start; if (!len) - return squash_slash(def); + return squash_slash(null_strdup(def)); /* * Generally we prefer the shorter name, especially @@ -644,8 +684,7 @@ static char *find_name_common(const char *line, char *def, int p_value, if (def) { int deflen = strlen(def); if (deflen < len && !strncmp(start, def, deflen)) - return squash_slash(def); - free(def); + return squash_slash(xstrdup(def)); } if (root) { @@ -842,8 +881,10 @@ static void parse_traditional_patch(const char *first, const char *second, struc name = find_name_traditional(first, NULL, p_value); patch->old_name = name; } else { - name = find_name_traditional(first, NULL, p_value); - name = find_name_traditional(second, name, p_value); + char *first_name; + first_name = find_name_traditional(first, NULL, p_value); + name = find_name_traditional(second, first_name, p_value); + free(first_name); if (has_epoch_timestamp(first)) { patch->is_new = 1; patch->is_delete = 0; @@ -853,7 +894,8 @@ static void parse_traditional_patch(const char *first, const char *second, struc patch->is_delete = 1; patch->old_name = name; } else { - patch->old_name = patch->new_name = name; + patch->old_name = name; + patch->new_name = xstrdup(name); } } if (!name) @@ -903,13 +945,19 @@ static char *gitdiff_verify_name(const char *line, int isnull, char *orig_name, static int gitdiff_oldname(const char *line, struct patch *patch) { + char *orig = patch->old_name; patch->old_name = gitdiff_verify_name(line, patch->is_new, patch->old_name, "old"); + if (orig != patch->old_name) + free(orig); return 0; } static int gitdiff_newname(const char *line, struct patch *patch) { + char *orig = patch->new_name; patch->new_name = gitdiff_verify_name(line, patch->is_delete, patch->new_name, "new"); + if (orig != patch->new_name) + free(orig); return 0; } @@ -928,20 +976,23 @@ static int gitdiff_newmode(const char *line, struct patch *patch) static int gitdiff_delete(const char *line, struct patch *patch) { patch->is_delete = 1; - patch->old_name = patch->def_name; + free(patch->old_name); + patch->old_name = null_strdup(patch->def_name); return gitdiff_oldmode(line, patch); } static int gitdiff_newfile(const char *line, struct patch *patch) { patch->is_new = 1; - patch->new_name = patch->def_name; + free(patch->new_name); + patch->new_name = null_strdup(patch->def_name); return gitdiff_newmode(line, patch); } static int gitdiff_copysrc(const char *line, struct patch *patch) { patch->is_copy = 1; + free(patch->old_name); patch->old_name = find_name(line, NULL, p_value ? p_value - 1 : 0, 0); return 0; } @@ -949,6 +1000,7 @@ static int gitdiff_copysrc(const char *line, struct patch *patch) static int gitdiff_copydst(const char *line, struct patch *patch) { patch->is_copy = 1; + free(patch->new_name); patch->new_name = find_name(line, NULL, p_value ? p_value - 1 : 0, 0); return 0; } @@ -956,6 +1008,7 @@ static int gitdiff_copydst(const char *line, struct patch *patch) static int gitdiff_renamesrc(const char *line, struct patch *patch) { patch->is_rename = 1; + free(patch->old_name); patch->old_name = find_name(line, NULL, p_value ? p_value - 1 : 0, 0); return 0; } @@ -963,6 +1016,7 @@ static int gitdiff_renamesrc(const char *line, struct patch *patch) static int gitdiff_renamedst(const char *line, struct patch *patch) { patch->is_rename = 1; + free(patch->new_name); patch->new_name = find_name(line, NULL, p_value ? p_value - 1 : 0, 0); return 0; } @@ -1044,7 +1098,7 @@ static const char *stop_at_slash(const char *line, int llen) * creation or deletion of an empty file. In any of these cases, * both sides are the same name under a/ and b/ respectively. */ -static char *git_header_name(char *line, int llen) +static char *git_header_name(const char *line, int llen) { const char *name; const char *second = NULL; @@ -1171,7 +1225,7 @@ static char *git_header_name(char *line, int llen) } /* Verify that we recognize the lines following a git header */ -static int parse_git_header(char *line, int len, unsigned int size, struct patch *patch) +static int parse_git_header(const char *line, int len, unsigned int size, struct patch *patch) { unsigned long offset; @@ -1287,7 +1341,7 @@ static int parse_range(const char *line, int len, int offset, const char *expect return offset + ex; } -static void recount_diff(char *line, int size, struct fragment *fragment) +static void recount_diff(const char *line, int size, struct fragment *fragment) { int oldlines = 0, newlines = 0, ret = 0; @@ -1341,7 +1395,7 @@ static void recount_diff(char *line, int size, struct fragment *fragment) * Parse a unified diff fragment header of the * form "@@ -a,b +c,d @@" */ -static int parse_fragment_header(char *line, int len, struct fragment *fragment) +static int parse_fragment_header(const char *line, int len, struct fragment *fragment) { int offset; @@ -1355,7 +1409,7 @@ static int parse_fragment_header(char *line, int len, struct fragment *fragment) return offset; } -static int find_header(char *line, unsigned long size, int *hdrsize, struct patch *patch) +static int find_header(const char *line, unsigned long size, int *hdrsize, struct patch *patch) { unsigned long offset, len; @@ -1403,7 +1457,8 @@ static int find_header(char *line, unsigned long size, int *hdrsize, struct patc if (!patch->def_name) die("git diff header lacks filename information when removing " "%d leading pathname components (line %d)" , p_value, linenr); - patch->old_name = patch->new_name = patch->def_name; + patch->old_name = xstrdup(patch->def_name); + patch->new_name = xstrdup(patch->def_name); } if (!patch->is_delete && !patch->new_name) die("git diff header lacks filename information " @@ -1466,7 +1521,7 @@ static void check_whitespace(const char *line, int len, unsigned ws_rule) * between a "---" that is part of a patch, and a "---" that starts * the next patch is to look at the line counts.. */ -static int parse_fragment(char *line, unsigned long size, +static int parse_fragment(const char *line, unsigned long size, struct patch *patch, struct fragment *fragment) { int added, deleted; @@ -1562,7 +1617,15 @@ static int parse_fragment(char *line, unsigned long size, return offset; } -static int parse_single_patch(char *line, unsigned long size, struct patch *patch) +/* + * We have seen "diff --git a/... b/..." header (or a traditional patch + * header). Read hunks that belong to this patch into fragments and hang + * them to the given patch structure. + * + * The (fragment->patch, fragment->size) pair points into the memory given + * by the caller, not a copy, when we return. + */ +static int parse_single_patch(const char *line, unsigned long size, struct patch *patch) { unsigned long offset = 0; unsigned long oldlines = 0, newlines = 0, context = 0; @@ -1655,6 +1718,11 @@ static char *inflate_it(const void *data, unsigned long size, return out; } +/* + * Read a binary hunk and return a new fragment; fragment->patch + * points at an allocated memory that the caller must free, so + * it is marked as "->free_patch = 1". + */ static struct fragment *parse_binary_hunk(char **buf_p, unsigned long *sz_p, int *status_p, @@ -1742,6 +1810,7 @@ static struct fragment *parse_binary_hunk(char **buf_p, frag = xcalloc(1, sizeof(*frag)); frag->patch = inflate_it(data, hunk_size, origlen); + frag->free_patch = 1; if (!frag->patch) goto corrupt; free(data); @@ -1807,6 +1876,13 @@ static int parse_binary(char *buffer, unsigned long size, struct patch *patch) return used; } +/* + * Read the patch text in "buffer" taht extends for "size" bytes; stop + * reading after seeing a single patch (i.e. changes to a single file). + * Create fragments (i.e. patch hunks) and hang them to the given patch. + * Return the number of bytes consumed, so that the caller can call us + * again for the next patch. + */ static int parse_chunk(char *buffer, unsigned long size, struct patch *patch) { int hdrsize, patchsize; @@ -2367,6 +2443,11 @@ static void remove_last_line(struct image *img) img->len -= img->line[--img->nr].len; } +/* + * The change from "preimage" and "postimage" has been found to + * apply at applied_pos (counts in line numbers) in "img". + * Update "img" to remove "preimage" and replace it with "postimage". + */ static void update_image(struct image *img, int applied_pos, struct image *preimage, @@ -2438,6 +2519,11 @@ static void update_image(struct image *img, img->nr = nr; } +/* + * Use the patch-hunk text in "frag" to prepare two images (preimage and + * postimage) for the hunk. Find lines that match "preimage" in "img" and + * replace the part of "img" with "postimage" text. + */ static int apply_one_fragment(struct image *img, struct fragment *frag, int inaccurate_eof, unsigned ws_rule, int nth_fragment) @@ -2728,6 +2814,12 @@ static int apply_binary_fragment(struct image *img, struct patch *patch) return -1; } +/* + * Replace "img" with the result of applying the binary patch. + * The binary patch data itself in patch->fragment is still kept + * but the preimage prepared by the caller in "img" is freed here + * or in the helper function apply_binary_fragment() this calls. + */ static int apply_binary(struct image *img, struct patch *patch) { const char *name = patch->old_name ? patch->old_name : patch->new_name; @@ -2935,7 +3027,7 @@ static int apply_data(struct patch *patch, struct stat *st, struct cache_entry * return error("patch %s has been renamed/deleted", patch->old_name); } - /* We have a patched copy in memory use that */ + /* We have a patched copy in memory; use that. */ strbuf_add(&buf, tpatch->result, tpatch->resultsize); } else if (cached) { if (read_file_or_gitlink(ce, &buf)) @@ -2948,7 +3040,10 @@ static int apply_data(struct patch *patch, struct stat *st, struct cache_entry * /* * There is no way to apply subproject * patch without looking at the index. + * NEEDSWORK: shouldn't this be flagged + * as an error??? */ + free_fragment_list(patch->fragments); patch->fragments = NULL; } } else { @@ -3085,10 +3180,15 @@ static int check_preimage(struct patch *patch, struct cache_entry **ce, struct s is_new: patch->is_new = 1; patch->is_delete = 0; + free(patch->old_name); patch->old_name = NULL; return 0; } +/* + * Check and apply the patch in-core; leave the result in patch->result + * for the caller to write it out to the final destination. + */ static int check_patch(struct patch *patch) { struct stat st; @@ -3665,15 +3765,8 @@ static void prefix_patches(struct patch *p) if (!prefix || p->is_toplevel_relative) return; for ( ; p; p = p->next) { - if (p->new_name == p->old_name) { - char *prefixed = p->new_name; - prefix_one(&prefixed); - p->new_name = p->old_name = prefixed; - } - else { - prefix_one(&p->new_name); - prefix_one(&p->old_name); - } + prefix_one(&p->new_name); + prefix_one(&p->old_name); } } @@ -3683,12 +3776,10 @@ static void prefix_patches(struct patch *p) static int apply_patch(int fd, const char *filename, int options) { size_t offset; - struct strbuf buf = STRBUF_INIT; + struct strbuf buf = STRBUF_INIT; /* owns the patch text */ struct patch *list = NULL, **listp = &list; int skipped_patch = 0; - /* FIXME - memory leak when using multiple patch files as inputs */ - memset(&fn_table, 0, sizeof(struct string_list)); patch_input_file = filename; read_patch_file(&buf, fd); offset = 0; @@ -3712,8 +3803,7 @@ static int apply_patch(int fd, const char *filename, int options) listp = &patch->next; } else { - /* perhaps free it a bit better? */ - free(patch); + free_patch(patch); skipped_patch++; } offset += nr; @@ -3754,7 +3844,9 @@ static int apply_patch(int fd, const char *filename, int options) if (summary) summary_patch_list(list); + free_patch_list(list); strbuf_release(&buf); + string_list_clear(&fn_table, 0); return 0; } diff --git a/builtin/blame.c b/builtin/blame.c index b35bd6249d..324d476abf 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -2302,6 +2302,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix) OPT_BIT('s', NULL, &output_option, "Suppress author name and timestamp (Default: off)", OUTPUT_NO_AUTHOR), OPT_BIT('e', "show-email", &output_option, "Show author email instead of name (Default: off)", OUTPUT_SHOW_EMAIL), OPT_BIT('w', NULL, &xdl_opts, "Ignore whitespace differences", XDF_IGNORE_WHITESPACE), + OPT_BIT(0, "minimal", &xdl_opts, "Spend extra cycles to find better match", XDF_NEED_MINIMAL), OPT_STRING('S', NULL, &revs_file, "file", "Use revisions from <file> instead of calling git-rev-list"), OPT_STRING(0, "contents", &contents_from, "file", "Use <file>'s contents as the final image"), { OPTION_CALLBACK, 'C', NULL, &opt, "score", "Find line copies within and across files", PARSE_OPT_OPTARG, blame_copy_callback }, diff --git a/builtin/branch.c b/builtin/branch.c index d8cccf725d..5f150b4e8a 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -146,7 +146,8 @@ static int branch_merged(int kind, const char *name, return merged; } -static int delete_branches(int argc, const char **argv, int force, int kinds) +static int delete_branches(int argc, const char **argv, int force, int kinds, + int quiet) { struct commit *rev, *head_rev = NULL; unsigned char sha1[20]; @@ -216,9 +217,10 @@ static int delete_branches(int argc, const char **argv, int force, int kinds) ret = 1; } else { struct strbuf buf = STRBUF_INIT; - printf(_("Deleted %sbranch %s (was %s).\n"), remote, - bname.buf, - find_unique_abbrev(sha1, DEFAULT_ABBREV)); + if (!quiet) + printf(_("Deleted %sbranch %s (was %s).\n"), + remote, bname.buf, + find_unique_abbrev(sha1, DEFAULT_ABBREV)); strbuf_addf(&buf, "branch.%s", bname.buf); if (git_config_rename_section(buf.buf, NULL) < 0) warning(_("Update of config-file failed")); @@ -678,6 +680,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) int delete = 0, rename = 0, force_create = 0, list = 0; int verbose = 0, abbrev = -1, detached = 0; int reflog = 0, edit_description = 0; + int quiet = 0; enum branch_track track; int kinds = REF_LOCAL_BRANCH; struct commit_list *with_commit = NULL; @@ -686,6 +689,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) OPT_GROUP("Generic options"), OPT__VERBOSE(&verbose, "show hash and subject, give twice for upstream branch"), + OPT__QUIET(&quiet, "suppress informational messages"), OPT_SET_INT('t', "track", &track, "set up tracking mode (see git-pull(1))", BRANCH_TRACK_EXPLICIT), OPT_SET_INT( 0, "set-upstream", &track, "change upstream info", @@ -766,7 +770,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) abbrev = DEFAULT_ABBREV; if (delete) - return delete_branches(argc, argv, delete > 1, kinds); + return delete_branches(argc, argv, delete > 1, kinds, quiet); else if (list) return print_ref_list(kinds, detached, verbose, abbrev, with_commit, argv); @@ -808,7 +812,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) if (kinds != REF_LOCAL_BRANCH) die(_("-a and -r options to 'git branch' do not make sense with a branch name")); create_branch(head, argv[0], (argc == 2) ? argv[1] : head, - force_create, reflog, 0, track); + force_create, reflog, 0, quiet, track); } else usage_with_options(builtin_branch_usage, options); diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 8ed501f220..36a9104433 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -11,6 +11,7 @@ #include "parse-options.h" #include "diff.h" #include "userdiff.h" +#include "streaming.h" #define BATCH 1 #define BATCH_CHECK 2 @@ -127,6 +128,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name) return cmd_ls_tree(2, ls_args, NULL); } + if (type == OBJ_BLOB) + return stream_blob_to_fd(1, sha1, NULL, 0); buf = read_sha1_file(sha1, &type, &size); if (!buf) die("Cannot read object %s", obj_name); @@ -149,6 +152,28 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name) break; case 0: + if (type_from_string(exp_type) == OBJ_BLOB) { + unsigned char blob_sha1[20]; + if (sha1_object_info(sha1, NULL) == OBJ_TAG) { + enum object_type type; + unsigned long size; + char *buffer = read_sha1_file(sha1, &type, &size); + if (memcmp(buffer, "object ", 7) || + get_sha1_hex(buffer + 7, blob_sha1)) + die("%s not a valid tag", sha1_to_hex(sha1)); + free(buffer); + } else + hashcpy(blob_sha1, sha1); + + if (sha1_object_info(blob_sha1, NULL) == OBJ_BLOB) + return stream_blob_to_fd(1, blob_sha1, NULL, 0); + /* + * we attempted to dereference a tag to a blob + * and failed; there may be new dereference + * mechanisms this code is not aware of. + * fall-back to the usual case. + */ + } buf = read_object_with_reference(sha1, exp_type, &size, NULL); break; diff --git a/builtin/checkout.c b/builtin/checkout.c index 6b9061f26f..23fc56d88d 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -543,6 +543,7 @@ static void update_refs_for_switch(struct checkout_opts *opts, opts->new_branch_force ? 1 : 0, opts->new_branch_log, opts->new_branch_force ? 1 : 0, + opts->quiet, opts->track); new->name = opts->new_branch; setup_branch_path(new); diff --git a/builtin/commit.c b/builtin/commit.c index 3714582e19..b257ae8774 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -533,9 +533,20 @@ static int is_a_merge(const struct commit *current_head) static const char sign_off_header[] = "Signed-off-by: "; +static void export_one(const char *var, const char *s, const char *e, int hack) +{ + struct strbuf buf = STRBUF_INIT; + if (hack) + strbuf_addch(&buf, hack); + strbuf_addf(&buf, "%.*s", (int)(e - s), s); + setenv(var, buf.buf, 1); + strbuf_release(&buf); +} + static void determine_author_info(struct strbuf *author_ident) { char *name, *email, *date; + struct ident_split author; name = getenv("GIT_AUTHOR_NAME"); email = getenv("GIT_AUTHOR_EMAIL"); @@ -585,6 +596,11 @@ static void determine_author_info(struct strbuf *author_ident) date = force_date; strbuf_addstr(author_ident, fmt_ident(name, email, date, IDENT_ERROR_ON_NO_NAME)); + if (!split_ident_line(&author, author_ident->buf, author_ident->len)) { + export_one("GIT_AUTHOR_NAME", author.name_begin, author.name_end, 0); + export_one("GIT_AUTHOR_EMAIL", author.mail_begin, author.mail_end, 0); + export_one("GIT_AUTHOR_DATE", author.date_begin, author.tz_end, '@'); + } } static int ends_rfc2822_footer(struct strbuf *sb) @@ -652,6 +668,9 @@ static int prepare_to_commit(const char *index_file, const char *prefix, int ident_shown = 0; int clean_message_contents = (cleanup_mode != CLEANUP_NONE); + /* This checks and barfs if author is badly specified */ + determine_author_info(author_ident); + if (!no_verify && run_hook(index_file, "pre-commit", NULL)) return 0; @@ -771,9 +790,6 @@ static int prepare_to_commit(const char *index_file, const char *prefix, strbuf_release(&sb); - /* This checks and barfs if author is badly specified */ - determine_author_info(author_ident); - /* This checks if committer ident is explicitly given */ strbuf_addstr(&committer_ident, git_committer_info(0)); if (use_editor && include_status) { @@ -905,27 +921,10 @@ static int prepare_to_commit(const char *index_file, const char *prefix, return 1; } -/* - * Find out if the message in the strbuf contains only whitespace and - * Signed-off-by lines. - */ -static int message_is_empty(struct strbuf *sb) +static int rest_is_empty(struct strbuf *sb, int start) { - struct strbuf tmpl = STRBUF_INIT; + int i, eol; const char *nl; - int eol, i, start = 0; - - if (cleanup_mode == CLEANUP_NONE && sb->len) - return 0; - - /* See if the template is just a prefix of the message. */ - if (template_file && strbuf_read_file(&tmpl, template_file, 0) > 0) { - stripspace(&tmpl, cleanup_mode == CLEANUP_ALL); - if (start + tmpl.len <= sb->len && - memcmp(tmpl.buf, sb->buf + start, tmpl.len) == 0) - start += tmpl.len; - } - strbuf_release(&tmpl); /* Check if the rest is just whitespace and Signed-of-by's. */ for (i = start; i < sb->len; i++) { @@ -948,6 +947,40 @@ static int message_is_empty(struct strbuf *sb) return 1; } +/* + * Find out if the message in the strbuf contains only whitespace and + * Signed-off-by lines. + */ +static int message_is_empty(struct strbuf *sb) +{ + if (cleanup_mode == CLEANUP_NONE && sb->len) + return 0; + return rest_is_empty(sb, 0); +} + +/* + * See if the user edited the message in the editor or left what + * was in the template intact + */ +static int template_untouched(struct strbuf *sb) +{ + struct strbuf tmpl = STRBUF_INIT; + char *start; + + if (cleanup_mode == CLEANUP_NONE && sb->len) + return 0; + + if (!template_file || strbuf_read_file(&tmpl, template_file, 0) <= 0) + return 0; + + stripspace(&tmpl, cleanup_mode == CLEANUP_ALL); + start = (char *)skip_prefix(sb->buf, tmpl.buf); + if (!start) + start = sb->buf; + strbuf_release(&tmpl); + return rest_is_empty(sb, start - sb->buf); +} + static const char *find_author_by_nickname(const char *name) { struct rev_info revs; @@ -1055,6 +1088,8 @@ static int parse_and_validate_options(int argc, const char *argv[], die(_("Only one of -c/-C/-F/--fixup can be used.")); if (message.len && f > 0) die((_("Option -m cannot be combined with -c/-C/-F/--fixup."))); + if (f || message.len) + template_file = NULL; if (edit_message) use_message = edit_message; if (amend && !use_message && !fixup_message) @@ -1494,6 +1529,11 @@ int cmd_commit(int argc, const char **argv, const char *prefix) if (cleanup_mode != CLEANUP_NONE) stripspace(&sb, cleanup_mode == CLEANUP_ALL); + if (template_untouched(&sb) && !allow_empty_message) { + rollback_index_files(); + fprintf(stderr, _("Aborting commit; you did not edit the message.\n")); + exit(1); + } if (message_is_empty(&sb) && !allow_empty_message) { rollback_index_files(); fprintf(stderr, _("Aborting commit due to empty commit message.\n")); diff --git a/builtin/diff.c b/builtin/diff.c index 424c815f9b..9069dc41be 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -327,7 +327,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix) add_head_to_pending(&rev); if (!rev.pending.nr) { struct tree *tree; - tree = lookup_tree((const unsigned char*)EMPTY_TREE_SHA1_BIN); + tree = lookup_tree(EMPTY_TREE_SHA1_BIN); add_pending_object(&rev, &tree->object, "HEAD"); } break; diff --git a/builtin/fetch.c b/builtin/fetch.c index 65f5f9b72f..cfb43df4e8 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -300,11 +300,11 @@ static int update_local_ref(struct ref *ref, else { msg = "storing head"; what = _("[new branch]"); - if ((recurse_submodules != RECURSE_SUBMODULES_OFF) && - (recurse_submodules != RECURSE_SUBMODULES_ON)) - check_for_new_submodule_commits(ref->new_sha1); } + if ((recurse_submodules != RECURSE_SUBMODULES_OFF) && + (recurse_submodules != RECURSE_SUBMODULES_ON)) + check_for_new_submodule_commits(ref->new_sha1); r = s_update_ref(msg, ref, 0); strbuf_addf(display, "%c %-*s %-*s -> %s%s", r ? '!' : '*', diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c index c81a7fef26..1bc6b8b8c3 100644 --- a/builtin/fmt-merge-msg.c +++ b/builtin/fmt-merge-msg.c @@ -27,6 +27,8 @@ int fmt_merge_msg_config(const char *key, const char *value, void *cb) merge_log_config = DEFAULT_MERGE_LOG_LEN; } else if (!strcmp(key, "merge.branchdesc")) { use_branch_desc = git_config_bool(key, value); + } else { + return git_default_config(key, value, cb); } return 0; } @@ -180,6 +182,101 @@ static void add_branch_desc(struct strbuf *out, const char *name) strbuf_release(&desc); } +#define util_as_integral(elem) ((intptr_t)((elem)->util)) + +static void record_person(int which, struct string_list *people, + struct commit *commit) +{ + char name_buf[MAX_GITNAME], *name, *name_end; + struct string_list_item *elem; + const char *field = (which == 'a') ? "\nauthor " : "\ncommitter "; + + name = strstr(commit->buffer, field); + if (!name) + return; + name += strlen(field); + name_end = strchrnul(name, '<'); + if (*name_end) + name_end--; + while (isspace(*name_end) && name <= name_end) + name_end--; + if (name_end < name || name + MAX_GITNAME <= name_end) + return; + memcpy(name_buf, name, name_end - name + 1); + name_buf[name_end - name + 1] = '\0'; + + elem = string_list_lookup(people, name_buf); + if (!elem) { + elem = string_list_insert(people, name_buf); + elem->util = (void *)0; + } + elem->util = (void*)(util_as_integral(elem) + 1); +} + +static int cmp_string_list_util_as_integral(const void *a_, const void *b_) +{ + const struct string_list_item *a = a_, *b = b_; + return util_as_integral(b) - util_as_integral(a); +} + +static void add_people_count(struct strbuf *out, struct string_list *people) +{ + if (people->nr == 1) + strbuf_addf(out, "%s", people->items[0].string); + else if (people->nr == 2) + strbuf_addf(out, "%s (%d) and %s (%d)", + people->items[0].string, + (int)util_as_integral(&people->items[0]), + people->items[1].string, + (int)util_as_integral(&people->items[1])); + else if (people->nr) + strbuf_addf(out, "%s (%d) and others", + people->items[0].string, + (int)util_as_integral(&people->items[0])); +} + +static void credit_people(struct strbuf *out, + struct string_list *them, + int kind) +{ + const char *label; + const char *me; + + if (kind == 'a') { + label = "\nBy "; + me = git_author_info(IDENT_NO_DATE); + } else { + label = "\nvia "; + me = git_committer_info(IDENT_NO_DATE); + } + + if (!them->nr || + (them->nr == 1 && + me && + (me = skip_prefix(me, them->items->string)) != NULL && + skip_prefix(me, " <"))) + return; + strbuf_addstr(out, label); + add_people_count(out, them); +} + +static void add_people_info(struct strbuf *out, + struct string_list *authors, + struct string_list *committers) +{ + if (authors->nr) + qsort(authors->items, + authors->nr, sizeof(authors->items[0]), + cmp_string_list_util_as_integral); + if (committers->nr) + qsort(committers->items, + committers->nr, sizeof(committers->items[0]), + cmp_string_list_util_as_integral); + + credit_people(out, authors, 'a'); + credit_people(out, committers, 'c'); +} + static void shortlog(const char *name, struct origin_data *origin_data, struct commit *head, @@ -190,6 +287,8 @@ static void shortlog(const char *name, struct commit *commit; struct object *branch; struct string_list subjects = STRING_LIST_INIT_DUP; + struct string_list authors = STRING_LIST_INIT_DUP; + struct string_list committers = STRING_LIST_INIT_DUP; int flags = UNINTERESTING | TREESAME | SEEN | SHOWN | ADDED; struct strbuf sb = STRBUF_INIT; const unsigned char *sha1 = origin_data->sha1; @@ -199,7 +298,6 @@ static void shortlog(const char *name, return; setup_revisions(0, NULL, rev, NULL); - rev->ignore_merges = 1; add_pending_object(rev, branch, name); add_pending_object(rev, &head->object, "^HEAD"); head->object.flags |= UNINTERESTING; @@ -208,10 +306,15 @@ static void shortlog(const char *name, while ((commit = get_revision(rev)) != NULL) { struct pretty_print_context ctx = {0}; - /* ignore merges */ - if (commit->parents && commit->parents->next) + if (commit->parents && commit->parents->next) { + /* do not list a merge but count committer */ + record_person('c', &committers, commit); continue; - + } + if (!count) + /* the 'tip' committer */ + record_person('c', &committers, commit); + record_person('a', &authors, commit); count++; if (subjects.nr > limit) continue; @@ -226,6 +329,7 @@ static void shortlog(const char *name, string_list_append(&subjects, strbuf_detach(&sb, NULL)); } + add_people_info(out, &authors, &committers); if (count > limit) strbuf_addf(out, "\n* %s: (%d commits)\n", name, count); else @@ -246,6 +350,8 @@ static void shortlog(const char *name, rev->commits = NULL; rev->pending.nr = 0; + string_list_clear(&authors, 0); + string_list_clear(&committers, 0); string_list_clear(&subjects, 0); } diff --git a/builtin/fsck.c b/builtin/fsck.c index 67eb553c7d..a710227a64 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -12,6 +12,7 @@ #include "parse-options.h" #include "dir.h" #include "progress.h" +#include "streaming.h" #define REACHABLE 0x0001 #define SEEN 0x0002 @@ -238,13 +239,8 @@ static void check_unreachable_object(struct object *obj) if (!(f = fopen(filename, "w"))) die_errno("Could not open '%s'", filename); if (obj->type == OBJ_BLOB) { - enum object_type type; - unsigned long size; - char *buf = read_sha1_file(obj->sha1, - &type, &size); - if (buf && fwrite(buf, 1, size, f) != size) + if (stream_blob_to_fd(fileno(f), obj->sha1, NULL, 1)) die_errno("Could not write '%s'", filename); - free(buf); } else fprintf(f, "%s\n", sha1_to_hex(obj->sha1)); if (fclose(f)) diff --git a/builtin/log.c b/builtin/log.c index 8a47012b0b..690caa7830 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -20,6 +20,7 @@ #include "string-list.h" #include "parse-options.h" #include "branch.h" +#include "streaming.h" /* Set a default date-time format for git log ("log.date" config variable) */ static const char *default_date_mode = NULL; @@ -383,8 +384,13 @@ static void show_tagger(char *buf, int len, struct rev_info *rev) strbuf_release(&out); } -static int show_object(const unsigned char *sha1, int show_tag_object, - struct rev_info *rev) +static int show_blob_object(const unsigned char *sha1, struct rev_info *rev) +{ + fflush(stdout); + return stream_blob_to_fd(1, sha1, NULL, 0); +} + +static int show_tag_object(const unsigned char *sha1, struct rev_info *rev) { unsigned long size; enum object_type type; @@ -394,16 +400,16 @@ static int show_object(const unsigned char *sha1, int show_tag_object, if (!buf) return error(_("Could not read object %s"), sha1_to_hex(sha1)); - if (show_tag_object) - while (offset < size && buf[offset] != '\n') { - int new_offset = offset + 1; - while (new_offset < size && buf[new_offset++] != '\n') - ; /* do nothing */ - if (!prefixcmp(buf + offset, "tagger ")) - show_tagger(buf + offset + 7, - new_offset - offset - 7, rev); - offset = new_offset; - } + assert(type == OBJ_TAG); + while (offset < size && buf[offset] != '\n') { + int new_offset = offset + 1; + while (new_offset < size && buf[new_offset++] != '\n') + ; /* do nothing */ + if (!prefixcmp(buf + offset, "tagger ")) + show_tagger(buf + offset + 7, + new_offset - offset - 7, rev); + offset = new_offset; + } if (offset < size) fwrite(buf + offset, size - offset, 1, stdout); @@ -463,7 +469,7 @@ int cmd_show(int argc, const char **argv, const char *prefix) const char *name = objects[i].name; switch (o->type) { case OBJ_BLOB: - ret = show_object(o->sha1, 0, NULL); + ret = show_blob_object(o->sha1, NULL); break; case OBJ_TAG: { struct tag *t = (struct tag *)o; @@ -474,7 +480,7 @@ int cmd_show(int argc, const char **argv, const char *prefix) diff_get_color_opt(&rev.diffopt, DIFF_COMMIT), t->tag, diff_get_color_opt(&rev.diffopt, DIFF_RESET)); - ret = show_object(o->sha1, 1, &rev); + ret = show_tag_object(o->sha1, &rev); rev.shown_one = 1; if (ret) break; diff --git a/builtin/push.c b/builtin/push.c index d315475f16..693671315e 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -24,6 +24,7 @@ static int progress = -1; static const char **refspec; static int refspec_nr; static int refspec_alloc; +static int default_matching_used; static void add_refspec(const char *ref) { @@ -65,6 +66,16 @@ static void set_refspecs(const char **refs, int nr) } } +static int push_url_of_remote(struct remote *remote, const char ***url_p) +{ + if (remote->pushurl_nr) { + *url_p = remote->pushurl; + return remote->pushurl_nr; + } + *url_p = remote->url; + return remote->url_nr; +} + static void setup_push_upstream(struct remote *remote) { struct strbuf refspec = STRBUF_INIT; @@ -76,7 +87,7 @@ static void setup_push_upstream(struct remote *remote) "\n" " git push %s HEAD:<name-of-remote-branch>\n"), remote->name); - if (!branch->merge_nr || !branch->merge) + if (!branch->merge_nr || !branch->merge || !branch->remote_name) die(_("The current branch %s has no upstream branch.\n" "To push the current branch and set the remote as upstream, use\n" "\n" @@ -87,6 +98,12 @@ static void setup_push_upstream(struct remote *remote) if (branch->merge_nr != 1) die(_("The current branch %s has multiple upstream branches, " "refusing to push."), branch->name); + if (strcmp(branch->remote_name, remote->name)) + die(_("You are pushing to remote '%s', which is not the upstream of\n" + "your current branch '%s', without telling me what to push\n" + "to update which remote branch."), + remote->name, branch->name); + strbuf_addf(&refspec, "%s:%s", branch->name, branch->merge[0]->src); add_refspec(refspec.buf); } @@ -95,6 +112,9 @@ static void setup_default_push_refspecs(struct remote *remote) { switch (push_default) { default: + case PUSH_DEFAULT_UNSPECIFIED: + default_matching_used = 1; + /* fallthru */ case PUSH_DEFAULT_MATCHING: add_refspec(":"); break; @@ -114,6 +134,45 @@ static void setup_default_push_refspecs(struct remote *remote) } } +static const char message_advice_pull_before_push[] = + N_("Updates were rejected because the tip of your current branch is behind\n" + "its remote counterpart. Merge the remote changes (e.g. 'git pull')\n" + "before pushing again.\n" + "See the 'Note about fast-forwards' in 'git push --help' for details."); + +static const char message_advice_use_upstream[] = + N_("Updates were rejected because a pushed branch tip is behind its remote\n" + "counterpart. If you did not intend to push that branch, you may want to\n" + "specify branches to push or set the 'push.default' configuration\n" + "variable to 'current' or 'upstream' to push only the current branch."); + +static const char message_advice_checkout_pull_push[] = + N_("Updates were rejected because a pushed branch tip is behind its remote\n" + "counterpart. Check out this branch and merge the remote changes\n" + "(e.g. 'git pull') before pushing again.\n" + "See the 'Note about fast-forwards' in 'git push --help' for details."); + +static void advise_pull_before_push(void) +{ + if (!advice_push_non_ff_current || !advice_push_nonfastforward) + return; + advise(_(message_advice_pull_before_push)); +} + +static void advise_use_upstream(void) +{ + if (!advice_push_non_ff_default || !advice_push_nonfastforward) + return; + advise(_(message_advice_use_upstream)); +} + +static void advise_checkout_pull_push(void) +{ + if (!advice_push_non_ff_matching || !advice_push_nonfastforward) + return; + advise(_(message_advice_checkout_pull_push)); +} + static int push_with_options(struct transport *transport, int flags) { int err; @@ -135,14 +194,21 @@ static int push_with_options(struct transport *transport, int flags) error(_("failed to push some refs to '%s'"), transport->url); err |= transport_disconnect(transport); - if (!err) return 0; - if (nonfastforward && advice_push_nonfastforward) { - fprintf(stderr, _("To prevent you from losing history, non-fast-forward updates were rejected\n" - "Merge the remote changes (e.g. 'git pull') before pushing again. See the\n" - "'Note about fast-forwards' section of 'git push --help' for details.\n")); + switch (nonfastforward) { + default: + break; + case NON_FF_HEAD: + advise_pull_before_push(); + break; + case NON_FF_OTHER: + if (default_matching_used) + advise_use_upstream(); + else + advise_checkout_pull_push(); + break; } return 1; @@ -196,13 +262,7 @@ static int do_push(const char *repo, int flags) setup_default_push_refspecs(remote); } errs = 0; - if (remote->pushurl_nr) { - url = remote->pushurl; - url_nr = remote->pushurl_nr; - } else { - url = remote->url; - url_nr = remote->url_nr; - } + url_nr = push_url_of_remote(remote, &url); if (url_nr) { for (i = 0; i < url_nr; i++) { struct transport *transport = diff --git a/builtin/remote.c b/builtin/remote.c index fec92bc66e..b5645fe0ae 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -9,7 +9,7 @@ static const char * const builtin_remote_usage[] = { "git remote [-v | --verbose]", - "git remote add [-t <branch>] [-m <master>] [-f] [--mirror=<fetch|push>] <name> <url>", + "git remote add [-t <branch>] [-m <master>] [-f] [--tags|--no-tags] [--mirror=<fetch|push>] <name> <url>", "git remote rename <old> <new>", "git remote rm <name>", "git remote set-head <name> (-a | -d | <branch>)", @@ -17,7 +17,7 @@ static const char * const builtin_remote_usage[] = { "git remote prune [-n | --dry-run] <name>", "git remote [-v | --verbose] update [-p | --prune] [(<group> | <remote>)...]", "git remote set-branches [--add] <name> <branch>...", - "git remote set-url <name> <newurl> [<oldurl>]", + "git remote set-url [--push] <name> <newurl> [<oldurl>]", "git remote set-url --add <name> <newurl>", "git remote set-url --delete <name> <url>", NULL diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index 98d1cbecca..733f626f6c 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -634,6 +634,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) if (!strcmp(arg, "--show-prefix")) { if (prefix) puts(prefix); + else + putchar('\n'); continue; } if (!strcmp(arg, "--show-cdup")) { diff --git a/builtin/update-server-info.c b/builtin/update-server-info.c index b90dce6358..0d63c4498c 100644 --- a/builtin/update-server-info.c +++ b/builtin/update-server-info.c @@ -15,6 +15,7 @@ int cmd_update_server_info(int argc, const char **argv, const char *prefix) OPT_END() }; + git_config(git_default_config, NULL); argc = parse_options(argc, argv, prefix, options, update_server_info_usage, 0); if (argc > 0) @@ -625,7 +625,8 @@ enum push_default_type { PUSH_DEFAULT_NOTHING = 0, PUSH_DEFAULT_MATCHING, PUSH_DEFAULT_UPSTREAM, - PUSH_DEFAULT_CURRENT + PUSH_DEFAULT_CURRENT, + PUSH_DEFAULT_UNSPECIFIED }; extern enum branch_track git_branch_track; @@ -708,6 +709,19 @@ static inline void hashclr(unsigned char *hash) #define EMPTY_TREE_SHA1_BIN \ ((const unsigned char *) EMPTY_TREE_SHA1_BIN_LITERAL) +#define EMPTY_BLOB_SHA1_HEX \ + "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391" +#define EMPTY_BLOB_SHA1_BIN_LITERAL \ + "\xe6\x9d\xe2\x9b\xb2\xd1\xd6\x43\x4b\x8b" \ + "\x29\xae\x77\x5a\xd8\xc2\xe4\x8c\x53\x91" +#define EMPTY_BLOB_SHA1_BIN \ + ((const unsigned char *) EMPTY_BLOB_SHA1_BIN_LITERAL) + +static inline int is_empty_blob_sha1(const unsigned char *sha1) +{ + return !hashcmp(sha1, EMPTY_BLOB_SHA1_BIN); +} + int git_mkstemp(char *path, size_t n, const char *template); int git_mkstemps(char *path, size_t n, const char *template, int suffix_len); @@ -928,6 +942,22 @@ extern const char *fmt_name(const char *name, const char *email); extern const char *git_editor(void); extern const char *git_pager(int stdout_is_tty); +struct ident_split { + const char *name_begin; + const char *name_end; + const char *mail_begin; + const char *mail_end; + const char *date_begin; + const char *date_end; + const char *tz_begin; + const char *tz_end; +}; +/* + * Signals an success with 0, but time part of the result may be NULL + * if the input lacks timestamp and zone + */ +extern int split_ident_line(struct ident_split *, const char *, int); + struct checkout { const char *base_dir; int base_dir_len; @@ -1276,4 +1306,6 @@ extern struct startup_info *startup_info; /* builtin/merge.c */ int checkout_fast_forward(const unsigned char *from, const unsigned char *to); +int sane_execvp(const char *file, char *const argv[]); + #endif /* CACHE_H */ diff --git a/combine-diff.c b/combine-diff.c index a2e8dcf855..9786680368 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -423,7 +423,7 @@ static int make_hunks(struct sline *sline, unsigned long cnt, hunk_begin, j); la = (la + context < cnt + 1) ? (la + context) : cnt + 1; - while (j <= --la) { + while (la && j <= --la) { if (sline[la].flag & mark) { contin = 1; break; diff --git a/command-list.txt b/command-list.txt index a36ee9b015..38ec5f7b86 100644 --- a/command-list.txt +++ b/command-list.txt @@ -76,6 +76,7 @@ git-mktree plumbingmanipulators git-mv mainporcelain common git-name-rev plumbinginterrogators git-notes mainporcelain +git-p4 foreignscminterface git-pack-objects plumbingmanipulators git-pack-redundant plumbinginterrogators git-pack-refs ancillarymanipulators @@ -7,6 +7,7 @@ #include "revision.h" #include "notes.h" #include "gpg-interface.h" +#include "mergesort.h" int save_commit_buffer = 1; @@ -360,6 +361,21 @@ struct commit_list *commit_list_insert(struct commit *item, struct commit_list * return new_list; } +void commit_list_reverse(struct commit_list **list_p) +{ + struct commit_list *prev = NULL, *curr = *list_p, *next; + + if (!list_p) + return; + while (curr) { + next = curr->next; + curr->next = prev; + prev = curr; + curr = next; + } + *list_p = prev; +} + unsigned commit_list_count(const struct commit_list *l) { unsigned c = 0; @@ -390,15 +406,31 @@ struct commit_list * commit_list_insert_by_date(struct commit *item, struct comm return commit_list_insert(item, pp); } +static int commit_list_compare_by_date(const void *a, const void *b) +{ + unsigned long a_date = ((const struct commit_list *)a)->item->date; + unsigned long b_date = ((const struct commit_list *)b)->item->date; + if (a_date < b_date) + return 1; + if (a_date > b_date) + return -1; + return 0; +} + +static void *commit_list_get_next(const void *a) +{ + return ((const struct commit_list *)a)->next; +} + +static void commit_list_set_next(void *a, void *next) +{ + ((struct commit_list *)a)->next = next; +} void commit_list_sort_by_date(struct commit_list **list) { - struct commit_list *ret = NULL; - while (*list) { - commit_list_insert_by_date((*list)->item, &ret); - *list = (*list)->next; - } - *list = ret; + *list = llist_mergesort(*list, commit_list_get_next, commit_list_set_next, + commit_list_compare_by_date); } struct commit *pop_most_recent_commit(struct commit_list **list, @@ -57,6 +57,7 @@ unsigned commit_list_count(const struct commit_list *l); struct commit_list *commit_list_insert_by_date(struct commit *item, struct commit_list **list); void commit_list_sort_by_date(struct commit_list **list); +void commit_list_reverse(struct commit_list **list_p); void free_commit_list(struct commit_list *list); diff --git a/compat/mingw.c b/compat/mingw.c index a0ac487c0c..afc892d6b1 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -1003,7 +1003,7 @@ static void mingw_execve(const char *cmd, char *const *argv, char *const *env) } } -void mingw_execvp(const char *cmd, char *const *argv) +int mingw_execvp(const char *cmd, char *const *argv) { char **path = get_path_split(); char *prog = path_lookup(cmd, path, 0); @@ -1015,11 +1015,13 @@ void mingw_execvp(const char *cmd, char *const *argv) errno = ENOENT; free_path_split(path); + return -1; } -void mingw_execv(const char *cmd, char *const *argv) +int mingw_execv(const char *cmd, char *const *argv) { mingw_execve(cmd, argv, environ); + return -1; } int mingw_kill(pid_t pid, int sig) diff --git a/compat/mingw.h b/compat/mingw.h index 0ff1e04812..ef5b15014e 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -274,9 +274,9 @@ int mingw_utime(const char *file_name, const struct utimbuf *times); pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **env, const char *dir, int fhin, int fhout, int fherr); -void mingw_execvp(const char *cmd, char *const *argv); +int mingw_execvp(const char *cmd, char *const *argv); #define execvp mingw_execvp -void mingw_execv(const char *cmd, char *const *argv); +int mingw_execv(const char *cmd, char *const *argv); #define execv mingw_execv static inline unsigned int git_ntohl(unsigned int x) diff --git a/configure.ac b/configure.ac index 72f7958824..e1255506a6 100644 --- a/configure.ac +++ b/configure.ac @@ -1,65 +1,55 @@ # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. -AC_PREREQ(2.59) -AC_INIT([git], [@@GIT_VERSION@@], [git@vger.kernel.org]) - -AC_CONFIG_SRCDIR([git.c]) - -config_file=config.mak.autogen -config_append=config.mak.append -config_in=config.mak.in - -echo "# ${config_append}. Generated by configure." > "${config_append}" - +## Definitions of private macros. -## Definitions of macros # GIT_CONF_APPEND_LINE(LINE) # -------------------------- # Append LINE to file ${config_append} AC_DEFUN([GIT_CONF_APPEND_LINE], -[echo "$1" >> "${config_append}"])# GIT_CONF_APPEND_LINE -# + [echo "$1" >> "${config_append}"]) + # GIT_ARG_SET_PATH(PROGRAM) # ------------------------- # Provide --with-PROGRAM=PATH option to set PATH to PROGRAM # Optional second argument allows setting NO_PROGRAM=YesPlease if # --without-PROGRAM version used. AC_DEFUN([GIT_ARG_SET_PATH], -[AC_ARG_WITH([$1], - [AS_HELP_STRING([--with-$1=PATH], - [provide PATH to $1])], - [GIT_CONF_APPEND_PATH($1,$2)],[]) -])# GIT_ARG_SET_PATH -# + [AC_ARG_WITH([$1], + [AS_HELP_STRING([--with-$1=PATH], + [provide PATH to $1])], + [GIT_CONF_APPEND_PATH([$1], [$2])], + [])]) + # GIT_CONF_APPEND_PATH(PROGRAM) -# ------------------------------ +# ----------------------------- # Parse --with-PROGRAM=PATH option to set PROGRAM_PATH=PATH # Used by GIT_ARG_SET_PATH(PROGRAM) # Optional second argument allows setting NO_PROGRAM=YesPlease if # --without-PROGRAM is used. AC_DEFUN([GIT_CONF_APPEND_PATH], -[PROGRAM=m4_toupper($1); \ -if test "$withval" = "no"; then \ - if test -n "$2"; then \ - m4_toupper($1)_PATH=$withval; \ - AC_MSG_NOTICE([Disabling use of ${PROGRAM}]); \ - GIT_CONF_APPEND_LINE(NO_${PROGRAM}=YesPlease); \ - GIT_CONF_APPEND_LINE(${PROGRAM}_PATH=); \ - else \ - AC_MSG_ERROR([You cannot use git without $1]); \ - fi; \ -else \ - if test "$withval" = "yes"; then \ - AC_MSG_WARN([You should provide path for --with-$1=PATH]); \ - else \ - m4_toupper($1)_PATH=$withval; \ - AC_MSG_NOTICE([Setting m4_toupper($1)_PATH to $withval]); \ - GIT_CONF_APPEND_LINE(${PROGRAM}_PATH=$withval); \ - fi; \ -fi; \ -]) # GIT_CONF_APPEND_PATH -# + [m4_pushdef([GIT_UC_PROGRAM], m4_toupper([$1]))dnl + PROGRAM=GIT_UC_PROGRAM + if test "$withval" = "no"; then + if test -n "$2"; then + GIT_UC_PROGRAM[]_PATH=$withval + AC_MSG_NOTICE([Disabling use of ${PROGRAM}]) + GIT_CONF_APPEND_LINE(NO_${PROGRAM}=YesPlease) + GIT_CONF_APPEND_LINE(${PROGRAM}_PATH=) + else + AC_MSG_ERROR([You cannot use git without $1]) + fi + else + if test "$withval" = "yes"; then + AC_MSG_WARN([You should provide path for --with-$1=PATH]) + else + GIT_UC_PROGRAM[]_PATH=$withval + AC_MSG_NOTICE([Setting GIT_UC_PROGRAM[]_PATH to $withval]) + GIT_CONF_APPEND_LINE(${PROGRAM}_PATH=$withval) + fi + fi + m4_popdef([GIT_UC_PROGRAM])]) + # GIT_PARSE_WITH(PACKAGE) # ----------------------- # For use in AC_ARG_WITH action-if-found, for packages default ON. @@ -67,21 +57,22 @@ fi; \ # * Set PACKAGEDIR=PATH for --with-PACKAGE=PATH # * Unset NO_PACKAGE for --with-PACKAGE without ARG AC_DEFUN([GIT_PARSE_WITH], -[PACKAGE=m4_toupper($1); \ -if test "$withval" = "no"; then \ - m4_toupper(NO_$1)=YesPlease; \ -elif test "$withval" = "yes"; then \ - m4_toupper(NO_$1)=; \ -else \ - m4_toupper(NO_$1)=; \ - m4_toupper($1)DIR=$withval; \ - AC_MSG_NOTICE([Setting m4_toupper($1)DIR to $withval]); \ - GIT_CONF_APPEND_LINE(${PACKAGE}DIR=$withval); \ -fi \ -])# GIT_PARSE_WITH -# + [m4_pushdef([GIT_UC_PACKAGE], m4_toupper([$1]))dnl + PACKAGE=GIT_UC_PACKAGE + if test "$withval" = "no"; then + NO_[]GIT_UC_PACKAGE=YesPlease + elif test "$withval" = "yes"; then + NO_[]GIT_UC_PACKAGE= + else + NO_[]GIT_UC_PACKAGE= + GIT_UC_PACKAGE[]DIR=$withval + AC_MSG_NOTICE([Setting GIT_UC_PACKAGE[]DIR to $withval]) + GIT_CONF_APPEND_LINE(${PACKAGE}DIR=$withval) + fi + m4_popdef([GIT_UC_PACKAGE])]) + # GIT_PARSE_WITH_SET_MAKE_VAR(WITHNAME, VAR, HELP_TEXT) -# --------------------- +# ----------------------------------------------------- # Set VAR to the value specied by --with-WITHNAME. # No verification of arguments is performed, but warnings are issued # if either 'yes' or 'no' is specified. @@ -90,33 +81,32 @@ fi \ AC_DEFUN([GIT_PARSE_WITH_SET_MAKE_VAR], [AC_ARG_WITH([$1], [AS_HELP_STRING([--with-$1=VALUE], $3)], - if test -n "$withval"; then \ - if test "$withval" = "yes" -o "$withval" = "no"; then \ + if test -n "$withval"; then + if test "$withval" = "yes" -o "$withval" = "no"; then AC_MSG_WARN([You likely do not want either 'yes' or 'no' as] - [a value for $1 ($2). Maybe you do...?]); \ - fi; \ - \ - AC_MSG_NOTICE([Setting $2 to $withval]); \ - GIT_CONF_APPEND_LINE($2=$withval); \ + [a value for $1 ($2). Maybe you do...?]) + fi + AC_MSG_NOTICE([Setting $2 to $withval]) + GIT_CONF_APPEND_LINE($2=$withval) fi)])# GIT_PARSE_WITH_SET_MAKE_VAR -dnl -dnl GIT_CHECK_FUNC(FUNCTION, IFTRUE, IFFALSE) -dnl ----------------------------------------- -dnl Similar to AC_CHECK_FUNC, but on systems that do not generate -dnl warnings for missing prototypes (e.g. FreeBSD when compiling without -dnl -Wall), it does not work. By looking for function definition in -dnl libraries, this problem can be worked around. +# +# GIT_CHECK_FUNC(FUNCTION, IFTRUE, IFFALSE) +# ----------------------------------------- +# Similar to AC_CHECK_FUNC, but on systems that do not generate +# warnings for missing prototypes (e.g. FreeBSD when compiling without +# -Wall), it does not work. By looking for function definition in +# libraries, this problem can be worked around. AC_DEFUN([GIT_CHECK_FUNC],[AC_CHECK_FUNC([$1],[ AC_SEARCH_LIBS([$1],, [$2],[$3]) ],[$3])]) -dnl -dnl GIT_STASH_FLAGS(BASEPATH_VAR) -dnl ----------------------------- -dnl Allow for easy stashing of LDFLAGS and CPPFLAGS before running -dnl tests that may want to take user settings into account. +# +# GIT_STASH_FLAGS(BASEPATH_VAR) +# ----------------------------- +# Allow for easy stashing of LDFLAGS and CPPFLAGS before running +# tests that may want to take user settings into account. AC_DEFUN([GIT_STASH_FLAGS],[ if test -n "$1"; then old_CPPFLAGS="$CPPFLAGS" @@ -137,6 +127,19 @@ if test -n "$1"; then fi ]) +## Configure body starts here. + +AC_PREREQ(2.59) +AC_INIT([git], [@@GIT_VERSION@@], [git@vger.kernel.org]) + +AC_CONFIG_SRCDIR([git.c]) + +config_file=config.mak.autogen +config_append=config.mak.append +config_in=config.mak.in + +echo "# ${config_append}. Generated by configure." > "${config_append}" + # Directories holding "saner" versions of common or POSIX binaries. AC_ARG_WITH([sane-tool-path], [AS_HELP_STRING( @@ -161,14 +164,13 @@ AC_ARG_WITH([sane-tool-path], AC_ARG_WITH([lib], [AS_HELP_STRING([--with-lib=ARG], [ARG specifies alternative name for lib directory])], - [if test "$withval" = "no" || test "$withval" = "yes"; then \ - AC_MSG_WARN([You should provide name for --with-lib=ARG]); \ -else \ - lib=$withval; \ - AC_MSG_NOTICE([Setting lib to '$lib']); \ - GIT_CONF_APPEND_LINE(lib=$withval); \ -fi; \ -],[]) + [if test "$withval" = "no" || test "$withval" = "yes"; then + AC_MSG_WARN([You should provide name for --with-lib=ARG]) + else + lib=$withval + AC_MSG_NOTICE([Setting lib to '$lib']) + GIT_CONF_APPEND_LINE(lib=$withval) + fi]) if test -z "$lib"; then AC_MSG_NOTICE([Setting lib to 'lib' (the default)]) @@ -234,9 +236,9 @@ AC_MSG_NOTICE([CHECKS for site configuration]) # /foo/bar/include and /foo/bar/lib directories. AC_ARG_WITH(openssl, AS_HELP_STRING([--with-openssl],[use OpenSSL library (default is YES)]) -AS_HELP_STRING([], [ARG can be prefix for openssl library and headers]),\ -GIT_PARSE_WITH(openssl)) -# +AS_HELP_STRING([], [ARG can be prefix for openssl library and headers]), +GIT_PARSE_WITH([openssl])) + # Define USE_LIBPCRE if you have and want to use libpcre. git-grep will be # able to use Perl-compatible regular expressions. # @@ -246,17 +248,16 @@ GIT_PARSE_WITH(openssl)) AC_ARG_WITH(libpcre, AS_HELP_STRING([--with-libpcre],[support Perl-compatible regexes (default is NO)]) AS_HELP_STRING([], [ARG can be also prefix for libpcre library and headers]), -if test "$withval" = "no"; then \ - USE_LIBPCRE=; \ -elif test "$withval" = "yes"; then \ - USE_LIBPCRE=YesPlease; \ -else - USE_LIBPCRE=YesPlease; \ - LIBPCREDIR=$withval; \ - AC_MSG_NOTICE([Setting LIBPCREDIR to $withval]); \ - GIT_CONF_APPEND_LINE(LIBPCREDIR=$withval); \ -fi \ -) + if test "$withval" = "no"; then + USE_LIBPCRE= + elif test "$withval" = "yes"; then + USE_LIBPCRE=YesPlease + else + USE_LIBPCRE=YesPlease + LIBPCREDIR=$withval + AC_MSG_NOTICE([Setting LIBPCREDIR to $withval]) + GIT_CONF_APPEND_LINE(LIBPCREDIR=$withval) + fi) # # Define NO_CURL if you do not have curl installed. git-http-pull and # git-http-push are not built, and you cannot use http:// and https:// @@ -364,7 +365,7 @@ AC_ARG_WITH(tcltk, AS_HELP_STRING([--with-tcltk],[use Tcl/Tk GUI (default is YES)]) AS_HELP_STRING([],[ARG is the full path to the Tcl/Tk interpreter.]) AS_HELP_STRING([],[Bare --with-tcltk will make the GUI part only if]) -AS_HELP_STRING([],[Tcl/Tk interpreter will be found in a system.]),\ +AS_HELP_STRING([],[Tcl/Tk interpreter will be found in a system.]), GIT_PARSE_WITH(tcltk)) # diff --git a/contrib/fast-import/git-p4.README b/contrib/fast-import/git-p4.README new file mode 100644 index 0000000000..cec5ecfa7c --- /dev/null +++ b/contrib/fast-import/git-p4.README @@ -0,0 +1,12 @@ +The git-p4 script moved to the top-level of the git source directory. + +Invoke it as any other git command, like "git p4 clone", for instance. + +Note that the top-level git-p4.py script is now the source. It is +built using make to git-p4, which will be installed. + +Windows users can copy the git-p4.py source script directly, possibly +invoking it through a batch file called "git-p4.bat" in the same folder. +It should contain just one line: + + @python "%~d0%~p0git-p4.py" %* diff --git a/contrib/fast-import/git-p4.bat b/contrib/fast-import/git-p4.bat deleted file mode 100644 index 9f97e884f5..0000000000 --- a/contrib/fast-import/git-p4.bat +++ /dev/null @@ -1 +0,0 @@ -@python "%~d0%~p0git-p4" %* diff --git a/contrib/subtree/.gitignore b/contrib/subtree/.gitignore new file mode 100644 index 0000000000..7e77c9d022 --- /dev/null +++ b/contrib/subtree/.gitignore @@ -0,0 +1,5 @@ +*~ +git-subtree.xml +git-subtree.1 +mainline +subproj diff --git a/contrib/subtree/COPYING b/contrib/subtree/COPYING new file mode 100644 index 0000000000..d511905c16 --- /dev/null +++ b/contrib/subtree/COPYING @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/contrib/subtree/INSTALL b/contrib/subtree/INSTALL new file mode 100644 index 0000000000..7ab0cf4509 --- /dev/null +++ b/contrib/subtree/INSTALL @@ -0,0 +1,28 @@ +HOW TO INSTALL git-subtree +========================== + +First, build from the top source directory. + +Then, in contrib/subtree, run: + + make + make install + make install-doc + +If you used configure to do the main build the git-subtree build will +pick up those settings. If not, you will likely have to provide a +value for prefix: + + make prefix=<some dir> + make prefix=<some dir> install + make prefix=<some dir> install-doc + +To run tests first copy git-subtree to the main build area so the +newly-built git can find it: + + cp git-subtree ../.. + +Then: + + make test + diff --git a/contrib/subtree/Makefile b/contrib/subtree/Makefile new file mode 100644 index 0000000000..05cdd5c9b2 --- /dev/null +++ b/contrib/subtree/Makefile @@ -0,0 +1,52 @@ +-include ../../config.mak.autogen +-include ../../config.mak + +prefix ?= /usr/local +mandir ?= $(prefix)/share/man +libexecdir ?= $(prefix)/libexec/git-core +gitdir ?= $(shell git --exec-path) +man1dir ?= $(mandir)/man1 + +gitver ?= $(word 3,$(shell git --version)) + +# this should be set to a 'standard' bsd-type install program +INSTALL ?= install + +ASCIIDOC_CONF = ../../Documentation/asciidoc.conf +MANPAGE_NORMAL_XSL = ../../Documentation/manpage-normal.xsl + +GIT_SUBTREE_SH := git-subtree.sh +GIT_SUBTREE := git-subtree + +GIT_SUBTREE_DOC := git-subtree.1 +GIT_SUBTREE_XML := git-subtree.xml +GIT_SUBTREE_TXT := git-subtree.txt + +all: $(GIT_SUBTREE) + +$(GIT_SUBTREE): $(GIT_SUBTREE_SH) + cp $< $@ && chmod +x $@ + +doc: $(GIT_SUBTREE_DOC) + +install: $(GIT_SUBTREE) + $(INSTALL) -m 755 $(GIT_SUBTREE) $(libexecdir) + +install-doc: install-man + +install-man: $(GIT_SUBTREE_DOC) + $(INSTALL) -m 644 $^ $(man1dir) + +$(GIT_SUBTREE_DOC): $(GIT_SUBTREE_XML) + xmlto -m $(MANPAGE_NORMAL_XSL) man $^ + +$(GIT_SUBTREE_XML): $(GIT_SUBTREE_TXT) + asciidoc -b docbook -d manpage -f $(ASCIIDOC_CONF) \ + -agit_version=$(gitver) $^ + +test: + $(MAKE) -C t/ test + +clean: + rm -f *~ *.xml *.html *.1 + rm -rf subproj mainline diff --git a/contrib/subtree/README b/contrib/subtree/README new file mode 100644 index 0000000000..c686b4a69b --- /dev/null +++ b/contrib/subtree/README @@ -0,0 +1,8 @@ + +Please read git-subtree.txt for documentation. + +Please don't contact me using github mail; it's slow, ugly, and worst of +all, redundant. Email me instead at apenwarr@gmail.com and I'll be happy to +help. + +Avery diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh new file mode 100755 index 0000000000..920c664bb7 --- /dev/null +++ b/contrib/subtree/git-subtree.sh @@ -0,0 +1,712 @@ +#!/bin/bash +# +# git-subtree.sh: split/join git repositories in subdirectories of this one +# +# Copyright (C) 2009 Avery Pennarun <apenwarr@gmail.com> +# +if [ $# -eq 0 ]; then + set -- -h +fi +OPTS_SPEC="\ +git subtree add --prefix=<prefix> <commit> +git subtree merge --prefix=<prefix> <commit> +git subtree pull --prefix=<prefix> <repository> <refspec...> +git subtree push --prefix=<prefix> <repository> <refspec...> +git subtree split --prefix=<prefix> <commit...> +-- +h,help show the help +q quiet +d show debug messages +P,prefix= the name of the subdir to split out +m,message= use the given message as the commit message for the merge commit + options for 'split' +annotate= add a prefix to commit message of new commits +b,branch= create a new branch from the split subtree +ignore-joins ignore prior --rejoin commits +onto= try connecting new tree to an existing one +rejoin merge the new branch back into HEAD + options for 'add', 'merge', 'pull' and 'push' +squash merge subtree changes as a single commit +" +eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)" + +PATH=$PATH:$(git --exec-path) +. git-sh-setup + +require_work_tree + +quiet= +branch= +debug= +command= +onto= +rejoin= +ignore_joins= +annotate= +squash= +message= + +debug() +{ + if [ -n "$debug" ]; then + echo "$@" >&2 + fi +} + +say() +{ + if [ -z "$quiet" ]; then + echo "$@" >&2 + fi +} + +assert() +{ + if "$@"; then + : + else + die "assertion failed: " "$@" + fi +} + + +#echo "Options: $*" + +while [ $# -gt 0 ]; do + opt="$1" + shift + case "$opt" in + -q) quiet=1 ;; + -d) debug=1 ;; + --annotate) annotate="$1"; shift ;; + --no-annotate) annotate= ;; + -b) branch="$1"; shift ;; + -P) prefix="$1"; shift ;; + -m) message="$1"; shift ;; + --no-prefix) prefix= ;; + --onto) onto="$1"; shift ;; + --no-onto) onto= ;; + --rejoin) rejoin=1 ;; + --no-rejoin) rejoin= ;; + --ignore-joins) ignore_joins=1 ;; + --no-ignore-joins) ignore_joins= ;; + --squash) squash=1 ;; + --no-squash) squash= ;; + --) break ;; + *) die "Unexpected option: $opt" ;; + esac +done + +command="$1" +shift +case "$command" in + add|merge|pull) default= ;; + split|push) default="--default HEAD" ;; + *) die "Unknown command '$command'" ;; +esac + +if [ -z "$prefix" ]; then + die "You must provide the --prefix option." +fi + +case "$command" in + add) [ -e "$prefix" ] && + die "prefix '$prefix' already exists." ;; + *) [ -e "$prefix" ] || + die "'$prefix' does not exist; use 'git subtree add'" ;; +esac + +dir="$(dirname "$prefix/.")" + +if [ "$command" != "pull" -a "$command" != "add" -a "$command" != "push" ]; then + revs=$(git rev-parse $default --revs-only "$@") || exit $? + dirs="$(git rev-parse --no-revs --no-flags "$@")" || exit $? + if [ -n "$dirs" ]; then + die "Error: Use --prefix instead of bare filenames." + fi +fi + +debug "command: {$command}" +debug "quiet: {$quiet}" +debug "revs: {$revs}" +debug "dir: {$dir}" +debug "opts: {$*}" +debug + +cache_setup() +{ + cachedir="$GIT_DIR/subtree-cache/$$" + rm -rf "$cachedir" || die "Can't delete old cachedir: $cachedir" + mkdir -p "$cachedir" || die "Can't create new cachedir: $cachedir" + mkdir -p "$cachedir/notree" || die "Can't create new cachedir: $cachedir/notree" + debug "Using cachedir: $cachedir" >&2 +} + +cache_get() +{ + for oldrev in $*; do + if [ -r "$cachedir/$oldrev" ]; then + read newrev <"$cachedir/$oldrev" + echo $newrev + fi + done +} + +cache_miss() +{ + for oldrev in $*; do + if [ ! -r "$cachedir/$oldrev" ]; then + echo $oldrev + fi + done +} + +check_parents() +{ + missed=$(cache_miss $*) + for miss in $missed; do + if [ ! -r "$cachedir/notree/$miss" ]; then + debug " incorrect order: $miss" + fi + done +} + +set_notree() +{ + echo "1" > "$cachedir/notree/$1" +} + +cache_set() +{ + oldrev="$1" + newrev="$2" + if [ "$oldrev" != "latest_old" \ + -a "$oldrev" != "latest_new" \ + -a -e "$cachedir/$oldrev" ]; then + die "cache for $oldrev already exists!" + fi + echo "$newrev" >"$cachedir/$oldrev" +} + +rev_exists() +{ + if git rev-parse "$1" >/dev/null 2>&1; then + return 0 + else + return 1 + fi +} + +rev_is_descendant_of_branch() +{ + newrev="$1" + branch="$2" + branch_hash=$(git rev-parse $branch) + match=$(git rev-list -1 $branch_hash ^$newrev) + + if [ -z "$match" ]; then + return 0 + else + return 1 + fi +} + +# if a commit doesn't have a parent, this might not work. But we only want +# to remove the parent from the rev-list, and since it doesn't exist, it won't +# be there anyway, so do nothing in that case. +try_remove_previous() +{ + if rev_exists "$1^"; then + echo "^$1^" + fi +} + +find_latest_squash() +{ + debug "Looking for latest squash ($dir)..." + dir="$1" + sq= + main= + sub= + git log --grep="^git-subtree-dir: $dir/*\$" \ + --pretty=format:'START %H%n%s%n%n%b%nEND%n' HEAD | + while read a b junk; do + debug "$a $b $junk" + debug "{{$sq/$main/$sub}}" + case "$a" in + START) sq="$b" ;; + git-subtree-mainline:) main="$b" ;; + git-subtree-split:) sub="$b" ;; + END) + if [ -n "$sub" ]; then + if [ -n "$main" ]; then + # a rejoin commit? + # Pretend its sub was a squash. + sq="$sub" + fi + debug "Squash found: $sq $sub" + echo "$sq" "$sub" + break + fi + sq= + main= + sub= + ;; + esac + done +} + +find_existing_splits() +{ + debug "Looking for prior splits..." + dir="$1" + revs="$2" + main= + sub= + git log --grep="^git-subtree-dir: $dir/*\$" \ + --pretty=format:'START %H%n%s%n%n%b%nEND%n' $revs | + while read a b junk; do + case "$a" in + START) sq="$b" ;; + git-subtree-mainline:) main="$b" ;; + git-subtree-split:) sub="$b" ;; + END) + debug " Main is: '$main'" + if [ -z "$main" -a -n "$sub" ]; then + # squash commits refer to a subtree + debug " Squash: $sq from $sub" + cache_set "$sq" "$sub" + fi + if [ -n "$main" -a -n "$sub" ]; then + debug " Prior: $main -> $sub" + cache_set $main $sub + cache_set $sub $sub + try_remove_previous "$main" + try_remove_previous "$sub" + fi + main= + sub= + ;; + esac + done +} + +copy_commit() +{ + # We're going to set some environment vars here, so + # do it in a subshell to get rid of them safely later + debug copy_commit "{$1}" "{$2}" "{$3}" + git log -1 --pretty=format:'%an%n%ae%n%ad%n%cn%n%ce%n%cd%n%s%n%n%b' "$1" | + ( + read GIT_AUTHOR_NAME + read GIT_AUTHOR_EMAIL + read GIT_AUTHOR_DATE + read GIT_COMMITTER_NAME + read GIT_COMMITTER_EMAIL + read GIT_COMMITTER_DATE + export GIT_AUTHOR_NAME \ + GIT_AUTHOR_EMAIL \ + GIT_AUTHOR_DATE \ + GIT_COMMITTER_NAME \ + GIT_COMMITTER_EMAIL \ + GIT_COMMITTER_DATE + (echo -n "$annotate"; cat ) | + git commit-tree "$2" $3 # reads the rest of stdin + ) || die "Can't copy commit $1" +} + +add_msg() +{ + dir="$1" + latest_old="$2" + latest_new="$3" + if [ -n "$message" ]; then + commit_message="$message" + else + commit_message="Add '$dir/' from commit '$latest_new'" + fi + cat <<-EOF + $commit_message + + git-subtree-dir: $dir + git-subtree-mainline: $latest_old + git-subtree-split: $latest_new + EOF +} + +add_squashed_msg() +{ + if [ -n "$message" ]; then + echo "$message" + else + echo "Merge commit '$1' as '$2'" + fi +} + +rejoin_msg() +{ + dir="$1" + latest_old="$2" + latest_new="$3" + if [ -n "$message" ]; then + commit_message="$message" + else + commit_message="Split '$dir/' into commit '$latest_new'" + fi + cat <<-EOF + $commit_message + + git-subtree-dir: $dir + git-subtree-mainline: $latest_old + git-subtree-split: $latest_new + EOF +} + +squash_msg() +{ + dir="$1" + oldsub="$2" + newsub="$3" + newsub_short=$(git rev-parse --short "$newsub") + + if [ -n "$oldsub" ]; then + oldsub_short=$(git rev-parse --short "$oldsub") + echo "Squashed '$dir/' changes from $oldsub_short..$newsub_short" + echo + git log --pretty=tformat:'%h %s' "$oldsub..$newsub" + git log --pretty=tformat:'REVERT: %h %s' "$newsub..$oldsub" + else + echo "Squashed '$dir/' content from commit $newsub_short" + fi + + echo + echo "git-subtree-dir: $dir" + echo "git-subtree-split: $newsub" +} + +toptree_for_commit() +{ + commit="$1" + git log -1 --pretty=format:'%T' "$commit" -- || exit $? +} + +subtree_for_commit() +{ + commit="$1" + dir="$2" + git ls-tree "$commit" -- "$dir" | + while read mode type tree name; do + assert [ "$name" = "$dir" ] + assert [ "$type" = "tree" -o "$type" = "commit" ] + [ "$type" = "commit" ] && continue # ignore submodules + echo $tree + break + done +} + +tree_changed() +{ + tree=$1 + shift + if [ $# -ne 1 ]; then + return 0 # weird parents, consider it changed + else + ptree=$(toptree_for_commit $1) + if [ "$ptree" != "$tree" ]; then + return 0 # changed + else + return 1 # not changed + fi + fi +} + +new_squash_commit() +{ + old="$1" + oldsub="$2" + newsub="$3" + tree=$(toptree_for_commit $newsub) || exit $? + if [ -n "$old" ]; then + squash_msg "$dir" "$oldsub" "$newsub" | + git commit-tree "$tree" -p "$old" || exit $? + else + squash_msg "$dir" "" "$newsub" | + git commit-tree "$tree" || exit $? + fi +} + +copy_or_skip() +{ + rev="$1" + tree="$2" + newparents="$3" + assert [ -n "$tree" ] + + identical= + nonidentical= + p= + gotparents= + for parent in $newparents; do + ptree=$(toptree_for_commit $parent) || exit $? + [ -z "$ptree" ] && continue + if [ "$ptree" = "$tree" ]; then + # an identical parent could be used in place of this rev. + identical="$parent" + else + nonidentical="$parent" + fi + + # sometimes both old parents map to the same newparent; + # eliminate duplicates + is_new=1 + for gp in $gotparents; do + if [ "$gp" = "$parent" ]; then + is_new= + break + fi + done + if [ -n "$is_new" ]; then + gotparents="$gotparents $parent" + p="$p -p $parent" + fi + done + + if [ -n "$identical" ]; then + echo $identical + else + copy_commit $rev $tree "$p" || exit $? + fi +} + +ensure_clean() +{ + if ! git diff-index HEAD --exit-code --quiet 2>&1; then + die "Working tree has modifications. Cannot add." + fi + if ! git diff-index --cached HEAD --exit-code --quiet 2>&1; then + die "Index has modifications. Cannot add." + fi +} + +cmd_add() +{ + if [ -e "$dir" ]; then + die "'$dir' already exists. Cannot add." + fi + + ensure_clean + + if [ $# -eq 1 ]; then + "cmd_add_commit" "$@" + elif [ $# -eq 2 ]; then + "cmd_add_repository" "$@" + else + say "error: parameters were '$@'" + die "Provide either a refspec or a repository and refspec." + fi +} + +cmd_add_repository() +{ + echo "git fetch" "$@" + repository=$1 + refspec=$2 + git fetch "$@" || exit $? + revs=FETCH_HEAD + set -- $revs + cmd_add_commit "$@" +} + +cmd_add_commit() +{ + revs=$(git rev-parse $default --revs-only "$@") || exit $? + set -- $revs + rev="$1" + + debug "Adding $dir as '$rev'..." + git read-tree --prefix="$dir" $rev || exit $? + git checkout -- "$dir" || exit $? + tree=$(git write-tree) || exit $? + + headrev=$(git rev-parse HEAD) || exit $? + if [ -n "$headrev" -a "$headrev" != "$rev" ]; then + headp="-p $headrev" + else + headp= + fi + + if [ -n "$squash" ]; then + rev=$(new_squash_commit "" "" "$rev") || exit $? + commit=$(add_squashed_msg "$rev" "$dir" | + git commit-tree $tree $headp -p "$rev") || exit $? + else + commit=$(add_msg "$dir" "$headrev" "$rev" | + git commit-tree $tree $headp -p "$rev") || exit $? + fi + git reset "$commit" || exit $? + + say "Added dir '$dir'" +} + +cmd_split() +{ + debug "Splitting $dir..." + cache_setup || exit $? + + if [ -n "$onto" ]; then + debug "Reading history for --onto=$onto..." + git rev-list $onto | + while read rev; do + # the 'onto' history is already just the subdir, so + # any parent we find there can be used verbatim + debug " cache: $rev" + cache_set $rev $rev + done + fi + + if [ -n "$ignore_joins" ]; then + unrevs= + else + unrevs="$(find_existing_splits "$dir" "$revs")" + fi + + # We can't restrict rev-list to only $dir here, because some of our + # parents have the $dir contents the root, and those won't match. + # (and rev-list --follow doesn't seem to solve this) + grl='git rev-list --topo-order --reverse --parents $revs $unrevs' + revmax=$(eval "$grl" | wc -l) + revcount=0 + createcount=0 + eval "$grl" | + while read rev parents; do + revcount=$(($revcount + 1)) + say -n "$revcount/$revmax ($createcount)
" + debug "Processing commit: $rev" + exists=$(cache_get $rev) + if [ -n "$exists" ]; then + debug " prior: $exists" + continue + fi + createcount=$(($createcount + 1)) + debug " parents: $parents" + newparents=$(cache_get $parents) + debug " newparents: $newparents" + + tree=$(subtree_for_commit $rev "$dir") + debug " tree is: $tree" + + check_parents $parents + + # ugly. is there no better way to tell if this is a subtree + # vs. a mainline commit? Does it matter? + if [ -z $tree ]; then + set_notree $rev + if [ -n "$newparents" ]; then + cache_set $rev $rev + fi + continue + fi + + newrev=$(copy_or_skip "$rev" "$tree" "$newparents") || exit $? + debug " newrev is: $newrev" + cache_set $rev $newrev + cache_set latest_new $newrev + cache_set latest_old $rev + done || exit $? + latest_new=$(cache_get latest_new) + if [ -z "$latest_new" ]; then + die "No new revisions were found" + fi + + if [ -n "$rejoin" ]; then + debug "Merging split branch into HEAD..." + latest_old=$(cache_get latest_old) + git merge -s ours \ + -m "$(rejoin_msg $dir $latest_old $latest_new)" \ + $latest_new >&2 || exit $? + fi + if [ -n "$branch" ]; then + if rev_exists "refs/heads/$branch"; then + if ! rev_is_descendant_of_branch $latest_new $branch; then + die "Branch '$branch' is not an ancestor of commit '$latest_new'." + fi + action='Updated' + else + action='Created' + fi + git update-ref -m 'subtree split' "refs/heads/$branch" $latest_new || exit $? + say "$action branch '$branch'" + fi + echo $latest_new + exit 0 +} + +cmd_merge() +{ + revs=$(git rev-parse $default --revs-only "$@") || exit $? + ensure_clean + + set -- $revs + if [ $# -ne 1 ]; then + die "You must provide exactly one revision. Got: '$revs'" + fi + rev="$1" + + if [ -n "$squash" ]; then + first_split="$(find_latest_squash "$dir")" + if [ -z "$first_split" ]; then + die "Can't squash-merge: '$dir' was never added." + fi + set $first_split + old=$1 + sub=$2 + if [ "$sub" = "$rev" ]; then + say "Subtree is already at commit $rev." + exit 0 + fi + new=$(new_squash_commit "$old" "$sub" "$rev") || exit $? + debug "New squash commit: $new" + rev="$new" + fi + + version=$(git version) + if [ "$version" \< "git version 1.7" ]; then + if [ -n "$message" ]; then + git merge -s subtree --message="$message" $rev + else + git merge -s subtree $rev + fi + else + if [ -n "$message" ]; then + git merge -Xsubtree="$prefix" --message="$message" $rev + else + git merge -Xsubtree="$prefix" $rev + fi + fi +} + +cmd_pull() +{ + ensure_clean + git fetch "$@" || exit $? + revs=FETCH_HEAD + set -- $revs + cmd_merge "$@" +} + +cmd_push() +{ + if [ $# -ne 2 ]; then + die "You must provide <repository> <refspec>" + fi + if [ -e "$dir" ]; then + repository=$1 + refspec=$2 + echo "git push using: " $repository $refspec + git push $repository $(git subtree split --prefix=$prefix):refs/heads/$refspec + else + die "'$dir' must already exist. Try 'git subtree add'." + fi +} + +"cmd_$command" "$@" diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt new file mode 100644 index 0000000000..0c44fda011 --- /dev/null +++ b/contrib/subtree/git-subtree.txt @@ -0,0 +1,366 @@ +git-subtree(1) +============== + +NAME +---- +git-subtree - Merge subtrees together and split repository into subtrees + + +SYNOPSIS +-------- +[verse] +'git subtree' add -P <prefix> <commit> +'git subtree' pull -P <prefix> <repository> <refspec...> +'git subtree' push -P <prefix> <repository> <refspec...> +'git subtree' merge -P <prefix> <commit> +'git subtree' split -P <prefix> [OPTIONS] [<commit>] + + +DESCRIPTION +----------- +Subtrees allow subprojects to be included within a subdirectory +of the main project, optionally including the subproject's +entire history. + +For example, you could include the source code for a library +as a subdirectory of your application. + +Subtrees are not to be confused with submodules, which are meant for +the same task. Unlike submodules, subtrees do not need any special +constructions (like .gitmodule files or gitlinks) be present in +your repository, and do not force end-users of your +repository to do anything special or to understand how subtrees +work. A subtree is just a subdirectory that can be +committed to, branched, and merged along with your project in +any way you want. + +They are also not to be confused with using the subtree merge +strategy. The main difference is that, besides merging +the other project as a subdirectory, you can also extract the +entire history of a subdirectory from your project and make it +into a standalone project. Unlike the subtree merge strategy +you can alternate back and forth between these +two operations. If the standalone library gets updated, you can +automatically merge the changes into your project; if you +update the library inside your project, you can "split" the +changes back out again and merge them back into the library +project. + +For example, if a library you made for one application ends up being +useful elsewhere, you can extract its entire history and publish +that as its own git repository, without accidentally +intermingling the history of your application project. + +[TIP] +In order to keep your commit messages clean, we recommend that +people split their commits between the subtrees and the main +project as much as possible. That is, if you make a change that +affects both the library and the main application, commit it in +two pieces. That way, when you split the library commits out +later, their descriptions will still make sense. But if this +isn't important to you, it's not *necessary*. git subtree will +simply leave out the non-library-related parts of the commit +when it splits it out into the subproject later. + + +COMMANDS +-------- +add:: + Create the <prefix> subtree by importing its contents + from the given <refspec> or <repository> and remote <refspec>. + A new commit is created automatically, joining the imported + project's history with your own. With '--squash', imports + only a single commit from the subproject, rather than its + entire history. + +merge:: + Merge recent changes up to <commit> into the <prefix> + subtree. As with normal 'git merge', this doesn't + remove your own local changes; it just merges those + changes into the latest <commit>. With '--squash', + creates only one commit that contains all the changes, + rather than merging in the entire history. + + If you use '--squash', the merge direction doesn't + always have to be forward; you can use this command to + go back in time from v2.5 to v2.4, for example. If your + merge introduces a conflict, you can resolve it in the + usual ways. + +pull:: + Exactly like 'merge', but parallels 'git pull' in that + it fetches the given commit from the specified remote + repository. + +push:: + Does a 'split' (see above) using the <prefix> supplied + and then does a 'git push' to push the result to the + repository and refspec. This can be used to push your + subtree to different branches of the remote repository. + +split:: + Extract a new, synthetic project history from the + history of the <prefix> subtree. The new history + includes only the commits (including merges) that + affected <prefix>, and each of those commits now has the + contents of <prefix> at the root of the project instead + of in a subdirectory. Thus, the newly created history + is suitable for export as a separate git repository. + + After splitting successfully, a single commit id is + printed to stdout. This corresponds to the HEAD of the + newly created tree, which you can manipulate however you + want. + + Repeated splits of exactly the same history are + guaranteed to be identical (ie. to produce the same + commit ids). Because of this, if you add new commits + and then re-split, the new commits will be attached as + commits on top of the history you generated last time, + so 'git merge' and friends will work as expected. + + Note that if you use '--squash' when you merge, you + should usually not just '--rejoin' when you split. + + +OPTIONS +------- +-q:: +--quiet:: + Suppress unnecessary output messages on stderr. + +-d:: +--debug:: + Produce even more unnecessary output messages on stderr. + +-P <prefix>:: +--prefix=<prefix>:: + Specify the path in the repository to the subtree you + want to manipulate. This option is mandatory + for all commands. + +-m <message>:: +--message=<message>:: + This option is only valid for add, merge and pull (unsure). + Specify <message> as the commit message for the merge commit. + + +OPTIONS FOR add, merge, push, pull +---------------------------------- +--squash:: + This option is only valid for add, merge, push and pull + commands. + + Instead of merging the entire history from the subtree + project, produce only a single commit that contains all + the differences you want to merge, and then merge that + new commit into your project. + + Using this option helps to reduce log clutter. People + rarely want to see every change that happened between + v1.0 and v1.1 of the library they're using, since none of the + interim versions were ever included in their application. + + Using '--squash' also helps avoid problems when the same + subproject is included multiple times in the same + project, or is removed and then re-added. In such a + case, it doesn't make sense to combine the histories + anyway, since it's unclear which part of the history + belongs to which subtree. + + Furthermore, with '--squash', you can switch back and + forth between different versions of a subtree, rather + than strictly forward. 'git subtree merge --squash' + always adjusts the subtree to match the exactly + specified commit, even if getting to that commit would + require undoing some changes that were added earlier. + + Whether or not you use '--squash', changes made in your + local repository remain intact and can be later split + and send upstream to the subproject. + + +OPTIONS FOR split +----------------- +--annotate=<annotation>:: + This option is only valid for the split command. + + When generating synthetic history, add <annotation> as a + prefix to each commit message. Since we're creating new + commits with the same commit message, but possibly + different content, from the original commits, this can help + to differentiate them and avoid confusion. + + Whenever you split, you need to use the same + <annotation>, or else you don't have a guarantee that + the new re-created history will be identical to the old + one. That will prevent merging from working correctly. + git subtree tries to make it work anyway, particularly + if you use --rejoin, but it may not always be effective. + +-b <branch>:: +--branch=<branch>:: + This option is only valid for the split command. + + After generating the synthetic history, create a new + branch called <branch> that contains the new history. + This is suitable for immediate pushing upstream. + <branch> must not already exist. + +--ignore-joins:: + This option is only valid for the split command. + + If you use '--rejoin', git subtree attempts to optimize + its history reconstruction to generate only the new + commits since the last '--rejoin'. '--ignore-join' + disables this behaviour, forcing it to regenerate the + entire history. In a large project, this can take a + long time. + +--onto=<onto>:: + This option is only valid for the split command. + + If your subtree was originally imported using something + other than git subtree, its history may not match what + git subtree is expecting. In that case, you can specify + the commit id <onto> that corresponds to the first + revision of the subproject's history that was imported + into your project, and git subtree will attempt to build + its history from there. + + If you used 'git subtree add', you should never need + this option. + +--rejoin:: + This option is only valid for the split command. + + After splitting, merge the newly created synthetic + history back into your main project. That way, future + splits can search only the part of history that has + been added since the most recent --rejoin. + + If your split commits end up merged into the upstream + subproject, and then you want to get the latest upstream + version, this will allow git's merge algorithm to more + intelligently avoid conflicts (since it knows these + synthetic commits are already part of the upstream + repository). + + Unfortunately, using this option results in 'git log' + showing an extra copy of every new commit that was + created (the original, and the synthetic one). + + If you do all your merges with '--squash', don't use + '--rejoin' when you split, because you don't want the + subproject's history to be part of your project anyway. + + +EXAMPLE 1. Add command +---------------------- +Let's assume that you have a local repository that you would like +to add an external vendor library to. In this case we will add the +git-subtree repository as a subdirectory of your already existing +git-extensions repository in ~/git-extensions/: + + $ git subtree add --prefix=git-subtree --squash \ + git://github.com/apenwarr/git-subtree.git master + +'master' needs to be a valid remote ref and can be a different branch +name + +You can omit the --squash flag, but doing so will increase the number +of commits that are incldued in your local repository. + +We now have a ~/git-extensions/git-subtree directory containing code +from the master branch of git://github.com/apenwarr/git-subtree.git +in our git-extensions repository. + +EXAMPLE 2. Extract a subtree using commit, merge and pull +--------------------------------------------------------- +Let's use the repository for the git source code as an example. +First, get your own copy of the git.git repository: + + $ git clone git://git.kernel.org/pub/scm/git/git.git test-git + $ cd test-git + +gitweb (commit 1130ef3) was merged into git as of commit +0a8f4f0, after which it was no longer maintained separately. +But imagine it had been maintained separately, and we wanted to +extract git's changes to gitweb since that time, to share with +the upstream. You could do this: + + $ git subtree split --prefix=gitweb --annotate='(split) ' \ + 0a8f4f0^.. --onto=1130ef3 --rejoin \ + --branch gitweb-latest + $ gitk gitweb-latest + $ git push git@github.com:whatever/gitweb.git gitweb-latest:master + +(We use '0a8f4f0^..' because that means "all the changes from +0a8f4f0 to the current version, including 0a8f4f0 itself.") + +If gitweb had originally been merged using 'git subtree add' (or +a previous split had already been done with --rejoin specified) +then you can do all your splits without having to remember any +weird commit ids: + + $ git subtree split --prefix=gitweb --annotate='(split) ' --rejoin \ + --branch gitweb-latest2 + +And you can merge changes back in from the upstream project just +as easily: + + $ git subtree pull --prefix=gitweb \ + git@github.com:whatever/gitweb.git master + +Or, using '--squash', you can actually rewind to an earlier +version of gitweb: + + $ git subtree merge --prefix=gitweb --squash gitweb-latest~10 + +Then make some changes: + + $ date >gitweb/myfile + $ git add gitweb/myfile + $ git commit -m 'created myfile' + +And fast forward again: + + $ git subtree merge --prefix=gitweb --squash gitweb-latest + +And notice that your change is still intact: + + $ ls -l gitweb/myfile + +And you can split it out and look at your changes versus +the standard gitweb: + + git log gitweb-latest..$(git subtree split --prefix=gitweb) + +EXAMPLE 3. Extract a subtree using branch +----------------------------------------- +Suppose you have a source directory with many files and +subdirectories, and you want to extract the lib directory to its own +git project. Here's a short way to do it: + +First, make the new repository wherever you want: + + $ <go to the new location> + $ git init --bare + +Back in your original directory: + + $ git subtree split --prefix=lib --annotate="(split)" -b split + +Then push the new branch onto the new empty repository: + + $ git push <new-repo> split:master + + +AUTHOR +------ +Written by Avery Pennarun <apenwarr@gmail.com> + + +GIT +--- +Part of the linkgit:git[1] suite diff --git a/contrib/subtree/t/Makefile b/contrib/subtree/t/Makefile new file mode 100644 index 0000000000..c864810389 --- /dev/null +++ b/contrib/subtree/t/Makefile @@ -0,0 +1,69 @@ +# Run tests +# +# Copyright (c) 2005 Junio C Hamano +# + +-include ../../../config.mak.autogen +-include ../../../config.mak + +#GIT_TEST_OPTS=--verbose --debug +SHELL_PATH ?= $(SHELL) +PERL_PATH ?= /usr/bin/perl +TAR ?= $(TAR) +RM ?= rm -f +PROVE ?= prove +DEFAULT_TEST_TARGET ?= test + +# Shell quote; +SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH)) + +T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh) + +all: $(DEFAULT_TEST_TARGET) + +test: pre-clean $(TEST_LINT) + $(MAKE) aggregate-results-and-cleanup + +prove: pre-clean $(TEST_LINT) + @echo "*** prove ***"; GIT_CONFIG=.git/config $(PROVE) --exec '$(SHELL_PATH_SQ)' $(GIT_PROVE_OPTS) $(T) :: $(GIT_TEST_OPTS) + $(MAKE) clean + +$(T): + @echo "*** $@ ***"; GIT_CONFIG=.git/config '$(SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS) + +pre-clean: + $(RM) -r test-results + +clean: + $(RM) -r 'trash directory'.* test-results + $(RM) -r valgrind/bin + $(RM) .prove + +test-lint: test-lint-duplicates test-lint-executable + +test-lint-duplicates: + @dups=`echo $(T) | tr ' ' '\n' | sed 's/-.*//' | sort | uniq -d` && \ + test -z "$$dups" || { \ + echo >&2 "duplicate test numbers:" $$dups; exit 1; } + +test-lint-executable: + @bad=`for i in $(T); do test -x "$$i" || echo $$i; done` && \ + test -z "$$bad" || { \ + echo >&2 "non-executable tests:" $$bad; exit 1; } + +aggregate-results-and-cleanup: $(T) + $(MAKE) aggregate-results + $(MAKE) clean + +aggregate-results: + for f in ../../../t/test-results/t*-*.counts; do \ + echo "$$f"; \ + done | '$(SHELL_PATH_SQ)' ../../../t/aggregate-results.sh + +valgrind: + $(MAKE) GIT_TEST_OPTS="$(GIT_TEST_OPTS) --valgrind" + +test-results: + mkdir -p test-results + +.PHONY: pre-clean $(T) aggregate-results clean valgrind diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh new file mode 100755 index 0000000000..bc2eeb0944 --- /dev/null +++ b/contrib/subtree/t/t7900-subtree.sh @@ -0,0 +1,508 @@ +#!/bin/sh +# +# Copyright (c) 2012 Avery Pennaraum +# +test_description='Basic porcelain support for subtrees + +This test verifies the basic operation of the merge, pull, add +and split subcommands of git subtree. +' + +export TEST_DIRECTORY=$(pwd)/../../../t + +. ../../../t/test-lib.sh + +create() +{ + echo "$1" >"$1" + git add "$1" +} + + +check_equal() +{ + test_debug 'echo' + test_debug "echo \"check a:\" \"{$1}\"" + test_debug "echo \" b:\" \"{$2}\"" + if [ "$1" = "$2" ]; then + return 0 + else + return 1 + fi +} + +fixnl() +{ + t="" + while read x; do + t="$t$x " + done + echo $t +} + +multiline() +{ + while read x; do + set -- $x + for d in "$@"; do + echo "$d" + done + done +} + +undo() +{ + git reset --hard HEAD~ +} + +last_commit_message() +{ + git log --pretty=format:%s -1 +} + +# 1 +test_expect_success 'init subproj' ' + test_create_repo subproj +' + +# To the subproject! +cd subproj + +# 2 +test_expect_success 'add sub1' ' + create sub1 && + git commit -m "sub1" && + git branch sub1 && + git branch -m master subproj +' + +# 3 +test_expect_success 'add sub2' ' + create sub2 && + git commit -m "sub2" && + git branch sub2 +' + +# 4 +test_expect_success 'add sub3' ' + create sub3 && + git commit -m "sub3" && + git branch sub3 +' + +# Back to mainline +cd .. + +# 5 +test_expect_success 'add main4' ' + create main4 && + git commit -m "main4" && + git branch -m master mainline && + git branch subdir +' + +# 6 +test_expect_success 'fetch subproj history' ' + git fetch ./subproj sub1 && + git branch sub1 FETCH_HEAD +' + +# 7 +test_expect_success 'no subtree exists in main tree' ' + test_must_fail git subtree merge --prefix=subdir sub1 +' + +# 8 +test_expect_success 'no pull from non-existant subtree' ' + test_must_fail git subtree pull --prefix=subdir ./subproj sub1 +' + +# 9 +test_expect_success 'check if --message works for add' ' + git subtree add --prefix=subdir --message="Added subproject" sub1 && + check_equal ''"$(last_commit_message)"'' "Added subproject" && + undo +' + +# 10 +test_expect_success 'check if --message works as -m and --prefix as -P' ' + git subtree add -P subdir -m "Added subproject using git subtree" sub1 && + check_equal ''"$(last_commit_message)"'' "Added subproject using git subtree" && + undo +' + +# 11 +test_expect_success 'check if --message works with squash too' ' + git subtree add -P subdir -m "Added subproject with squash" --squash sub1 && + check_equal ''"$(last_commit_message)"'' "Added subproject with squash" && + undo +' + +# 12 +test_expect_success 'add subproj to mainline' ' + git subtree add --prefix=subdir/ FETCH_HEAD && + check_equal ''"$(last_commit_message)"'' "Add '"'subdir/'"' from commit '"'"'''"$(git rev-parse sub1)"'''"'"'" +' + +# 13 +# this shouldn't actually do anything, since FETCH_HEAD is already a parent +test_expect_success 'merge fetched subproj' ' + git merge -m "merge -s -ours" -s ours FETCH_HEAD +' + +# 14 +test_expect_success 'add main-sub5' ' + create subdir/main-sub5 && + git commit -m "main-sub5" +' + +# 15 +test_expect_success 'add main6' ' + create main6 && + git commit -m "main6 boring" +' + +# 16 +test_expect_success 'add main-sub7' ' + create subdir/main-sub7 && + git commit -m "main-sub7" +' + +# 17 +test_expect_success 'fetch new subproj history' ' + git fetch ./subproj sub2 && + git branch sub2 FETCH_HEAD +' + +# 18 +test_expect_success 'check if --message works for merge' ' + git subtree merge --prefix=subdir -m "Merged changes from subproject" sub2 && + check_equal ''"$(last_commit_message)"'' "Merged changes from subproject" && + undo +' + +# 19 +test_expect_success 'check if --message for merge works with squash too' ' + git subtree merge --prefix subdir -m "Merged changes from subproject using squash" --squash sub2 && + check_equal ''"$(last_commit_message)"'' "Merged changes from subproject using squash" && + undo +' + +# 20 +test_expect_success 'merge new subproj history into subdir' ' + git subtree merge --prefix=subdir FETCH_HEAD && + git branch pre-split && + check_equal ''"$(last_commit_message)"'' "Merge commit '"'"'"$(git rev-parse sub2)"'"'"' into mainline" +' + +# 21 +test_expect_success 'Check that prefix argument is required for split' ' + echo "You must provide the --prefix option." > expected && + test_must_fail git subtree split > actual 2>&1 && + test_debug "echo -n expected: " && + test_debug "cat expected" && + test_debug "echo -n actual: " && + test_debug "cat actual" && + test_cmp expected actual && + rm -f expected actual +' + +# 22 +test_expect_success 'Check that the <prefix> exists for a split' ' + echo "'"'"'non-existent-directory'"'"'" does not exist\; use "'"'"'git subtree add'"'"'" > expected && + test_must_fail git subtree split --prefix=non-existent-directory > actual 2>&1 && + test_debug "echo -n expected: " && + test_debug "cat expected" && + test_debug "echo -n actual: " && + test_debug "cat actual" && + test_cmp expected actual +# rm -f expected actual +' + +# 23 +test_expect_success 'check if --message works for split+rejoin' ' + spl1=''"$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"'' && + git branch spl1 "$spl1" && + check_equal ''"$(last_commit_message)"'' "Split & rejoin" && + undo +' + +# 24 +test_expect_success 'check split with --branch' ' + spl1=$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin) && + undo && + git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --branch splitbr1 && + check_equal ''"$(git rev-parse splitbr1)"'' "$spl1" +' + +# 25 +test_expect_success 'check split with --branch for an existing branch' ' + spl1=''"$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"'' && + undo && + git branch splitbr2 sub1 && + git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --branch splitbr2 && + check_equal ''"$(git rev-parse splitbr2)"'' "$spl1" +' + +# 26 +test_expect_success 'check split with --branch for an incompatible branch' ' + test_must_fail git subtree split --prefix subdir --onto FETCH_HEAD --branch subdir +' + + +# 27 +test_expect_success 'check split+rejoin' ' + spl1=''"$(git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"'' && + undo && + git subtree split --annotate='"'*'"' --prefix subdir --onto FETCH_HEAD --rejoin && + check_equal ''"$(last_commit_message)"'' "Split '"'"'subdir/'"'"' into commit '"'"'"$spl1"'"'"'" +' + +# 28 +test_expect_success 'add main-sub8' ' + create subdir/main-sub8 && + git commit -m "main-sub8" +' + +# To the subproject! +cd ./subproj + +# 29 +test_expect_success 'merge split into subproj' ' + git fetch .. spl1 && + git branch spl1 FETCH_HEAD && + git merge FETCH_HEAD +' + +# 30 +test_expect_success 'add sub9' ' + create sub9 && + git commit -m "sub9" +' + +# Back to mainline +cd .. + +# 31 +test_expect_success 'split for sub8' ' + split2=''"$(git subtree split --annotate='"'*'"' --prefix subdir/ --rejoin)"'' + git branch split2 "$split2" +' + +# 32 +test_expect_success 'add main-sub10' ' + create subdir/main-sub10 && + git commit -m "main-sub10" +' + +# 33 +test_expect_success 'split for sub10' ' + spl3=''"$(git subtree split --annotate='"'*'"' --prefix subdir --rejoin)"'' && + git branch spl3 "$spl3" +' + +# To the subproject! +cd ./subproj + +# 34 +test_expect_success 'merge split into subproj' ' + git fetch .. spl3 && + git branch spl3 FETCH_HEAD && + git merge FETCH_HEAD && + git branch subproj-merge-spl3 +' + +chkm="main4 main6" +chkms="main-sub10 main-sub5 main-sub7 main-sub8" +chkms_sub=$(echo $chkms | multiline | sed 's,^,subdir/,' | fixnl) +chks="sub1 sub2 sub3 sub9" +chks_sub=$(echo $chks | multiline | sed 's,^,subdir/,' | fixnl) + +# 35 +test_expect_success 'make sure exactly the right set of files ends up in the subproj' ' + subfiles=''"$(git ls-files | fixnl)"'' && + check_equal "$subfiles" "$chkms $chks" +' + +# 36 +test_expect_success 'make sure the subproj history *only* contains commits that affect the subdir' ' + allchanges=''"$(git log --name-only --pretty=format:'"''"' | sort | fixnl)"'' && + check_equal "$allchanges" "$chkms $chks" +' + +# Back to mainline +cd .. + +# 37 +test_expect_success 'pull from subproj' ' + git fetch ./subproj subproj-merge-spl3 && + git branch subproj-merge-spl3 FETCH_HEAD && + git subtree pull --prefix=subdir ./subproj subproj-merge-spl3 +' + +# 38 +test_expect_success 'make sure exactly the right set of files ends up in the mainline' ' + mainfiles=''"$(git ls-files | fixnl)"'' && + check_equal "$mainfiles" "$chkm $chkms_sub $chks_sub" +' + +# 39 +test_expect_success 'make sure each filename changed exactly once in the entire history' ' + # main-sub?? and /subdir/main-sub?? both change, because those are the + # changes that were split into their own history. And subdir/sub?? never + # change, since they were *only* changed in the subtree branch. + allchanges=''"$(git log --name-only --pretty=format:'"''"' | sort | fixnl)"'' && + check_equal "$allchanges" ''"$(echo $chkms $chkm $chks $chkms_sub | multiline | sort | fixnl)"'' +' + +# 40 +test_expect_success 'make sure the --rejoin commits never make it into subproj' ' + check_equal ''"$(git log --pretty=format:'"'%s'"' HEAD^2 | grep -i split)"'' "" +' + +# 41 +test_expect_success 'make sure no "git subtree" tagged commits make it into subproj' ' + # They are meaningless to subproj since one side of the merge refers to the mainline + check_equal ''"$(git log --pretty=format:'"'%s%n%b'"' HEAD^2 | grep "git-subtree.*:")"'' "" +' + +# prepare second pair of repositories +mkdir test2 +cd test2 + +# 42 +test_expect_success 'init main' ' + test_create_repo main +' + +cd main + +# 43 +test_expect_success 'add main1' ' + create main1 && + git commit -m "main1" +' + +cd .. + +# 44 +test_expect_success 'init sub' ' + test_create_repo sub +' + +cd sub + +# 45 +test_expect_success 'add sub2' ' + create sub2 && + git commit -m "sub2" +' + +cd ../main + +# check if split can find proper base without --onto + +# 46 +test_expect_success 'add sub as subdir in main' ' + git fetch ../sub master && + git branch sub2 FETCH_HEAD && + git subtree add --prefix subdir sub2 +' + +cd ../sub + +# 47 +test_expect_success 'add sub3' ' + create sub3 && + git commit -m "sub3" +' + +cd ../main + +# 48 +test_expect_success 'merge from sub' ' + git fetch ../sub master && + git branch sub3 FETCH_HEAD && + git subtree merge --prefix subdir sub3 +' + +# 49 +test_expect_success 'add main-sub4' ' + create subdir/main-sub4 && + git commit -m "main-sub4" +' + +# 50 +test_expect_success 'split for main-sub4 without --onto' ' + git subtree split --prefix subdir --branch mainsub4 +' + +# at this point, the new commit parent should be sub3 if it is not, +# something went wrong (the "newparent" of "master~" commit should +# have been sub3, but it was not, because its cache was not set to +# itself) + +# 51 +test_expect_success 'check that the commit parent is sub3' ' + check_equal ''"$(git log --pretty=format:%P -1 mainsub4)"'' ''"$(git rev-parse sub3)"'' +' + +# 52 +test_expect_success 'add main-sub5' ' + mkdir subdir2 && + create subdir2/main-sub5 && + git commit -m "main-sub5" +' + +# 53 +test_expect_success 'split for main-sub5 without --onto' ' + # also test that we still can split out an entirely new subtree + # if the parent of the first commit in the tree is not empty, + # then the new subtree has accidently been attached to something + git subtree split --prefix subdir2 --branch mainsub5 && + check_equal ''"$(git log --pretty=format:%P -1 mainsub5)"'' "" +' + +# make sure no patch changes more than one file. The original set of commits +# changed only one file each. A multi-file change would imply that we pruned +# commits too aggressively. +joincommits() +{ + commit= + all= + while read x y; do + #echo "{$x}" >&2 + if [ -z "$x" ]; then + continue + elif [ "$x" = "commit:" ]; then + if [ -n "$commit" ]; then + echo "$commit $all" + all= + fi + commit="$y" + else + all="$all $y" + fi + done + echo "$commit $all" +} + +# 54 +test_expect_success 'verify one file change per commit' ' + x= && + list=''"$(git log --pretty=format:'"'commit: %H'"' | joincommits)"'' && +# test_debug "echo HERE" && +# test_debug "echo ''"$list"''" && + (git log --pretty=format:'"'commit: %H'"' | joincommits | + ( while read commit a b; do + test_debug "echo Verifying commit "''"$commit"'' + test_debug "echo a: "''"$a"'' + test_debug "echo b: "''"$b"'' + check_equal "$b" "" + x=1 + done + check_equal "$x" 1 + )) +' + +test_done diff --git a/contrib/subtree/todo b/contrib/subtree/todo new file mode 100644 index 0000000000..7e44b0024f --- /dev/null +++ b/contrib/subtree/todo @@ -0,0 +1,50 @@ + + delete tempdir + + 'git subtree rejoin' option to do the same as --rejoin, eg. after a + rebase + + --prefix doesn't force the subtree correctly in merge/pull: + "-s subtree" should be given an explicit subtree option? + There doesn't seem to be a way to do this. We'd have to + patch git-merge-subtree. Ugh. + (but we could avoid this problem by generating squashes with + exactly the right subtree structure, rather than using + subtree merge...) + + add a 'push' subcommand to parallel 'pull' + + add a 'log' subcommand to see what's new in a subtree? + + add to-submodule and from-submodule commands + + automated tests for --squash stuff + + "add" command non-obviously requires a commitid; would be easier if + it had a "pull" sort of mode instead + + "pull" and "merge" commands should fail if you've never merged + that --prefix before + + docs should provide an example of "add" + + note that the initial split doesn't *have* to have a commitid + specified... that's just an optimization + + if you try to add (or maybe merge?) with an invalid commitid, you + get a misleading "prefix must end with /" message from + one of the other git tools that git-subtree calls. Should + detect this situation and print the *real* problem. + + "pull --squash" should do fetch-synthesize-merge, but instead just + does "pull" directly, which doesn't work at all. + + make a 'force-update' that does what 'add' does even if the subtree + already exists. That way we can help people who imported + subtrees "incorrectly" (eg. by just copying in the files) in + the past. + + guess --prefix automatically if possible based on pwd + + make a 'git subtree grafts' that automatically expands --squash'd + commits so you can see the full history if you want it. @@ -989,10 +989,74 @@ static void diff_words_flush(struct emit_callback *ecbdata) diff_words_show(ecbdata->diff_words); } +static void diff_filespec_load_driver(struct diff_filespec *one) +{ + /* Use already-loaded driver */ + if (one->driver) + return; + + if (S_ISREG(one->mode)) + one->driver = userdiff_find_by_path(one->path); + + /* Fallback to default settings */ + if (!one->driver) + one->driver = userdiff_find_by_name("default"); +} + +static const char *userdiff_word_regex(struct diff_filespec *one) +{ + diff_filespec_load_driver(one); + return one->driver->word_regex; +} + +static void init_diff_words_data(struct emit_callback *ecbdata, + struct diff_options *orig_opts, + struct diff_filespec *one, + struct diff_filespec *two) +{ + int i; + struct diff_options *o = xmalloc(sizeof(struct diff_options)); + memcpy(o, orig_opts, sizeof(struct diff_options)); + + ecbdata->diff_words = + xcalloc(1, sizeof(struct diff_words_data)); + ecbdata->diff_words->type = o->word_diff; + ecbdata->diff_words->opt = o; + if (!o->word_regex) + o->word_regex = userdiff_word_regex(one); + if (!o->word_regex) + o->word_regex = userdiff_word_regex(two); + if (!o->word_regex) + o->word_regex = diff_word_regex_cfg; + if (o->word_regex) { + ecbdata->diff_words->word_regex = (regex_t *) + xmalloc(sizeof(regex_t)); + if (regcomp(ecbdata->diff_words->word_regex, + o->word_regex, + REG_EXTENDED | REG_NEWLINE)) + die ("Invalid regular expression: %s", + o->word_regex); + } + for (i = 0; i < ARRAY_SIZE(diff_words_styles); i++) { + if (o->word_diff == diff_words_styles[i].type) { + ecbdata->diff_words->style = + &diff_words_styles[i]; + break; + } + } + if (want_color(o->use_color)) { + struct diff_words_style *st = ecbdata->diff_words->style; + st->old.color = diff_get_color_opt(o, DIFF_FILE_OLD); + st->new.color = diff_get_color_opt(o, DIFF_FILE_NEW); + st->ctx.color = diff_get_color_opt(o, DIFF_PLAIN); + } +} + static void free_diff_words_data(struct emit_callback *ecbdata) { if (ecbdata->diff_words) { diff_words_flush(ecbdata); + free (ecbdata->diff_words->opt); free (ecbdata->diff_words->minus.text.ptr); free (ecbdata->diff_words->minus.orig); free (ecbdata->diff_words->plus.text.ptr); @@ -2061,20 +2125,6 @@ static void emit_binary_diff(FILE *file, mmfile_t *one, mmfile_t *two, char *pre emit_binary_diff_body(file, two, one, prefix); } -static void diff_filespec_load_driver(struct diff_filespec *one) -{ - /* Use already-loaded driver */ - if (one->driver) - return; - - if (S_ISREG(one->mode)) - one->driver = userdiff_find_by_path(one->path); - - /* Fallback to default settings */ - if (!one->driver) - one->driver = userdiff_find_by_name("default"); -} - int diff_filespec_is_binary(struct diff_filespec *one) { if (one->is_binary == -1) { @@ -2100,12 +2150,6 @@ static const struct userdiff_funcname *diff_funcname_pattern(struct diff_filespe return one->driver->funcname.pattern ? &one->driver->funcname : NULL; } -static const char *userdiff_word_regex(struct diff_filespec *one) -{ - diff_filespec_load_driver(one); - return one->driver->word_regex; -} - void diff_set_mnemonic_prefix(struct diff_options *options, const char *a, const char *b) { if (!options->a_prefix) @@ -2292,42 +2336,8 @@ static void builtin_diff(const char *name_a, xecfg.ctxlen = strtoul(diffopts + 10, NULL, 10); else if (!prefixcmp(diffopts, "-u")) xecfg.ctxlen = strtoul(diffopts + 2, NULL, 10); - if (o->word_diff) { - int i; - - ecbdata.diff_words = - xcalloc(1, sizeof(struct diff_words_data)); - ecbdata.diff_words->type = o->word_diff; - ecbdata.diff_words->opt = o; - if (!o->word_regex) - o->word_regex = userdiff_word_regex(one); - if (!o->word_regex) - o->word_regex = userdiff_word_regex(two); - if (!o->word_regex) - o->word_regex = diff_word_regex_cfg; - if (o->word_regex) { - ecbdata.diff_words->word_regex = (regex_t *) - xmalloc(sizeof(regex_t)); - if (regcomp(ecbdata.diff_words->word_regex, - o->word_regex, - REG_EXTENDED | REG_NEWLINE)) - die ("Invalid regular expression: %s", - o->word_regex); - } - for (i = 0; i < ARRAY_SIZE(diff_words_styles); i++) { - if (o->word_diff == diff_words_styles[i].type) { - ecbdata.diff_words->style = - &diff_words_styles[i]; - break; - } - } - if (want_color(o->use_color)) { - struct diff_words_style *st = ecbdata.diff_words->style; - st->old.color = diff_get_color_opt(o, DIFF_FILE_OLD); - st->new.color = diff_get_color_opt(o, DIFF_FILE_NEW); - st->ctx.color = diff_get_color_opt(o, DIFF_PLAIN); - } - } + if (o->word_diff) + init_diff_words_data(&ecbdata, o, one, two); xdi_diff_outf(&mf1, &mf2, fn_out_consume, &ecbdata, &xpp, &xecfg); if (o->word_diff) @@ -3136,6 +3146,7 @@ void diff_setup(struct diff_options *options) options->rename_limit = -1; options->dirstat_permille = diff_dirstat_permille_default; options->context = 3; + DIFF_OPT_SET(options, RENAME_EMPTY); options->change = diff_change; options->add_remove = diff_addremove; @@ -3506,6 +3517,10 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac) } else if (!strcmp(arg, "--no-renames")) options->detect_rename = 0; + else if (!strcmp(arg, "--rename-empty")) + DIFF_OPT_SET(options, RENAME_EMPTY); + else if (!strcmp(arg, "--no-rename-empty")) + DIFF_OPT_CLR(options, RENAME_EMPTY); else if (!strcmp(arg, "--relative")) DIFF_OPT_SET(options, RELATIVE_NAME); else if (!prefixcmp(arg, "--relative=")) { @@ -3525,9 +3540,9 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac) else if (!strcmp(arg, "--ignore-space-at-eol")) DIFF_XDL_SET(options, IGNORE_WHITESPACE_AT_EOL); else if (!strcmp(arg, "--patience")) - DIFF_XDL_SET(options, PATIENCE_DIFF); + options->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF); else if (!strcmp(arg, "--histogram")) - DIFF_XDL_SET(options, HISTOGRAM_DIFF); + options->xdl_opts = DIFF_WITH_ALG(options, HISTOGRAM_DIFF); /* flags options */ else if (!strcmp(arg, "--binary")) { @@ -4399,6 +4414,12 @@ void diff_flush(struct diff_options *options) if (output_format & DIFF_FORMAT_PATCH) { if (separator) { + if (options->output_prefix) { + struct strbuf *msg = NULL; + msg = options->output_prefix(options, + options->output_prefix_data); + fwrite(msg->buf, msg->len, 1, stdout); + } putc(options->line_termination, options->file); if (options->stat_sep) { /* attach patch instead of inline */ @@ -60,7 +60,7 @@ typedef struct strbuf *(*diff_prefix_fn_t)(struct diff_options *opt, void *data) #define DIFF_OPT_SILENT_ON_REMOVE (1 << 5) #define DIFF_OPT_FIND_COPIES_HARDER (1 << 6) #define DIFF_OPT_FOLLOW_RENAMES (1 << 7) -/* (1 << 8) unused */ +#define DIFF_OPT_RENAME_EMPTY (1 << 8) /* (1 << 9) unused */ #define DIFF_OPT_HAS_CHANGES (1 << 10) #define DIFF_OPT_QUICK (1 << 11) @@ -91,6 +91,8 @@ typedef struct strbuf *(*diff_prefix_fn_t)(struct diff_options *opt, void *data) #define DIFF_XDL_SET(opts, flag) ((opts)->xdl_opts |= XDF_##flag) #define DIFF_XDL_CLR(opts, flag) ((opts)->xdl_opts &= ~XDF_##flag) +#define DIFF_WITH_ALG(opts, flag) (((opts)->xdl_opts & ~XDF_DIFF_ALGORITHM_MASK) | XDF_##flag) + enum diff_words_type { DIFF_WORDS_NONE = 0, DIFF_WORDS_PORCELAIN, diff --git a/diffcore-rename.c b/diffcore-rename.c index f639601c76..216a7a4bbc 100644 --- a/diffcore-rename.c +++ b/diffcore-rename.c @@ -512,9 +512,15 @@ void diffcore_rename(struct diff_options *options) else if (options->single_follow && strcmp(options->single_follow, p->two->path)) continue; /* not interested */ + else if (!DIFF_OPT_TST(options, RENAME_EMPTY) && + is_empty_blob_sha1(p->two->sha1)) + continue; else locate_rename_dst(p->two, 1); } + else if (!DIFF_OPT_TST(options, RENAME_EMPTY) && + is_empty_blob_sha1(p->one->sha1)) + continue; else if (!DIFF_PAIR_UNMERGED(p) && !DIFF_FILE_VALID(p->two)) { /* * If the source is a broken "delete", and @@ -1172,22 +1172,32 @@ int is_empty_dir(const char *path) return ret; } -int remove_dir_recursively(struct strbuf *path, int flag) +static int remove_dir_recurse(struct strbuf *path, int flag, int *kept_up) { DIR *dir; struct dirent *e; - int ret = 0, original_len = path->len, len; + int ret = 0, original_len = path->len, len, kept_down = 0; int only_empty = (flag & REMOVE_DIR_EMPTY_ONLY); + int keep_toplevel = (flag & REMOVE_DIR_KEEP_TOPLEVEL); unsigned char submodule_head[20]; if ((flag & REMOVE_DIR_KEEP_NESTED_GIT) && - !resolve_gitlink_ref(path->buf, "HEAD", submodule_head)) + !resolve_gitlink_ref(path->buf, "HEAD", submodule_head)) { /* Do not descend and nuke a nested git work tree. */ + if (kept_up) + *kept_up = 1; return 0; + } + flag &= ~REMOVE_DIR_KEEP_TOPLEVEL; dir = opendir(path->buf); - if (!dir) - return rmdir(path->buf); + if (!dir) { + /* an empty dir could be removed even if it is unreadble */ + if (!keep_toplevel) + return rmdir(path->buf); + else + return -1; + } if (path->buf[original_len - 1] != '/') strbuf_addch(path, '/'); @@ -1202,7 +1212,7 @@ int remove_dir_recursively(struct strbuf *path, int flag) if (lstat(path->buf, &st)) ; /* fall thru */ else if (S_ISDIR(st.st_mode)) { - if (!remove_dir_recursively(path, only_empty)) + if (!remove_dir_recurse(path, flag, &kept_down)) continue; /* happy */ } else if (!only_empty && !unlink(path->buf)) continue; /* happy, too */ @@ -1214,11 +1224,22 @@ int remove_dir_recursively(struct strbuf *path, int flag) closedir(dir); strbuf_setlen(path, original_len); - if (!ret) + if (!ret && !keep_toplevel && !kept_down) ret = rmdir(path->buf); + else if (kept_up) + /* + * report the uplevel that it is not an error that we + * did not rmdir() our directory. + */ + *kept_up = !ret; return ret; } +int remove_dir_recursively(struct strbuf *path, int flag) +{ + return remove_dir_recurse(path, flag, NULL); +} + void setup_standard_excludes(struct dir_struct *dir) { const char *path; @@ -102,6 +102,7 @@ extern void setup_standard_excludes(struct dir_struct *dir); #define REMOVE_DIR_EMPTY_ONLY 01 #define REMOVE_DIR_KEEP_NESTED_GIT 02 +#define REMOVE_DIR_KEEP_TOPLEVEL 04 extern int remove_dir_recursively(struct strbuf *path, int flag); /* tries to remove the path with empty directories along it, ignores ENOENT */ @@ -120,58 +120,15 @@ static int streaming_write_entry(struct cache_entry *ce, char *path, const struct checkout *state, int to_tempfile, int *fstat_done, struct stat *statbuf) { - struct git_istream *st; - enum object_type type; - unsigned long sz; int result = -1; - ssize_t kept = 0; - int fd = -1; - - st = open_istream(ce->sha1, &type, &sz, filter); - if (!st) - return -1; - if (type != OBJ_BLOB) - goto close_and_exit; + int fd; fd = open_output_fd(path, ce, to_tempfile); - if (fd < 0) - goto close_and_exit; - - for (;;) { - char buf[1024 * 16]; - ssize_t wrote, holeto; - ssize_t readlen = read_istream(st, buf, sizeof(buf)); - - if (!readlen) - break; - if (sizeof(buf) == readlen) { - for (holeto = 0; holeto < readlen; holeto++) - if (buf[holeto]) - break; - if (readlen == holeto) { - kept += holeto; - continue; - } - } - - if (kept && lseek(fd, kept, SEEK_CUR) == (off_t) -1) - goto close_and_exit; - else - kept = 0; - wrote = write_in_full(fd, buf, readlen); - - if (wrote != readlen) - goto close_and_exit; - } - if (kept && (lseek(fd, kept - 1, SEEK_CUR) == (off_t) -1 || - write(fd, "", 1) != 1)) - goto close_and_exit; - *fstat_done = fstat_output(fd, state, statbuf); - -close_and_exit: - close_istream(st); - if (0 <= fd) + if (0 <= fd) { + result = stream_blob_to_fd(fd, ce->sha1, filter, 1); + *fstat_done = fstat_output(fd, state, statbuf); result = close(fd); + } if (result && 0 <= fd) unlink(path); return result; diff --git a/environment.c b/environment.c index c93b8f44df..d7e6c65763 100644 --- a/environment.c +++ b/environment.c @@ -52,7 +52,7 @@ enum safe_crlf safe_crlf = SAFE_CRLF_WARN; unsigned whitespace_rule_cfg = WS_DEFAULT_RULE; enum branch_track git_branch_track = BRANCH_TRACK_REMOTE; enum rebase_setup_type autorebase = AUTOREBASE_NEVER; -enum push_default_type push_default = PUSH_DEFAULT_MATCHING; +enum push_default_type push_default = PUSH_DEFAULT_UNSPECIFIED; #ifndef OBJECT_CREATION_MODE #define OBJECT_CREATION_MODE OBJECT_CREATION_USES_HARDLINKS #endif diff --git a/exec_cmd.c b/exec_cmd.c index 171e841531..125fa6fabf 100644 --- a/exec_cmd.c +++ b/exec_cmd.c @@ -134,7 +134,7 @@ int execv_git_cmd(const char **argv) { trace_argv_printf(nargv, "trace: exec:"); /* execvp() can only ever return if it fails */ - execvp("git", (char **)nargv); + sane_execvp("git", (char **)nargv); trace_printf("trace: exec failed: %s\n", strerror(errno)); diff --git a/git-add--interactive.perl b/git-add--interactive.perl index 8f0839d205..d948aa88db 100755 --- a/git-add--interactive.perl +++ b/git-add--interactive.perl @@ -268,6 +268,7 @@ sub get_empty_tree { # FILE: is file different from index? # INDEX_ADDDEL: is it add/delete between HEAD and index? # FILE_ADDDEL: is it add/delete between index and file? +# UNMERGED: is the path unmerged sub list_modified { my ($only) = @_; @@ -318,16 +319,10 @@ sub list_modified { } } - for (run_cmd_pipe(qw(git diff-files --numstat --summary --), @tracked)) { + for (run_cmd_pipe(qw(git diff-files --numstat --summary --raw --), @tracked)) { if (($add, $del, $file) = /^([-\d]+) ([-\d]+) (.*)/) { $file = unquote_path($file); - if (!exists $data{$file}) { - $data{$file} = +{ - INDEX => 'unchanged', - BINARY => 0, - }; - } my ($change, $bin); if ($add eq '-' && $del eq '-') { $change = 'binary'; @@ -346,6 +341,18 @@ sub list_modified { $file = unquote_path($file); $data{$file}{FILE_ADDDEL} = $adddel; } + elsif (/^:[0-7]+ [0-7]+ [0-9a-f]+ [0-9a-f]+ (.) (.*)$/) { + $file = unquote_path($2); + if (!exists $data{$file}) { + $data{$file} = +{ + INDEX => 'unchanged', + BINARY => 0, + }; + } + if ($1 eq 'U') { + $data{$file}{UNMERGED} = 1; + } + } } for (sort keys %data) { @@ -1190,6 +1197,10 @@ sub apply_patch_for_checkout_commit { sub patch_update_cmd { my @all_mods = list_modified($patch_mode_flavour{FILTER}); + error_msg "ignoring unmerged: $_->{VALUE}\n" + for grep { $_->{UNMERGED} } @all_mods; + @all_mods = grep { !$_->{UNMERGED} } @all_mods; + my @mods = grep { !($_->{BINARY}) } @all_mods; my @them; @@ -24,6 +24,7 @@ ignore-space-change pass it through git-apply ignore-whitespace pass it through git-apply directory= pass it through git-apply exclude= pass it through git-apply +include= pass it through git-apply C= pass it through git-apply p= pass it through git-apply patch-format= format the patch(es) are in @@ -138,6 +139,12 @@ fall_back_3way () { say Using index info to reconstruct a base tree... cmd='GIT_INDEX_FILE="$dotest/patch-merge-tmp-index"' + + if test -z "$GIT_QUIET" + then + eval "$cmd git diff-index --cached --diff-filter=AM --name-status HEAD" + fi + cmd="$cmd git apply --cached $git_apply_opt"' <"$dotest/patch"' if eval "$cmd" then @@ -412,7 +419,7 @@ do ;; --resolvemsg) shift; resolvemsg=$1 ;; - --whitespace|--directory|--exclude) + --whitespace|--directory|--exclude|--include) git_apply_opt="$git_apply_opt $(sq "$1=$2")"; shift ;; -C|-p) git_apply_opt="$git_apply_opt $(sq "$1$2")"; shift ;; diff --git a/contrib/fast-import/git-p4 b/git-p4.py index c5362c4c11..f910d5af1c 100755 --- a/contrib/fast-import/git-p4 +++ b/git-p4.py @@ -1129,12 +1129,12 @@ class P4Submit(Command, P4UserMap): print "The following files should be scheduled for deletion with p4 delete:" print " ".join(filesToDelete) die("Please resolve and submit the conflict manually and " - + "continue afterwards with git-p4 submit --continue") + + "continue afterwards with git p4 submit --continue") elif response == "w": system(diffcmd + " > patch.txt") print "Patch saved to patch.txt in %s !" % self.clientPath die("Please resolve and submit the conflict manually and " - "continue afterwards with git-p4 submit --continue") + "continue afterwards with git p4 submit --continue") system(applyPatchCmd) @@ -1178,8 +1178,8 @@ class P4Submit(Command, P4UserMap): if self.checkAuthorship and not self.p4UserIsMe(p4User): submitTemplate += "######## git author %s does not match your p4 account.\n" % gitEmail - submitTemplate += "######## Use git-p4 option --preserve-user to modify authorship\n" - submitTemplate += "######## Use git-p4 config git-p4.skipUserNameCheck hides this message.\n" + submitTemplate += "######## Use option --preserve-user to modify authorship.\n" + submitTemplate += "######## Variable git-p4.skipUserNameCheck hides this message.\n" separatorLine = "######## everything below this line is just the diff #######\n" @@ -2254,7 +2254,7 @@ class P4Sync(Command, P4UserMap): details["change"] = newestRevision - # Use time from top-most change so that all git-p4 clones of + # Use time from top-most change so that all git p4 clones of # the same p4 repo have the same commit SHA1s. res = p4CmdList("describe -s %d" % newestRevision) newestTime = None @@ -2474,8 +2474,8 @@ class P4Sync(Command, P4UserMap): changes.sort() else: - # catch "git-p4 sync" with no new branches, in a repo that - # does not have any existing git-p4 branches + # catch "git p4 sync" with no new branches, in a repo that + # does not have any existing p4 branches if len(args) == 0 and not self.p4BranchesInGit: die("No remote p4 branches. Perhaps you never did \"git p4 clone\" in here."); if self.verbose: diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index 5812222eb9..2e1325824c 100644 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -672,7 +672,7 @@ rearrange_squash () { case "$action" in continue) # do we have anything to commit? - if git diff-index --cached --quiet --ignore-submodules HEAD -- + if git diff-index --cached --quiet HEAD -- then : Nothing to commit -- skip this else @@ -846,6 +846,8 @@ cat >> "$todo" << EOF # f, fixup = like "squash", but discard this commit's log message # x, exec = run command (the rest of the line) using shell # +# These lines can be re-ordered; they are executed from top to bottom. +# # If you remove a line here THAT COMMIT WILL BE LOST. # However, if you remove everything, the rebase will be aborted. # diff --git a/git-submodule.sh b/git-submodule.sh index efc86ad4e0..3d94a14079 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -167,10 +167,11 @@ module_clone() a=${a%/} b=${b%/} - rel=$(echo $b | sed -e 's|[^/]*|..|g') + # Turn each leading "*/" component into "../" + rel=$(echo $b | sed -e 's|[^/][^/]*|..|g') echo "gitdir: $rel/$a" >"$path/.git" - rel=$(echo $a | sed -e 's|[^/]*|..|g') + rel=$(echo $a | sed -e 's|[^/][^/]*|..|g') (clear_local_git_env; cd "$path" && GIT_WORK_TREE=. git config core.worktree "$rel/$b") } diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index a8b5fad266..4171de86e3 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -3886,6 +3886,7 @@ sub print_feed_meta { '-type' => "application/$type+xml" ); + $href_params{'extra_options'} = undef; $href_params{'action'} = $type; $link_attr{'-href'} = href(%href_params); print "<link ". @@ -7003,6 +7004,28 @@ sub snapshot_name { return wantarray ? ($name, $name) : $name; } +sub exit_if_unmodified_since { + my ($latest_epoch) = @_; + our $cgi; + + my $if_modified = $cgi->http('IF_MODIFIED_SINCE'); + if (defined $if_modified) { + my $since; + if (eval { require HTTP::Date; 1; }) { + $since = HTTP::Date::str2time($if_modified); + } elsif (eval { require Time::ParseDate; 1; }) { + $since = Time::ParseDate::parsedate($if_modified, GMT => 1); + } + if (defined $since && $latest_epoch <= $since) { + my %latest_date = parse_date($latest_epoch); + print $cgi->header( + -last_modified => $latest_date{'rfc2822'}, + -status => '304 Not Modified'); + goto DONE_GITWEB; + } + } +} + sub git_snapshot { my $format = $input_params{'snapshot_format'}; if (!@snapshot_fmts) { @@ -7029,6 +7052,10 @@ sub git_snapshot { my ($name, $prefix) = snapshot_name($project, $hash); my $filename = "$name$known_snapshot_formats{$format}{'suffix'}"; + + my %co = parse_commit($hash); + exit_if_unmodified_since($co{'committer_epoch'}) if %co; + my $cmd = quote_command( git_cmd(), 'archive', "--format=$known_snapshot_formats{$format}{'format'}", @@ -7038,9 +7065,15 @@ sub git_snapshot { } $filename =~ s/(["\\])/\\$1/g; + my %latest_date; + if (%co) { + %latest_date = parse_date($co{'committer_epoch'}, $co{'committer_tz'}); + } + print $cgi->header( -type => $known_snapshot_formats{$format}{'type'}, -content_disposition => 'inline; filename="' . $filename . '"', + %co ? (-last_modified => $latest_date{'rfc2822'}) : (), -status => '200 OK'); open my $fd, "-|", $cmd @@ -7820,33 +7853,14 @@ sub git_feed { if (defined($commitlist[0])) { %latest_commit = %{$commitlist[0]}; my $latest_epoch = $latest_commit{'committer_epoch'}; - %latest_date = parse_date($latest_epoch, $latest_commit{'comitter_tz'}); - my $if_modified = $cgi->http('IF_MODIFIED_SINCE'); - if (defined $if_modified) { - my $since; - if (eval { require HTTP::Date; 1; }) { - $since = HTTP::Date::str2time($if_modified); - } elsif (eval { require Time::ParseDate; 1; }) { - $since = Time::ParseDate::parsedate($if_modified, GMT => 1); - } - if (defined $since && $latest_epoch <= $since) { - print $cgi->header( - -type => $content_type, - -charset => 'utf-8', - -last_modified => $latest_date{'rfc2822'}, - -status => '304 Not Modified'); - return; - } - } - print $cgi->header( - -type => $content_type, - -charset => 'utf-8', - -last_modified => $latest_date{'rfc2822'}); - } else { - print $cgi->header( - -type => $content_type, - -charset => 'utf-8'); + exit_if_unmodified_since($latest_epoch); + %latest_date = parse_date($latest_epoch, $latest_commit{'comitter_tz'}); } + print $cgi->header( + -type => $content_type, + -charset => 'utf-8', + %latest_date ? (-last_modified => $latest_date{'rfc2822'}) : (), + -status => '200 OK'); # Optimization: skip generating the body if client asks only # for Last-Modified date. diff --git a/http-backend.c b/http-backend.c index 869d515383..f50e77fb28 100644 --- a/http-backend.c +++ b/http-backend.c @@ -7,6 +7,7 @@ #include "run-command.h" #include "string-list.h" #include "url.h" +#include "argv-array.h" static const char content_type[] = "Content-Type"; static const char content_length[] = "Content-Length"; @@ -317,8 +318,7 @@ static void run_service(const char **argv) const char *encoding = getenv("HTTP_CONTENT_ENCODING"); const char *user = getenv("REMOTE_USER"); const char *host = getenv("REMOTE_ADDR"); - char *env[3]; - struct strbuf buf = STRBUF_INIT; + struct argv_array env = ARGV_ARRAY_INIT; int gzipped_request = 0; struct child_process cld; @@ -332,17 +332,15 @@ static void run_service(const char **argv) if (!host || !*host) host = "(none)"; - memset(&env, 0, sizeof(env)); - strbuf_addf(&buf, "GIT_COMMITTER_NAME=%s", user); - env[0] = strbuf_detach(&buf, NULL); - - strbuf_addf(&buf, "GIT_COMMITTER_EMAIL=%s@http.%s", user, host); - env[1] = strbuf_detach(&buf, NULL); - env[2] = NULL; + if (!getenv("GIT_COMMITTER_NAME")) + argv_array_pushf(&env, "GIT_COMMITTER_NAME=%s", user); + if (!getenv("GIT_COMMITTER_EMAIL")) + argv_array_pushf(&env, "GIT_COMMITTER_EMAIL=%s@http.%s", + user, host); memset(&cld, 0, sizeof(cld)); cld.argv = argv; - cld.env = (const char *const *)env; + cld.env = env.argv; if (gzipped_request) cld.in = -1; cld.git_cmd = 1; @@ -357,9 +355,7 @@ static void run_service(const char **argv) if (finish_command(&cld)) exit(1); - free(env[0]); - free(env[1]); - strbuf_release(&buf); + argv_array_clear(&env); } static int show_text_ref(const char *name, const unsigned char *sha1, @@ -220,6 +220,74 @@ static int copy(char *buf, size_t size, int offset, const char *src) return offset; } +/* + * Reverse of fmt_ident(); given an ident line, split the fields + * to allow the caller to parse it. + * Signal a success by returning 0, but date/tz fields of the result + * can still be NULL if the input line only has the name/email part + * (e.g. reading from a reflog entry). + */ +int split_ident_line(struct ident_split *split, const char *line, int len) +{ + const char *cp; + size_t span; + int status = -1; + + memset(split, 0, sizeof(*split)); + + split->name_begin = line; + for (cp = line; *cp && cp < line + len; cp++) + if (*cp == '<') { + split->mail_begin = cp + 1; + break; + } + if (!split->mail_begin) + return status; + + for (cp = split->mail_begin - 2; line < cp; cp--) + if (!isspace(*cp)) { + split->name_end = cp + 1; + break; + } + if (!split->name_end) + return status; + + for (cp = split->mail_begin; cp < line + len; cp++) + if (*cp == '>') { + split->mail_end = cp; + break; + } + if (!split->mail_end) + return status; + + for (cp = split->mail_end + 1; cp < line + len && isspace(*cp); cp++) + ; + if (line + len <= cp) + goto person_only; + split->date_begin = cp; + span = strspn(cp, "0123456789"); + if (!span) + goto person_only; + split->date_end = split->date_begin + span; + for (cp = split->date_end; cp < line + len && isspace(*cp); cp++) + ; + if (line + len <= cp || (*cp != '+' && *cp != '-')) + goto person_only; + split->tz_begin = cp; + span = strspn(cp + 1, "0123456789"); + if (!span) + goto person_only; + split->tz_end = split->tz_begin + 1 + span; + return 0; + +person_only: + split->date_begin = NULL; + split->date_end = NULL; + split->tz_begin = NULL; + split->tz_end = NULL; + return 0; +} + static const char *env_hint = "\n" "*** Please tell me who you are.\n" diff --git a/log-tree.c b/log-tree.c index cea8756866..34c49e7b33 100644 --- a/log-tree.c +++ b/log-tree.c @@ -711,14 +711,15 @@ int log_tree_diff_flush(struct rev_info *opt) opt->verbose_header && opt->commit_format != CMIT_FMT_ONELINE) { int pch = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_PATCH; - if ((pch & opt->diffopt.output_format) == pch) - printf("---"); if (opt->diffopt.output_prefix) { struct strbuf *msg = NULL; msg = opt->diffopt.output_prefix(&opt->diffopt, opt->diffopt.output_prefix_data); fwrite(msg->buf, msg->len, 1, stdout); } + if ((pch & opt->diffopt.output_format) == pch) { + printf("---"); + } putchar('\n'); } } diff --git a/merge-recursive.c b/merge-recursive.c index 6479a60cd1..680937c39e 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -485,6 +485,7 @@ static struct string_list *get_renames(struct merge_options *o, renames = xcalloc(1, sizeof(struct string_list)); diff_setup(&opts); DIFF_OPT_SET(&opts, RECURSIVE); + DIFF_OPT_CLR(&opts, RENAME_EMPTY); opts.detect_rename = DIFF_DETECT_RENAME; opts.rename_limit = o->merge_rename_limit >= 0 ? o->merge_rename_limit : o->diff_rename_limit >= 0 ? o->diff_rename_limit : @@ -1914,7 +1915,7 @@ int merge_recursive(struct merge_options *o, /* if there is no common ancestor, use an empty tree */ struct tree *tree; - tree = lookup_tree((const unsigned char *)EMPTY_TREE_SHA1_BIN); + tree = lookup_tree(EMPTY_TREE_SHA1_BIN); merged_common_ancestors = make_virtual_commit(tree, "ancestor"); } @@ -2068,9 +2069,9 @@ int parse_merge_opt(struct merge_options *o, const char *s) else if (!prefixcmp(s, "subtree=")) o->subtree_shift = s + strlen("subtree="); else if (!strcmp(s, "patience")) - o->xdl_opts |= XDF_PATIENCE_DIFF; + o->xdl_opts = DIFF_WITH_ALG(o, PATIENCE_DIFF); else if (!strcmp(s, "histogram")) - o->xdl_opts |= XDF_HISTOGRAM_DIFF; + o->xdl_opts = DIFF_WITH_ALG(o, HISTOGRAM_DIFF); else if (!strcmp(s, "ignore-space-change")) o->xdl_opts |= XDF_IGNORE_WHITESPACE_CHANGE; else if (!strcmp(s, "ignore-all-space")) diff --git a/mergesort.c b/mergesort.c new file mode 100644 index 0000000000..e5fdf2ee4a --- /dev/null +++ b/mergesort.c @@ -0,0 +1,73 @@ +#include "cache.h" +#include "mergesort.h" + +struct mergesort_sublist { + void *ptr; + unsigned long len; +}; + +static void *get_nth_next(void *list, unsigned long n, + void *(*get_next_fn)(const void *)) +{ + while (n-- && list) + list = get_next_fn(list); + return list; +} + +static void *pop_item(struct mergesort_sublist *l, + void *(*get_next_fn)(const void *)) +{ + void *p = l->ptr; + l->ptr = get_next_fn(l->ptr); + l->len = l->ptr ? (l->len - 1) : 0; + return p; +} + +void *llist_mergesort(void *list, + void *(*get_next_fn)(const void *), + void (*set_next_fn)(void *, void *), + int (*compare_fn)(const void *, const void *)) +{ + unsigned long l; + + if (!list) + return NULL; + for (l = 1; ; l *= 2) { + void *curr; + struct mergesort_sublist p, q; + + p.ptr = list; + q.ptr = get_nth_next(p.ptr, l, get_next_fn); + if (!q.ptr) + break; + p.len = q.len = l; + + if (compare_fn(p.ptr, q.ptr) > 0) + list = curr = pop_item(&q, get_next_fn); + else + list = curr = pop_item(&p, get_next_fn); + + while (p.ptr) { + while (p.len || q.len) { + void *prev = curr; + + if (!p.len) + curr = pop_item(&q, get_next_fn); + else if (!q.len) + curr = pop_item(&p, get_next_fn); + else if (compare_fn(p.ptr, q.ptr) > 0) + curr = pop_item(&q, get_next_fn); + else + curr = pop_item(&p, get_next_fn); + set_next_fn(prev, curr); + } + p.ptr = q.ptr; + p.len = l; + q.ptr = get_nth_next(p.ptr, l, get_next_fn); + q.len = q.ptr ? l : 0; + + } + set_next_fn(curr, NULL); + } + return list; +} diff --git a/mergesort.h b/mergesort.h new file mode 100644 index 0000000000..644cff1f96 --- /dev/null +++ b/mergesort.h @@ -0,0 +1,17 @@ +#ifndef MERGESORT_H +#define MERGESORT_H + +/* + * Sort linked list in place. + * - get_next_fn() returns the next element given an element of a linked list. + * - set_next_fn() takes two elements A and B, and makes B the "next" element + * of A on the list. + * - compare_fn() takes two elements A and B, and returns negative, 0, positive + * as the same sign as "subtracting" B from A. + */ +void *llist_mergesort(void *list, + void *(*get_next_fn)(const void *), + void (*set_next_fn)(void *, void *), + int (*compare_fn)(const void *, const void *)); + +#endif diff --git a/notes-merge.c b/notes-merge.c index fb0832f97d..74aa77ce4b 100644 --- a/notes-merge.c +++ b/notes-merge.c @@ -267,7 +267,8 @@ static void check_notes_merge_worktree(struct notes_merge_options *o) * Must establish NOTES_MERGE_WORKTREE. * Abort if NOTES_MERGE_WORKTREE already exists */ - if (file_exists(git_path(NOTES_MERGE_WORKTREE))) { + if (file_exists(git_path(NOTES_MERGE_WORKTREE)) && + !is_empty_dir(git_path(NOTES_MERGE_WORKTREE))) { if (advice_resolve_conflict) die("You have not concluded your previous " "notes merge (%s exists).\nPlease, use " @@ -687,51 +688,60 @@ int notes_merge_commit(struct notes_merge_options *o, { /* * Iterate through files in .git/NOTES_MERGE_WORKTREE and add all - * found notes to 'partial_tree'. Write the updates notes tree to + * found notes to 'partial_tree'. Write the updated notes tree to * the DB, and commit the resulting tree object while reusing the * commit message and parents from 'partial_commit'. * Finally store the new commit object SHA1 into 'result_sha1'. */ - struct dir_struct dir; - char *path = xstrdup(git_path(NOTES_MERGE_WORKTREE "/")); - int path_len = strlen(path), i; + DIR *dir; + struct dirent *e; + struct strbuf path = STRBUF_INIT; char *msg = strstr(partial_commit->buffer, "\n\n"); struct strbuf sb_msg = STRBUF_INIT; + int baselen; + strbuf_addstr(&path, git_path(NOTES_MERGE_WORKTREE)); if (o->verbosity >= 3) - printf("Committing notes in notes merge worktree at %.*s\n", - path_len - 1, path); + printf("Committing notes in notes merge worktree at %s\n", + path.buf); if (!msg || msg[2] == '\0') die("partial notes commit has empty message"); msg += 2; - memset(&dir, 0, sizeof(dir)); - read_directory(&dir, path, path_len, NULL); - for (i = 0; i < dir.nr; i++) { - struct dir_entry *ent = dir.entries[i]; + dir = opendir(path.buf); + if (!dir) + die_errno("could not open %s", path.buf); + + strbuf_addch(&path, '/'); + baselen = path.len; + while ((e = readdir(dir)) != NULL) { struct stat st; - const char *relpath = ent->name + path_len; unsigned char obj_sha1[20], blob_sha1[20]; - if (ent->len - path_len != 40 || get_sha1_hex(relpath, obj_sha1)) { + if (is_dot_or_dotdot(e->d_name)) + continue; + + if (strlen(e->d_name) != 40 || get_sha1_hex(e->d_name, obj_sha1)) { if (o->verbosity >= 3) - printf("Skipping non-SHA1 entry '%s'\n", - ent->name); + printf("Skipping non-SHA1 entry '%s%s'\n", + path.buf, e->d_name); continue; } + strbuf_addstr(&path, e->d_name); /* write file as blob, and add to partial_tree */ - if (stat(ent->name, &st)) - die_errno("Failed to stat '%s'", ent->name); - if (index_path(blob_sha1, ent->name, &st, HASH_WRITE_OBJECT)) - die("Failed to write blob object from '%s'", ent->name); + if (stat(path.buf, &st)) + die_errno("Failed to stat '%s'", path.buf); + if (index_path(blob_sha1, path.buf, &st, HASH_WRITE_OBJECT)) + die("Failed to write blob object from '%s'", path.buf); if (add_note(partial_tree, obj_sha1, blob_sha1, NULL)) die("Failed to add resolved note '%s' to notes tree", - ent->name); + path.buf); if (o->verbosity >= 4) printf("Added resolved note for object %s: %s\n", sha1_to_hex(obj_sha1), sha1_to_hex(blob_sha1)); + strbuf_setlen(&path, baselen); } strbuf_attach(&sb_msg, msg, strlen(msg), strlen(msg) + 1); @@ -740,20 +750,25 @@ int notes_merge_commit(struct notes_merge_options *o, if (o->verbosity >= 4) printf("Finalized notes merge commit: %s\n", sha1_to_hex(result_sha1)); - free(path); + strbuf_release(&path); + closedir(dir); return 0; } int notes_merge_abort(struct notes_merge_options *o) { - /* Remove .git/NOTES_MERGE_WORKTREE directory and all files within */ + /* + * Remove all files within .git/NOTES_MERGE_WORKTREE. We do not remove + * the .git/NOTES_MERGE_WORKTREE directory itself, since it might be + * the current working directory of the user. + */ struct strbuf buf = STRBUF_INIT; int ret; strbuf_addstr(&buf, git_path(NOTES_MERGE_WORKTREE)); if (o->verbosity >= 3) - printf("Removing notes merge worktree at %s\n", buf.buf); - ret = remove_dir_recursively(&buf, 0); + printf("Removing notes merge worktree at %s/*\n", buf.buf); + ret = remove_dir_recursively(&buf, REMOVE_DIR_KEEP_TOPLEVEL); strbuf_release(&buf); return ret; } @@ -198,6 +198,17 @@ struct object *parse_object(const unsigned char *sha1) if (obj && obj->parsed) return obj; + if ((obj && obj->type == OBJ_BLOB) || + (!obj && has_sha1_file(sha1) && + sha1_object_info(sha1, NULL) == OBJ_BLOB)) { + if (check_sha1_signature(repl, NULL, 0, NULL) < 0) { + error("sha1 mismatch %s\n", sha1_to_hex(repl)); + return NULL; + } + parse_blob_buffer(lookup_blob(sha1), NULL, 0); + return lookup_object(sha1); + } + buffer = read_sha1_file(sha1, &type, &size); if (buffer) { if (check_sha1_signature(repl, buffer, size, typename(type)) < 0) { @@ -531,41 +531,24 @@ static size_t format_person_part(struct strbuf *sb, char part, { /* currently all placeholders have same length */ const int placeholder_len = 2; - int start, end, tz = 0; + int tz; unsigned long date = 0; - char *ep; - const char *name_start, *name_end, *mail_start, *mail_end, *msg_end = msg+len; char person_name[1024]; char person_mail[1024]; + struct ident_split s; + const char *name_start, *name_end, *mail_start, *mail_end; - /* advance 'end' to point to email start delimiter */ - for (end = 0; end < len && msg[end] != '<'; end++) - ; /* do nothing */ - - /* - * When end points at the '<' that we found, it should have - * matching '>' later, which means 'end' must be strictly - * below len - 1. - */ - if (end >= len - 2) + if (split_ident_line(&s, msg, len) < 0) goto skip; - /* Seek for both name and email part */ - name_start = msg; - name_end = msg+end; - while (name_end > name_start && isspace(*(name_end-1))) - name_end--; - mail_start = msg+end+1; - mail_end = mail_start; - while (mail_end < msg_end && *mail_end != '>') - mail_end++; - if (mail_end == msg_end) - goto skip; - end = mail_end-msg; + name_start = s.name_begin; + name_end = s.name_end; + mail_start = s.mail_begin; + mail_end = s.mail_end; if (part == 'N' || part == 'E') { /* mailmap lookup */ - strlcpy(person_name, name_start, name_end-name_start+1); - strlcpy(person_mail, mail_start, mail_end-mail_start+1); + strlcpy(person_name, name_start, name_end - name_start + 1); + strlcpy(person_mail, mail_start, mail_end - mail_start + 1); mailmap_name(person_mail, sizeof(person_mail), person_name, sizeof(person_name)); name_start = person_name; name_end = name_start + strlen(person_name); @@ -581,28 +564,20 @@ static size_t format_person_part(struct strbuf *sb, char part, return placeholder_len; } - /* advance 'start' to point to date start delimiter */ - for (start = end + 1; start < len && isspace(msg[start]); start++) - ; /* do nothing */ - if (start >= len) - goto skip; - date = strtoul(msg + start, &ep, 10); - if (msg + start == ep) + if (!s.date_begin) goto skip; + date = strtoul(s.date_begin, NULL, 10); + if (part == 't') { /* date, UNIX timestamp */ - strbuf_add(sb, msg + start, ep - (msg + start)); + strbuf_add(sb, s.date_begin, s.date_end - s.date_begin); return placeholder_len; } /* parse tz */ - for (start = ep - msg + 1; start < len && isspace(msg[start]); start++) - ; /* do nothing */ - if (start + 1 < len) { - tz = strtoul(msg + start + 1, NULL, 10); - if (msg[start] == '-') - tz = -tz; - } + tz = strtoul(s.tz_begin + 1, NULL, 10); + if (*s.tz_begin == '-') + tz = -tz; switch (part) { case 'd': /* date */ @@ -621,8 +596,9 @@ static size_t format_person_part(struct strbuf *sb, char part, skip: /* - * bogus commit, 'sb' cannot be updated, but we still need to - * compute a valid return value. + * reading from either a bogus commit, or a reflog entry with + * %gn, %ge, etc.; 'sb' cannot be updated, but we still need + * to compute a valid return value. */ if (part == 'n' || part == 'e' || part == 't' || part == 'd' || part == 'D' || part == 'r' || part == 'i') diff --git a/read-cache.c b/read-cache.c index 274e54b4f3..6c8f395836 100644 --- a/read-cache.c +++ b/read-cache.c @@ -157,16 +157,6 @@ static int ce_modified_check_fs(struct cache_entry *ce, struct stat *st) return 0; } -static int is_empty_blob_sha1(const unsigned char *sha1) -{ - static const unsigned char empty_blob_sha1[20] = { - 0xe6,0x9d,0xe2,0x9b,0xb2,0xd1,0xd6,0x43,0x4b,0x8b, - 0x29,0xae,0x77,0x5a,0xd8,0xc2,0xe4,0x8c,0x53,0x91 - }; - - return !hashcmp(sha1, empty_blob_sha1); -} - static int ce_match_stat_basic(struct cache_entry *ce, struct stat *st) { unsigned int changed = 0; diff --git a/revision.c b/revision.c index b3554ed11b..92095f5fcb 100644 --- a/revision.c +++ b/revision.c @@ -2076,11 +2076,13 @@ int prepare_revision_walk(struct rev_info *revs) if (commit) { if (!(commit->object.flags & SEEN)) { commit->object.flags |= SEEN; - commit_list_insert_by_date(commit, &revs->commits); + commit_list_insert(commit, &revs->commits); } } e++; } + commit_list_reverse(&revs->commits); + commit_list_sort_by_date(&revs->commits); if (!revs->leak_pending) free(list); diff --git a/run-command.c b/run-command.c index 1db8abf984..606791dc67 100644 --- a/run-command.c +++ b/run-command.c @@ -4,6 +4,10 @@ #include "sigchain.h" #include "argv-array.h" +#ifndef SHELL_PATH +# define SHELL_PATH "/bin/sh" +#endif + struct child_to_clean { pid_t pid; struct child_to_clean *next; @@ -76,6 +80,68 @@ static inline void dup_devnull(int to) } #endif +static char *locate_in_PATH(const char *file) +{ + const char *p = getenv("PATH"); + struct strbuf buf = STRBUF_INIT; + + if (!p || !*p) + return NULL; + + while (1) { + const char *end = strchrnul(p, ':'); + + strbuf_reset(&buf); + + /* POSIX specifies an empty entry as the current directory. */ + if (end != p) { + strbuf_add(&buf, p, end - p); + strbuf_addch(&buf, '/'); + } + strbuf_addstr(&buf, file); + + if (!access(buf.buf, F_OK)) + return strbuf_detach(&buf, NULL); + + if (!*end) + break; + p = end + 1; + } + + strbuf_release(&buf); + return NULL; +} + +static int exists_in_PATH(const char *file) +{ + char *r = locate_in_PATH(file); + free(r); + return r != NULL; +} + +int sane_execvp(const char *file, char * const argv[]) +{ + if (!execvp(file, argv)) + return 0; /* cannot happen ;-) */ + + /* + * When a command can't be found because one of the directories + * listed in $PATH is unsearchable, execvp reports EACCES, but + * careful usability testing (read: analysis of occasional bug + * reports) reveals that "No such file or directory" is more + * intuitive. + * + * We avoid commands with "/", because execvp will not do $PATH + * lookups in that case. + * + * The reassignment of EACCES to errno looks like a no-op below, + * but we need to protect against exists_in_PATH overwriting errno. + */ + if (errno == EACCES && !strchr(file, '/')) + errno = exists_in_PATH(file) ? EACCES : ENOENT; + return -1; +} + static const char **prepare_shell_cmd(const char **argv) { int argc, nargc = 0; @@ -90,7 +156,11 @@ static const char **prepare_shell_cmd(const char **argv) die("BUG: shell command is empty"); if (strcspn(argv[0], "|&;<>()$`\\\"' \t\n*?[#~=%") != strlen(argv[0])) { +#ifndef WIN32 + nargv[nargc++] = SHELL_PATH; +#else nargv[nargc++] = "sh"; +#endif nargv[nargc++] = "-c"; if (argc < 2) @@ -114,7 +184,7 @@ static int execv_shell_cmd(const char **argv) { const char **nargv = prepare_shell_cmd(argv); trace_argv_printf(nargv, "trace: exec:"); - execvp(nargv[0], (char **)nargv); + sane_execvp(nargv[0], (char **)nargv); free(nargv); return -1; } @@ -339,7 +409,7 @@ fail_pipe: } else if (cmd->use_shell) { execv_shell_cmd(cmd->argv); } else { - execvp(cmd->argv[0], (char *const*) cmd->argv); + sane_execvp(cmd->argv[0], (char *const*) cmd->argv); } if (errno == ENOENT) { if (!cmd->silent_exec_failure) diff --git a/sequencer.c b/sequencer.c index a37846a594..4307364b26 100644 --- a/sequencer.c +++ b/sequencer.c @@ -164,7 +164,7 @@ static void write_message(struct strbuf *msgbuf, const char *filename) static struct tree *empty_tree(void) { - return lookup_tree((const unsigned char *)EMPTY_TREE_SHA1_BIN); + return lookup_tree(EMPTY_TREE_SHA1_BIN); } static int error_dirty_index(struct replay_opts *opts) diff --git a/sha1_file.c b/sha1_file.c index 4f06a0e450..ad314f08b9 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -19,6 +19,7 @@ #include "pack-revindex.h" #include "sha1-lookup.h" #include "bulk-checkin.h" +#include "streaming.h" #ifndef O_NOATIME #if defined(__linux__) && (defined(__i386__) || defined(__PPC__)) @@ -1146,10 +1147,47 @@ static const struct packed_git *has_packed_and_bad(const unsigned char *sha1) return NULL; } -int check_sha1_signature(const unsigned char *sha1, void *map, unsigned long size, const char *type) +/* + * With an in-core object data in "map", rehash it to make sure the + * object name actually matches "sha1" to detect object corruption. + * With "map" == NULL, try reading the object named with "sha1" using + * the streaming interface and rehash it to do the same. + */ +int check_sha1_signature(const unsigned char *sha1, void *map, + unsigned long size, const char *type) { unsigned char real_sha1[20]; - hash_sha1_file(map, size, type, real_sha1); + enum object_type obj_type; + struct git_istream *st; + git_SHA_CTX c; + char hdr[32]; + int hdrlen; + + if (map) { + hash_sha1_file(map, size, type, real_sha1); + return hashcmp(sha1, real_sha1) ? -1 : 0; + } + + st = open_istream(sha1, &obj_type, &size, NULL); + if (!st) + return -1; + + /* Generate the header */ + hdrlen = sprintf(hdr, "%s %lu", typename(obj_type), size) + 1; + + /* Sha1.. */ + git_SHA1_Init(&c); + git_SHA1_Update(&c, hdr, hdrlen); + for (;;) { + char buf[1024 * 16]; + ssize_t readlen = read_istream(st, buf, sizeof(buf)); + + if (!readlen) + break; + git_SHA1_Update(&c, buf, readlen); + } + git_SHA1_Final(real_sha1, &c); + close_istream(st); return hashcmp(sha1, real_sha1) ? -1 : 0; } diff --git a/streaming.c b/streaming.c index 71072e1b1d..7e7ee2be6f 100644 --- a/streaming.c +++ b/streaming.c @@ -489,3 +489,58 @@ static open_method_decl(incore) return st->u.incore.buf ? 0 : -1; } + + +/**************************************************************** + * Users of streaming interface + ****************************************************************/ + +int stream_blob_to_fd(int fd, unsigned const char *sha1, struct stream_filter *filter, + int can_seek) +{ + struct git_istream *st; + enum object_type type; + unsigned long sz; + ssize_t kept = 0; + int result = -1; + + st = open_istream(sha1, &type, &sz, filter); + if (!st) + return result; + if (type != OBJ_BLOB) + goto close_and_exit; + for (;;) { + char buf[1024 * 16]; + ssize_t wrote, holeto; + ssize_t readlen = read_istream(st, buf, sizeof(buf)); + + if (!readlen) + break; + if (can_seek && sizeof(buf) == readlen) { + for (holeto = 0; holeto < readlen; holeto++) + if (buf[holeto]) + break; + if (readlen == holeto) { + kept += holeto; + continue; + } + } + + if (kept && lseek(fd, kept, SEEK_CUR) == (off_t) -1) + goto close_and_exit; + else + kept = 0; + wrote = write_in_full(fd, buf, readlen); + + if (wrote != readlen) + goto close_and_exit; + } + if (kept && (lseek(fd, kept - 1, SEEK_CUR) == (off_t) -1 || + write(fd, "", 1) != 1)) + goto close_and_exit; + result = 0; + + close_and_exit: + close_istream(st); + return result; +} diff --git a/streaming.h b/streaming.h index 589e857b8c..3e827709c8 100644 --- a/streaming.h +++ b/streaming.h @@ -12,4 +12,6 @@ extern struct git_istream *open_istream(const unsigned char *, enum object_type extern int close_istream(struct git_istream *); extern ssize_t read_istream(struct git_istream *, char *, size_t); +extern int stream_blob_to_fd(int fd, const unsigned char *, struct stream_filter *, int can_seek); + #endif /* STREAMING_H */ diff --git a/submodule.h b/submodule.h index 80e04f3c8c..9c5e5c0c30 100644 --- a/submodule.h +++ b/submodule.h @@ -13,7 +13,7 @@ enum { void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt, const char *path); int submodule_config(const char *var, const char *value, void *cb); -void gitmodules_config(); +void gitmodules_config(void); int parse_submodule_config_option(const char *var, const char *value); void handle_ignore_submodules_arg(struct diff_options *diffopt, const char *); int parse_fetch_recurse_submodules_arg(const char *opt, const char *arg); diff --git a/t/lib-git-p4.sh b/t/lib-git-p4.sh index a870f9a5d2..b90986c2c9 100644 --- a/t/lib-git-p4.sh +++ b/t/lib-git-p4.sh @@ -1,20 +1,18 @@ # -# Library code for git-p4 tests +# Library code for git p4 tests # . ./test-lib.sh if ! test_have_prereq PYTHON; then - skip_all='skipping git-p4 tests; python not available' + skip_all='skipping git p4 tests; python not available' test_done fi ( p4 -h && p4d -h ) >/dev/null 2>&1 || { - skip_all='skipping git-p4 tests; no p4 or p4d' + skip_all='skipping git p4 tests; no p4 or p4d' test_done } -GITP4="$GIT_BUILD_DIR/contrib/fast-import/git-p4" - # Try to pick a unique port: guess a large number, then hope # no more than one of each test is running. # diff --git a/t/lib-httpd.sh b/t/lib-httpd.sh index f7dc0781d5..094d490893 100644 --- a/t/lib-httpd.sh +++ b/t/lib-httpd.sh @@ -160,6 +160,6 @@ test_http_push_nonff() { ' test_expect_success 'non-fast-forward push shows help message' ' - test_i18ngrep "To prevent you from losing history, non-fast-forward updates were rejected" output + test_i18ngrep "Updates were rejected because" output ' } diff --git a/t/lib-httpd/apache.conf b/t/lib-httpd/apache.conf index 3c12b05d60..de3762e247 100644 --- a/t/lib-httpd/apache.conf +++ b/t/lib-httpd/apache.conf @@ -52,8 +52,15 @@ Alias /auth/ www/auth/ <Location /smart_noexport/> SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH} </Location> +<Location /smart_custom_env/> + SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH} + SetEnv GIT_HTTP_EXPORT_ALL + SetEnv GIT_COMMITTER_NAME "Custom User" + SetEnv GIT_COMMITTER_EMAIL custom@example.com +</Location> ScriptAlias /smart/ ${GIT_EXEC_PATH}/git-http-backend/ ScriptAlias /smart_noexport/ ${GIT_EXEC_PATH}/git-http-backend/ +ScriptAlias /smart_custom_env/ ${GIT_EXEC_PATH}/git-http-backend/ <Directory ${GIT_EXEC_PATH}> Options None </Directory> diff --git a/t/t0061-run-command.sh b/t/t0061-run-command.sh index 8d4938f019..17e969df60 100755 --- a/t/t0061-run-command.sh +++ b/t/t0061-run-command.sh @@ -34,4 +34,17 @@ test_expect_success POSIXPERM 'run_command reports EACCES' ' grep "fatal: cannot exec.*hello.sh" err ' +test_expect_success POSIXPERM 'unreadable directory in PATH' ' + mkdir local-command && + test_when_finished "chmod u+rwx local-command && rm -fr local-command" && + git config alias.nitfol "!echo frotz" && + chmod a-rx local-command && + ( + PATH=./local-command:$PATH && + git nitfol >actual + ) && + echo frotz >expect && + test_cmp expect actual +' + test_done diff --git a/t/t0303-credential-external.sh b/t/t0303-credential-external.sh index 267f4c8ba3..f028fd1418 100755 --- a/t/t0303-credential-external.sh +++ b/t/t0303-credential-external.sh @@ -1,39 +1,60 @@ #!/bin/sh -test_description='external credential helper tests' -. ./test-lib.sh -. "$TEST_DIRECTORY"/lib-credential.sh +test_description='external credential helper tests -pre_test() { - test -z "$GIT_TEST_CREDENTIAL_HELPER_SETUP" || - eval "$GIT_TEST_CREDENTIAL_HELPER_SETUP" +This is a tool for authors of external helper tools to sanity-check +their helpers. If you have written the "git-credential-foo" helper, +you check it with: + + make GIT_TEST_CREDENTIAL_HELPER=foo t0303-credential-external.sh + +This assumes that your helper is capable of both storing and +retrieving credentials (some helpers may be read-only, and they will +fail these tests). + +Please note that the individual tests do not verify all of the +preconditions themselves, but rather build on each other. A failing +test means that tests later in the sequence can return false "OK" +results. + +If your helper supports time-based expiration with a configurable +timeout, you can test that feature with: + + make GIT_TEST_CREDENTIAL_HELPER=foo \ + GIT_TEST_CREDENTIAL_HELPER_TIMEOUT="foo --timeout=1" \ + t0303-credential-external.sh - # clean before the test in case there is cruft left - # over from a previous run that would impact results - helper_test_clean "$GIT_TEST_CREDENTIAL_HELPER" -} +If your helper requires additional setup before the tests are started, +you can set GIT_TEST_CREDENTIAL_HELPER_SETUP to a sequence of shell +commands. +' -post_test() { - # clean afterwards so that we are good citizens - # and don't leave cruft in the helper's storage, which - # might be long-term system storage - helper_test_clean "$GIT_TEST_CREDENTIAL_HELPER" -} +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-credential.sh if test -z "$GIT_TEST_CREDENTIAL_HELPER"; then - say "# skipping external helper tests (set GIT_TEST_CREDENTIAL_HELPER)" -else - pre_test - helper_test "$GIT_TEST_CREDENTIAL_HELPER" - post_test + skip_all="used to test external credential helpers" + test_done fi +test -z "$GIT_TEST_CREDENTIAL_HELPER_SETUP" || + eval "$GIT_TEST_CREDENTIAL_HELPER_SETUP" + +# clean before the test in case there is cruft left +# over from a previous run that would impact results +helper_test_clean "$GIT_TEST_CREDENTIAL_HELPER" + +helper_test "$GIT_TEST_CREDENTIAL_HELPER" + if test -z "$GIT_TEST_CREDENTIAL_HELPER_TIMEOUT"; then - say "# skipping external helper timeout tests" + say "# skipping timeout tests (GIT_TEST_CREDENTIAL_HELPER_TIMEOUT not set)" else - pre_test helper_test_timeout "$GIT_TEST_CREDENTIAL_HELPER_TIMEOUT" - post_test fi +# clean afterwards so that we are good citizens +# and don't leave cruft in the helper's storage, which +# might be long-term system storage +helper_test_clean "$GIT_TEST_CREDENTIAL_HELPER" + test_done diff --git a/t/t1050-large.sh b/t/t1050-large.sh index 29d6024b7f..4d127f19b7 100755 --- a/t/t1050-large.sh +++ b/t/t1050-large.sh @@ -6,11 +6,15 @@ test_description='adding and checking out large blobs' . ./test-lib.sh test_expect_success setup ' - git config core.bigfilethreshold 200k && + # clone does not allow us to pass core.bigfilethreshold to + # new repos, so set core.bigfilethreshold globally + git config --global core.bigfilethreshold 200k && echo X | dd of=large1 bs=1k seek=2000 && echo X | dd of=large2 bs=1k seek=2000 && echo X | dd of=large3 bs=1k seek=2000 && - echo Y | dd of=huge bs=1k seek=2500 + echo Y | dd of=huge bs=1k seek=2500 && + GIT_ALLOC_LIMIT=1500 && + export GIT_ALLOC_LIMIT ' test_expect_success 'add a large file or two' ' @@ -100,4 +104,34 @@ test_expect_success 'packsize limit' ' ) ' +test_expect_success 'diff --raw' ' + git commit -q -m initial && + echo modified >>large1 && + git add large1 && + git commit -q -m modified && + git diff --raw HEAD^ +' + +test_expect_success 'hash-object' ' + git hash-object large1 +' + +test_expect_success 'cat-file a large file' ' + git cat-file blob :large1 >/dev/null +' + +test_expect_success 'cat-file a large file from a tag' ' + git tag -m largefile largefiletag :large1 && + git cat-file blob largefiletag >/dev/null +' + +test_expect_success 'git-show a large file' ' + git show :large1 >/dev/null + +' + +test_expect_success 'repack' ' + git repack -ad +' + test_done diff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh index 252fc82837..236b13a3ab 100755 --- a/t/t1410-reflog.sh +++ b/t/t1410-reflog.sh @@ -100,8 +100,7 @@ test_expect_success setup ' check_fsck && - loglen=$(wc -l <.git/logs/refs/heads/master) && - test $loglen = 4 + test_line_count = 4 .git/logs/refs/heads/master ' test_expect_success rewind ' @@ -117,8 +116,7 @@ test_expect_success rewind ' check_have A B C D E F G H I J K L && - loglen=$(wc -l <.git/logs/refs/heads/master) && - test $loglen = 5 + test_line_count = 5 .git/logs/refs/heads/master ' test_expect_success 'corrupt and check' ' @@ -136,8 +134,7 @@ test_expect_success 'reflog expire --dry-run should not touch reflog' ' --stale-fix \ --all && - loglen=$(wc -l <.git/logs/refs/heads/master) && - test $loglen = 5 && + test_line_count = 5 .git/logs/refs/heads/master && check_fsck "missing blob $F" ' @@ -150,8 +147,7 @@ test_expect_success 'reflog expire' ' --stale-fix \ --all && - loglen=$(wc -l <.git/logs/refs/heads/master) && - test $loglen = 2 && + test_line_count = 2 .git/logs/refs/heads/master && check_fsck "dangling commit $K" ' @@ -217,9 +213,7 @@ test_expect_success 'delete' ' test_expect_success 'rewind2' ' test_tick && git reset --hard HEAD~2 && - loglen=$(wc -l <.git/logs/refs/heads/master) && - test $loglen = 4 - + test_line_count = 4 .git/logs/refs/heads/master ' test_expect_success '--expire=never' ' @@ -228,9 +222,7 @@ test_expect_success '--expire=never' ' --expire=never \ --expire-unreachable=never \ --all && - loglen=$(wc -l <.git/logs/refs/heads/master) && - test $loglen = 4 - + test_line_count = 4 .git/logs/refs/heads/master ' test_expect_success 'gc.reflogexpire=never' ' @@ -238,8 +230,7 @@ test_expect_success 'gc.reflogexpire=never' ' git config gc.reflogexpire never && git config gc.reflogexpireunreachable never && git reflog expire --verbose --all && - loglen=$(wc -l <.git/logs/refs/heads/master) && - test $loglen = 4 + test_line_count = 4 .git/logs/refs/heads/master ' test_expect_success 'gc.reflogexpire=false' ' @@ -247,8 +238,7 @@ test_expect_success 'gc.reflogexpire=false' ' git config gc.reflogexpire false && git config gc.reflogexpireunreachable false && git reflog expire --verbose --all && - loglen=$(wc -l <.git/logs/refs/heads/master) && - test $loglen = 4 && + test_line_count = 4 .git/logs/refs/heads/master && git config --unset gc.reflogexpire && git config --unset gc.reflogexpireunreachable diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh index e661147c57..8f36aa9fc4 100755 --- a/t/t1501-worktree.sh +++ b/t/t1501-worktree.sh @@ -68,7 +68,7 @@ test_expect_success 'inside work tree' ' ) ' -test_expect_failure 'empty prefix is actually written out' ' +test_expect_success 'empty prefix is actually written out' ' echo >expected && ( cd work && diff --git a/t/t2004-checkout-cache-temp.sh b/t/t2004-checkout-cache-temp.sh index 36cca14d95..0f4b2896af 100755 --- a/t/t2004-checkout-cache-temp.sh +++ b/t/t2004-checkout-cache-temp.sh @@ -40,7 +40,7 @@ test_expect_success \ rm -f path* .merge_* out .git/index && git read-tree $t1 && git checkout-index --temp -- path1 >out && -test $(wc -l <out) = 1 && +test_line_count = 1 out && test $(cut "-d " -f2 out) = path1 && p=$(cut "-d " -f1 out) && test -f $p && @@ -51,7 +51,7 @@ test_expect_success \ rm -f path* .merge_* out .git/index && git read-tree $t1 && git checkout-index -a --temp >out && -test $(wc -l <out) = 5 && +test_line_count = 5 out && for f in path0 path1 path3 path4 asubdir/path5 do test $(grep $f out | cut "-d " -f2) = $f && @@ -69,7 +69,7 @@ test_expect_success \ 'checkout one stage 2 to temporary file' ' rm -f path* .merge_* out && git checkout-index --stage=2 --temp -- path1 >out && -test $(wc -l <out) = 1 && +test_line_count = 1 out && test $(cut "-d " -f2 out) = path1 && p=$(cut "-d " -f1 out) && test -f $p && @@ -79,7 +79,7 @@ test_expect_success \ 'checkout all stage 2 to temporary files' ' rm -f path* .merge_* out && git checkout-index --all --stage=2 --temp >out && -test $(wc -l <out) = 3 && +test_line_count = 3 out && for f in path1 path2 path4 do test $(grep $f out | cut "-d " -f2) = $f && @@ -92,13 +92,13 @@ test_expect_success \ 'checkout all stages/one file to nothing' ' rm -f path* .merge_* out && git checkout-index --stage=all --temp -- path0 >out && -test $(wc -l <out) = 0' +test_line_count = 0 out' test_expect_success \ 'checkout all stages/one file to temporary files' ' rm -f path* .merge_* out && git checkout-index --stage=all --temp -- path1 >out && -test $(wc -l <out) = 1 && +test_line_count = 1 out && test $(cut "-d " -f2 out) = path1 && cut "-d " -f1 out | (read s1 s2 s3 && test -f $s1 && @@ -112,7 +112,7 @@ test_expect_success \ 'checkout some stages/one file to temporary files' ' rm -f path* .merge_* out && git checkout-index --stage=all --temp -- path2 >out && -test $(wc -l <out) = 1 && +test_line_count = 1 out && test $(cut "-d " -f2 out) = path2 && cut "-d " -f1 out | (read s1 s2 s3 && test $s1 = . && @@ -125,7 +125,7 @@ test_expect_success \ 'checkout all stages/all files to temporary files' ' rm -f path* .merge_* out && git checkout-index -a --stage=all --temp >out && -test $(wc -l <out) = 5' +test_line_count = 5 out' test_expect_success \ '-- path0: no entry' ' @@ -185,7 +185,7 @@ test_expect_success \ 'checkout --temp within subdir' ' (cd asubdir && git checkout-index -a --stage=all >out && - test $(wc -l <out) = 1 && + test_line_count = 1 out && test $(grep path5 out | cut "-d " -f2) = path5 && grep path5 out | cut "-d " -f1 | (read s1 s2 s3 && test -f ../$s1 && @@ -203,7 +203,7 @@ t4=$(git write-tree) && rm -f .git/index && git read-tree $t4 && git checkout-index --temp -a >out && -test $(wc -l <out) = 1 && +test_line_count = 1 out && test $(cut "-d " -f2 out) = a && p=$(cut "-d " -f1 out) && test -f $p && diff --git a/t/t2020-checkout-detach.sh b/t/t2020-checkout-detach.sh index 068fba4c8e..b37ce25c42 100755 --- a/t/t2020-checkout-detach.sh +++ b/t/t2020-checkout-detach.sh @@ -148,7 +148,7 @@ test_expect_success 'tracking count is accurate after orphan check' ' git config branch.child.merge refs/heads/master && git checkout child^ && git checkout child >stdout && - test_cmp expect stdout + test_i18ncmp expect stdout ' test_done diff --git a/t/t2030-unresolve-info.sh b/t/t2030-unresolve-info.sh index cb7effe0a3..f2620650ce 100755 --- a/t/t2030-unresolve-info.sh +++ b/t/t2030-unresolve-info.sh @@ -113,7 +113,7 @@ test_expect_success 'unmerge with plumbing' ' prime_resolve_undo && git update-index --unresolve fi/le && git ls-files -u >actual && - test $(wc -l <actual) = 3 + test_line_count = 3 actual ' test_expect_success 'rerere and rerere forget' ' diff --git a/t/t3300-funny-names.sh b/t/t3300-funny-names.sh index 9f00ada5f7..c53c9f65eb 100755 --- a/t/t3300-funny-names.sh +++ b/t/t3300-funny-names.sh @@ -15,184 +15,204 @@ p0='no-funny' p1='tabs ," (dq) and spaces' p2='just space' -cat >"$p0" <<\EOF -1. A quick brown fox jumps over the lazy cat, oops dog. -2. A quick brown fox jumps over the lazy cat, oops dog. -3. A quick brown fox jumps over the lazy cat, oops dog. -EOF - -cat 2>/dev/null >"$p1" "$p0" -echo 'Foo Bar Baz' >"$p2" +test_expect_success 'setup' ' + cat >"$p0" <<-\EOF && + 1. A quick brown fox jumps over the lazy cat, oops dog. + 2. A quick brown fox jumps over the lazy cat, oops dog. + 3. A quick brown fox jumps over the lazy cat, oops dog. + EOF + + { cat "$p0" >"$p1" || :; } && + { echo "Foo Bar Baz" >"$p2" || :; } && + + if test -f "$p1" && cmp "$p0" "$p1" + then + test_set_prereq TABS_IN_FILENAMES + fi +' -if test -f "$p1" && cmp "$p0" "$p1" +if ! test_have_prereq TABS_IN_FILENAMES then - test_set_prereq TABS_IN_FILENAMES -else # since FAT/NTFS does not allow tabs in filenames, skip this test - say 'Your filesystem does not allow tabs in filenames' + skip_all='Your filesystem does not allow tabs in filenames' + test_done fi -test_expect_success TABS_IN_FILENAMES 'setup expect' " -echo 'just space -no-funny' >expected -" +test_expect_success 'setup: populate index and tree' ' + git update-index --add "$p0" "$p2" && + t0=$(git write-tree) +' -test_expect_success TABS_IN_FILENAMES 'git ls-files no-funny' \ - 'git update-index --add "$p0" "$p2" && +test_expect_success 'ls-files prints space in filename verbatim' ' + printf "%s\n" "just space" no-funny >expected && git ls-files >current && - test_cmp expected current' - -test_expect_success TABS_IN_FILENAMES 'setup expect' ' -t0=`git write-tree` && -echo "$t0" >t0 && + test_cmp expected current +' -cat > expected <<\EOF -just space -no-funny -"tabs\t,\" (dq) and spaces" -EOF +test_expect_success 'setup: add funny filename' ' + git update-index --add "$p1" && + t1=$(git write-tree) ' -test_expect_success TABS_IN_FILENAMES 'git ls-files with-funny' \ - 'git update-index --add "$p1" && +test_expect_success 'ls-files quotes funny filename' ' + cat >expected <<-\EOF && + just space + no-funny + "tabs\t,\" (dq) and spaces" + EOF git ls-files >current && - test_cmp expected current' - -test_expect_success TABS_IN_FILENAMES 'setup expect' " -echo 'just space -no-funny -tabs ,\" (dq) and spaces' >expected -" - -test_expect_success TABS_IN_FILENAMES 'git ls-files -z with-funny' \ - 'git ls-files -z | perl -pe y/\\000/\\012/ >current && - test_cmp expected current' - -test_expect_success TABS_IN_FILENAMES 'setup expect' ' -t1=`git write-tree` && -echo "$t1" >t1 && - -cat > expected <<\EOF -just space -no-funny -"tabs\t,\" (dq) and spaces" -EOF -' - -test_expect_success TABS_IN_FILENAMES 'git ls-tree with funny' \ - 'git ls-tree -r $t1 | sed -e "s/^[^ ]* //" >current && - test_cmp expected current' - -test_expect_success TABS_IN_FILENAMES 'setup expect' ' -cat > expected <<\EOF -A "tabs\t,\" (dq) and spaces" -EOF -' - -test_expect_success TABS_IN_FILENAMES 'git diff-index with-funny' \ - 'git diff-index --name-status $t0 >current && - test_cmp expected current' - -test_expect_success TABS_IN_FILENAMES 'git diff-tree with-funny' \ - 'git diff-tree --name-status $t0 $t1 >current && - test_cmp expected current' - -test_expect_success TABS_IN_FILENAMES 'setup expect' " -echo 'A -tabs ,\" (dq) and spaces' >expected -" - -test_expect_success TABS_IN_FILENAMES 'git diff-index -z with-funny' \ - 'git diff-index -z --name-status $t0 | perl -pe y/\\000/\\012/ >current && - test_cmp expected current' - -test_expect_success TABS_IN_FILENAMES 'git diff-tree -z with-funny' \ - 'git diff-tree -z --name-status $t0 $t1 | perl -pe y/\\000/\\012/ >current && - test_cmp expected current' - -test_expect_success TABS_IN_FILENAMES 'setup expect' ' -cat > expected <<\EOF -CNUM no-funny "tabs\t,\" (dq) and spaces" -EOF -' - -test_expect_success TABS_IN_FILENAMES '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 && - test_cmp expected current' - -test_expect_success TABS_IN_FILENAMES 'setup expect' ' -cat > expected <<\EOF -RNUM no-funny "tabs\t,\" (dq) and spaces" -EOF -' - -test_expect_success TABS_IN_FILENAMES '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 && - test_cmp expected current' - -test_expect_success TABS_IN_FILENAMES 'setup expect' ' -cat > expected <<\EOF -diff --git a/no-funny "b/tabs\t,\" (dq) and spaces" -similarity index NUM% -rename from no-funny -rename to "tabs\t,\" (dq) and spaces" -EOF -' - -test_expect_success TABS_IN_FILENAMES 'git diff-tree delete with-funny' \ - 'git diff-index -M -p $t0 | - sed -e "s/index [0-9]*%/index NUM%/" >current && - test_cmp expected current' - -test_expect_success TABS_IN_FILENAMES 'setup expect' ' -chmod +x "$p1" && -cat > expected <<\EOF -diff --git a/no-funny "b/tabs\t,\" (dq) and spaces" -old mode 100644 -new mode 100755 -similarity index NUM% -rename from no-funny -rename to "tabs\t,\" (dq) and spaces" -EOF -' - -test_expect_success TABS_IN_FILENAMES 'git diff-tree delete with-funny' \ - 'git diff-index -M -p $t0 | - sed -e "s/index [0-9]*%/index NUM%/" >current && - test_cmp expected current' - -test_expect_success TABS_IN_FILENAMES 'setup expect' ' -cat >expected <<\EOF - "tabs\t,\" (dq) and spaces" - 1 file changed, 0 insertions(+), 0 deletions(-) -EOF -' - -test_expect_success TABS_IN_FILENAMES 'git diff-tree rename with-funny applied' \ - 'git diff-index -M -p $t0 | - git apply --stat | sed -e "s/|.*//" -e "s/ *\$//" >current && - test_cmp expected current' - -test_expect_success TABS_IN_FILENAMES 'setup expect' ' -cat > expected <<\EOF - no-funny - "tabs\t,\" (dq) and spaces" - 2 files changed, 3 insertions(+), 3 deletions(-) -EOF -' - -test_expect_success TABS_IN_FILENAMES 'git diff-tree delete with-funny applied' \ - 'git diff-index -p $t0 | - git apply --stat | sed -e "s/|.*//" -e "s/ *\$//" >current && - test_cmp expected current' - -test_expect_success TABS_IN_FILENAMES 'git apply non-git diff' \ - 'git diff-index -p $t0 | - sed -ne "/^[-+@]/p" | - git apply --stat | sed -e "s/|.*//" -e "s/ *\$//" >current && - test_cmp expected current' + test_cmp expected current +' + +test_expect_success 'ls-files -z does not quote funny filename' ' + cat >expected <<-\EOF && + just space + no-funny + tabs ," (dq) and spaces + EOF + git ls-files -z >ls-files.z && + perl -pe "y/\000/\012/" <ls-files.z >current && + test_cmp expected current +' + +test_expect_success 'ls-tree quotes funny filename' ' + cat >expected <<-\EOF && + just space + no-funny + "tabs\t,\" (dq) and spaces" + EOF + git ls-tree -r $t1 >ls-tree && + sed -e "s/^[^ ]* //" <ls-tree >current && + test_cmp expected current +' + +test_expect_success 'diff-index --name-status quotes funny filename' ' + cat >expected <<-\EOF && + A "tabs\t,\" (dq) and spaces" + EOF + git diff-index --name-status $t0 >current && + test_cmp expected current +' + +test_expect_success 'diff-tree --name-status quotes funny filename' ' + cat >expected <<-\EOF && + A "tabs\t,\" (dq) and spaces" + EOF + git diff-tree --name-status $t0 $t1 >current && + test_cmp expected current +' + +test_expect_success 'diff-index -z does not quote funny filename' ' + cat >expected <<-\EOF && + A + tabs ," (dq) and spaces + EOF + git diff-index -z --name-status $t0 >diff-index.z && + perl -pe "y/\000/\012/" <diff-index.z >current && + test_cmp expected current +' + +test_expect_success 'diff-tree -z does not quote funny filename' ' + cat >expected <<-\EOF && + A + tabs ," (dq) and spaces + EOF + git diff-tree -z --name-status $t0 $t1 >diff-tree.z && + perl -pe y/\\000/\\012/ <diff-tree.z >current && + test_cmp expected current +' + +test_expect_success 'diff-tree --find-copies-harder quotes funny filename' ' + cat >expected <<-\EOF && + CNUM no-funny "tabs\t,\" (dq) and spaces" + EOF + git diff-tree -C --find-copies-harder --name-status $t0 $t1 >out && + sed -e "s/^C[0-9]*/CNUM/" <out >current && + test_cmp expected current +' + +test_expect_success 'setup: remove unfunny index entry' ' + git update-index --force-remove "$p0" +' + +test_expect_success 'diff-tree -M quotes funny filename' ' + cat >expected <<-\EOF && + RNUM no-funny "tabs\t,\" (dq) and spaces" + EOF + git diff-index -M --name-status $t0 >out && + sed -e "s/^R[0-9]*/RNUM/" <out >current && + test_cmp expected current +' + +test_expect_success 'diff-index -M -p quotes funny filename' ' + cat >expected <<-\EOF && + diff --git a/no-funny "b/tabs\t,\" (dq) and spaces" + similarity index NUM% + rename from no-funny + rename to "tabs\t,\" (dq) and spaces" + EOF + git diff-index -M -p $t0 >diff && + sed -e "s/index [0-9]*%/index NUM%/" <diff >current && + test_cmp expected current +' + +test_expect_success 'setup: mode change' ' + chmod +x "$p1" +' + +test_expect_success 'diff-index -M -p with mode change quotes funny filename' ' + cat >expected <<-\EOF && + diff --git a/no-funny "b/tabs\t,\" (dq) and spaces" + old mode 100644 + new mode 100755 + similarity index NUM% + rename from no-funny + rename to "tabs\t,\" (dq) and spaces" + EOF + git diff-index -M -p $t0 >diff && + sed -e "s/index [0-9]*%/index NUM%/" <diff >current && + test_cmp expected current +' + +test_expect_success 'diffstat for rename quotes funny filename' ' + cat >expected <<-\EOF && + "tabs\t,\" (dq) and spaces" + 1 file changed, 0 insertions(+), 0 deletions(-) + EOF + git diff-index -M -p $t0 >diff && + git apply --stat <diff >diffstat && + sed -e "s/|.*//" -e "s/ *\$//" <diffstat >current && + test_i18ncmp expected current +' + +test_expect_success 'numstat for rename quotes funny filename' ' + cat >expected <<-\EOF && + 0 0 "tabs\t,\" (dq) and spaces" + EOF + git diff-index -M -p $t0 >diff && + git apply --numstat <diff >current && + test_cmp expected current +' + +test_expect_success 'numstat without -M quotes funny filename' ' + cat >expected <<-\EOF && + 0 3 no-funny + 3 0 "tabs\t,\" (dq) and spaces" + EOF + git diff-index -p $t0 >diff && + git apply --numstat <diff >current && + test_cmp expected current +' + +test_expect_success 'numstat for non-git rename diff quotes funny filename' ' + cat >expected <<-\EOF && + 0 3 no-funny + 3 0 "tabs\t,\" (dq) and spaces" + EOF + git diff-index -p $t0 >git-diff && + sed -ne "/^[-+@]/p" <git-diff >diff && + git apply --numstat <diff >current && + test_cmp expected current +' test_done diff --git a/t/t3310-notes-merge-manual-resolve.sh b/t/t3310-notes-merge-manual-resolve.sh index 4367197953..195bb97f85 100755 --- a/t/t3310-notes-merge-manual-resolve.sh +++ b/t/t3310-notes-merge-manual-resolve.sh @@ -324,7 +324,7 @@ y and z notes on 4th commit EOF git notes merge --commit && # No .git/NOTES_MERGE_* files left - test_must_fail ls .git/NOTES_MERGE_* >output 2>/dev/null && + test_might_fail ls .git/NOTES_MERGE_* >output 2>/dev/null && test_cmp /dev/null output && # Merge commit has pre-merge y and pre-merge z as parents test "$(git rev-parse refs/notes/m^1)" = "$(cat pre_merge_y)" && @@ -386,7 +386,7 @@ test_expect_success 'redo merge of z into m (== y) with default ("manual") resol test_expect_success 'abort notes merge' ' git notes merge --abort && # No .git/NOTES_MERGE_* files left - test_must_fail ls .git/NOTES_MERGE_* >output 2>/dev/null && + test_might_fail ls .git/NOTES_MERGE_* >output 2>/dev/null && test_cmp /dev/null output && # m has not moved (still == y) test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)" && @@ -453,7 +453,7 @@ EOF # Finalize merge git notes merge --commit && # No .git/NOTES_MERGE_* files left - test_must_fail ls .git/NOTES_MERGE_* >output 2>/dev/null && + test_might_fail ls .git/NOTES_MERGE_* >output 2>/dev/null && test_cmp /dev/null output && # Merge commit has pre-merge y and pre-merge z as parents test "$(git rev-parse refs/notes/m^1)" = "$(cat pre_merge_y)" && @@ -542,7 +542,7 @@ EOF test_expect_success 'resolve situation by aborting the notes merge' ' git notes merge --abort && # No .git/NOTES_MERGE_* files left - test_must_fail ls .git/NOTES_MERGE_* >output 2>/dev/null && + test_might_fail ls .git/NOTES_MERGE_* >output 2>/dev/null && test_cmp /dev/null output && # m has not moved (still == w) test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/w)" && @@ -553,4 +553,23 @@ test_expect_success 'resolve situation by aborting the notes merge' ' verify_notes z ' +cat >expect_notes <<EOF +foo +bar +EOF + +test_expect_success 'switch cwd before committing notes merge' ' + git notes add -m foo HEAD && + git notes --ref=other add -m bar HEAD && + test_must_fail git notes merge refs/notes/other && + ( + cd .git/NOTES_MERGE_WORKTREE && + echo "foo" > $(git rev-parse HEAD) && + echo "bar" >> $(git rev-parse HEAD) && + git notes merge --commit + ) && + git notes show HEAD > actual_notes && + test_cmp expect_notes actual_notes +' + test_done diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index b981572d73..7fd2127625 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -624,8 +624,38 @@ test_expect_success 'submodule rebase -i' ' FAKE_LINES="1 squash 2 3" git rebase -i A ' +test_expect_success 'submodule conflict setup' ' + git tag submodule-base && + git checkout HEAD^ && + ( + cd sub && git checkout HEAD^ && echo 4 >elif && + git add elif && git commit -m "submodule conflict" + ) && + git add sub && + test_tick && + git commit -m "Conflict in submodule" && + git tag submodule-topic +' + +test_expect_success 'rebase -i continue with only submodule staged' ' + test_must_fail git rebase -i submodule-base && + git add sub && + git rebase --continue && + test $(git rev-parse submodule-base) != $(git rev-parse HEAD) +' + +test_expect_success 'rebase -i continue with unstaged submodule' ' + git checkout submodule-topic && + git reset --hard && + test_must_fail git rebase -i submodule-base && + git reset && + git rebase --continue && + test $(git rev-parse submodule-base) = $(git rev-parse HEAD) +' + test_expect_success 'avoid unnecessary reset' ' git checkout master && + git reset --hard && test-chmtime =123456789 file3 && git update-index --refresh && HEAD=$(git rev-parse HEAD) && diff --git a/t/t3415-rebase-autosquash.sh b/t/t3415-rebase-autosquash.sh index b38be8e937..a1e86c4097 100755 --- a/t/t3415-rebase-autosquash.sh +++ b/t/t3415-rebase-autosquash.sh @@ -33,7 +33,7 @@ test_auto_fixup () { test_tick && git rebase $2 -i HEAD^^^ && git log --oneline >actual && - test 3 = $(wc -l <actual) && + test_line_count = 3 actual && git diff --exit-code $1 && test 1 = "$(git cat-file blob HEAD^:file1)" && test 1 = $(git cat-file commit HEAD^ | grep first | wc -l) @@ -62,7 +62,7 @@ test_auto_squash () { test_tick && git rebase $2 -i HEAD^^^ && git log --oneline >actual && - test 3 = $(wc -l <actual) && + test_line_count = 3 actual && git diff --exit-code $1 && test 1 = "$(git cat-file blob HEAD^:file1)" && test 2 = $(git cat-file commit HEAD^ | grep first | wc -l) @@ -90,7 +90,7 @@ test_expect_success 'misspelled auto squash' ' test_tick && git rebase --autosquash -i HEAD^^^ && git log --oneline >actual && - test 4 = $(wc -l <actual) && + test_line_count = 4 actual && git diff --exit-code final-missquash && test 0 = $(git rev-list final-missquash...HEAD | wc -l) ' @@ -109,7 +109,7 @@ test_expect_success 'auto squash that matches 2 commits' ' test_tick && git rebase --autosquash -i HEAD~4 && git log --oneline >actual && - test 4 = $(wc -l <actual) && + test_line_count = 4 actual && git diff --exit-code final-multisquash && test 1 = "$(git cat-file blob HEAD^^:file1)" && test 2 = $(git cat-file commit HEAD^^ | grep first | wc -l) && @@ -130,7 +130,7 @@ test_expect_success 'auto squash that matches a commit after the squash' ' test_tick && git rebase --autosquash -i HEAD~4 && git log --oneline >actual && - test 5 = $(wc -l <actual) && + test_line_count = 5 actual && git diff --exit-code final-presquash && test 0 = "$(git cat-file blob HEAD^^:file1)" && test 1 = "$(git cat-file blob HEAD^:file1)" && @@ -147,7 +147,7 @@ test_expect_success 'auto squash that matches a sha1' ' test_tick && git rebase --autosquash -i HEAD^^^ && git log --oneline >actual && - test 3 = $(wc -l <actual) && + test_line_count = 3 actual && git diff --exit-code final-shasquash && test 1 = "$(git cat-file blob HEAD^:file1)" && test 1 = $(git cat-file commit HEAD^ | grep squash | wc -l) @@ -163,7 +163,7 @@ test_expect_success 'auto squash that matches longer sha1' ' test_tick && git rebase --autosquash -i HEAD^^^ && git log --oneline >actual && - test 3 = $(wc -l <actual) && + test_line_count = 3 actual && git diff --exit-code final-longshasquash && test 1 = "$(git cat-file blob HEAD^:file1)" && test 1 = $(git cat-file commit HEAD^ | grep squash | wc -l) @@ -179,7 +179,7 @@ test_auto_commit_flags () { test_tick && git rebase --autosquash -i HEAD^^^ && git log --oneline >actual && - test 3 = $(wc -l <actual) && + test_line_count = 3 actual && git diff --exit-code final-commit-$1 && test 1 = "$(git cat-file blob HEAD^:file1)" && test $2 = $(git cat-file commit HEAD^ | grep first | wc -l) diff --git a/t/t3508-cherry-pick-many-commits.sh b/t/t3508-cherry-pick-many-commits.sh index 1b3a344158..75f7ff4f2f 100755 --- a/t/t3508-cherry-pick-many-commits.sh +++ b/t/t3508-cherry-pick-many-commits.sh @@ -35,6 +35,16 @@ test_expect_success setup ' ' test_expect_success 'cherry-pick first..fourth works' ' + git checkout -f master && + git reset --hard first && + test_tick && + git cherry-pick first..fourth && + git diff --quiet other && + git diff --quiet HEAD other && + check_head_differs_from fourth +' + +test_expect_success 'output to keep user entertained during multi-pick' ' cat <<-\EOF >expected && [master OBJID] second Author: A U Thor <author@example.com> @@ -51,15 +61,22 @@ test_expect_success 'cherry-pick first..fourth works' ' git reset --hard first && test_tick && git cherry-pick first..fourth >actual && + sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy && + test_line_count -ge 3 actual.fuzzy && + test_i18ncmp expected actual.fuzzy +' + +test_expect_success 'cherry-pick --strategy resolve first..fourth works' ' + git checkout -f master && + git reset --hard first && + test_tick && + git cherry-pick --strategy resolve first..fourth && git diff --quiet other && git diff --quiet HEAD other && - - sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy && - test_cmp expected actual.fuzzy && check_head_differs_from fourth ' -test_expect_success 'cherry-pick --strategy resolve first..fourth works' ' +test_expect_success 'output during multi-pick indicates merge strategy' ' cat <<-\EOF >expected && Trying simple merge. [master OBJID] second @@ -79,11 +96,8 @@ test_expect_success 'cherry-pick --strategy resolve first..fourth works' ' git reset --hard first && test_tick && git cherry-pick --strategy resolve first..fourth >actual && - git diff --quiet other && - git diff --quiet HEAD other && sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy && - test_cmp expected actual.fuzzy && - check_head_differs_from fourth + test_i18ncmp expected actual.fuzzy ' test_expect_success 'cherry-pick --ff first..fourth works' ' diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index 9e236f9cc0..098a6ae4a0 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -330,4 +330,30 @@ test_expect_success PERL 'split hunk "add -p (edit)"' ' ! grep "^+15" actual ' +test_expect_success 'patch mode ignores unmerged entries' ' + git reset --hard && + test_commit conflict && + test_commit non-conflict && + git checkout -b side && + test_commit side conflict.t && + git checkout master && + test_commit master conflict.t && + test_must_fail git merge side && + echo changed >non-conflict.t && + echo y | git add -p >output && + ! grep a/conflict.t output && + cat >expected <<-\EOF && + * Unmerged path conflict.t + diff --git a/non-conflict.t b/non-conflict.t + index f766221..5ea2ed4 100644 + --- a/non-conflict.t + +++ b/non-conflict.t + @@ -1 +1 @@ + -non-conflict + +changed + EOF + git diff --cached >diff && + test_cmp expected diff +' + test_done diff --git a/t/t3900-i18n-commit.sh b/t/t3900-i18n-commit.sh index d48a7c002d..37ddabba2d 100755 --- a/t/t3900-i18n-commit.sh +++ b/t/t3900-i18n-commit.sh @@ -160,7 +160,7 @@ test_commit_autosquash_flags () { git config --unset-all i18n.commitencoding && git rebase --autosquash -i HEAD^^^ && git log --oneline >actual && - test 3 = $(wc -l <actual) + test_line_count = 3 actual ' } diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh index 663c60a12e..3addb804d5 100755 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@ -432,7 +432,7 @@ test_expect_success 'stash branch - stashes on stack, stash-like argument' ' test $(git ls-files --modified | wc -l) -eq 1 ' -test_expect_success 'stash show - stashes on stack, stash-like argument' ' +test_expect_success 'stash show format defaults to --stat' ' git stash clear && test_when_finished "git reset --hard HEAD" && git reset --hard && @@ -447,6 +447,21 @@ test_expect_success 'stash show - stashes on stack, stash-like argument' ' 1 file changed, 1 insertion(+) EOF git stash show ${STASH_ID} >actual && + test_i18ncmp expected actual +' + +test_expect_success 'stash show - stashes on stack, stash-like argument' ' + git stash clear && + test_when_finished "git reset --hard HEAD" && + git reset --hard && + echo foo >> file && + git stash && + test_when_finished "git stash drop" && + echo bar >> file && + STASH_ID=$(git stash create) && + git reset --hard && + echo "1 0 file" >expected && + git stash show --numstat ${STASH_ID} >actual && test_cmp expected actual ' @@ -480,11 +495,8 @@ test_expect_success 'stash show - no stashes on stack, stash-like argument' ' echo foo >> file && STASH_ID=$(git stash create) && git reset --hard && - cat >expected <<-EOF && - file | 1 + - 1 file changed, 1 insertion(+) - EOF - git stash show ${STASH_ID} >actual && + echo "1 0 file" >expected && + git stash show --numstat ${STASH_ID} >actual && test_cmp expected actual ' diff --git a/t/t4012-diff-binary.sh b/t/t4012-diff-binary.sh index 2d9f9a0cf1..ed24ddd88a 100755 --- a/t/t4012-diff-binary.sh +++ b/t/t4012-diff-binary.sh @@ -8,6 +8,13 @@ test_description='Binary diff and apply . ./test-lib.sh +cat >expect.binary-numstat <<\EOF +1 1 a +- - b +1 1 c +- - d +EOF + test_expect_success 'prepare repository' \ 'echo AIT >a && echo BIT >b && echo CIT >c && echo DIT >d && git update-index --add a b c d && @@ -23,13 +30,23 @@ cat > expected <<\EOF d | Bin 4 files changed, 2 insertions(+), 2 deletions(-) EOF -test_expect_success 'diff without --binary' \ - 'git diff | git apply --stat --summary >current && - test_cmp expected current' +test_expect_success '"apply --stat" output for binary file change' ' + git diff >diff && + git apply --stat --summary <diff >current && + test_i18ncmp expected current +' -test_expect_success 'diff with --binary' \ - 'git diff --binary | git apply --stat --summary >current && - test_cmp expected current' +test_expect_success 'apply --numstat notices binary file change' ' + git diff >diff && + git apply --numstat <diff >current && + test_cmp expect.binary-numstat current +' + +test_expect_success 'apply --numstat understands diff --binary format' ' + git diff --binary >diff && + git apply --numstat <diff >current && + test_cmp expect.binary-numstat current +' # apply needs to be able to skip the binary material correctly # in order to report the line number of a corrupt patch. diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh index 93a6f20871..e77c09c37e 100755 --- a/t/t4013-diff-various.sh +++ b/t/t4013-diff-various.sh @@ -128,7 +128,12 @@ do } >"$actual" && if test -f "$expect" then - test_cmp "$expect" "$actual" && + case $cmd in + *format-patch* | *-stat*) + test_i18ncmp "$expect" "$actual";; + *) + test_cmp "$expect" "$actual";; + esac && rm -f "$actual" else # this is to help developing new tests. diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index 7dfe716cf9..b473b6d6eb 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -518,11 +518,6 @@ test_expect_success 'shortlog of cover-letter wraps overly-long onelines' ' ' cat > expect << EOF ---- - file | 16 ++++++++++++++++ - 1 file changed, 16 insertions(+) - -diff --git a/file b/file index 40f36c6..2dc5c23 100644 --- a/file +++ b/file @@ -537,7 +532,9 @@ EOF test_expect_success 'format-patch respects -U' ' git format-patch -U4 -2 && - sed -e "1,/^\$/d" -e "/^+5/q" < 0001-This-is-an-excessively-long-subject-line-for-a-messa.patch > output && + sed -e "1,/^diff/d" -e "/^+5/q" \ + <0001-This-is-an-excessively-long-subject-line-for-a-messa.patch \ + >output && test_cmp expect output ' diff --git a/t/t4016-diff-quote.sh b/t/t4016-diff-quote.sh index ab0c2f0574..3ec71184ba 100755 --- a/t/t4016-diff-quote.sh +++ b/t/t4016-diff-quote.sh @@ -57,22 +57,33 @@ test_expect_success TABS_IN_FILENAMES 'git diff --summary -M HEAD' ' test_cmp expect actual ' -test_expect_success TABS_IN_FILENAMES 'setup expected files' ' -cat >expect <<\EOF - pathname.1 => "Rpathname\twith HT.0" | 0 - pathname.3 => "Rpathname\nwith LF.0" | 0 - "pathname\twith HT.3" => "Rpathname\nwith LF.1" | 0 - pathname.2 => Rpathname with SP.0 | 0 - "pathname\twith HT.2" => Rpathname with SP.1 | 0 - pathname.0 => Rpathname.0 | 0 - "pathname\twith HT.0" => Rpathname.1 | 0 - 7 files changed, 0 insertions(+), 0 deletions(-) -EOF +test_expect_success TABS_IN_FILENAMES 'git diff --numstat -M HEAD' ' + cat >expect <<-\EOF && + 0 0 pathname.1 => "Rpathname\twith HT.0" + 0 0 pathname.3 => "Rpathname\nwith LF.0" + 0 0 "pathname\twith HT.3" => "Rpathname\nwith LF.1" + 0 0 pathname.2 => Rpathname with SP.0 + 0 0 "pathname\twith HT.2" => Rpathname with SP.1 + 0 0 pathname.0 => Rpathname.0 + 0 0 "pathname\twith HT.0" => Rpathname.1 + EOF + git diff --numstat -M HEAD >actual && + test_cmp expect actual ' test_expect_success TABS_IN_FILENAMES 'git diff --stat -M HEAD' ' + cat >expect <<-\EOF && + pathname.1 => "Rpathname\twith HT.0" | 0 + pathname.3 => "Rpathname\nwith LF.0" | 0 + "pathname\twith HT.3" => "Rpathname\nwith LF.1" | 0 + pathname.2 => Rpathname with SP.0 | 0 + "pathname\twith HT.2" => Rpathname with SP.1 | 0 + pathname.0 => Rpathname.0 | 0 + "pathname\twith HT.0" => Rpathname.1 | 0 + 7 files changed, 0 insertions(+), 0 deletions(-) + EOF git diff --stat -M HEAD >actual && - test_cmp expect actual + test_i18ncmp expect actual ' test_done diff --git a/t/t4030-diff-textconv.sh b/t/t4030-diff-textconv.sh index 4ac162cfcf..06b05df848 100755 --- a/t/t4030-diff-textconv.sh +++ b/t/t4030-diff-textconv.sh @@ -91,7 +91,11 @@ EOF test_expect_success 'diffstat does not run textconv' ' echo file diff=fail >.gitattributes && git diff --stat HEAD^ HEAD >actual && - test_cmp expect.stat actual + test_i18ncmp expect.stat actual && + + head -n1 <expect.stat >expect.line1 && + head -n1 <actual >actual.line1 && + test_cmp expect.line1 actual.line1 ' # restore working setup echo file diff=foo >.gitattributes diff --git a/t/t4031-diff-rewrite-binary.sh b/t/t4031-diff-rewrite-binary.sh index 7d7470f21b..c8296fa4fc 100755 --- a/t/t4031-diff-rewrite-binary.sh +++ b/t/t4031-diff-rewrite-binary.sh @@ -44,10 +44,16 @@ test_expect_success 'rewrite diff can show binary patch' ' grep "GIT binary patch" diff ' -test_expect_success 'rewrite diff --stat shows binary changes' ' +test_expect_success 'rewrite diff --numstat shows binary changes' ' + git diff -B --numstat --summary >diff && + grep -e "- - " diff && + grep " rewrite file" diff +' + +test_expect_success 'diff --stat counts binary rewrite as 0 lines' ' git diff -B --stat --summary >diff && grep "Bin" diff && - grep "0 insertions.*0 deletions" diff && + test_i18ngrep "0 insertions.*0 deletions" diff && grep " rewrite file" diff ' diff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh index 5c2012111c..30d42cb3bf 100755 --- a/t/t4034-diff-words.sh +++ b/t/t4034-diff-words.sh @@ -3,6 +3,7 @@ test_description='word diff colors' . ./test-lib.sh +. "$TEST_DIRECTORY"/diff-lib.sh cat >pre.simple <<-\EOF h(4) @@ -293,6 +294,10 @@ test_expect_success '--word-diff=none' ' word_diff --word-diff=plain --word-diff=none ' +test_expect_success 'unset default driver' ' + test_unconfig diff.wordregex +' + test_language_driver bibtex test_language_driver cpp test_language_driver csharp @@ -348,4 +353,35 @@ test_expect_success 'word-diff with no newline at EOF' ' word_diff --word-diff=plain ' +test_expect_success 'setup history with two files' ' + echo "a b; c" >a.tex && + echo "a b; c" >z.txt && + git add a.tex z.txt && + git commit -minitial && + + # modify both + echo "a bx; c" >a.tex && + echo "a bx; c" >z.txt && + git commit -mmodified -a +' + +test_expect_success 'wordRegex for the first file does not apply to the second' ' + echo "*.tex diff=tex" >.gitattributes && + git config diff.tex.wordRegex "[a-z]+|." && + cat >expect <<-\EOF && + diff --git a/a.tex b/a.tex + --- a/a.tex + +++ b/a.tex + @@ -1 +1 @@ + a [-b-]{+bx+}; c + diff --git a/z.txt b/z.txt + --- a/z.txt + +++ b/z.txt + @@ -1 +1 @@ + a [-b;-]{+bx;+} c + EOF + git diff --word-diff HEAD~ >actual && + compare_diff_patch expect actual +' + test_done diff --git a/t/t4035-diff-quiet.sh b/t/t4035-diff-quiet.sh index e747e84227..cdb9202f57 100755 --- a/t/t4035-diff-quiet.sh +++ b/t/t4035-diff-quiet.sh @@ -15,65 +15,65 @@ test_expect_success 'setup' ' test_expect_success 'git diff-tree HEAD^ HEAD' ' git diff-tree --quiet HEAD^ HEAD >cnt - test $? = 1 && test $(wc -l <cnt) = 0 + test $? = 1 && test_line_count = 0 cnt ' test_expect_success 'git diff-tree HEAD^ HEAD -- a' ' git diff-tree --quiet HEAD^ HEAD -- a >cnt - test $? = 0 && test $(wc -l <cnt) = 0 + test $? = 0 && test_line_count = 0 cnt ' test_expect_success 'git diff-tree HEAD^ HEAD -- b' ' git diff-tree --quiet HEAD^ HEAD -- b >cnt - test $? = 1 && test $(wc -l <cnt) = 0 + test $? = 1 && test_line_count = 0 cnt ' # this diff outputs one line: sha1 of the given head test_expect_success 'echo HEAD | git diff-tree --stdin' ' echo $(git rev-parse HEAD) | git diff-tree --quiet --stdin >cnt - test $? = 1 && test $(wc -l <cnt) = 1 + test $? = 1 && test_line_count = 1 cnt ' test_expect_success 'git diff-tree HEAD HEAD' ' git diff-tree --quiet HEAD HEAD >cnt - test $? = 0 && test $(wc -l <cnt) = 0 + test $? = 0 && test_line_count = 0 cnt ' test_expect_success 'git diff-files' ' git diff-files --quiet >cnt - test $? = 0 && test $(wc -l <cnt) = 0 + test $? = 0 && test_line_count = 0 cnt ' test_expect_success 'git diff-index --cached HEAD' ' git diff-index --quiet --cached HEAD >cnt - test $? = 0 && test $(wc -l <cnt) = 0 + test $? = 0 && test_line_count = 0 cnt ' test_expect_success 'git diff-index --cached HEAD^' ' git diff-index --quiet --cached HEAD^ >cnt - test $? = 1 && test $(wc -l <cnt) = 0 + test $? = 1 && test_line_count = 0 cnt ' test_expect_success 'git diff-index --cached HEAD^' ' echo text >>b && echo 3 >c && git add . && { git diff-index --quiet --cached HEAD^ >cnt - test $? = 1 && test $(wc -l <cnt) = 0 + test $? = 1 && test_line_count = 0 cnt } ' test_expect_success 'git diff-tree -Stext HEAD^ HEAD -- b' ' git commit -m "text in b" && { git diff-tree --quiet -Stext HEAD^ HEAD -- b >cnt - test $? = 1 && test $(wc -l <cnt) = 0 + test $? = 1 && test_line_count = 0 cnt } ' test_expect_success 'git diff-tree -Snot-found HEAD^ HEAD -- b' ' git diff-tree --quiet -Snot-found HEAD^ HEAD -- b >cnt - test $? = 0 && test $(wc -l <cnt) = 0 + test $? = 0 && test_line_count = 0 cnt ' test_expect_success 'git diff-files' ' echo 3 >>c && { git diff-files --quiet >cnt - test $? = 1 && test $(wc -l <cnt) = 0 + test $? = 1 && test_line_count = 0 cnt } ' test_expect_success 'git diff-index --cached HEAD' ' git update-index c && { git diff-index --quiet --cached HEAD >cnt - test $? = 1 && test $(wc -l <cnt) = 0 + test $? = 1 && test_line_count = 0 cnt } ' diff --git a/t/t4043-diff-rename-binary.sh b/t/t4043-diff-rename-binary.sh index 06012811a1..2a2cf91352 100755 --- a/t/t4043-diff-rename-binary.sh +++ b/t/t4043-diff-rename-binary.sh @@ -23,9 +23,8 @@ test_expect_success 'move the files into a "sub" directory' ' ' cat > expected <<\EOF - bar => sub/bar | Bin 5 -> 5 bytes - foo => sub/foo | 0 - 2 files changed, 0 insertions(+), 0 deletions(-) +- - bar => sub/bar +0 0 foo => sub/foo diff --git a/bar b/sub/bar similarity index 100% @@ -38,7 +37,8 @@ rename to sub/foo EOF test_expect_success 'git show -C -C report renames' ' - git show -C -C --raw --binary --stat | tail -n 12 > current && + git show -C -C --raw --binary --numstat >patch-with-stat && + tail -n 11 patch-with-stat >current && test_cmp expected current ' diff --git a/t/t4045-diff-relative.sh b/t/t4045-diff-relative.sh index bd119be106..18fadcf06e 100755 --- a/t/t4045-diff-relative.sh +++ b/t/t4045-diff-relative.sh @@ -29,6 +29,18 @@ test_expect_success "-p $*" " " } +check_numstat() { +expect=$1; shift +cat >expected <<EOF +1 0 $expect +EOF +test_expect_success "--numstat $*" " + echo '1 0 $expect' >expected && + git diff --numstat $* HEAD^ >actual && + test_cmp expected actual +" +} + check_stat() { expect=$1; shift cat >expected <<EOF @@ -37,7 +49,7 @@ cat >expected <<EOF EOF test_expect_success "--stat $*" " git diff --stat $* HEAD^ >actual && - test_cmp expected actual + test_i18ncmp expected actual " } @@ -52,7 +64,7 @@ test_expect_success "--raw $*" " " } -for type in diff stat raw; do +for type in diff numstat stat raw; do check_$type file2 --relative=subdir/ check_$type file2 --relative=subdir check_$type dir/file2 --relative=sub diff --git a/t/t4047-diff-dirstat.sh b/t/t4047-diff-dirstat.sh index 29e80a58cd..ed7e093366 100755 --- a/t/t4047-diff-dirstat.sh +++ b/t/t4047-diff-dirstat.sh @@ -252,50 +252,47 @@ EOF ' cat <<EOF >expect_diff_stat - changed/text | 2 +- - dst/copy/changed/text | 10 ++++++++++ - dst/copy/rearranged/text | 10 ++++++++++ - dst/copy/unchanged/text | 10 ++++++++++ - dst/move/changed/text | 10 ++++++++++ - dst/move/rearranged/text | 10 ++++++++++ - dst/move/unchanged/text | 10 ++++++++++ - rearranged/text | 2 +- - src/move/changed/text | 10 ---------- - src/move/rearranged/text | 10 ---------- - src/move/unchanged/text | 10 ---------- - 11 files changed, 62 insertions(+), 32 deletions(-) +1 1 changed/text +10 0 dst/copy/changed/text +10 0 dst/copy/rearranged/text +10 0 dst/copy/unchanged/text +10 0 dst/move/changed/text +10 0 dst/move/rearranged/text +10 0 dst/move/unchanged/text +1 1 rearranged/text +0 10 src/move/changed/text +0 10 src/move/rearranged/text +0 10 src/move/unchanged/text EOF cat <<EOF >expect_diff_stat_M - changed/text | 2 +- - dst/copy/changed/text | 10 ++++++++++ - dst/copy/rearranged/text | 10 ++++++++++ - dst/copy/unchanged/text | 10 ++++++++++ - {src => dst}/move/changed/text | 2 +- - {src => dst}/move/rearranged/text | 2 +- - {src => dst}/move/unchanged/text | 0 - rearranged/text | 2 +- - 8 files changed, 34 insertions(+), 4 deletions(-) +1 1 changed/text +10 0 dst/copy/changed/text +10 0 dst/copy/rearranged/text +10 0 dst/copy/unchanged/text +1 1 {src => dst}/move/changed/text +1 1 {src => dst}/move/rearranged/text +0 0 {src => dst}/move/unchanged/text +1 1 rearranged/text EOF cat <<EOF >expect_diff_stat_CC - changed/text | 2 +- - {src => dst}/copy/changed/text | 2 +- - {src => dst}/copy/rearranged/text | 2 +- - {src => dst}/copy/unchanged/text | 0 - {src => dst}/move/changed/text | 2 +- - {src => dst}/move/rearranged/text | 2 +- - {src => dst}/move/unchanged/text | 0 - rearranged/text | 2 +- - 8 files changed, 6 insertions(+), 6 deletions(-) -EOF - -test_expect_success 'sanity check setup (--stat)' ' - git diff --stat HEAD^..HEAD >actual_diff_stat && +1 1 changed/text +1 1 {src => dst}/copy/changed/text +1 1 {src => dst}/copy/rearranged/text +0 0 {src => dst}/copy/unchanged/text +1 1 {src => dst}/move/changed/text +1 1 {src => dst}/move/rearranged/text +0 0 {src => dst}/move/unchanged/text +1 1 rearranged/text +EOF + +test_expect_success 'sanity check setup (--numstat)' ' + git diff --numstat HEAD^..HEAD >actual_diff_stat && test_cmp expect_diff_stat actual_diff_stat && - git diff --stat -M HEAD^..HEAD >actual_diff_stat_M && + git diff --numstat -M HEAD^..HEAD >actual_diff_stat_M && test_cmp expect_diff_stat_M actual_diff_stat_M && - git diff --stat -C -C HEAD^..HEAD >actual_diff_stat_CC && + git diff --numstat -C -C HEAD^..HEAD >actual_diff_stat_CC && test_cmp expect_diff_stat_CC actual_diff_stat_CC ' diff --git a/t/t4049-diff-stat-count.sh b/t/t4049-diff-stat-count.sh index a6d1887536..591ffbc075 100755 --- a/t/t4049-diff-stat-count.sh +++ b/t/t4049-diff-stat-count.sh @@ -19,7 +19,7 @@ test_expect_success setup ' 2 files changed, 2 insertions(+) EOF git diff --stat --stat-count=2 >actual && - test_cmp expect actual + test_i18ncmp expect actual ' test_done diff --git a/t/t4100-apply-stat.sh b/t/t4100-apply-stat.sh index 9b433de836..744b8e51be 100755 --- a/t/t4100-apply-stat.sh +++ b/t/t4100-apply-stat.sh @@ -17,13 +17,13 @@ do test_expect_success "$title" ' git apply --stat --summary \ <"$TEST_DIRECTORY/t4100/t-apply-$num.patch" >current && - test_cmp "$TEST_DIRECTORY"/t4100/t-apply-$num.expect current + test_i18ncmp "$TEST_DIRECTORY"/t4100/t-apply-$num.expect current ' test_expect_success "$title with recount" ' sed -e "$UNC" <"$TEST_DIRECTORY/t4100/t-apply-$num.patch" | git apply --recount --stat --summary >current && - test_cmp "$TEST_DIRECTORY"/t4100/t-apply-$num.expect current + test_i18ncmp "$TEST_DIRECTORY"/t4100/t-apply-$num.expect current ' done <<\EOF rename diff --git a/t/t4150-am.sh b/t/t4150-am.sh index ccc0280f52..cdafd7e7c1 100755 --- a/t/t4150-am.sh +++ b/t/t4150-am.sh @@ -525,9 +525,9 @@ test_expect_success 'am empty-file does not infloop' ' git reset --hard && touch empty-file && test_tick && - { git am empty-file > actual 2>&1 && false || :; } && + test_must_fail git am empty-file 2>actual && echo Patch format detection failed. >expected && - test_cmp expected actual + test_i18ncmp expected actual ' test_done diff --git a/t/t4202-log.sh b/t/t4202-log.sh index 222f7559e9..32cf0bd218 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -516,4 +516,294 @@ test_expect_success 'show added path under "--follow -M"' ' ) ' +cat >expect <<\EOF +* commit COMMIT_OBJECT_NAME +|\ Merge: MERGE_PARENTS +| | Author: A U Thor <author@example.com> +| | +| | Merge HEADS DESCRIPTION +| | +| * commit COMMIT_OBJECT_NAME +| | Author: A U Thor <author@example.com> +| | +| | reach +| | --- +| | reach.t | 1 + +| | 1 file changed, 1 insertion(+) +| | +| | diff --git a/reach.t b/reach.t +| | new file mode 100644 +| | index 0000000..10c9591 +| | --- /dev/null +| | +++ b/reach.t +| | @@ -0,0 +1 @@ +| | +reach +| | +| \ +*-. \ commit COMMIT_OBJECT_NAME +|\ \ \ Merge: MERGE_PARENTS +| | | | Author: A U Thor <author@example.com> +| | | | +| | | | Merge HEADS DESCRIPTION +| | | | +| | * | commit COMMIT_OBJECT_NAME +| | |/ Author: A U Thor <author@example.com> +| | | +| | | octopus-b +| | | --- +| | | octopus-b.t | 1 + +| | | 1 file changed, 1 insertion(+) +| | | +| | | diff --git a/octopus-b.t b/octopus-b.t +| | | new file mode 100644 +| | | index 0000000..d5fcad0 +| | | --- /dev/null +| | | +++ b/octopus-b.t +| | | @@ -0,0 +1 @@ +| | | +octopus-b +| | | +| * | commit COMMIT_OBJECT_NAME +| |/ Author: A U Thor <author@example.com> +| | +| | octopus-a +| | --- +| | octopus-a.t | 1 + +| | 1 file changed, 1 insertion(+) +| | +| | diff --git a/octopus-a.t b/octopus-a.t +| | new file mode 100644 +| | index 0000000..11ee015 +| | --- /dev/null +| | +++ b/octopus-a.t +| | @@ -0,0 +1 @@ +| | +octopus-a +| | +* | commit COMMIT_OBJECT_NAME +|/ Author: A U Thor <author@example.com> +| +| seventh +| --- +| seventh.t | 1 + +| 1 file changed, 1 insertion(+) +| +| diff --git a/seventh.t b/seventh.t +| new file mode 100644 +| index 0000000..9744ffc +| --- /dev/null +| +++ b/seventh.t +| @@ -0,0 +1 @@ +| +seventh +| +* commit COMMIT_OBJECT_NAME +|\ Merge: MERGE_PARENTS +| | Author: A U Thor <author@example.com> +| | +| | Merge branch 'tangle' +| | +| * commit COMMIT_OBJECT_NAME +| |\ Merge: MERGE_PARENTS +| | | Author: A U Thor <author@example.com> +| | | +| | | Merge branch 'side' (early part) into tangle +| | | +| * | commit COMMIT_OBJECT_NAME +| |\ \ Merge: MERGE_PARENTS +| | | | Author: A U Thor <author@example.com> +| | | | +| | | | Merge branch 'master' (early part) into tangle +| | | | +| * | | commit COMMIT_OBJECT_NAME +| | | | Author: A U Thor <author@example.com> +| | | | +| | | | tangle-a +| | | | --- +| | | | tangle-a | 1 + +| | | | 1 file changed, 1 insertion(+) +| | | | +| | | | diff --git a/tangle-a b/tangle-a +| | | | new file mode 100644 +| | | | index 0000000..7898192 +| | | | --- /dev/null +| | | | +++ b/tangle-a +| | | | @@ -0,0 +1 @@ +| | | | +a +| | | | +* | | | commit COMMIT_OBJECT_NAME +|\ \ \ \ Merge: MERGE_PARENTS +| | | | | Author: A U Thor <author@example.com> +| | | | | +| | | | | Merge branch 'side' +| | | | | +| * | | | commit COMMIT_OBJECT_NAME +| | |_|/ Author: A U Thor <author@example.com> +| |/| | +| | | | side-2 +| | | | --- +| | | | 2 | 1 + +| | | | 1 file changed, 1 insertion(+) +| | | | +| | | | diff --git a/2 b/2 +| | | | new file mode 100644 +| | | | index 0000000..0cfbf08 +| | | | --- /dev/null +| | | | +++ b/2 +| | | | @@ -0,0 +1 @@ +| | | | +2 +| | | | +| * | | commit COMMIT_OBJECT_NAME +| | | | Author: A U Thor <author@example.com> +| | | | +| | | | side-1 +| | | | --- +| | | | 1 | 1 + +| | | | 1 file changed, 1 insertion(+) +| | | | +| | | | diff --git a/1 b/1 +| | | | new file mode 100644 +| | | | index 0000000..d00491f +| | | | --- /dev/null +| | | | +++ b/1 +| | | | @@ -0,0 +1 @@ +| | | | +1 +| | | | +* | | | commit COMMIT_OBJECT_NAME +| | | | Author: A U Thor <author@example.com> +| | | | +| | | | Second +| | | | --- +| | | | one | 1 + +| | | | 1 file changed, 1 insertion(+) +| | | | +| | | | diff --git a/one b/one +| | | | new file mode 100644 +| | | | index 0000000..9a33383 +| | | | --- /dev/null +| | | | +++ b/one +| | | | @@ -0,0 +1 @@ +| | | | +case +| | | | +* | | | commit COMMIT_OBJECT_NAME +| |_|/ Author: A U Thor <author@example.com> +|/| | +| | | sixth +| | | --- +| | | a/two | 1 - +| | | 1 file changed, 1 deletion(-) +| | | +| | | diff --git a/a/two b/a/two +| | | deleted file mode 100644 +| | | index 9245af5..0000000 +| | | --- a/a/two +| | | +++ /dev/null +| | | @@ -1 +0,0 @@ +| | | -ni +| | | +* | | commit COMMIT_OBJECT_NAME +| | | Author: A U Thor <author@example.com> +| | | +| | | fifth +| | | --- +| | | a/two | 1 + +| | | 1 file changed, 1 insertion(+) +| | | +| | | diff --git a/a/two b/a/two +| | | new file mode 100644 +| | | index 0000000..9245af5 +| | | --- /dev/null +| | | +++ b/a/two +| | | @@ -0,0 +1 @@ +| | | +ni +| | | +* | | commit COMMIT_OBJECT_NAME +|/ / Author: A U Thor <author@example.com> +| | +| | fourth +| | --- +| | ein | 1 + +| | 1 file changed, 1 insertion(+) +| | +| | diff --git a/ein b/ein +| | new file mode 100644 +| | index 0000000..9d7e69f +| | --- /dev/null +| | +++ b/ein +| | @@ -0,0 +1 @@ +| | +ichi +| | +* | commit COMMIT_OBJECT_NAME +|/ Author: A U Thor <author@example.com> +| +| third +| --- +| ichi | 1 + +| one | 1 - +| 2 files changed, 1 insertion(+), 1 deletion(-) +| +| diff --git a/ichi b/ichi +| new file mode 100644 +| index 0000000..9d7e69f +| --- /dev/null +| +++ b/ichi +| @@ -0,0 +1 @@ +| +ichi +| diff --git a/one b/one +| deleted file mode 100644 +| index 9d7e69f..0000000 +| --- a/one +| +++ /dev/null +| @@ -1 +0,0 @@ +| -ichi +| +* commit COMMIT_OBJECT_NAME +| Author: A U Thor <author@example.com> +| +| second +| --- +| one | 2 +- +| 1 file changed, 1 insertion(+), 1 deletion(-) +| +| diff --git a/one b/one +| index 5626abf..9d7e69f 100644 +| --- a/one +| +++ b/one +| @@ -1 +1 @@ +| -one +| +ichi +| +* commit COMMIT_OBJECT_NAME + Author: A U Thor <author@example.com> + + initial + --- + one | 1 + + 1 file changed, 1 insertion(+) + + diff --git a/one b/one + new file mode 100644 + index 0000000..5626abf + --- /dev/null + +++ b/one + @@ -0,0 +1 @@ + +one +EOF + +sanitize_output () { + sed -e 's/ *$//' \ + -e 's/commit [0-9a-f]*$/commit COMMIT_OBJECT_NAME/' \ + -e 's/Merge: [ 0-9a-f]*$/Merge: MERGE_PARENTS/' \ + -e 's/Merge tag.*/Merge HEADS DESCRIPTION/' \ + -e 's/Merge commit.*/Merge HEADS DESCRIPTION/' \ + -e 's/, 0 deletions(-)//' \ + -e 's/, 0 insertions(+)//' \ + -e 's/ 1 files changed, / 1 file changed, /' \ + -e 's/, 1 deletions(-)/, 1 deletion(-)/' \ + -e 's/, 1 insertions(+)/, 1 insertion(+)/' +} + +test_expect_success 'log --graph with diff and stats' ' + git log --graph --pretty=short --stat -p >actual && + sanitize_output >actual.sanitized <actual && + test_cmp expect actual.sanitized +' + test_done diff --git a/t/t5100-mailinfo.sh b/t/t5100-mailinfo.sh index ebc36c1758..81904d9ec8 100755 --- a/t/t5100-mailinfo.sh +++ b/t/t5100-mailinfo.sh @@ -65,7 +65,7 @@ test_expect_success 'respect NULs' ' git mailsplit -d3 -o. "$TEST_DIRECTORY"/t5100/nul-plain && test_cmp "$TEST_DIRECTORY"/t5100/nul-plain 001 && (cat 001 | git mailinfo msg patch) && - test 4 = $(wc -l < patch) + test_line_count = 4 patch ' diff --git a/t/t5150-request-pull.sh b/t/t5150-request-pull.sh index 2af8947eeb..432f98c357 100755 --- a/t/t5150-request-pull.sh +++ b/t/t5150-request-pull.sh @@ -216,7 +216,7 @@ test_expect_success 'pull request format' ' git request-pull initial "$downstream_url" >../request ) && <request sed -nf fuzz.sed >request.fuzzy && - test_cmp expect request.fuzzy + test_i18ncmp expect request.fuzzy ' diff --git a/t/t5528-push-default.sh b/t/t5528-push-default.sh new file mode 100755 index 0000000000..c334c51a07 --- /dev/null +++ b/t/t5528-push-default.sh @@ -0,0 +1,54 @@ +#!/bin/sh + +test_description='check various push.default settings' +. ./test-lib.sh + +test_expect_success 'setup bare remotes' ' + git init --bare repo1 && + git remote add parent1 repo1 && + git init --bare repo2 && + git remote add parent2 repo2 && + test_commit one && + git push parent1 HEAD && + git push parent2 HEAD +' + +test_expect_success '"upstream" pushes to configured upstream' ' + git checkout master && + test_config branch.master.remote parent1 && + test_config branch.master.merge refs/heads/foo && + test_config push.default upstream && + test_commit two && + git push && + echo two >expect && + git --git-dir=repo1 log -1 --format=%s foo >actual && + test_cmp expect actual +' + +test_expect_success '"upstream" does not push on unconfigured remote' ' + git checkout master && + test_unconfig branch.master.remote && + test_config push.default upstream && + test_commit three && + test_must_fail git push +' + +test_expect_success '"upstream" does not push on unconfigured branch' ' + git checkout master && + test_config branch.master.remote parent1 && + test_unconfig branch.master.merge && + test_config push.default upstream + test_commit four && + test_must_fail git push +' + +test_expect_success '"upstream" does not push when remotes do not match' ' + git checkout master && + test_config branch.master.remote parent1 && + test_config branch.master.merge refs/heads/foo && + test_config push.default upstream && + test_commit five && + test_must_fail git push parent2 +' + +test_done diff --git a/t/t5541-http-push.sh b/t/t5541-http-push.sh index cc6f081711..5b170be2c0 100755 --- a/t/t5541-http-push.sh +++ b/t/t5541-http-push.sh @@ -30,6 +30,7 @@ test_expect_success 'setup remote repository' ' git clone --bare test_repo test_repo.git && cd test_repo.git && git config http.receivepack true && + git config core.logallrefupdates true && ORIG_HEAD=$(git rev-parse --verify HEAD) && cd - && mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH" @@ -167,7 +168,7 @@ test_expect_success 'push fails for non-fast-forward refs unmatched by remote he ' test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper: our output' ' - test_i18ngrep "To prevent you from losing history, non-fast-forward updates were rejected" \ + test_i18ngrep "Updates were rejected because" \ output ' @@ -222,5 +223,25 @@ test_expect_success TTY 'quiet push' ' test_cmp /dev/null output ' +test_expect_success 'http push gives sane defaults to reflog' ' + cd "$ROOT_PATH"/test_repo_clone && + test_commit reflog-test && + git push "$HTTPD_URL"/smart/test_repo.git && + git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \ + log -g -1 --format="%gn <%ge>" >actual && + echo "anonymous <anonymous@http.127.0.0.1>" >expect && + test_cmp expect actual +' + +test_expect_success 'http push respects GIT_COMMITTER_* in reflog' ' + cd "$ROOT_PATH"/test_repo_clone && + test_commit custom-reflog-test && + git push "$HTTPD_URL"/smart_custom_env/test_repo.git && + git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \ + log -g -1 --format="%gn <%ge>" >actual && + echo "Custom User <custom@example.com>" >expect && + test_cmp expect actual +' + stop_httpd test_done diff --git a/t/t5700-clone-reference.sh b/t/t5700-clone-reference.sh index bbc4691bd7..c47d450cc3 100755 --- a/t/t5700-clone-reference.sh +++ b/t/t5700-clone-reference.sh @@ -34,7 +34,7 @@ test_expect_success 'cloning with reference (-l -s)' \ cd "$base_dir" test_expect_success 'existence of info/alternates' \ -'test `wc -l <C/.git/objects/info/alternates` = 2' +'test_line_count = 2 C/.git/objects/info/alternates' cd "$base_dir" @@ -63,7 +63,7 @@ test_expect_success 'fetched no objects' \ cd "$base_dir" test_expect_success 'existence of info/alternates' \ -'test `wc -l <D/.git/objects/info/alternates` = 1' +'test_line_count = 1 D/.git/objects/info/alternates' cd "$base_dir" diff --git a/t/t5710-info-alternate.sh b/t/t5710-info-alternate.sh index ef7127c1b3..aa045295de 100755 --- a/t/t5710-info-alternate.sh +++ b/t/t5710-info-alternate.sh @@ -18,7 +18,7 @@ reachable_via() { test_valid_repo() { git fsck --full > fsck.log && - test `wc -l < fsck.log` = 0 + test_line_count = 0 fsck.log } base_dir=`pwd` diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh index 444279077e..a01d244502 100755 --- a/t/t6006-rev-list-format.sh +++ b/t/t6006-rev-list-format.sh @@ -188,23 +188,23 @@ test_expect_success 'empty email' ' test_expect_success 'del LF before empty (1)' ' git show -s --pretty=format:"%s%n%-b%nThanks%n" HEAD^^ >actual && - test $(wc -l <actual) = 2 + test_line_count = 2 actual ' test_expect_success 'del LF before empty (2)' ' git show -s --pretty=format:"%s%n%-b%nThanks%n" HEAD >actual && - test $(wc -l <actual) = 6 && + test_line_count = 6 actual && grep "^$" actual ' test_expect_success 'add LF before non-empty (1)' ' git show -s --pretty=format:"%s%+b%nThanks%n" HEAD^^ >actual && - test $(wc -l <actual) = 2 + test_line_count = 2 actual ' test_expect_success 'add LF before non-empty (2)' ' git show -s --pretty=format:"%s%+b%nThanks%n" HEAD >actual && - test $(wc -l <actual) = 6 && + test_line_count = 6 actual && grep "^$" actual ' @@ -278,8 +278,9 @@ test_expect_success 'oneline with empty message' ' git commit -m "dummy" --allow-empty && git filter-branch --msg-filter "sed -e s/dummy//" HEAD^^.. && git rev-list --oneline HEAD >test.txt && - test $(git rev-list --oneline HEAD | wc -l) -eq 5 && - test $(git rev-list --oneline --graph HEAD | wc -l) -eq 5 + test_line_count = 5 test.txt && + git rev-list --oneline --graph HEAD >testg.txt && + test_line_count = 5 testg.txt ' test_done diff --git a/t/t6022-merge-rename.sh b/t/t6022-merge-rename.sh index 9d8584e957..1104249182 100755 --- a/t/t6022-merge-rename.sh +++ b/t/t6022-merge-rename.sh @@ -884,4 +884,20 @@ test_expect_success 'no spurious "refusing to lose untracked" message' ' ! grep "refusing to lose untracked file" errors.txt ' +test_expect_success 'do not follow renames for empty files' ' + git checkout -f -b empty-base && + >empty1 && + git add empty1 && + git commit -m base && + echo content >empty1 && + git add empty1 && + git commit -m fill && + git checkout -b empty-topic HEAD^ && + git mv empty1 empty2 && + git commit -m rename && + test_must_fail git merge empty-base && + >expect && + test_cmp expect empty2 +' + test_done diff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh index 691e4a4481..72e28ee535 100755 --- a/t/t6030-bisect-porcelain.sh +++ b/t/t6030-bisect-porcelain.sh @@ -480,7 +480,7 @@ test_expect_success 'many merge bases creation' ' git merge -m "merge HASH7 and SIDE_HASH7" "$HASH7" && B_HASH=$(git rev-parse --verify HEAD) && git merge-base --all "$A_HASH" "$B_HASH" > merge_bases.txt && - test $(wc -l < merge_bases.txt) = "2" && + test_line_count = 2 merge_bases.txt && grep "$HASH5" merge_bases.txt && grep "$SIDE_HASH5" merge_bases.txt ' diff --git a/t/t6032-merge-large-rename.sh b/t/t6032-merge-large-rename.sh index 94f010be8a..15beecc3c6 100755 --- a/t/t6032-merge-large-rename.sh +++ b/t/t6032-merge-large-rename.sh @@ -97,7 +97,7 @@ test_expect_success 'setup large simple rename' ' test_expect_success 'massive simple rename does not spam added files' ' sane_unset GIT_MERGE_VERBOSITY && git merge --no-stat simple-rename | grep -v Removing >output && - test 5 -gt "$(wc -l < output)" + test_line_count -lt 5 output ' test_done diff --git a/t/t6040-tracking-info.sh b/t/t6040-tracking-info.sh index 19272bc551..ec2b516c3f 100755 --- a/t/t6040-tracking-info.sh +++ b/t/t6040-tracking-info.sh @@ -71,13 +71,13 @@ test_expect_success 'checkout' ' ( cd test && git checkout b1 ) >actual && - grep "have 1 and 1 different" actual + test_i18ngrep "have 1 and 1 different" actual ' test_expect_success 'checkout with local tracked branch' ' git checkout master && git checkout follower >actual && - grep "is ahead of" actual + test_i18ngrep "is ahead of" actual ' test_expect_success 'status' ' @@ -87,14 +87,14 @@ test_expect_success 'status' ' # reports nothing to commit test_must_fail git commit --dry-run ) >actual && - grep "have 1 and 1 different" actual + test_i18ngrep "have 1 and 1 different" actual ' test_expect_success 'fail to track lightweight tags' ' git checkout master && git tag light && test_must_fail git branch --track lighttrack light >actual && - test_must_fail grep "set up to track" actual && + test_i18ngrep ! "set up to track" actual && test_must_fail git checkout lighttrack ' @@ -102,7 +102,7 @@ test_expect_success 'fail to track annotated tags' ' git checkout master && git tag -m heavy heavy && test_must_fail git branch --track heavytrack heavy >actual && - test_must_fail grep "set up to track" actual && + test_i18ngrep ! "set up to track" actual && test_must_fail git checkout heavytrack ' diff --git a/t/t6042-merge-rename-corner-cases.sh b/t/t6042-merge-rename-corner-cases.sh index 32591f9413..466fa3804b 100755 --- a/t/t6042-merge-rename-corner-cases.sh +++ b/t/t6042-merge-rename-corner-cases.sh @@ -104,7 +104,7 @@ test_expect_failure 'conflict caused if rename not detected' ' test 0 -eq $(git ls-files -u | wc -l) && test 0 -eq $(git ls-files -o | wc -l) && - test 6 -eq $(wc -l < c) && + test_line_count = 6 c && test $(git rev-parse HEAD:a) = $(git rev-parse B:a) && test $(git rev-parse HEAD:b) = $(git rev-parse A:b) ' diff --git a/t/t6200-fmt-merge-msg.sh b/t/t6200-fmt-merge-msg.sh index 9a16806921..9b50f54cc2 100755 --- a/t/t6200-fmt-merge-msg.sh +++ b/t/t6200-fmt-merge-msg.sh @@ -35,15 +35,18 @@ test_expect_success setup ' echo "l3" >two && test_tick && - git commit -a -m "Left #3" && + GIT_COMMITTER_NAME="Another Committer" \ + GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #3" && echo "l4" >two && test_tick && - git commit -a -m "Left #4" && + GIT_COMMITTER_NAME="Another Committer" \ + GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #4" && echo "l5" >two && test_tick && - git commit -a -m "Left #5" && + GIT_COMMITTER_NAME="Another Committer" \ + GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #5" && git tag tag-l5 && git checkout right && @@ -99,6 +102,8 @@ test_expect_success '[merge] summary/log configuration' ' cat >expected <<-EOF && Merge branch ${apos}left${apos} + By Another Author (3) and A U Thor (2) + via Another Committer * left: Left #5 Left #4 @@ -144,6 +149,8 @@ test_expect_success 'merge.log=3 limits shortlog length' ' cat >expected <<-EOF && Merge branch ${apos}left${apos} + By Another Author (3) and A U Thor (2) + via Another Committer * left: (5 commits) Left #5 Left #4 @@ -159,6 +166,8 @@ test_expect_success 'merge.log=5 shows all 5 commits' ' cat >expected <<-EOF && Merge branch ${apos}left${apos} + By Another Author (3) and A U Thor (2) + via Another Committer * left: Left #5 Left #4 @@ -181,6 +190,8 @@ test_expect_success '--log=3 limits shortlog length' ' cat >expected <<-EOF && Merge branch ${apos}left${apos} + By Another Author (3) and A U Thor (2) + via Another Committer * left: (5 commits) Left #5 Left #4 @@ -196,6 +207,8 @@ test_expect_success '--log=5 shows all 5 commits' ' cat >expected <<-EOF && Merge branch ${apos}left${apos} + By Another Author (3) and A U Thor (2) + via Another Committer * left: Left #5 Left #4 @@ -225,6 +238,8 @@ test_expect_success 'fmt-merge-msg -m' ' cat >expected.log <<-EOF && Sync with left + By Another Author (3) and A U Thor (2) + via Another Committer * ${apos}left${apos} of $(pwd): Left #5 Left #4 @@ -256,6 +271,8 @@ test_expect_success 'setup: expected shortlog for two branches' ' cat >expected <<-EOF Merge branches ${apos}left${apos} and ${apos}right${apos} + By Another Author (3) and A U Thor (2) + via Another Committer * left: Left #5 Left #4 @@ -379,6 +396,8 @@ test_expect_success 'merge-msg two tags' ' Common #2 Common #1 + By Another Author (3) and A U Thor (2) + via Another Committer * tag ${apos}tag-l5${apos}: Left #5 Left #4 @@ -407,6 +426,8 @@ test_expect_success 'merge-msg tag and branch' ' Common #2 Common #1 + By Another Author (3) and A U Thor (2) + via Another Committer * left: Left #5 Left #4 diff --git a/t/t7201-co.sh b/t/t7201-co.sh index 07fb53adcb..be9672e5a0 100755 --- a/t/t7201-co.sh +++ b/t/t7201-co.sh @@ -229,7 +229,7 @@ test_expect_success 'checkout to detach HEAD (with advice declined)' ' git checkout -f renamer && git clean -f && git checkout renamer^ 2>messages && test_i18ngrep "HEAD is now at 7329388" messages && - test 1 -eq $(wc -l <messages) && + test_line_count = 1 messages && H=$(git rev-parse --verify HEAD) && M=$(git show-ref -s --verify refs/heads/master) && test "z$H" = "z$M" && @@ -247,7 +247,7 @@ test_expect_success 'checkout to detach HEAD' ' git checkout -f renamer && git clean -f && git checkout renamer^ 2>messages && test_i18ngrep "HEAD is now at 7329388" messages && - test 1 -lt $(wc -l <messages) && + test_line_count -gt 1 messages && H=$(git rev-parse --verify HEAD) && M=$(git show-ref -s --verify refs/heads/master) && test "z$H" = "z$M" && diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh index 800b5368a5..ccfb54de7a 100755 --- a/t/t7300-clean.sh +++ b/t/t7300-clean.sh @@ -399,8 +399,8 @@ test_expect_success SANITY 'removal failure' ' ' test_expect_success 'nested git work tree' ' - rm -fr foo bar && - mkdir foo bar && + rm -fr foo bar baz && + mkdir -p foo bar baz/boo && ( cd foo && git init && @@ -412,15 +412,24 @@ test_expect_success 'nested git work tree' ' cd bar && >goodbye.people ) && + ( + cd baz/boo && + git init && + >deeper.world + git add . && + git commit -a -m deeply.nested + ) && git clean -f -d && test -f foo/.git/index && test -f foo/hello.world && + test -f baz/boo/.git/index && + test -f baz/boo/deeper.world && ! test -d bar ' test_expect_success 'force removal of nested git work tree' ' - rm -fr foo bar && - mkdir foo bar && + rm -fr foo bar baz && + mkdir -p foo bar baz/boo && ( cd foo && git init && @@ -432,9 +441,17 @@ test_expect_success 'force removal of nested git work tree' ' cd bar && >goodbye.people ) && + ( + cd baz/boo && + git init && + >deeper.world + git add . && + git commit -a -m deeply.nested + ) && git clean -f -f -d && ! test -d foo && - ! test -d bar + ! test -d bar && + ! test -d baz ' test_expect_success 'git clean -e' ' diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index b377a7af28..81827e696f 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -234,7 +234,7 @@ EOF test_expect_success 'status should only print one line' ' git submodule status >lines && - test $(wc -l <lines) = 1 + test_line_count = 1 lines ' test_expect_success 'setup - fetch commit name from submodule' ' diff --git a/t/t7408-submodule-reference.sh b/t/t7408-submodule-reference.sh index ab37c368d0..a45fadc58e 100755 --- a/t/t7408-submodule-reference.sh +++ b/t/t7408-submodule-reference.sh @@ -43,7 +43,7 @@ git commit -m B-super-added' cd "$base_dir" test_expect_success 'after add: existence of info/alternates' \ -'test `wc -l <super/.git/modules/sub/objects/info/alternates` = 1' +'test_line_count = 1 super/.git/modules/sub/objects/info/alternates' cd "$base_dir" @@ -66,7 +66,7 @@ test_expect_success 'update with reference' \ cd "$base_dir" test_expect_success 'after update: existence of info/alternates' \ -'test `wc -l <super-clone/.git/modules/sub/objects/info/alternates` = 1' +'test_line_count = 1 super-clone/.git/modules/sub/objects/info/alternates' cd "$base_dir" diff --git a/t/t7501-commit.sh b/t/t7501-commit.sh index 8bb38337a9..b20ca0eace 100755 --- a/t/t7501-commit.sh +++ b/t/t7501-commit.sh @@ -30,10 +30,12 @@ test_expect_success 'setup: initial commit' ' ' test_expect_success '-m and -F do not mix' ' + git checkout HEAD file && echo >>file && git add file && test_must_fail git commit -m foo -m bar -F file ' test_expect_success '-m and -C do not mix' ' + git checkout HEAD file && echo >>file && git add file && test_must_fail git commit -C HEAD -m illegal ' @@ -79,7 +81,19 @@ test_expect_success 'empty commit message' ' test_must_fail git commit -F msg -a ' +test_expect_success 'template "emptyness" check does not kick in with -F' ' + git checkout HEAD file && echo >>file && git add file && + git commit -t file -F file +' + +test_expect_success 'template "emptyness" check' ' + git checkout HEAD file && echo >>file && git add file && + test_must_fail git commit -t file 2>err && + test_i18ngrep "did not edit" err +' + test_expect_success 'setup: commit message from file' ' + git checkout HEAD file && echo >>file && git add file && echo this is the commit message, coming from a file >msg && git commit -F msg -a ' diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh index 3f3adc31b9..181456aa9a 100755 --- a/t/t7502-commit.sh +++ b/t/t7502-commit.sh @@ -335,7 +335,7 @@ test_expect_success 'A single-liner subject with a token plus colon is not a foo git reset --hard && git commit -s -m "hello: kitty" --allow-empty && git cat-file commit HEAD | sed -e "1,/^$/d" >actual && - test $(wc -l <actual) = 3 + test_line_count = 3 actual ' diff --git a/t/t7503-pre-commit-hook.sh b/t/t7503-pre-commit-hook.sh index ee7f0cd459..984889b39d 100755 --- a/t/t7503-pre-commit-hook.sh +++ b/t/t7503-pre-commit-hook.sh @@ -118,4 +118,22 @@ test_expect_success 'with failing hook requiring GIT_PREFIX' ' git checkout -- file ' +test_expect_success 'check the author in hook' ' + write_script "$HOOK" <<-\EOF && + test "$GIT_AUTHOR_NAME" = "New Author" && + test "$GIT_AUTHOR_EMAIL" = "newauthor@example.com" + EOF + test_must_fail git commit --allow-empty -m "by a.u.thor" && + ( + GIT_AUTHOR_NAME="New Author" && + GIT_AUTHOR_EMAIL="newauthor@example.com" && + export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL && + git commit --allow-empty -m "by new.author via env" && + git show -s + ) && + git commit --author="New Author <newauthor@example.com>" \ + --allow-empty -m "by new.author via command line" && + git show -s +' + test_done diff --git a/t/t7602-merge-octopus-many.sh b/t/t7602-merge-octopus-many.sh index 5783ebf3ab..bce0bd37cb 100755 --- a/t/t7602-merge-octopus-many.sh +++ b/t/t7602-merge-octopus-many.sh @@ -66,7 +66,7 @@ EOF test_expect_success 'merge output uses pretty names' ' git reset --hard c1 && git merge c2 c3 c4 >actual && - test_cmp actual expected + test_i18ncmp expected actual ' cat >expected <<\EOF @@ -80,7 +80,7 @@ EOF test_expect_success 'merge up-to-date output uses pretty names' ' git merge c4 c5 >actual && - test_cmp actual expected + test_i18ncmp expected actual ' cat >expected <<\EOF @@ -97,7 +97,7 @@ EOF test_expect_success 'merge fast-forward output uses pretty names' ' git reset --hard c0 && git merge c1 c2 >actual && - test_cmp actual expected + test_i18ncmp expected actual ' test_done diff --git a/t/t7607-merge-overwrite.sh b/t/t7607-merge-overwrite.sh index aa74184c31..6547eb8f54 100755 --- a/t/t7607-merge-overwrite.sh +++ b/t/t7607-merge-overwrite.sh @@ -92,6 +92,15 @@ test_expect_success 'will not overwrite removed file with staged changes' ' test_cmp important c1.c ' +test_expect_failure 'will not overwrite unstaged changes in renamed file' ' + git reset --hard c1 && + git mv c1.c other.c && + git commit -m rename && + cp important other.c && + git merge c1a && + test_cmp important other.c +' + test_expect_success 'will not overwrite untracked subtree' ' git reset --hard c0 && rm -rf sub && diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh index 4fb4c9384a..2763d795f0 100755 --- a/t/t7800-difftool.sh +++ b/t/t7800-difftool.sh @@ -83,6 +83,17 @@ test_expect_success PERL 'difftool ignores bad --tool values' ' test "$diff" = "" ' +test_expect_success PERL 'difftool forwards arguments to diff' ' + >for-diff && + git add for-diff && + echo changes>for-diff && + git add for-diff && + diff=$(git difftool --cached --no-prompt -- for-diff) && + test "$diff" = "" && + git reset -- for-diff && + rm for-diff +' + test_expect_success PERL 'difftool honors --gui' ' git config merge.tool bogus-tool && git config diff.tool bogus-tool && diff --git a/t/t9350-fast-export.sh b/t/t9350-fast-export.sh index 950d0ff498..b00196bd23 100755 --- a/t/t9350-fast-export.sh +++ b/t/t9350-fast-export.sh @@ -86,7 +86,7 @@ test_expect_success 'import/export-marks' ' git checkout -b marks master && git fast-export --export-marks=tmp-marks HEAD && test -s tmp-marks && - test $(wc -l < tmp-marks) -eq 3 && + test_line_count = 3 tmp-marks && test $( git fast-export --import-marks=tmp-marks\ --export-marks=tmp-marks HEAD | @@ -101,7 +101,7 @@ test_expect_success 'import/export-marks' ' grep ^commit\ | wc -l) \ -eq 1 && - test $(wc -l < tmp-marks) -eq 4 + test_line_count = 4 tmp-marks ' diff --git a/t/t9400-git-cvsserver-server.sh b/t/t9400-git-cvsserver-server.sh index 9199550ef4..d3e88f8dd6 100755 --- a/t/t9400-git-cvsserver-server.sh +++ b/t/t9400-git-cvsserver-server.sh @@ -476,14 +476,14 @@ test_expect_success 'cvs status' ' cd cvswork && GIT_CONFIG="$git_config" cvs update && GIT_CONFIG="$git_config" cvs status | grep "^File: status.file" >../out && - test $(wc -l <../out) = 2 + test_line_count = 2 ../out ' cd "$WORKDIR" test_expect_success 'cvs status (nonrecursive)' ' cd cvswork && GIT_CONFIG="$git_config" cvs status -l | grep "^File: status.file" >../out && - test $(wc -l <../out) = 1 + test_line_count = 1 ../out ' cd "$WORKDIR" diff --git a/t/t9501-gitweb-standalone-http-status.sh b/t/t9501-gitweb-standalone-http-status.sh index 31076edc5b..fa2f65f6be 100755 --- a/t/t9501-gitweb-standalone-http-status.sh +++ b/t/t9501-gitweb-standalone-http-status.sh @@ -92,7 +92,7 @@ test_debug 'cat gitweb.output' test_expect_success 'snapshots: bad tree-ish id (tagged object)' ' echo object > tag-object && git add tag-object && - git commit -m "Object to be tagged" && + test_tick && git commit -m "Object to be tagged" && git tag tagged-object `git hash-object tag-object` && gitweb_run "p=.git;a=snapshot;h=tagged-object;sf=tgz" && grep "400 - Object is not a tree-ish" gitweb.output @@ -112,6 +112,64 @@ test_expect_success 'snapshots: bad object id' ' ' test_debug 'cat gitweb.output' +# ---------------------------------------------------------------------- +# modification times (Last-Modified and If-Modified-Since) + +test_expect_success 'modification: feed last-modified' ' + gitweb_run "p=.git;a=atom;h=master" && + grep "Status: 200 OK" gitweb.headers && + grep "Last-modified: Thu, 7 Apr 2005 22:14:13 +0000" gitweb.headers +' +test_debug 'cat gitweb.headers' + +test_expect_success 'modification: feed if-modified-since (modified)' ' + export HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" && + test_when_finished "unset HTTP_IF_MODIFIED_SINCE" && + gitweb_run "p=.git;a=atom;h=master" && + grep "Status: 200 OK" gitweb.headers +' +test_debug 'cat gitweb.headers' + +test_expect_success 'modification: feed if-modified-since (unmodified)' ' + export HTTP_IF_MODIFIED_SINCE="Thu, 7 Apr 2005 22:14:13 +0000" && + test_when_finished "unset HTTP_IF_MODIFIED_SINCE" && + gitweb_run "p=.git;a=atom;h=master" && + grep "Status: 304 Not Modified" gitweb.headers +' +test_debug 'cat gitweb.headers' + +test_expect_success 'modification: snapshot last-modified' ' + gitweb_run "p=.git;a=snapshot;h=master;sf=tgz" && + grep "Status: 200 OK" gitweb.headers && + grep "Last-modified: Thu, 7 Apr 2005 22:14:13 +0000" gitweb.headers +' +test_debug 'cat gitweb.headers' + +test_expect_success 'modification: snapshot if-modified-since (modified)' ' + export HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" && + test_when_finished "unset HTTP_IF_MODIFIED_SINCE" && + gitweb_run "p=.git;a=snapshot;h=master;sf=tgz" && + grep "Status: 200 OK" gitweb.headers +' +test_debug 'cat gitweb.headers' + +test_expect_success 'modification: snapshot if-modified-since (unmodified)' ' + export HTTP_IF_MODIFIED_SINCE="Thu, 7 Apr 2005 22:14:13 +0000" && + test_when_finished "unset HTTP_IF_MODIFIED_SINCE" && + gitweb_run "p=.git;a=snapshot;h=master;sf=tgz" && + grep "Status: 304 Not Modified" gitweb.headers +' +test_debug 'cat gitweb.headers' + +test_expect_success 'modification: tree snapshot' ' + ID=`git rev-parse --verify HEAD^{tree}` && + export HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" && + test_when_finished "unset HTTP_IF_MODIFIED_SINCE" && + gitweb_run "p=.git;a=snapshot;h=$ID;sf=tgz" && + grep "Status: 200 OK" gitweb.headers && + ! grep -i "last-modified" gitweb.headers +' +test_debug 'cat gitweb.headers' # ---------------------------------------------------------------------- # load checking diff --git a/t/t9800-git-p4-basic.sh b/t/t9800-git-p4-basic.sh index 486c8eeb7e..13be144459 100755 --- a/t/t9800-git-p4-basic.sh +++ b/t/t9800-git-p4-basic.sh @@ -1,6 +1,6 @@ #!/bin/sh -test_description='git-p4 tests' +test_description='git p4 tests' . ./lib-git-p4.sh @@ -20,8 +20,8 @@ test_expect_success 'add p4 files' ' ) ' -test_expect_success 'basic git-p4 clone' ' - "$GITP4" clone --dest="$git" //depot && +test_expect_success 'basic git p4 clone' ' + git p4 clone --dest="$git" //depot && test_when_finished cleanup_git && ( cd "$git" && @@ -30,8 +30,8 @@ test_expect_success 'basic git-p4 clone' ' ) ' -test_expect_success 'git-p4 clone @all' ' - "$GITP4" clone --dest="$git" //depot@all && +test_expect_success 'git p4 clone @all' ' + git p4 clone --dest="$git" //depot@all && test_when_finished cleanup_git && ( cd "$git" && @@ -40,12 +40,12 @@ test_expect_success 'git-p4 clone @all' ' ) ' -test_expect_success 'git-p4 sync uninitialized repo' ' +test_expect_success 'git p4 sync uninitialized repo' ' test_create_repo "$git" && test_when_finished cleanup_git && ( cd "$git" && - test_must_fail "$GITP4" sync + test_must_fail git p4 sync ) ' @@ -53,13 +53,13 @@ test_expect_success 'git-p4 sync uninitialized repo' ' # Create a git repo by hand. Add a commit so that HEAD is valid. # Test imports a new p4 repository into a new git branch. # -test_expect_success 'git-p4 sync new branch' ' +test_expect_success 'git p4 sync new branch' ' test_create_repo "$git" && test_when_finished cleanup_git && ( cd "$git" && test_commit head && - "$GITP4" sync --branch=refs/remotes/p4/depot //depot@all && + git p4 sync --branch=refs/remotes/p4/depot //depot@all && git log --oneline p4/depot >lines && test_line_count = 2 lines ) @@ -76,7 +76,7 @@ test_expect_success 'clone two dirs' ' p4 add sub2/f2 && p4 submit -d "sub2/f2" ) && - "$GITP4" clone --dest="$git" //depot/sub1 //depot/sub2 && + git p4 clone --dest="$git" //depot/sub1 //depot/sub2 && test_when_finished cleanup_git && ( cd "$git" && @@ -94,7 +94,7 @@ test_expect_success 'clone two dirs, @all' ' p4 add sub1/f3 && p4 submit -d "sub1/f3" ) && - "$GITP4" clone --dest="$git" //depot/sub1@all //depot/sub2@all && + git p4 clone --dest="$git" //depot/sub1@all //depot/sub2@all && test_when_finished cleanup_git && ( cd "$git" && @@ -112,7 +112,7 @@ test_expect_success 'clone two dirs, @all, conflicting files' ' p4 add sub2/f3 && p4 submit -d "sub2/f3" ) && - "$GITP4" clone --dest="$git" //depot/sub1@all //depot/sub2@all && + git p4 clone --dest="$git" //depot/sub1@all //depot/sub2@all && test_when_finished cleanup_git && ( cd "$git" && @@ -134,7 +134,7 @@ test_expect_success 'exit when p4 fails to produce marshaled output' ' exit 1 EOF chmod 755 "$badp4dir"/p4 && - PATH="$badp4dir:$PATH" "$GITP4" clone --dest="$git" //depot >errs 2>&1 ; retval=$? && + PATH="$badp4dir:$PATH" git p4 clone --dest="$git" //depot >errs 2>&1 ; retval=$? && test $retval -eq 1 && test_must_fail grep -q Traceback errs ' @@ -151,8 +151,8 @@ test_expect_success 'add p4 files with wildcards in the names' ' ) ' -test_expect_success 'wildcard files git-p4 clone' ' - "$GITP4" clone --dest="$git" //depot && +test_expect_success 'wildcard files git p4 clone' ' + git p4 clone --dest="$git" //depot && test_when_finished cleanup_git && ( cd "$git" && @@ -164,7 +164,7 @@ test_expect_success 'wildcard files git-p4 clone' ' ' test_expect_success 'clone bare' ' - "$GITP4" clone --dest="$git" --bare //depot && + git p4 clone --dest="$git" --bare //depot && test_when_finished cleanup_git && ( cd "$git" && @@ -209,7 +209,7 @@ test_expect_success 'preserve users' ' p4_add_user alice Alice && p4_add_user bob Bob && p4_grant_admin alice && - "$GITP4" clone --dest="$git" //depot && + git p4 clone --dest="$git" //depot && test_when_finished cleanup_git && ( cd "$git" && @@ -218,7 +218,7 @@ test_expect_success 'preserve users' ' git commit --author "Alice <alice@localhost>" -m "a change by alice" file1 && git commit --author "Bob <bob@localhost>" -m "a change by bob" file2 && git config git-p4.skipSubmitEditCheck true && - P4EDITOR=touch P4USER=alice P4PASSWD=secret "$GITP4" commit --preserve-user && + P4EDITOR=touch P4USER=alice P4PASSWD=secret git p4 commit --preserve-user && p4_check_commit_author file1 alice && p4_check_commit_author file2 bob ) @@ -227,7 +227,7 @@ test_expect_success 'preserve users' ' # Test username support, submitting as bob, who lacks admin rights. Should # not submit change to p4 (git diff should show deltas). test_expect_success 'refuse to preserve users without perms' ' - "$GITP4" clone --dest="$git" //depot && + git p4 clone --dest="$git" //depot && test_when_finished cleanup_git && ( cd "$git" && @@ -236,14 +236,14 @@ test_expect_success 'refuse to preserve users without perms' ' git commit --author "Alice <alice@localhost>" -m "perms: a change by alice" file1 && P4EDITOR=touch P4USER=bob P4PASSWD=secret && export P4EDITOR P4USER P4PASSWD && - test_must_fail "$GITP4" commit --preserve-user && + test_must_fail git p4 commit --preserve-user && ! git diff --exit-code HEAD..p4/master ) ' # What happens with unknown author? Without allowMissingP4Users it should fail. test_expect_success 'preserve user where author is unknown to p4' ' - "$GITP4" clone --dest="$git" //depot && + git p4 clone --dest="$git" //depot && test_when_finished cleanup_git && ( cd "$git" && @@ -254,24 +254,24 @@ test_expect_success 'preserve user where author is unknown to p4' ' git commit --author "Charlie <charlie@localhost>" -m "preserve: a change by charlie" file1 && P4EDITOR=touch P4USER=alice P4PASSWD=secret && export P4EDITOR P4USER P4PASSWD && - test_must_fail "$GITP4" commit --preserve-user && + test_must_fail git p4 commit --preserve-user && ! git diff --exit-code HEAD..p4/master && echo "$0: repeat with allowMissingP4Users enabled" && git config git-p4.allowMissingP4Users true && git config git-p4.preserveUser true && - "$GITP4" commit && + git p4 commit && git diff --exit-code HEAD..p4/master && p4_check_commit_author file1 alice ) ' -# If we're *not* using --preserve-user, git-p4 should warn if we're submitting +# If we're *not* using --preserve-user, git p4 should warn if we're submitting # changes that are not all ours. # Test: user in p4 and user unknown to p4. # Test: warning disabled and user is the same. test_expect_success 'not preserving user with mixed authorship' ' - "$GITP4" clone --dest="$git" //depot && + git p4 clone --dest="$git" //depot && test_when_finished cleanup_git && ( cd "$git" && @@ -281,20 +281,20 @@ test_expect_success 'not preserving user with mixed authorship' ' make_change_by_user usernamefile3 Derek derek@localhost && P4EDITOR=cat P4USER=alice P4PASSWD=secret && export P4EDITOR P4USER P4PASSWD && - "$GITP4" commit |\ + git p4 commit |\ grep "git author derek@localhost does not match" && make_change_by_user usernamefile3 Charlie charlie@localhost && - "$GITP4" commit |\ + git p4 commit |\ grep "git author charlie@localhost does not match" && make_change_by_user usernamefile3 alice alice@localhost && - "$GITP4" commit |\ + git p4 commit |\ test_must_fail grep "git author.*does not match" && git config git-p4.skipUserNameCheck true && make_change_by_user usernamefile3 Charlie charlie@localhost && - "$GITP4" commit |\ + git p4 commit |\ test_must_fail grep "git author.*does not match" && p4_check_commit_author usernamefile3 alice @@ -313,7 +313,7 @@ test_expect_success 'initial import time from top change time' ' p4change=$(p4 -G changes -m 1 //depot/... | marshal_dump change) && p4time=$(p4 -G changes -m 1 //depot/... | marshal_dump time) && sleep 3 && - "$GITP4" clone --dest="$git" //depot && + git p4 clone --dest="$git" //depot && test_when_finished cleanup_git && ( cd "$git" && @@ -331,7 +331,7 @@ test_expect_success 'initial import time from top change time' ' # Repeat, this time with a smaller threshold and confirm that the rename is # detected in P4. test_expect_success 'detect renames' ' - "$GITP4" clone --dest="$git" //depot@all && + git p4 clone --dest="$git" //depot@all && test_when_finished cleanup_git && ( cd "$git" && @@ -340,7 +340,7 @@ test_expect_success 'detect renames' ' git mv file1 file4 && git commit -a -m "Rename file1 to file4" && git diff-tree -r -M HEAD && - "$GITP4" submit && + git p4 submit && p4 filelog //depot/file4 && p4 filelog //depot/file4 | test_must_fail grep -q "branch from" && @@ -348,7 +348,7 @@ test_expect_success 'detect renames' ' git commit -a -m "Rename file4 to file5" && git diff-tree -r -M HEAD && git config git-p4.detectRenames true && - "$GITP4" submit && + git p4 submit && p4 filelog //depot/file5 && p4 filelog //depot/file5 | grep -q "branch from //depot/file4" && @@ -360,7 +360,7 @@ test_expect_success 'detect renames' ' level=$(git diff-tree -r -M HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/R0*//") && test -n "$level" && test "$level" -gt 0 && test "$level" -lt 98 && git config git-p4.detectRenames $(($level + 2)) && - "$GITP4" submit && + git p4 submit && p4 filelog //depot/file6 && p4 filelog //depot/file6 | test_must_fail grep -q "branch from" && @@ -372,7 +372,7 @@ test_expect_success 'detect renames' ' level=$(git diff-tree -r -M HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/R0*//") && test -n "$level" && test "$level" -gt 2 && test "$level" -lt 100 && git config git-p4.detectRenames $(($level - 2)) && - "$GITP4" submit && + git p4 submit && p4 filelog //depot/file7 && p4 filelog //depot/file7 | grep -q "branch from //depot/file6" ) @@ -390,7 +390,7 @@ test_expect_success 'detect renames' ' # Modify and copy a file, configure a smaller threshold in detectCopies and # confirm that copy is detected in P4. test_expect_success 'detect copies' ' - "$GITP4" clone --dest="$git" //depot@all && + git p4 clone --dest="$git" //depot@all && test_when_finished cleanup_git && ( cd "$git" && @@ -400,7 +400,7 @@ test_expect_success 'detect copies' ' git add file8 && git commit -a -m "Copy file2 to file8" && git diff-tree -r -C HEAD && - "$GITP4" submit && + git p4 submit && p4 filelog //depot/file8 && p4 filelog //depot/file8 | test_must_fail grep -q "branch from" && @@ -409,7 +409,7 @@ test_expect_success 'detect copies' ' git commit -a -m "Copy file2 to file9" && git diff-tree -r -C HEAD && git config git-p4.detectCopies true && - "$GITP4" submit && + git p4 submit && p4 filelog //depot/file9 && p4 filelog //depot/file9 | test_must_fail grep -q "branch from" && @@ -418,7 +418,7 @@ test_expect_success 'detect copies' ' git add file2 file10 && git commit -a -m "Modify and copy file2 to file10" && git diff-tree -r -C HEAD && - "$GITP4" submit && + git p4 submit && p4 filelog //depot/file10 && p4 filelog //depot/file10 | grep -q "branch from //depot/file" && @@ -429,7 +429,7 @@ test_expect_success 'detect copies' ' src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) && test "$src" = file10 && git config git-p4.detectCopiesHarder true && - "$GITP4" submit && + git p4 submit && p4 filelog //depot/file11 && p4 filelog //depot/file11 | grep -q "branch from //depot/file" && @@ -443,7 +443,7 @@ test_expect_success 'detect copies' ' src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) && test "$src" = file10 && git config git-p4.detectCopies $(($level + 2)) && - "$GITP4" submit && + git p4 submit && p4 filelog //depot/file12 && p4 filelog //depot/file12 | test_must_fail grep -q "branch from" && @@ -457,7 +457,7 @@ test_expect_success 'detect copies' ' src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) && test "$src" = file10 && git config git-p4.detectCopies $(($level - 2)) && - "$GITP4" submit && + git p4 submit && p4 filelog //depot/file13 && p4 filelog //depot/file13 | grep -q "branch from //depot/file" ) diff --git a/t/t9801-git-p4-branch.sh b/t/t9801-git-p4-branch.sh index d414705416..2859256de3 100755 --- a/t/t9801-git-p4-branch.sh +++ b/t/t9801-git-p4-branch.sh @@ -1,6 +1,6 @@ #!/bin/sh -test_description='git-p4 p4 branching tests' +test_description='git p4 tests for p4 branches' . ./lib-git-p4.sh @@ -63,7 +63,7 @@ test_expect_success 'basic p4 branches' ' test_expect_success 'import main, no branch detection' ' test_when_finished cleanup_git && - "$GITP4" clone --dest="$git" //depot/main@all && + git p4 clone --dest="$git" //depot/main@all && ( cd "$git" && git log --oneline --graph --decorate --all && @@ -74,7 +74,7 @@ test_expect_success 'import main, no branch detection' ' test_expect_success 'import branch1, no branch detection' ' test_when_finished cleanup_git && - "$GITP4" clone --dest="$git" //depot/branch1@all && + git p4 clone --dest="$git" //depot/branch1@all && ( cd "$git" && git log --oneline --graph --decorate --all && @@ -85,7 +85,7 @@ test_expect_success 'import branch1, no branch detection' ' test_expect_success 'import branch2, no branch detection' ' test_when_finished cleanup_git && - "$GITP4" clone --dest="$git" //depot/branch2@all && + git p4 clone --dest="$git" //depot/branch2@all && ( cd "$git" && git log --oneline --graph --decorate --all && @@ -96,7 +96,7 @@ test_expect_success 'import branch2, no branch detection' ' test_expect_success 'import depot, no branch detection' ' test_when_finished cleanup_git && - "$GITP4" clone --dest="$git" //depot@all && + git p4 clone --dest="$git" //depot@all && ( cd "$git" && git log --oneline --graph --decorate --all && @@ -107,7 +107,7 @@ test_expect_success 'import depot, no branch detection' ' test_expect_success 'import depot, branch detection' ' test_when_finished cleanup_git && - "$GITP4" clone --dest="$git" --detect-branches //depot@all && + git p4 clone --dest="$git" --detect-branches //depot@all && ( cd "$git" && @@ -132,7 +132,7 @@ test_expect_success 'import depot, branch detection, branchList branch definitio ( cd "$git" && git config git-p4.branchList main:branch1 && - "$GITP4" clone --dest=. --detect-branches //depot@all && + git p4 clone --dest=. --detect-branches //depot@all && git log --oneline --graph --decorate --all && @@ -189,15 +189,15 @@ test_expect_success 'add simple p4 branches' ' # Configure branches through git-config and clone them. # All files are tested to make sure branches were cloned correctly. # Finally, make an update to branch1 on P4 side to check if it is imported -# correctly by git-p4. -test_expect_success 'git-p4 clone simple branches' ' +# correctly by git p4. +test_expect_success 'git p4 clone simple branches' ' test_when_finished cleanup_git && test_create_repo "$git" && ( cd "$git" && git config git-p4.branchList branch1:branch2 && git config --add git-p4.branchList branch1:branch3 && - "$GITP4" clone --dest=. --detect-branches //depot@all && + git p4 clone --dest=. --detect-branches //depot@all && git log --all --graph --decorate --stat && git reset --hard p4/depot/branch1 && test -f file1 && @@ -221,13 +221,13 @@ test_expect_success 'git-p4 clone simple branches' ' p4 submit -d "update file2 in branch3" && cd "$git" && git reset --hard p4/depot/branch1 && - "$GITP4" rebase && + git p4 rebase && grep file2_ file2 ) ' # Create a complex branch structure in P4 depot to check if they are correctly -# cloned. The branches are created from older changelists to check if git-p4 is +# cloned. The branches are created from older changelists to check if git p4 is # able to correctly detect them. # The final expected structure is: # `branch1 @@ -248,7 +248,7 @@ test_expect_success 'git-p4 clone simple branches' ' # `- file1 # `- file2 # `- file3 -test_expect_success 'git-p4 add complex branches' ' +test_expect_success 'git p4 add complex branches' ' test_when_finished cleanup_git && test_create_repo "$git" && ( @@ -263,10 +263,10 @@ test_expect_success 'git-p4 add complex branches' ' ) ' -# Configure branches through git-config and clone them. git-p4 will only be able +# Configure branches through git-config and clone them. git p4 will only be able # to clone the original structure if it is able to detect the origin changelist # of each branch. -test_expect_success 'git-p4 clone complex branches' ' +test_expect_success 'git p4 clone complex branches' ' test_when_finished cleanup_git && test_create_repo "$git" && ( @@ -275,7 +275,7 @@ test_expect_success 'git-p4 clone complex branches' ' git config --add git-p4.branchList branch1:branch3 && git config --add git-p4.branchList branch1:branch4 && git config --add git-p4.branchList branch1:branch5 && - "$GITP4" clone --dest=. --detect-branches //depot@all && + git p4 clone --dest=. --detect-branches //depot@all && git log --all --graph --decorate --stat && git reset --hard p4/depot/branch1 && test_path_is_file file1 && diff --git a/t/t9802-git-p4-filetype.sh b/t/t9802-git-p4-filetype.sh index 992bb8cf0b..21924dfd7d 100755 --- a/t/t9802-git-p4-filetype.sh +++ b/t/t9802-git-p4-filetype.sh @@ -1,6 +1,6 @@ #!/bin/sh -test_description='git-p4 p4 filetype tests' +test_description='git p4 filetype tests' . ./lib-git-p4.sh @@ -37,7 +37,7 @@ test_expect_success 'utf-16 file create' ' test_expect_success 'utf-16 file test' ' test_when_finished cleanup_git && - "$GITP4" clone --dest="$git" //depot@all && + git p4 clone --dest="$git" //depot@all && ( cd "$git" && @@ -84,7 +84,7 @@ test_expect_success 'keyword file test' ' build_smush && test_when_finished rm -f k_smush.py ko_smush.py && test_when_finished cleanup_git && - "$GITP4" clone --dest="$git" //depot@all && + git p4 clone --dest="$git" //depot@all && ( cd "$git" && @@ -94,7 +94,7 @@ test_expect_success 'keyword file test' ' "$PYTHON_PATH" "$TRASH_DIRECTORY/ko_smush.py" <"$cli/k-text-ko" >cli-k-text-ko-smush && test_cmp cli-k-text-ko-smush k-text-ko && - # utf16, even though p4 expands keywords, git-p4 does not + # utf16, even though p4 expands keywords, git p4 does not # try to undo that test_cmp "$cli/k-utf16-k" k-utf16-k && test_cmp "$cli/k-utf16-ko" k-utf16-ko @@ -125,7 +125,7 @@ test_expect_success 'ignore apple' ' p4 submit -d appledouble ) && test_when_finished cleanup_git && - "$GITP4" clone --dest="$git" //depot@all && + git p4 clone --dest="$git" //depot@all && ( cd "$git" && test ! -f double.png diff --git a/t/t9803-git-p4-shell-metachars.sh b/t/t9803-git-p4-shell-metachars.sh index db670207bd..fbacff34fe 100755 --- a/t/t9803-git-p4-shell-metachars.sh +++ b/t/t9803-git-p4-shell-metachars.sh @@ -1,6 +1,6 @@ #!/bin/sh -test_description='git-p4 transparency to shell metachars in filenames' +test_description='git p4 transparency to shell metachars in filenames' . ./lib-git-p4.sh @@ -18,7 +18,7 @@ test_expect_success 'init depot' ' ' test_expect_success 'shell metachars in filenames' ' - "$GITP4" clone --dest="$git" //depot && + git p4 clone --dest="$git" //depot && test_when_finished cleanup_git && ( cd "$git" && @@ -28,7 +28,7 @@ test_expect_success 'shell metachars in filenames' ' echo f2 >"file with spaces" && git add "file with spaces" && git commit -m "add files" && - P4EDITOR=touch "$GITP4" submit + P4EDITOR=touch git p4 submit ) && ( cd "$cli" && @@ -39,7 +39,7 @@ test_expect_success 'shell metachars in filenames' ' ' test_expect_success 'deleting with shell metachars' ' - "$GITP4" clone --dest="$git" //depot && + git p4 clone --dest="$git" //depot && test_when_finished cleanup_git && ( cd "$git" && @@ -47,7 +47,7 @@ test_expect_success 'deleting with shell metachars' ' git rm foo\$bar && git rm file\ with\ spaces && git commit -m "remove files" && - P4EDITOR=touch "$GITP4" submit + P4EDITOR=touch git p4 submit ) && ( cd "$cli" && @@ -97,7 +97,7 @@ test_expect_success 'branch with shell char' ' cd "$git" && git config git-p4.branchList main:branch\$3 && - "$GITP4" clone --dest=. --detect-branches //depot@all && + git p4 clone --dest=. --detect-branches //depot@all && git log --all --graph --decorate --stat && git reset --hard p4/depot/branch\$3 && test -f shell_char_branch_file && diff --git a/t/t9804-git-p4-label.sh b/t/t9804-git-p4-label.sh index a9e04efb88..e30f80e617 100755 --- a/t/t9804-git-p4-label.sh +++ b/t/t9804-git-p4-label.sh @@ -1,6 +1,6 @@ #!/bin/sh -test_description='git-p4 p4 label tests' +test_description='git p4 label tests' . ./lib-git-p4.sh @@ -50,7 +50,7 @@ test_expect_success 'basic p4 labels' ' p4 labels ... && - "$GITP4" clone --dest="$git" --detect-labels //depot@all && + git p4 clone --dest="$git" --detect-labels //depot@all && cd "$git" && git tag && @@ -89,7 +89,7 @@ test_expect_failure 'two labels on the same changelist' ' p4 labels ... && - "$GITP4" clone --dest="$git" --detect-labels //depot@all && + git p4 clone --dest="$git" --detect-labels //depot@all && cd "$git" && git tag | grep tag_f1 && diff --git a/t/t9805-git-p4-skip-submit-edit.sh b/t/t9805-git-p4-skip-submit-edit.sh index df929e0555..4a72f79522 100755 --- a/t/t9805-git-p4-skip-submit-edit.sh +++ b/t/t9805-git-p4-skip-submit-edit.sh @@ -1,6 +1,6 @@ #!/bin/sh -test_description='git-p4 skipSubmitEdit config variables' +test_description='git p4 skipSubmitEdit config variables' . ./lib-git-p4.sh @@ -19,33 +19,33 @@ test_expect_success 'init depot' ' # this works because EDITOR is set to : test_expect_success 'no config, unedited, say yes' ' - "$GITP4" clone --dest="$git" //depot && + git p4 clone --dest="$git" //depot && test_when_finished cleanup_git && ( cd "$git" && echo line >>file1 && git commit -a -m "change 2" && - echo y | "$GITP4" submit && + echo y | git p4 submit && p4 changes //depot/... >wc && test_line_count = 2 wc ) ' test_expect_success 'no config, unedited, say no' ' - "$GITP4" clone --dest="$git" //depot && + git p4 clone --dest="$git" //depot && test_when_finished cleanup_git && ( cd "$git" && echo line >>file1 && git commit -a -m "change 3 (not really)" && - printf "bad response\nn\n" | "$GITP4" submit && + printf "bad response\nn\n" | git p4 submit && p4 changes //depot/... >wc && test_line_count = 2 wc ) ' test_expect_success 'skipSubmitEdit' ' - "$GITP4" clone --dest="$git" //depot && + git p4 clone --dest="$git" //depot && test_when_finished cleanup_git && ( cd "$git" && @@ -54,21 +54,21 @@ test_expect_success 'skipSubmitEdit' ' git config core.editor /bin/false && echo line >>file1 && git commit -a -m "change 3" && - "$GITP4" submit && + git p4 submit && p4 changes //depot/... >wc && test_line_count = 3 wc ) ' test_expect_success 'skipSubmitEditCheck' ' - "$GITP4" clone --dest="$git" //depot && + git p4 clone --dest="$git" //depot && test_when_finished cleanup_git && ( cd "$git" && git config git-p4.skipSubmitEditCheck true && echo line >>file1 && git commit -a -m "change 4" && - "$GITP4" submit && + git p4 submit && p4 changes //depot/... >wc && test_line_count = 4 wc ) @@ -76,7 +76,7 @@ test_expect_success 'skipSubmitEditCheck' ' # check the normal case, where the template really is edited test_expect_success 'no config, edited' ' - "$GITP4" clone --dest="$git" //depot && + git p4 clone --dest="$git" //depot && test_when_finished cleanup_git && ed="$TRASH_DIRECTORY/ed.sh" && test_when_finished "rm \"$ed\"" && @@ -91,7 +91,7 @@ test_expect_success 'no config, edited' ' cd "$git" && echo line >>file1 && git commit -a -m "change 5" && - EDITOR="\"$ed\"" "$GITP4" submit && + EDITOR="\"$ed\"" git p4 submit && p4 changes //depot/... >wc && test_line_count = 5 wc ) diff --git a/t/t9806-git-p4-options.sh b/t/t9806-git-p4-options.sh index 0571602129..2892367830 100755 --- a/t/t9806-git-p4-options.sh +++ b/t/t9806-git-p4-options.sh @@ -1,6 +1,6 @@ #!/bin/sh -test_description='git-p4 options' +test_description='git p4 options' . ./lib-git-p4.sh @@ -24,11 +24,11 @@ test_expect_success 'init depot' ' ' test_expect_success 'clone no --git-dir' ' - test_must_fail "$GITP4" clone --git-dir=xx //depot + test_must_fail git p4 clone --git-dir=xx //depot ' test_expect_success 'clone --branch' ' - "$GITP4" clone --branch=refs/remotes/p4/sb --dest="$git" //depot && + git p4 clone --branch=refs/remotes/p4/sb --dest="$git" //depot && test_when_finished cleanup_git && ( cd "$git" && @@ -42,7 +42,7 @@ test_expect_success 'clone --changesfile' ' cf="$TRASH_DIRECTORY/cf" && test_when_finished "rm \"$cf\"" && printf "1\n3\n" >"$cf" && - "$GITP4" clone --changesfile="$cf" --dest="$git" //depot && + git p4 clone --changesfile="$cf" --dest="$git" //depot && test_when_finished cleanup_git && ( cd "$git" && @@ -58,14 +58,14 @@ test_expect_success 'clone --changesfile, @all' ' cf="$TRASH_DIRECTORY/cf" && test_when_finished "rm \"$cf\"" && printf "1\n3\n" >"$cf" && - test_must_fail "$GITP4" clone --changesfile="$cf" --dest="$git" //depot@all + test_must_fail git p4 clone --changesfile="$cf" --dest="$git" //depot@all ' # imports both master and p4/master in refs/heads # requires --import-local on sync to find p4 refs/heads # does not update master on sync, just p4/master test_expect_success 'clone/sync --import-local' ' - "$GITP4" clone --import-local --dest="$git" //depot@1,2 && + git p4 clone --import-local --dest="$git" //depot@1,2 && test_when_finished cleanup_git && ( cd "$git" && @@ -73,9 +73,9 @@ test_expect_success 'clone/sync --import-local' ' test_line_count = 2 lines && git log --oneline refs/heads/p4/master >lines && test_line_count = 2 lines && - test_must_fail "$GITP4" sync && + test_must_fail git p4 sync && - "$GITP4" sync --import-local && + git p4 sync --import-local && git log --oneline refs/heads/master >lines && test_line_count = 2 lines && git log --oneline refs/heads/p4/master >lines && @@ -84,7 +84,7 @@ test_expect_success 'clone/sync --import-local' ' ' test_expect_success 'clone --max-changes' ' - "$GITP4" clone --dest="$git" --max-changes 2 //depot@all && + git p4 clone --dest="$git" --max-changes 2 //depot@all && test_when_finished cleanup_git && ( cd "$git" && @@ -101,7 +101,7 @@ test_expect_success 'clone --keep-path' ' p4 add sub/dir/f4 && p4 submit -d "change 4" ) && - "$GITP4" clone --dest="$git" --keep-path //depot/sub/dir@all && + git p4 clone --dest="$git" --keep-path //depot/sub/dir@all && test_when_finished cleanup_git && ( cd "$git" && @@ -109,7 +109,7 @@ test_expect_success 'clone --keep-path' ' test_path_is_file sub/dir/f4 ) && cleanup_git && - "$GITP4" clone --dest="$git" //depot/sub/dir@all && + git p4 clone --dest="$git" //depot/sub/dir@all && ( cd "$git" && test_path_is_file f4 && @@ -126,7 +126,7 @@ test_expect_success 'clone --use-client-spec' ' ( # big usage message exec >/dev/null && - test_must_fail "$GITP4" clone --dest="$git" --use-client-spec + test_must_fail git p4 clone --dest="$git" --use-client-spec ) && cli2="$TRASH_DIRECTORY/cli2" && mkdir -p "$cli2" && @@ -142,7 +142,7 @@ test_expect_success 'clone --use-client-spec' ' ) && P4CLIENT=client2 && test_when_finished cleanup_git && - "$GITP4" clone --dest="$git" --use-client-spec //depot/... && + git p4 clone --dest="$git" --use-client-spec //depot/... && ( cd "$git" && test_path_is_file bus/dir/f4 && @@ -156,7 +156,7 @@ test_expect_success 'clone --use-client-spec' ' cd "$git" && git init && git config git-p4.useClientSpec true && - "$GITP4" sync //depot/... && + git p4 sync //depot/... && git checkout -b master p4/master && test_path_is_file bus/dir/f4 && test_path_is_missing file1 diff --git a/t/t9807-git-p4-submit.sh b/t/t9807-git-p4-submit.sh index b1f61e3db5..15417165e8 100755 --- a/t/t9807-git-p4-submit.sh +++ b/t/t9807-git-p4-submit.sh @@ -1,6 +1,6 @@ #!/bin/sh -test_description='git-p4 submit' +test_description='git p4 submit' . ./lib-git-p4.sh @@ -19,7 +19,7 @@ test_expect_success 'init depot' ' test_expect_success 'submit with no client dir' ' test_when_finished cleanup_git && - "$GITP4" clone --dest="$git" //depot && + git p4 clone --dest="$git" //depot && ( cd "$git" && echo file2 >file2 && @@ -27,20 +27,20 @@ test_expect_success 'submit with no client dir' ' git commit -m "git commit 2" && rm -rf "$cli" && git config git-p4.skipSubmitEdit true && - "$GITP4" submit + git p4 submit ) ' # make two commits, but tell it to apply only from HEAD^ test_expect_success 'submit --origin' ' test_when_finished cleanup_git && - "$GITP4" clone --dest="$git" //depot && + git p4 clone --dest="$git" //depot && ( cd "$git" && test_commit "file3" && test_commit "file4" && git config git-p4.skipSubmitEdit true && - "$GITP4" submit --origin=HEAD^ + git p4 submit --origin=HEAD^ ) && ( cd "$cli" && @@ -52,30 +52,30 @@ test_expect_success 'submit --origin' ' test_expect_success 'submit with allowSubmit' ' test_when_finished cleanup_git && - "$GITP4" clone --dest="$git" //depot && + git p4 clone --dest="$git" //depot && ( cd "$git" && test_commit "file5" && git config git-p4.skipSubmitEdit true && git config git-p4.allowSubmit "nobranch" && - test_must_fail "$GITP4" submit && + test_must_fail git p4 submit && git config git-p4.allowSubmit "nobranch,master" && - "$GITP4" submit + git p4 submit ) ' test_expect_success 'submit with master branch name from argv' ' test_when_finished cleanup_git && - "$GITP4" clone --dest="$git" //depot && + git p4 clone --dest="$git" //depot && ( cd "$git" && test_commit "file6" && git config git-p4.skipSubmitEdit true && - test_must_fail "$GITP4" submit nobranch && + test_must_fail git p4 submit nobranch && git branch otherbranch && git reset --hard HEAD^ && test_commit "file7" && - "$GITP4" submit otherbranch + git p4 submit otherbranch ) && ( cd "$cli" && diff --git a/t/t9808-git-p4-chdir.sh b/t/t9808-git-p4-chdir.sh index f0022839c7..2f8014a60e 100755 --- a/t/t9808-git-p4-chdir.sh +++ b/t/t9808-git-p4-chdir.sh @@ -1,6 +1,6 @@ #!/bin/sh -test_description='git-p4 relative chdir' +test_description='git p4 relative chdir' . ./lib-git-p4.sh @@ -26,7 +26,7 @@ test_expect_success 'P4CONFIG and absolute dir clone' ' ( P4CONFIG=p4config && export P4CONFIG && sane_unset P4PORT P4CLIENT && - "$GITP4" clone --verbose --dest="$git" //depot + git p4 clone --verbose --dest="$git" //depot ) ' @@ -38,7 +38,7 @@ test_expect_success 'P4CONFIG and relative dir clone' ' ( P4CONFIG=p4config && export P4CONFIG && sane_unset P4PORT P4CLIENT && - "$GITP4" clone --verbose --dest="git" //depot + git p4 clone --verbose --dest="git" //depot ) ' diff --git a/t/t9809-git-p4-client-view.sh b/t/t9809-git-p4-client-view.sh index 773a516ff0..796b02c7f3 100755 --- a/t/t9809-git-p4-client-view.sh +++ b/t/t9809-git-p4-client-view.sh @@ -1,6 +1,6 @@ #!/bin/sh -test_description='git-p4 client view' +test_description='git p4 client view' . ./lib-git-p4.sh @@ -96,25 +96,25 @@ test_expect_success 'init depot' ' test_expect_success 'unsupported view wildcard %%n' ' client_view "//depot/%%%%1/sub/... //client/sub/%%%%1/..." && test_when_finished cleanup_git && - test_must_fail "$GITP4" clone --use-client-spec --dest="$git" //depot + test_must_fail git p4 clone --use-client-spec --dest="$git" //depot ' test_expect_success 'unsupported view wildcard *' ' client_view "//depot/*/bar/... //client/*/bar/..." && test_when_finished cleanup_git && - test_must_fail "$GITP4" clone --use-client-spec --dest="$git" //depot + test_must_fail git p4 clone --use-client-spec --dest="$git" //depot ' test_expect_success 'wildcard ... only supported at end of spec 1' ' client_view "//depot/.../file11 //client/.../file11" && test_when_finished cleanup_git && - test_must_fail "$GITP4" clone --use-client-spec --dest="$git" //depot + test_must_fail git p4 clone --use-client-spec --dest="$git" //depot ' test_expect_success 'wildcard ... only supported at end of spec 2' ' client_view "//depot/.../a/... //client/.../a/..." && test_when_finished cleanup_git && - test_must_fail "$GITP4" clone --use-client-spec --dest="$git" //depot + test_must_fail git p4 clone --use-client-spec --dest="$git" //depot ' test_expect_success 'basic map' ' @@ -122,7 +122,7 @@ test_expect_success 'basic map' ' files="cli1/file11 cli1/file12" && client_verify $files && test_when_finished cleanup_git && - "$GITP4" clone --use-client-spec --dest="$git" //depot && + git p4 clone --use-client-spec --dest="$git" //depot && git_verify $files ' @@ -130,7 +130,7 @@ test_expect_success 'client view with no mappings' ' client_view && client_verify && test_when_finished cleanup_git && - "$GITP4" clone --use-client-spec --dest="$git" //depot && + git p4 clone --use-client-spec --dest="$git" //depot && git_verify ' @@ -139,7 +139,7 @@ test_expect_success 'single file map' ' files="file11" && client_verify $files && test_when_finished cleanup_git && - "$GITP4" clone --use-client-spec --dest="$git" //depot && + git p4 clone --use-client-spec --dest="$git" //depot && git_verify $files ' @@ -150,7 +150,7 @@ test_expect_success 'later mapping takes precedence (entire repo)' ' cli2/dir2/file21 cli2/dir2/file22" && client_verify $files && test_when_finished cleanup_git && - "$GITP4" clone --use-client-spec --dest="$git" //depot && + git p4 clone --use-client-spec --dest="$git" //depot && git_verify $files ' @@ -160,7 +160,7 @@ test_expect_success 'later mapping takes precedence (partial repo)' ' files="file21 file22" && client_verify $files && test_when_finished cleanup_git && - "$GITP4" clone --use-client-spec --dest="$git" //depot && + git p4 clone --use-client-spec --dest="$git" //depot && git_verify $files ' @@ -176,7 +176,7 @@ test_expect_success 'depot path matching rejected client path' ' files="cli12/file21 cli12/file22" && client_verify $files && test_when_finished cleanup_git && - "$GITP4" clone --use-client-spec --dest="$git" //depot && + git p4 clone --use-client-spec --dest="$git" //depot && git_verify $files ' @@ -187,7 +187,7 @@ test_expect_success 'exclusion wildcard, client rhs same (odd)' ' "-//depot/dir2/... //client/..." && client_verify && test_when_finished cleanup_git && - "$GITP4" clone --use-client-spec --dest="$git" //depot && + git p4 clone --use-client-spec --dest="$git" //depot && git_verify ' @@ -197,7 +197,7 @@ test_expect_success 'exclusion wildcard, client rhs different (normal)' ' files="dir1/file11 dir1/file12" && client_verify $files && test_when_finished cleanup_git && - "$GITP4" clone --use-client-spec --dest="$git" //depot && + git p4 clone --use-client-spec --dest="$git" //depot && git_verify $files ' @@ -207,7 +207,7 @@ test_expect_success 'exclusion single file' ' files="dir1/file11 dir1/file12 dir2/file21" && client_verify $files && test_when_finished cleanup_git && - "$GITP4" clone --use-client-spec --dest="$git" //depot && + git p4 clone --use-client-spec --dest="$git" //depot && git_verify $files ' @@ -217,7 +217,7 @@ test_expect_success 'overlay wildcard' ' files="cli/file11 cli/file12 cli/file21 cli/file22" && client_verify $files && test_when_finished cleanup_git && - "$GITP4" clone --use-client-spec --dest="$git" //depot && + git p4 clone --use-client-spec --dest="$git" //depot && git_verify $files ' @@ -227,7 +227,7 @@ test_expect_success 'overlay single file' ' files="cli/file11 cli/file12 cli/file21" && client_verify $files && test_when_finished cleanup_git && - "$GITP4" clone --use-client-spec --dest="$git" //depot && + git p4 clone --use-client-spec --dest="$git" //depot && git_verify $files ' @@ -238,7 +238,7 @@ test_expect_success 'exclusion with later inclusion' ' files="dir1/file11 dir1/file12 dir2incl/file21 dir2incl/file22" && client_verify $files && test_when_finished cleanup_git && - "$GITP4" clone --use-client-spec --dest="$git" //depot && + git p4 clone --use-client-spec --dest="$git" //depot && git_verify $files ' @@ -246,7 +246,7 @@ test_expect_success 'quotes on rhs only' ' client_view "//depot/dir1/... \"//client/cdir 1/...\"" && client_verify "cdir 1/file11" "cdir 1/file12" && test_when_finished cleanup_git && - "$GITP4" clone --use-client-spec --dest="$git" //depot && + git p4 clone --use-client-spec --dest="$git" //depot && git_verify "cdir 1/file11" "cdir 1/file12" ' @@ -258,7 +258,7 @@ test_expect_success 'quotes on rhs only' ' test_expect_success 'clone --use-client-spec sets useClientSpec' ' client_view "//depot/... //client/..." && test_when_finished cleanup_git && - "$GITP4" clone --use-client-spec --dest="$git" //depot && + git p4 clone --use-client-spec --dest="$git" //depot && ( cd "$git" && git config --bool git-p4.useClientSpec >actual && @@ -273,7 +273,7 @@ test_expect_success 'subdir clone' ' files="dir1/file11 dir1/file12 dir2/file21 dir2/file22" && client_verify $files && test_when_finished cleanup_git && - "$GITP4" clone --use-client-spec --dest="$git" //depot/dir1 && + git p4 clone --use-client-spec --dest="$git" //depot/dir1 && git_verify dir1/file11 dir1/file12 ' @@ -283,14 +283,14 @@ test_expect_success 'subdir clone' ' test_expect_success 'subdir clone, submit modify' ' client_view "//depot/... //client/..." && test_when_finished cleanup_git && - "$GITP4" clone --use-client-spec --dest="$git" //depot/dir1 && + git p4 clone --use-client-spec --dest="$git" //depot/dir1 && ( cd "$git" && git config git-p4.skipSubmitEdit true && echo line >>dir1/file12 && git add dir1/file12 && git commit -m dir1/file12 && - "$GITP4" submit + git p4 submit ) && ( cd "$cli" && @@ -302,14 +302,14 @@ test_expect_success 'subdir clone, submit modify' ' test_expect_success 'subdir clone, submit add' ' client_view "//depot/... //client/..." && test_when_finished cleanup_git && - "$GITP4" clone --use-client-spec --dest="$git" //depot/dir1 && + git p4 clone --use-client-spec --dest="$git" //depot/dir1 && ( cd "$git" && git config git-p4.skipSubmitEdit true && echo file13 >dir1/file13 && git add dir1/file13 && git commit -m dir1/file13 && - "$GITP4" submit + git p4 submit ) && ( cd "$cli" && @@ -320,13 +320,13 @@ test_expect_success 'subdir clone, submit add' ' test_expect_success 'subdir clone, submit delete' ' client_view "//depot/... //client/..." && test_when_finished cleanup_git && - "$GITP4" clone --use-client-spec --dest="$git" //depot/dir1 && + git p4 clone --use-client-spec --dest="$git" //depot/dir1 && ( cd "$git" && git config git-p4.skipSubmitEdit true && git rm dir1/file12 && git commit -m "delete dir1/file12" && - "$GITP4" submit + git p4 submit ) && ( cd "$cli" && @@ -337,7 +337,7 @@ test_expect_success 'subdir clone, submit delete' ' test_expect_success 'subdir clone, submit copy' ' client_view "//depot/... //client/..." && test_when_finished cleanup_git && - "$GITP4" clone --use-client-spec --dest="$git" //depot/dir1 && + git p4 clone --use-client-spec --dest="$git" //depot/dir1 && ( cd "$git" && git config git-p4.skipSubmitEdit true && @@ -345,7 +345,7 @@ test_expect_success 'subdir clone, submit copy' ' cp dir1/file11 dir1/file11a && git add dir1/file11a && git commit -m "copy to dir1/file11a" && - "$GITP4" submit + git p4 submit ) && ( cd "$cli" && @@ -356,14 +356,14 @@ test_expect_success 'subdir clone, submit copy' ' test_expect_success 'subdir clone, submit rename' ' client_view "//depot/... //client/..." && test_when_finished cleanup_git && - "$GITP4" clone --use-client-spec --dest="$git" //depot/dir1 && + git p4 clone --use-client-spec --dest="$git" //depot/dir1 && ( cd "$git" && git config git-p4.skipSubmitEdit true && git config git-p4.detectRenames true && git mv dir1/file13 dir1/file13a && git commit -m "rename dir1/file13 to dir1/file13a" && - "$GITP4" submit + git p4 submit ) && ( cd "$cli" && @@ -419,7 +419,7 @@ test_expect_success 'overlay collision 1 to 2' ' client_verify $files && test_cmp actual "$cli"/filecollide && test_when_finished cleanup_git && - "$GITP4" clone --use-client-spec --dest="$git" //depot && + git p4 clone --use-client-spec --dest="$git" //depot && git_verify $files && test_cmp actual "$git"/filecollide ' @@ -432,7 +432,7 @@ test_expect_failure 'overlay collision 2 to 1' ' client_verify $files && test_cmp actual "$cli"/filecollide && test_when_finished cleanup_git && - "$GITP4" clone --use-client-spec --dest="$git" //depot && + git p4 clone --use-client-spec --dest="$git" //depot && git_verify $files && test_cmp actual "$git"/filecollide ' @@ -454,7 +454,7 @@ test_expect_failure 'overlay collision 1 to 2, but 2 deleted' ' files="file11 file12 file21 file22" && client_verify $files && test_when_finished cleanup_git && - "$GITP4" clone --use-client-spec --dest="$git" //depot && + git p4 clone --use-client-spec --dest="$git" //depot && git_verify $files ' @@ -477,7 +477,7 @@ test_expect_failure 'overlay collision 1 to 2, but 2 deleted, then 1 updated' ' files="file11 file12 file21 file22" && client_verify $files && test_when_finished cleanup_git && - "$GITP4" clone --use-client-spec --dest="$git" //depot && + git p4 clone --use-client-spec --dest="$git" //depot && git_verify $files ' @@ -533,7 +533,7 @@ test_expect_success 'overlay sync: initial git checkout' ' echo dir1/colA >actual && client_verify $files && test_cmp actual "$cli"/colA && - "$GITP4" clone --use-client-spec --dest="$git" //depot && + git p4 clone --use-client-spec --dest="$git" //depot && git_verify $files && test_cmp actual "$git"/colA ' @@ -558,7 +558,7 @@ test_expect_success 'overlay sync: colA content switch' ' test_cmp actual "$cli"/colA && ( cd "$git" && - "$GITP4" sync --use-client-spec && + git p4 sync --use-client-spec && git merge --ff-only p4/master ) && git_verify $files && @@ -585,7 +585,7 @@ test_expect_success 'overlay sync: colB appears' ' test_cmp actual "$cli"/colB && ( cd "$git" && - "$GITP4" sync --use-client-spec && + git p4 sync --use-client-spec && git merge --ff-only p4/master ) && git_verify $files && @@ -613,7 +613,7 @@ test_expect_success 'overlay sync: colB disappears' ' test_when_finished cleanup_git && ( cd "$git" && - "$GITP4" sync --use-client-spec && + git p4 sync --use-client-spec && git merge --ff-only p4/master ) && git_verify $files @@ -671,7 +671,7 @@ test_expect_success 'overlay sync swap: initial git checkout' ' echo dir1/colA >actual && client_verify $files && test_cmp actual "$cli"/colA && - "$GITP4" clone --use-client-spec --dest="$git" //depot && + git p4 clone --use-client-spec --dest="$git" //depot && git_verify $files && test_cmp actual "$git"/colA ' @@ -696,7 +696,7 @@ test_expect_failure 'overlay sync swap: colA no content switch' ' test_cmp actual "$cli"/colA && ( cd "$git" && - "$GITP4" sync --use-client-spec && + git p4 sync --use-client-spec && git merge --ff-only p4/master ) && git_verify $files && @@ -723,7 +723,7 @@ test_expect_success 'overlay sync swap: colB appears' ' test_cmp actual "$cli"/colB && ( cd "$git" && - "$GITP4" sync --use-client-spec && + git p4 sync --use-client-spec && git merge --ff-only p4/master ) && git_verify $files && @@ -753,7 +753,7 @@ test_expect_failure 'overlay sync swap: colB no change' ' test_when_finished cleanup_git && ( cd "$git" && - "$GITP4" sync --use-client-spec && + git p4 sync --use-client-spec && git merge --ff-only p4/master ) && git_verify $files && @@ -801,7 +801,7 @@ test_expect_success 'quotes on lhs only' ' files="cdir1/file11 cdir1/file12" && client_verify $files && test_when_finished cleanup_git && - "$GITP4" clone --use-client-spec --dest="$git" //depot && + git p4 clone --use-client-spec --dest="$git" //depot && client_verify $files ' @@ -809,7 +809,7 @@ test_expect_success 'quotes on both sides' ' client_view "\"//depot/dir 1/...\" \"//client/cdir 1/...\"" && client_verify "cdir 1/file11" "cdir 1/file12" && test_when_finished cleanup_git && - "$GITP4" clone --use-client-spec --dest="$git" //depot && + git p4 clone --use-client-spec --dest="$git" //depot && git_verify "cdir 1/file11" "cdir 1/file12" ' diff --git a/t/t9810-git-p4-rcs.sh b/t/t9810-git-p4-rcs.sh index 49dfde0616..d8d9ca4679 100755 --- a/t/t9810-git-p4-rcs.sh +++ b/t/t9810-git-p4-rcs.sh @@ -84,13 +84,13 @@ scrub_ko_check () { # test_expect_success 'edit far away from RCS lines' ' test_when_finished cleanup_git && - "$GITP4" clone --dest="$git" //depot && + git p4 clone --dest="$git" //depot && ( cd "$git" && git config git-p4.skipSubmitEdit true && sed -i "s/^line7/line7 edit/" filek && git commit -m "filek line7 edit" filek && - "$GITP4" submit && + git p4 submit && scrub_k_check filek ) ' @@ -100,14 +100,14 @@ test_expect_success 'edit far away from RCS lines' ' # test_expect_success 'edit near RCS lines' ' test_when_finished cleanup_git && - "$GITP4" clone --dest="$git" //depot && + git p4 clone --dest="$git" //depot && ( cd "$git" && git config git-p4.skipSubmitEdit true && git config git-p4.attemptRCSCleanup true && sed -i "s/^line4/line4 edit/" filek && git commit -m "filek line4 edit" filek && - "$GITP4" submit && + git p4 submit && scrub_k_check filek ) ' @@ -117,14 +117,14 @@ test_expect_success 'edit near RCS lines' ' # test_expect_success 'edit keyword lines' ' test_when_finished cleanup_git && - "$GITP4" clone --dest="$git" //depot && + git p4 clone --dest="$git" //depot && ( cd "$git" && git config git-p4.skipSubmitEdit true && git config git-p4.attemptRCSCleanup true && sed -i "/Revision/d" filek && git commit -m "filek remove Revision line" filek && - "$GITP4" submit && + git p4 submit && scrub_k_check filek ) ' @@ -134,14 +134,14 @@ test_expect_success 'edit keyword lines' ' # test_expect_success 'scrub ko files differently' ' test_when_finished cleanup_git && - "$GITP4" clone --dest="$git" //depot && + git p4 clone --dest="$git" //depot && ( cd "$git" && git config git-p4.skipSubmitEdit true && git config git-p4.attemptRCSCleanup true && sed -i "s/^line4/line4 edit/" fileko && git commit -m "fileko line4 edit" fileko && - "$GITP4" submit && + git p4 submit && scrub_ko_check fileko && ! scrub_k_check fileko ) @@ -168,7 +168,7 @@ test_expect_success 'cleanup after failure' ' # test_expect_success 'do not scrub plain text' ' test_when_finished cleanup_git && - "$GITP4" clone --dest="$git" //depot && + git p4 clone --dest="$git" //depot && ( cd "$git" && git config git-p4.skipSubmitEdit true && @@ -181,7 +181,7 @@ test_expect_success 'do not scrub plain text' ' sed -i "s/^line5/line5 p4 edit/" file_text && p4 submit -d "file5 p4 edit" ) && - ! "$GITP4" submit && + ! git p4 submit && ( # exepct something like: # file_text - file(s) not opened on this client @@ -239,7 +239,7 @@ p4_append_to_file () { # even though the change itself would otherwise apply cleanly. test_expect_success 'cope with rcs keyword expansion damage' ' test_when_finished cleanup_git && - "$GITP4" clone --dest="$git" //depot && + git p4 clone --dest="$git" //depot && ( cd "$git" && git config git-p4.skipSubmitEdit true && @@ -252,10 +252,10 @@ test_expect_success 'cope with rcs keyword expansion damage' ' git add kwfile1.c && git commit -m "Zap an RCS kw line" && - "$GITP4" submit && - "$GITP4" rebase && + git p4 submit && + git p4 rebase && git diff p4/master && - "$GITP4" commit && + git p4 commit && echo "try modifying in both" && cd "$cli" && p4 edit kwfile1.c && @@ -265,8 +265,8 @@ test_expect_success 'cope with rcs keyword expansion damage' ' echo "line from git at the top" | cat - kwfile1.c >kwfile1.c.new && mv kwfile1.c.new kwfile1.c && git commit -m "Add line in git at the top" kwfile1.c && - "$GITP4" rebase && - "$GITP4" submit + git p4 rebase && + git p4 submit ) ' @@ -280,7 +280,7 @@ test_expect_success 'cope with rcs keyword file deletion' ' cat kwdelfile.c && grep 1 kwdelfile.c ) && - "$GITP4" clone --dest="$git" //depot && + git p4 clone --dest="$git" //depot && ( cd "$git" && grep Revision kwdelfile.c && @@ -288,7 +288,7 @@ test_expect_success 'cope with rcs keyword file deletion' ' git commit -m "Delete a file containing RCS keywords" && git config git-p4.skipSubmitEdit true && git config git-p4.attemptRCSCleanup true && - "$GITP4" submit + git p4 submit ) && ( cd "$cli" && @@ -301,7 +301,7 @@ test_expect_success 'cope with rcs keyword file deletion' ' # work fine without any special handling. test_expect_success 'Add keywords in git which match the default p4 values' ' test_when_finished cleanup_git && - "$GITP4" clone --dest="$git" //depot && + git p4 clone --dest="$git" //depot && ( cd "$git" && echo "NewKW: \$Revision\$" >>kwfile1.c && @@ -309,7 +309,7 @@ test_expect_success 'Add keywords in git which match the default p4 values' ' git commit -m "Adding RCS keywords in git" && git config git-p4.skipSubmitEdit true && git config git-p4.attemptRCSCleanup true && - "$GITP4" submit + git p4 submit ) && ( cd "$cli" && @@ -325,7 +325,7 @@ test_expect_success 'Add keywords in git which match the default p4 values' ' # test_expect_failure 'Add keywords in git which do not match the default p4 values' ' test_when_finished cleanup_git && - "$GITP4" clone --dest="$git" //depot && + git p4 clone --dest="$git" //depot && ( cd "$git" && echo "NewKW2: \$Revision:1\$" >>kwfile1.c && @@ -333,7 +333,7 @@ test_expect_failure 'Add keywords in git which do not match the default p4 value git commit -m "Adding RCS keywords in git" && git config git-p4.skipSubmitEdit true && git config git-p4.attemptRCSCleanup true && - "$GITP4" submit + git p4 submit ) && ( cd "$cli" && @@ -356,7 +356,7 @@ test_expect_success 'merge conflict handling still works' ' p4 add -t ktext merge2.c && p4 submit -d "add merge test file" ) && - "$GITP4" clone --dest="$git" //depot && + git p4 clone --dest="$git" //depot && ( cd "$git" && sed -e "/Hello/d" merge2.c >merge2.c.tmp && @@ -374,7 +374,7 @@ test_expect_success 'merge conflict handling still works' ' test -f merge2.c && git config git-p4.skipSubmitEdit true && git config git-p4.attemptRCSCleanup true && - !(echo "s" | "$GITP4" submit) && + !(echo "s" | git p4 submit) && git rebase --skip && ! test -f merge2.c ) diff --git a/test-mergesort.c b/test-mergesort.c new file mode 100644 index 0000000000..3f388b4ce0 --- /dev/null +++ b/test-mergesort.c @@ -0,0 +1,52 @@ +#include "cache.h" +#include "mergesort.h" + +struct line { + char *text; + struct line *next; +}; + +static void *get_next(const void *a) +{ + return ((const struct line *)a)->next; +} + +static void set_next(void *a, void *b) +{ + ((struct line *)a)->next = b; +} + +static int compare_strings(const void *a, const void *b) +{ + const struct line *x = a, *y = b; + return strcmp(x->text, y->text); +} + +int main(int argc, const char **argv) +{ + struct line *line, *p = NULL, *lines = NULL; + struct strbuf sb = STRBUF_INIT; + + for (;;) { + if (strbuf_getwholeline(&sb, stdin, '\n')) + break; + line = xmalloc(sizeof(struct line)); + line->text = strbuf_detach(&sb, NULL); + if (p) { + line->next = p->next; + p->next = line; + } else { + line->next = NULL; + lines = line; + } + p = line; + } + + lines = llist_mergesort(lines, get_next, set_next, compare_strings); + + while (lines) { + printf("%s", lines->text); + lines = lines->next; + } + return 0; +} diff --git a/test-subprocess.c b/test-subprocess.c index 8926bc52a9..f2d4c0d22b 100644 --- a/test-subprocess.c +++ b/test-subprocess.c @@ -1,7 +1,7 @@ #include "cache.h" #include "run-command.h" -int main(int argc, char **argv) +int main(int argc, const char **argv) { struct child_process cp; int nogit = 0; @@ -9,12 +9,12 @@ int main(int argc, char **argv) setup_git_directory_gently(&nogit); if (nogit) die("No git repo found"); - if (!strcmp(argv[1], "--setup-work-tree")) { + if (argc > 1 && !strcmp(argv[1], "--setup-work-tree")) { setup_work_tree(); argv++; } memset(&cp, 0, sizeof(cp)); cp.git_cmd = 1; - cp.argv = (const char **)argv+1; + cp.argv = argv + 1; return run_command(&cp); } diff --git a/transport.c b/transport.c index ea9dcb6612..2dfac700b6 100644 --- a/transport.c +++ b/transport.c @@ -721,6 +721,10 @@ void transport_print_push_status(const char *dest, struct ref *refs, { struct ref *ref; int n = 0; + unsigned char head_sha1[20]; + char *head; + + head = resolve_refdup("HEAD", head_sha1, 1, NULL); if (verbose) { for (ref = refs; ref; ref = ref->next) @@ -738,8 +742,13 @@ void transport_print_push_status(const char *dest, struct ref *refs, ref->status != REF_STATUS_UPTODATE && ref->status != REF_STATUS_OK) n += print_one_push_status(ref, dest, n, porcelain); - if (ref->status == REF_STATUS_REJECT_NONFASTFORWARD) - *nonfastforward = 1; + if (ref->status == REF_STATUS_REJECT_NONFASTFORWARD && + *nonfastforward != NON_FF_HEAD) { + if (!strcmp(head, ref->name)) + *nonfastforward = NON_FF_HEAD; + else + *nonfastforward = NON_FF_OTHER; + } } } diff --git a/transport.h b/transport.h index ce99ef8b7e..1631a35ea6 100644 --- a/transport.h +++ b/transport.h @@ -138,6 +138,8 @@ int transport_set_option(struct transport *transport, const char *name, void transport_set_verbosity(struct transport *transport, int verbosity, int force_progress); +#define NON_FF_HEAD 1 +#define NON_FF_OTHER 2 int transport_push(struct transport *connection, int refspec_nr, const char **refspec, int flags, int * nonfastforward); diff --git a/unpack-trees.c b/unpack-trees.c index 7c9ecf665d..36523da22a 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -102,21 +102,28 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts, opts->unpack_rejects[i].strdup_strings = 1; } -static void add_entry(struct unpack_trees_options *o, struct cache_entry *ce, - unsigned int set, unsigned int clear) +static void do_add_entry(struct unpack_trees_options *o, struct cache_entry *ce, + unsigned int set, unsigned int clear) { - unsigned int size = ce_size(ce); - struct cache_entry *new = xmalloc(size); - clear |= CE_HASHED | CE_UNHASHED; if (set & CE_REMOVE) set |= CE_WT_REMOVE; + ce->next = NULL; + ce->ce_flags = (ce->ce_flags & ~clear) | set; + add_index_entry(&o->result, ce, + ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE); +} + +static void add_entry(struct unpack_trees_options *o, struct cache_entry *ce, + unsigned int set, unsigned int clear) +{ + unsigned int size = ce_size(ce); + struct cache_entry *new = xmalloc(size); + memcpy(new, ce, size); - new->next = NULL; - new->ce_flags = (new->ce_flags & ~clear) | set; - add_index_entry(&o->result, new, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE); + do_add_entry(o, new, set, clear); } /* @@ -587,7 +594,7 @@ static int unpack_nondirectories(int n, unsigned long mask, for (i = 0; i < n; i++) if (src[i] && src[i] != o->df_conflict_entry) - add_entry(o, src[i], 0, 0); + do_add_entry(o, src[i], 0, 0); return 0; } @@ -772,7 +779,7 @@ static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str if (unpack_nondirectories(n, mask, dirmask, src, names, info) < 0) return -1; - if (src[0]) { + if (o->merge && src[0]) { if (ce_stage(src[0])) mark_ce_used_same_name(src[0], o); else @@ -9,6 +9,18 @@ static void do_nothing(size_t size) static void (*try_to_free_routine)(size_t size) = do_nothing; +static void memory_limit_check(size_t size) +{ + static int limit = -1; + if (limit == -1) { + const char *env = getenv("GIT_ALLOC_LIMIT"); + limit = env ? atoi(env) * 1024 : 0; + } + if (limit && size > limit) + die("attempting to allocate %"PRIuMAX" over limit %d", + (intmax_t)size, limit); +} + try_to_free_t set_try_to_free_routine(try_to_free_t routine) { try_to_free_t old = try_to_free_routine; @@ -32,7 +44,10 @@ char *xstrdup(const char *str) void *xmalloc(size_t size) { - void *ret = malloc(size); + void *ret; + + memory_limit_check(size); + ret = malloc(size); if (!ret && !size) ret = malloc(1); if (!ret) { @@ -79,7 +94,10 @@ char *xstrndup(const char *str, size_t len) void *xrealloc(void *ptr, size_t size) { - void *ret = realloc(ptr, size); + void *ret; + + memory_limit_check(size); + ret = realloc(ptr, size); if (!ret && !size) ret = realloc(ptr, 1); if (!ret) { @@ -95,7 +113,10 @@ void *xrealloc(void *ptr, size_t size) void *xcalloc(size_t nmemb, size_t size) { - void *ret = calloc(nmemb, size); + void *ret; + + memory_limit_check(size * nmemb); + ret = calloc(nmemb, size); if (!ret && (!nmemb || !size)) ret = calloc(1, 1); if (!ret) { diff --git a/xdiff/xdiff.h b/xdiff/xdiff.h index 00d36c3ac7..09215afe6e 100644 --- a/xdiff/xdiff.h +++ b/xdiff/xdiff.h @@ -32,14 +32,12 @@ extern "C" { #define XDF_IGNORE_WHITESPACE (1 << 2) #define XDF_IGNORE_WHITESPACE_CHANGE (1 << 3) #define XDF_IGNORE_WHITESPACE_AT_EOL (1 << 4) -#define XDF_PATIENCE_DIFF (1 << 5) -#define XDF_HISTOGRAM_DIFF (1 << 6) #define XDF_WHITESPACE_FLAGS (XDF_IGNORE_WHITESPACE | XDF_IGNORE_WHITESPACE_CHANGE | XDF_IGNORE_WHITESPACE_AT_EOL) -#define XDL_PATCH_NORMAL '-' -#define XDL_PATCH_REVERSE '+' -#define XDL_PATCH_MODEMASK ((1 << 8) - 1) -#define XDL_PATCH_IGNOREBSPACE (1 << 8) +#define XDF_PATIENCE_DIFF (1 << 5) +#define XDF_HISTOGRAM_DIFF (1 << 6) +#define XDF_DIFF_ALGORITHM_MASK (XDF_PATIENCE_DIFF | XDF_HISTOGRAM_DIFF) +#define XDF_DIFF_ALG(x) ((x) & XDF_DIFF_ALGORITHM_MASK) #define XDL_EMIT_FUNCNAMES (1 << 0) #define XDL_EMIT_COMMON (1 << 1) diff --git a/xdiff/xdiffi.c b/xdiff/xdiffi.c index 75a3922750..bc889e8789 100644 --- a/xdiff/xdiffi.c +++ b/xdiff/xdiffi.c @@ -328,10 +328,10 @@ int xdl_do_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, xdalgoenv_t xenv; diffdata_t dd1, dd2; - if (xpp->flags & XDF_PATIENCE_DIFF) + if (XDF_DIFF_ALG(xpp->flags) == XDF_PATIENCE_DIFF) return xdl_do_patience_diff(mf1, mf2, xpp, xe); - if (xpp->flags & XDF_HISTOGRAM_DIFF) + if (XDF_DIFF_ALG(xpp->flags) == XDF_HISTOGRAM_DIFF) return xdl_do_histogram_diff(mf1, mf2, xpp, xe); if (xdl_prepare_env(mf1, mf2, xpp, xe) < 0) { diff --git a/xdiff/xhistogram.c b/xdiff/xhistogram.c index 18f6f997c3..bf99787c3e 100644 --- a/xdiff/xhistogram.c +++ b/xdiff/xhistogram.c @@ -252,7 +252,7 @@ static int fall_back_to_classic_diff(struct histindex *index, int line1, int count1, int line2, int count2) { xpparam_t xpp; - xpp.flags = index->xpp->flags & ~XDF_HISTOGRAM_DIFF; + xpp.flags = index->xpp->flags & ~XDF_DIFF_ALGORITHM_MASK; return xdl_fall_back_diff(index->env, &xpp, line1, count1, line2, count2); diff --git a/xdiff/xpatience.c b/xdiff/xpatience.c index fdd7d0263f..04e1a1ab2a 100644 --- a/xdiff/xpatience.c +++ b/xdiff/xpatience.c @@ -288,7 +288,7 @@ static int fall_back_to_classic_diff(struct hashmap *map, int line1, int count1, int line2, int count2) { xpparam_t xpp; - xpp.flags = map->xpp->flags & ~XDF_PATIENCE_DIFF; + xpp.flags = map->xpp->flags & ~XDF_DIFF_ALGORITHM_MASK; return xdl_fall_back_diff(map->env, &xpp, line1, count1, line2, count2); diff --git a/xdiff/xprepare.c b/xdiff/xprepare.c index e419f4f726..63a22c630e 100644 --- a/xdiff/xprepare.c +++ b/xdiff/xprepare.c @@ -181,7 +181,7 @@ static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_ if (!(recs = (xrecord_t **) xdl_malloc(narec * sizeof(xrecord_t *)))) goto abort; - if (xpp->flags & XDF_HISTOGRAM_DIFF) + if (XDF_DIFF_ALG(xpp->flags) == XDF_HISTOGRAM_DIFF) hbits = hsize = 0; else { hbits = xdl_hashbits((unsigned int) narec); @@ -209,8 +209,8 @@ static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_ crec->ha = hav; recs[nrec++] = crec; - if (!(xpp->flags & XDF_HISTOGRAM_DIFF) && - xdl_classify_record(pass, cf, rhash, hbits, crec) < 0) + if ((XDF_DIFF_ALG(xpp->flags) != XDF_HISTOGRAM_DIFF) && + xdl_classify_record(pass, cf, rhash, hbits, crec) < 0) goto abort; } } @@ -273,16 +273,15 @@ int xdl_prepare_env(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, * (nrecs) will be updated correctly anyway by * xdl_prepare_ctx(). */ - sample = xpp->flags & XDF_HISTOGRAM_DIFF ? XDL_GUESS_NLINES2 : XDL_GUESS_NLINES1; + sample = (XDF_DIFF_ALG(xpp->flags) == XDF_HISTOGRAM_DIFF + ? XDL_GUESS_NLINES2 : XDL_GUESS_NLINES1); enl1 = xdl_guess_lines(mf1, sample) + 1; enl2 = xdl_guess_lines(mf2, sample) + 1; - if (!(xpp->flags & XDF_HISTOGRAM_DIFF) && - xdl_init_classifier(&cf, enl1 + enl2 + 1, xpp->flags) < 0) { - + if (XDF_DIFF_ALG(xpp->flags) != XDF_HISTOGRAM_DIFF && + xdl_init_classifier(&cf, enl1 + enl2 + 1, xpp->flags) < 0) return -1; - } if (xdl_prepare_ctx(1, mf1, enl1, xpp, &cf, &xe->xdf1) < 0) { @@ -296,9 +295,9 @@ int xdl_prepare_env(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, return -1; } - if (!(xpp->flags & XDF_PATIENCE_DIFF) && - !(xpp->flags & XDF_HISTOGRAM_DIFF) && - xdl_optimize_ctxs(&cf, &xe->xdf1, &xe->xdf2) < 0) { + if ((XDF_DIFF_ALG(xpp->flags) != XDF_PATIENCE_DIFF) && + (XDF_DIFF_ALG(xpp->flags) != XDF_HISTOGRAM_DIFF) && + xdl_optimize_ctxs(&cf, &xe->xdf1, &xe->xdf2) < 0) { xdl_free_ctx(&xe->xdf2); xdl_free_ctx(&xe->xdf1); |