diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index 894546dd75416f..49089de5c00242 100644 --- a/Documentation/CodingGuidelines +++ b/Documentation/CodingGuidelines @@ -328,9 +328,14 @@ For C programs: - When you come up with an API, document it. - - The first #include in C files, except in platform specific - compat/ implementations, should be git-compat-util.h or another - header file that includes it, such as cache.h or builtin.h. + - The first #include in C files, except in platform specific compat/ + implementations, must be either "git-compat-util.h", "cache.h" or + "builtin.h". You do not have to include more than one of these. + + - A C file must directly include the header files that declare the + functions and the types it uses, except for the functions and types + that are made available to it by including one of the header files + it must include by the previous rule. - If you are planning a new command, consider writing it in shell or perl first, so that changes in semantics can be easily @@ -441,6 +446,10 @@ Writing Documentation: --sort= --abbrev[=] + If a placeholder has multiple words, they are separated by dashes: + + --template= + Possibility of multiple occurrences is indicated by three dots: ... (One or more of .) @@ -457,12 +466,12 @@ Writing Documentation: (Zero or more of . Note that the dots are inside, not outside the brackets.) - Multiple alternatives are indicated with vertical bar: + Multiple alternatives are indicated with vertical bars: [-q | --quiet] [--utf8 | --no-utf8] Parentheses are used for grouping: - [(|)...] + [( | )...] (Any number of either or . Parens are needed to make it clear that "..." pertains to both and .) diff --git a/Documentation/config.txt b/Documentation/config.txt index 04e2a71687922b..ae6791db128130 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -2094,6 +2094,11 @@ rebase.autostash:: successful rebase might result in non-trivial conflicts. Defaults to false. +receive.advertiseatomic:: + By default, git-receive-pack will advertise the atomic push + capability to its clients. If you don't want to this capability + to be advertised, set this variable to false. + receive.autogc:: By default, git-receive-pack will run "git-gc --auto" after receiving data from git-push and updating refs. You can stop @@ -2153,11 +2158,15 @@ receive.denyCurrentBranch:: message. Defaults to "refuse". + Another option is "updateInstead" which will update the working -directory (must be clean) if pushing into the current branch. This option is +tree if pushing into the current branch. This option is intended for synchronizing working directories when one side is not easily accessible via interactive ssh (e.g. a live web site, hence the requirement that the working directory be clean). This mode also comes in handy when developing inside a VM to test and fix code on different Operating Systems. ++ +By default, "updateInstead" will refuse the push if the working tree or +the index have any difference from the HEAD, but the `push-to-checkout` +hook can be used to customize this. See linkgit:githooks[5]. receive.denyNonFastForwards:: If set to true, git-receive-pack will deny a ref update which is diff --git a/Documentation/git-hash-object.txt b/Documentation/git-hash-object.txt index 02c1f126855b24..2a2afdb4602635 100644 --- a/Documentation/git-hash-object.txt +++ b/Documentation/git-hash-object.txt @@ -9,8 +9,8 @@ git-hash-object - Compute object ID and optionally creates a blob from a file SYNOPSIS -------- [verse] -'git hash-object' [-t ] [-w] [--path=|--no-filters] [--stdin] [--] ... -'git hash-object' [-t ] [-w] --stdin-paths [--no-filters] < +'git hash-object' [--strict] [-t ] [-w] [--path=|--no-filters] [--stdin] [--] ... +'git hash-object' [--strict] [-t ] [-w] --stdin-paths [--no-filters] < DESCRIPTION ----------- @@ -25,6 +25,9 @@ specified, it defaults to "blob". OPTIONS ------- +--strict:: + Validate the object (equivalent to linkgit:git-fsck[1]). + -t :: Specify the type (default: "blob"). diff --git a/Documentation/git-mktree.txt b/Documentation/git-mktree.txt index 5c6ebdfad93ea8..774e34caf06f32 100644 --- a/Documentation/git-mktree.txt +++ b/Documentation/git-mktree.txt @@ -9,7 +9,7 @@ git-mktree - Build a tree-object from ls-tree formatted text SYNOPSIS -------- [verse] -'git mktree' [-z] [--missing] [--batch] +'git mktree' [-z] [--strict] [--missing] [--batch] DESCRIPTION ----------- @@ -23,6 +23,10 @@ OPTIONS -z:: Read the NUL-terminated `ls-tree -z` output instead. +--strict:: + Validate the tree object before writing (the validation is equivalent + to the one performed by linkgit:git-fsck[1]). + --missing:: Allow missing objects. The default behaviour (without this option) is to verify that each tree entry's sha1 identifies an existing diff --git a/Documentation/git-p4.txt b/Documentation/git-p4.txt index 6ab5f9497ab353..a1664b9f684bae 100644 --- a/Documentation/git-p4.txt +++ b/Documentation/git-p4.txt @@ -241,6 +241,9 @@ Git repository: Use a client spec to find the list of interesting files in p4. See the "CLIENT SPEC" section below. +-/ :: + Exclude selected depot paths when cloning or syncing. + Clone options ~~~~~~~~~~~~~ These options can be used in an initial 'clone', along with the 'sync' @@ -254,9 +257,6 @@ options described above. --bare:: Perform a bare clone. See linkgit:git-clone[1]. --/ :: - Exclude selected depot paths when cloning. - Submit options ~~~~~~~~~~~~~~ These options can be used to modify 'git p4 submit' behavior. diff --git a/Documentation/git-push.txt b/Documentation/git-push.txt index b17283ab7a1cc7..ea9757692ac6fa 100644 --- a/Documentation/git-push.txt +++ b/Documentation/git-push.txt @@ -9,7 +9,7 @@ git-push - Update remote refs along with associated objects SYNOPSIS -------- [verse] -'git push' [--all | --mirror | --tags] [--follow-tags] [-n | --dry-run] [--receive-pack=] +'git push' [--all | --mirror | --tags] [--follow-tags] [--atomic] [-n | --dry-run] [--receive-pack=] [--repo=] [-f | --force] [--prune] [-v | --verbose] [-u | --set-upstream] [--signed] [--force-with-lease[=[:]]] @@ -136,6 +136,11 @@ already exists on the remote side. logged. See linkgit:git-receive-pack[1] for the details on the receiving end. +--[no-]atomic:: + Use an atomic transaction on the remote side if available. + Either all refs are updated, or on error, no refs are updated. + If the server does not support atomic pushes the push will fail. + --receive-pack=:: --exec=:: Path to the 'git-receive-pack' program on the remote diff --git a/Documentation/git-send-pack.txt b/Documentation/git-send-pack.txt index 2a0de42a75d482..45c7725dc303ee 100644 --- a/Documentation/git-send-pack.txt +++ b/Documentation/git-send-pack.txt @@ -9,7 +9,7 @@ git-send-pack - Push objects over Git protocol to another repository SYNOPSIS -------- [verse] -'git send-pack' [--all] [--dry-run] [--force] [--receive-pack=] [--verbose] [--thin] [:] [...] +'git send-pack' [--all] [--dry-run] [--force] [--receive-pack=] [--verbose] [--thin] [--atomic] [:] [...] DESCRIPTION ----------- @@ -62,6 +62,11 @@ be in a separate packet, and the list must end with a flush packet. Send a "thin" pack, which records objects in deltified form based on objects not included in the pack to reduce network traffic. +--atomic:: + Use an atomic transaction for updating the refs. If any of the refs + fails to update then the entire push will fail without changing any + refs. + :: A remote host to house the repository. When this part is specified, 'git-receive-pack' is invoked via diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index 9ef2469373a5d7..7ba0ac965dd626 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -341,6 +341,36 @@ Both standard output and standard error output are forwarded to 'git send-pack' on the other end, so you can simply `echo` messages for the user. +push-to-checkout +~~~~~~~~~~~~~~~~ + +This hook is invoked by 'git-receive-pack' on the remote repository, +which happens when a 'git push' is done on a local repository, when +the push tries to update the branch that is currently checked out +and the `receive.denyCurrentBranch` configuration variable is set to +`updateInstead`. Such a push by default is refused if the working +tree and the index of the remote repository has any difference from +the currently checked out commit; when both the working tree and the +index match the current commit, they are updated to match the newly +pushed tip of the branch. This hook is to be used to override the +default behaviour. + +The hook receives the commit with which the tip of the current +branch is going to be updated. It can exit with a non-zero status +to refuse the push (when it does so, it must not modify the index or +the working tree). Or it can make any necessary changes to the +working tree and to the index to bring them to the desired state +when the tip of the current branch is updated to the new commit, and +exit with a zero status. + +For example, the hook can simply run `git read-tree -u -m HEAD "$1"` +in order to emulate 'git fetch' that is run in the reverse direction +with `git push`, as the two-tree form of `read-tree -u -m` is +essentially the same as `git checkout` that switches branches while +keeping the local changes in the working tree that do not interfere +with the difference between the branches. + + pre-auto-gc ~~~~~~~~~~~ diff --git a/Documentation/pretty-options.txt b/Documentation/pretty-options.txt index 8569e29d08784c..74aa01a0ec27b6 100644 --- a/Documentation/pretty-options.txt +++ b/Documentation/pretty-options.txt @@ -3,9 +3,13 @@ Pretty-print the contents of the commit logs in a given format, where '' can be one of 'oneline', 'short', 'medium', - 'full', 'fuller', 'email', 'raw' and 'format:'. See - the "PRETTY FORMATS" section for some additional details for each - format. When omitted, the format defaults to 'medium'. + 'full', 'fuller', 'email', 'raw', 'format:' + and 'tformat:'. When '' is none of the above, + and has '%placeholder' in it, it acts as if + '--pretty=tformat:' were given. ++ +See the "PRETTY FORMATS" section for some additional details for each +format. When '=' part is omitted, it defaults to 'medium'. + Note: you can specify the default pretty format in the repository configuration (see linkgit:git-config[1]). diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt index 2984f407a9f308..0f3d460d34a628 100644 --- a/Documentation/rev-list-options.txt +++ b/Documentation/rev-list-options.txt @@ -66,6 +66,10 @@ if it is part of the log message. Limit the commits output to ones that match all given `--grep`, instead of ones that match at least one. +--invert-grep:: + Limit the commits output to ones with log message that do not + match the pattern specified with `--grep=`. + -i:: --regexp-ignore-case:: Match the regular expression limiting patterns without regard to letter diff --git a/Documentation/technical/protocol-capabilities.txt b/Documentation/technical/protocol-capabilities.txt index 6d5424c1bde5d9..4f8a7bfb4c68e4 100644 --- a/Documentation/technical/protocol-capabilities.txt +++ b/Documentation/technical/protocol-capabilities.txt @@ -18,8 +18,9 @@ was sent. Server MUST NOT ignore capabilities that client requested and server advertised. As a consequence of these rules, server MUST NOT advertise capabilities it does not understand. -The 'report-status', 'delete-refs', 'quiet', and 'push-cert' capabilities -are sent and recognized by the receive-pack (push to server) process. +The 'atomic', 'report-status', 'delete-refs', 'quiet', and 'push-cert' +capabilities are sent and recognized by the receive-pack (push to server) +process. The 'ofs-delta' and 'side-band-64k' capabilities are sent and recognized by both upload-pack and receive-pack protocols. The 'agent' capability @@ -244,6 +245,14 @@ respond with the 'quiet' capability to suppress server-side progress reporting if the local progress reporting is also being suppressed (e.g., via `push -q`, or if stderr does not go to a tty). +atomic +------ + +If the server sends the 'atomic' capability it is capable of accepting +atomic pushes. If the pushing client requests this capability, the server +will update the refs in one atomic transaction. Either all refs are +updated or none. + allow-tip-sha1-in-want ---------------------- diff --git a/Makefile b/Makefile index c44eb3a8511c1d..4b8427981e963a 100644 --- a/Makefile +++ b/Makefile @@ -348,6 +348,15 @@ all:: # # Define NO_HMAC_CTX_CLEANUP if your OpenSSL is version 0.9.6b or earlier to # cleanup the HMAC context with the older HMAC_cleanup function. +# +# Define USE_PARENS_AROUND_GETTEXT_N to "yes" if your compiler happily +# compiles the following initialization: +# +# static const char s[] = ("FOO"); +# +# and define it to "no" if you need to remove the parentheses () around the +# constant. The default is "auto", which means to use parentheses if your +# compiler is detected to support it. GIT-VERSION-FILE: FORCE @$(SHELL_PATH) ./GIT-VERSION-GEN @@ -355,7 +364,7 @@ GIT-VERSION-FILE: FORCE # CFLAGS and LDFLAGS are for the users to override from the command line. -CFLAGS = -g -O2 -Wall +CFLAGS = -g -Wall LDFLAGS = ALL_CFLAGS = $(CPPFLAGS) $(CFLAGS) ALL_LDFLAGS = $(LDFLAGS) @@ -955,6 +964,14 @@ ifneq (,$(SOCKLEN_T)) BASIC_CFLAGS += -Dsocklen_t=$(SOCKLEN_T) endif +ifeq (yes,$(USE_PARENS_AROUND_GETTEXT_N)) + BASIC_CFLAGS += -DUSE_PARENS_AROUND_GETTEXT_N=1 +else +ifeq (no,$(USE_PARENS_AROUND_GETTEXT_N)) + BASIC_CFLAGS += -DUSE_PARENS_AROUND_GETTEXT_N=0 +endif +endif + ifeq ($(uname_S),Darwin) ifndef NO_FINK ifeq ($(shell test -d /sw/lib && echo y),y) diff --git a/advice.c b/advice.c index 3b8bf3c6da6afd..575bec20b35a31 100644 --- a/advice.c +++ b/advice.c @@ -105,7 +105,7 @@ void detach_advice(const char *new_name) "state without impacting any branches by performing another checkout.\n\n" "If you want to create a new branch to retain commits you create, you may\n" "do so (now or later) by using -b with the checkout command again. Example:\n\n" - " git checkout -b new_branch_name\n\n"; + " git checkout -b \n\n"; fprintf(stderr, fmt, new_name); } diff --git a/archive.c b/archive.c index 9e30246b640245..96057ed830e521 100644 --- a/archive.c +++ b/archive.c @@ -8,9 +8,9 @@ #include "dir.h" static char const * const archive_usage[] = { - N_("git archive [options] [...]"), + N_("git archive [] [...]"), N_("git archive --list"), - N_("git archive --remote [--exec ] [options] [...]"), + N_("git archive --remote [--exec ] [] [...]"), N_("git archive --remote [--exec ] --list"), NULL }; diff --git a/builtin/add.c b/builtin/add.c index 1074e3234964de..3390933d68b2dd 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -19,7 +19,7 @@ #include "argv-array.h" static const char * const builtin_add_usage[] = { - N_("git add [options] [--] ..."), + N_("git add [] [--] ..."), NULL }; static int patch_interactive, add_interactive, edit_interactive; diff --git a/builtin/apply.c b/builtin/apply.c index 0aad91283959bc..23bda962879501 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -55,7 +55,7 @@ static const char *fake_ancestor; static int line_termination = '\n'; static unsigned int p_context = UINT_MAX; static const char * const apply_usage[] = { - N_("git apply [options] [...]"), + N_("git apply [] [...]"), NULL }; @@ -657,11 +657,6 @@ static size_t diff_timestamp_len(const char *line, size_t len) return line + len - end; } -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) { @@ -684,10 +679,10 @@ static char *find_name_common(const char *line, const char *def, start = line; } if (!start) - return squash_slash(null_strdup(def)); + return squash_slash(xstrdup_or_null(def)); len = line - start; if (!len) - return squash_slash(null_strdup(def)); + return squash_slash(xstrdup_or_null(def)); /* * Generally we prefer the shorter name, especially @@ -909,7 +904,7 @@ static void parse_traditional_patch(const char *first, const char *second, struc patch->old_name = name; } else { patch->old_name = name; - patch->new_name = null_strdup(name); + patch->new_name = xstrdup_or_null(name); } } if (!name) @@ -998,7 +993,7 @@ static int gitdiff_delete(const char *line, struct patch *patch) { patch->is_delete = 1; free(patch->old_name); - patch->old_name = null_strdup(patch->def_name); + patch->old_name = xstrdup_or_null(patch->def_name); return gitdiff_oldmode(line, patch); } @@ -1006,7 +1001,7 @@ static int gitdiff_newfile(const char *line, struct patch *patch) { patch->is_new = 1; free(patch->new_name); - patch->new_name = null_strdup(patch->def_name); + patch->new_name = xstrdup_or_null(patch->def_name); return gitdiff_newmode(line, patch); } diff --git a/builtin/blame.c b/builtin/blame.c index 303e217ae919f2..44b0134ea295ba 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -27,12 +27,12 @@ #include "line-range.h" #include "line-log.h" -static char blame_usage[] = N_("git blame [options] [rev-opts] [rev] [--] file"); +static char blame_usage[] = N_("git blame [] [] [] [--] file"); static const char *blame_opt_usage[] = { blame_usage, "", - N_("[rev-opts] are documented in git-rev-list(1)"), + N_(" are documented in git-rev-list(1)"), NULL }; @@ -2390,7 +2390,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt, return commit; } -static const char *prepare_final(struct scoreboard *sb) +static char *prepare_final(struct scoreboard *sb) { int i; const char *final_commit_name = NULL; @@ -2415,10 +2415,10 @@ static const char *prepare_final(struct scoreboard *sb) sb->final = (struct commit *) obj; final_commit_name = revs->pending.objects[i].name; } - return final_commit_name; + return xstrdup_or_null(final_commit_name); } -static const char *prepare_initial(struct scoreboard *sb) +static char *prepare_initial(struct scoreboard *sb) { int i; const char *final_commit_name = NULL; @@ -2445,7 +2445,7 @@ static const char *prepare_initial(struct scoreboard *sb) } if (!final_commit_name) die("No commit to dig down to?"); - return final_commit_name; + return xstrdup(final_commit_name); } static int blame_copy_callback(const struct option *option, const char *arg, int unset) @@ -2489,7 +2489,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix) struct origin *o; struct blame_entry *ent = NULL; long dashdash_pos, lno; - const char *final_commit_name = NULL; + char *final_commit_name = NULL; enum object_type type; static struct string_list range_list; @@ -2786,6 +2786,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix) assign_blame(&sb, opt); + free(final_commit_name); + if (incremental) return 0; diff --git a/builtin/branch.c b/builtin/branch.c index dc6f0b266c9cf6..6a25957e9f9daf 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -21,10 +21,10 @@ #include "wt-status.h" static const char * const builtin_branch_usage[] = { - N_("git branch [options] [-r | -a] [--merged | --no-merged]"), - N_("git branch [options] [-l] [-f] []"), - N_("git branch [options] [-r] (-d | -D) ..."), - N_("git branch [options] (-m | -M) [] "), + N_("git branch [] [-r | -a] [--merged | --no-merged]"), + N_("git branch [] [-l] [-f] []"), + N_("git branch [] [-r] (-d | -D) ..."), + N_("git branch [] (-m | -M) [] "), NULL }; diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 31b133b357f34e..df99df4db1ddb0 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -323,8 +323,8 @@ static int batch_objects(struct batch_options *opt) } static const char * const cat_file_usage[] = { - N_("git cat-file (-t|-s|-e|-p||--textconv) "), - N_("git cat-file (--batch|--batch-check) < "), + N_("git cat-file (-t | -s | -e | -p | | --textconv) "), + N_("git cat-file (--batch | --batch-check) < "), NULL }; diff --git a/builtin/check-attr.c b/builtin/check-attr.c index 5600ec3f6165ae..21d2bedcc930ab 100644 --- a/builtin/check-attr.c +++ b/builtin/check-attr.c @@ -8,8 +8,8 @@ static int all_attrs; static int cached_attrs; static int stdin_paths; static const char * const check_attr_usage[] = { -N_("git check-attr [-a | --all | attr...] [--] pathname..."), -N_("git check-attr --stdin [-z] [-a | --all | attr...] < "), +N_("git check-attr [-a | --all | ...] [--] ..."), +N_("git check-attr --stdin [-z] [-a | --all | ...] < "), NULL }; diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c index 594463a11bcba3..dc8d97c56c6099 100644 --- a/builtin/check-ignore.c +++ b/builtin/check-ignore.c @@ -7,8 +7,8 @@ static int quiet, verbose, stdin_paths, show_non_matching, no_index; static const char * const check_ignore_usage[] = { -"git check-ignore [options] pathname...", -"git check-ignore [options] --stdin < ", +"git check-ignore [] ...", +"git check-ignore [] --stdin < ", NULL }; diff --git a/builtin/check-mailmap.c b/builtin/check-mailmap.c index 8f4d809bd8c005..eaaea546d30871 100644 --- a/builtin/check-mailmap.c +++ b/builtin/check-mailmap.c @@ -5,7 +5,7 @@ static int use_stdin; static const char * const check_mailmap_usage[] = { -N_("git check-mailmap [options] ..."), +N_("git check-mailmap [] ..."), NULL }; diff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c index 28a7320271a955..fd915d59841ecc 100644 --- a/builtin/check-ref-format.c +++ b/builtin/check-ref-format.c @@ -8,7 +8,7 @@ #include "strbuf.h" static const char builtin_check_ref_format_usage[] = -"git check-ref-format [--normalize] [options] \n" +"git check-ref-format [--normalize] [] \n" " or: git check-ref-format --branch "; /* diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c index 031780f49e0b3a..9ca2da15836d16 100644 --- a/builtin/checkout-index.c +++ b/builtin/checkout-index.c @@ -123,7 +123,7 @@ static void checkout_all(const char *prefix, int prefix_length) } static const char * const builtin_checkout_index_usage[] = { - N_("git checkout-index [options] [--] [...]"), + N_("git checkout-index [] [--] [...]"), NULL }; diff --git a/builtin/checkout.c b/builtin/checkout.c index 52d6cbb0a84e26..3e141fc1491949 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -22,8 +22,8 @@ #include "argv-array.h" static const char * const checkout_usage[] = { - N_("git checkout [options] "), - N_("git checkout [options] [] -- ..."), + N_("git checkout [] "), + N_("git checkout [] [] -- ..."), NULL, }; @@ -746,7 +746,7 @@ static void suggest_reattach(struct commit *commit, struct rev_info *revs) _( "If you want to keep them by creating a new branch, " "this may be a good time\nto do so with:\n\n" - " git branch new_branch_name %s\n\n"), + " git branch %s\n\n"), find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV)); } @@ -1127,7 +1127,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) OPT_BOOL(0, "ignore-skip-worktree-bits", &opts.ignore_skipworktree, N_("do not limit pathspecs to sparse entries only")), OPT_HIDDEN_BOOL(0, "guess", &dwim_new_local_branch, - N_("second guess 'git checkout no-such-branch'")), + N_("second guess 'git checkout '")), OPT_END(), }; diff --git a/builtin/clone.c b/builtin/clone.c index 316c75d0b342d0..957246723e94ef 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -34,7 +34,7 @@ * */ static const char * const builtin_clone_usage[] = { - N_("git clone [options] [--] []"), + N_("git clone [] [--] []"), NULL }; diff --git a/builtin/column.c b/builtin/column.c index 75818520e1b74d..449413c8a873eb 100644 --- a/builtin/column.c +++ b/builtin/column.c @@ -6,7 +6,7 @@ #include "column.h" static const char * const builtin_column_usage[] = { - N_("git column [options]"), + N_("git column []"), NULL }; static unsigned int colopts; diff --git a/builtin/commit.c b/builtin/commit.c index 7d90c3591567d1..7f467133b88c10 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -34,12 +34,12 @@ #include "mailmap.h" static const char * const builtin_commit_usage[] = { - N_("git commit [options] [--] ..."), + N_("git commit [] [--] ..."), NULL }; static const char * const builtin_status_usage[] = { - N_("git status [options] [--] ..."), + N_("git status [] [--] ..."), NULL }; @@ -559,20 +559,14 @@ static void set_ident_var(char **buf, char *val) *buf = val; } -static char *envdup(const char *var) -{ - const char *val = getenv(var); - return val ? xstrdup(val) : NULL; -} - static void determine_author_info(struct strbuf *author_ident) { char *name, *email, *date; struct ident_split author; - name = envdup("GIT_AUTHOR_NAME"); - email = envdup("GIT_AUTHOR_EMAIL"); - date = envdup("GIT_AUTHOR_DATE"); + name = xstrdup_or_null(getenv("GIT_AUTHOR_NAME")); + email = xstrdup_or_null(getenv("GIT_AUTHOR_EMAIL")); + date = xstrdup_or_null(getenv("GIT_AUTHOR_DATE")); if (author_message) { struct ident_split ident; diff --git a/builtin/config.c b/builtin/config.c index 15a7bea936d667..d32c5327e53e14 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -5,7 +5,7 @@ #include "urlmatch.h" static const char *const builtin_config_usage[] = { - N_("git config [options]"), + N_("git config []"), NULL }; diff --git a/builtin/describe.c b/builtin/describe.c index 9103193b4f65dc..e00a75b121826e 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -14,8 +14,8 @@ #define MAX_TAGS (FLAG_BITS - 1) static const char * const describe_usage[] = { - N_("git describe [options] *"), - N_("git describe [options] --dirty"), + N_("git describe [] [...]"), + N_("git describe [] --dirty"), NULL }; diff --git a/builtin/diff-files.c b/builtin/diff-files.c index 9200069363ff01..8ed2eb8813a442 100644 --- a/builtin/diff-files.c +++ b/builtin/diff-files.c @@ -11,7 +11,7 @@ #include "submodule.h" static const char diff_files_usage[] = -"git diff-files [-q] [-0/-1/2/3 |-c|--cc] [] [...]" +"git diff-files [-q] [-0 | -1 | -2 | -3 | -c | --cc] [] [...]" COMMON_DIFF_OPTIONS_HELP; int cmd_diff_files(int argc, const char **argv, const char *prefix) diff --git a/builtin/diff-index.c b/builtin/diff-index.c index ce15b23042d847..d979824f9395a0 100644 --- a/builtin/diff-index.c +++ b/builtin/diff-index.c @@ -7,7 +7,7 @@ static const char diff_cache_usage[] = "git diff-index [-m] [--cached] " -"[] [...]" +"[] [...]" COMMON_DIFF_OPTIONS_HELP; int cmd_diff_index(int argc, const char **argv, const char *prefix) diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c index 1c4ad6223eb954..12b683d0217856 100644 --- a/builtin/diff-tree.c +++ b/builtin/diff-tree.c @@ -82,7 +82,7 @@ static int diff_tree_stdin(char *line) static const char diff_tree_usage[] = "git diff-tree [--stdin] [-m] [-c] [--cc] [-s] [-v] [--pretty] [-t] [-r] [--root] " -"[] [] [...]\n" +"[] [] [...]\n" " -r diff recursively\n" " --root include the initial commit as diff against /dev/null\n" COMMON_DIFF_OPTIONS_HELP; diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c index 1262b405f8212e..4a6b340ab67622 100644 --- a/builtin/fetch-pack.c +++ b/builtin/fetch-pack.c @@ -6,7 +6,7 @@ #include "sha1-array.h" static const char fetch_pack_usage[] = -"git fetch-pack [--all] [--stdin] [--quiet|-q] [--keep|-k] [--thin] " +"git fetch-pack [--all] [--stdin] [--quiet | -q] [--keep | -k] [--thin] " "[--include-tag] [--upload-pack=] [--depth=] " "[--no-progress] [--diag-url] [-v] [:] [...]"; diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c index af7919e51e7179..1d962dc569eaaf 100644 --- a/builtin/fmt-merge-msg.c +++ b/builtin/fmt-merge-msg.c @@ -10,7 +10,7 @@ #include "gpg-interface.h" static const char * const fmt_merge_msg_usage[] = { - N_("git fmt-merge-msg [-m ] [--log[=]|--no-log] [--file ]"), + N_("git fmt-merge-msg [-m ] [--log[=] | --no-log] [--file ]"), NULL }; diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c index a0123f6146b53d..19be78a943d303 100644 --- a/builtin/for-each-ref.c +++ b/builtin/for-each-ref.c @@ -1061,7 +1061,7 @@ static int opt_parse_sort(const struct option *opt, const char *arg, int unset) } static char const * const for_each_ref_usage[] = { - N_("git for-each-ref [options] []"), + N_("git for-each-ref [] []"), NULL }; diff --git a/builtin/fsck.c b/builtin/fsck.c index a27515aeaa2deb..0c757862e8cd41 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -600,7 +600,7 @@ static int fsck_cache_tree(struct cache_tree *it) } static char const * const fsck_usage[] = { - N_("git fsck [options] [...]"), + N_("git fsck [] [...]"), NULL }; diff --git a/builtin/gc.c b/builtin/gc.c index 005adbebea80a8..5c634afc0022c0 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -21,7 +21,7 @@ #define FAILED_RUN "failed to run %s" static const char * const builtin_gc_usage[] = { - N_("git gc [options]"), + N_("git gc []"), NULL }; diff --git a/builtin/grep.c b/builtin/grep.c index 4063882f06536a..9262b73b6f5efd 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -20,7 +20,7 @@ #include "pathspec.h" static char const * const grep_usage[] = { - N_("git grep [options] [-e] [...] [[--] ...]"), + N_("git grep [] [-e] [...] [[--] ...]"), NULL }; diff --git a/builtin/hash-object.c b/builtin/hash-object.c index 61583633182da3..f3eb7857800a59 100644 --- a/builtin/hash-object.c +++ b/builtin/hash-object.c @@ -79,8 +79,8 @@ static void hash_stdin_paths(const char *type, int no_filters, unsigned flags, int cmd_hash_object(int argc, const char **argv, const char *prefix) { static const char * const hash_object_usage[] = { - N_("git hash-object [-t ] [-w] [--path=|--no-filters] [--stdin] [--] ..."), - N_("git hash-object --stdin-paths < "), + N_("git hash-object [--strict] [-t ] [-w] [--path= | --no-filters] [--stdin] [--] ..."), + N_("git hash-object [--strict] --stdin-paths < "), NULL }; const char *type = blob_type; @@ -88,6 +88,7 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix) int stdin_paths = 0; int no_filters = 0; int literally = 0; + int strict = 0; unsigned flags = HASH_FORMAT_CHECK; const char *vpath = NULL; const struct option hash_object_options[] = { @@ -97,6 +98,7 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix) OPT_COUNTUP( 0 , "stdin", &hashstdin, N_("read the object from stdin")), OPT_BOOL( 0 , "stdin-paths", &stdin_paths, N_("read file names from stdin")), OPT_BOOL( 0 , "no-filters", &no_filters, N_("store file as is without filters")), + OPT_BOOL( 0, "strict", &strict, N_("validate thoroughly before writing")), OPT_BOOL( 0, "literally", &literally, N_("just hash any random garbage to create corrupt objects for debugging Git")), OPT_STRING( 0 , "path", &vpath, N_("file"), N_("process file as it were from this path")), OPT_END() @@ -137,8 +139,18 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix) usage_with_options(hash_object_usage, hash_object_options); } + if (strict) + flags |= HASH_FORMAT_STRICT; + if (hashstdin) +{ +if (getenv("DEBUG_BOGUS_COMMIT")) { +int fd = open("bogus-commit", O_RDONLY); +hash_fd(fd, type, vpath, flags, literally); +close(fd); +} else hash_fd(0, type, vpath, flags, literally); +} for (i = 0 ; i < argc; i++) { const char *arg = argv[i]; diff --git a/builtin/help.c b/builtin/help.c index e78c135e010afa..6133fe496b00e3 100644 --- a/builtin/help.c +++ b/builtin/help.c @@ -49,7 +49,7 @@ static struct option builtin_help_options[] = { }; static const char * const builtin_help_usage[] = { - N_("git help [--all] [--guides] [--man|--web|--info] [command]"), + N_("git help [--all] [--guides] [--man | --web | --info] []"), NULL }; diff --git a/builtin/init-db.c b/builtin/init-db.c index 9966522b4a97a0..6723d39c3baf35 100644 --- a/builtin/init-db.c +++ b/builtin/init-db.c @@ -472,7 +472,7 @@ static int shared_callback(const struct option *opt, const char *arg, int unset) } static const char *const init_db_usage[] = { - N_("git init [-q | --quiet] [--bare] [--template=] [--shared[=]] [directory]"), + N_("git init [-q | --quiet] [--bare] [--template=] [--shared[=]] []"), NULL }; diff --git a/builtin/log.c b/builtin/log.c index 923ffe72ced41f..dd8f3fcfc45178 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -39,7 +39,7 @@ static const char *fmt_pretty; static const char * const builtin_log_usage[] = { N_("git log [] [] [[--] ...]"), - N_("git show [options] ..."), + N_("git show [] ..."), NULL }; @@ -705,7 +705,7 @@ static int git_format_config(const char *var, const char *value, void *cb) return 0; } if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff") || - !strcmp(var, "color.ui")) { + !strcmp(var, "color.ui") || !strcmp(var, "diff.submodule")) { return 0; } if (!strcmp(var, "format.numbered")) { @@ -1023,7 +1023,7 @@ static const char *set_outdir(const char *prefix, const char *output_directory) } static const char * const builtin_format_patch_usage[] = { - N_("git format-patch [options] [ | ]"), + N_("git format-patch [] [ | ]"), NULL }; diff --git a/builtin/ls-files.c b/builtin/ls-files.c index 99cee20fb07ce7..914054d36734ba 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -398,7 +398,7 @@ int report_path_error(const char *ps_matched, } static const char * const ls_files_usage[] = { - N_("git ls-files [options] [...]"), + N_("git ls-files [] [...]"), NULL }; diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c index b2a4b92992748a..4554dbc8a98c0d 100644 --- a/builtin/ls-remote.c +++ b/builtin/ls-remote.c @@ -5,7 +5,7 @@ static const char ls_remote_usage[] = "git ls-remote [--heads] [--tags] [-u | --upload-pack ]\n" -" [-q|--quiet] [--exit-code] [--get-url] [ [...]]"; +" [-q | --quiet] [--exit-code] [--get-url] [ [...]]"; /* * Is there one among the list of patterns that match the tail part diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c index c8a47c173d0117..999a5250fbe7e6 100644 --- a/builtin/mailinfo.c +++ b/builtin/mailinfo.c @@ -1031,7 +1031,7 @@ static int git_mailinfo_config(const char *var, const char *value, void *unused) } static const char mailinfo_usage[] = - "git mailinfo [-k|-b] [-m | --message-id] [-u | --encoding= | -n] [--scissors | --no-scissors] msg patch < mail >info"; + "git mailinfo [-k | -b] [-m | --message-id] [-u | --encoding= | -n] [--scissors | --no-scissors] < mail >info"; int cmd_mailinfo(int argc, const char **argv, const char *prefix) { diff --git a/builtin/merge-base.c b/builtin/merge-base.c index fdebef6fa157e9..08a8217890df59 100644 --- a/builtin/merge-base.c +++ b/builtin/merge-base.c @@ -26,8 +26,8 @@ static int show_merge_base(struct commit **rev, int rev_nr, int show_all) } static const char * const merge_base_usage[] = { - N_("git merge-base [-a|--all] ..."), - N_("git merge-base [-a|--all] --octopus ..."), + N_("git merge-base [-a | --all] ..."), + N_("git merge-base [-a | --all] --octopus ..."), N_("git merge-base --independent ..."), N_("git merge-base --is-ancestor "), N_("git merge-base --fork-point []"), diff --git a/builtin/merge-file.c b/builtin/merge-file.c index 844f84f40bf0f8..131edc245fdc0f 100644 --- a/builtin/merge-file.c +++ b/builtin/merge-file.c @@ -5,7 +5,7 @@ #include "parse-options.h" static const char *const merge_file_usage[] = { - N_("git merge-file [options] [-L name1 [-L orig [-L name2]]] file1 orig_file file2"), + N_("git merge-file [] [-L [-L [-L ]]] "), NULL }; @@ -42,7 +42,7 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix) N_("for conflicts, use this marker size")), OPT__QUIET(&quiet, N_("do not warn about conflicts")), OPT_CALLBACK('L', NULL, names, N_("name"), - N_("set labels for file1/orig_file/file2"), &label_cb), + N_("set labels for file1/orig-file/file2"), &label_cb), OPT_END(), }; diff --git a/builtin/merge-index.c b/builtin/merge-index.c index b416d928492c43..1a1eafa6fdc2e9 100644 --- a/builtin/merge-index.c +++ b/builtin/merge-index.c @@ -75,7 +75,7 @@ int cmd_merge_index(int argc, const char **argv, const char *prefix) signal(SIGCHLD, SIG_DFL); if (argc < 3) - usage("git merge-index [-o] [-q] (-a | [--] *)"); + usage("git merge-index [-o] [-q] (-a | [--] [...])"); read_cache(); diff --git a/builtin/merge.c b/builtin/merge.c index c638fd5a9a8165..3b0f8f96d41684 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -42,8 +42,8 @@ struct strategy { }; static const char * const builtin_merge_usage[] = { - N_("git merge [options] [...]"), - N_("git merge [options] HEAD "), + N_("git merge [] [...]"), + N_("git merge [] HEAD "), N_("git merge --abort"), NULL }; diff --git a/builtin/mktree.c b/builtin/mktree.c index a964d6be521c09..baf47fba06c436 100644 --- a/builtin/mktree.c +++ b/builtin/mktree.c @@ -7,7 +7,10 @@ #include "quote.h" #include "tree.h" #include "parse-options.h" +#include "tree.h" +#include "fsck.h" +static int strict; static struct treeent { unsigned mode; unsigned char sha1[20]; @@ -56,6 +59,16 @@ static void write_tree(unsigned char *sha1) strbuf_add(&buf, ent->sha1, 20); } + if (strict) { + struct tree tree; + memset(&tree, 0, sizeof(tree)); + tree.object.type = OBJ_TREE; + parse_tree_buffer(&tree, buf.buf, buf.len); + if (fsck_object(&tree.object, buf.buf, buf.len, 1, + fsck_error_function)) + exit(1); + } + write_sha1_file(buf.buf, buf.len, tree_type, sha1); strbuf_release(&buf); } @@ -150,6 +163,7 @@ int cmd_mktree(int ac, const char **av, const char *prefix) OPT_SET_INT('z', NULL, &line_termination, N_("input is NUL terminated"), '\0'), OPT_SET_INT( 0 , "missing", &allow_missing, N_("allow missing objects"), 1), OPT_SET_INT( 0 , "batch", &is_batch_mode, N_("allow creation of more than one tree"), 1), + OPT_BOOL( 0 , "strict", &strict, N_("validate the tree object")), OPT_END() }; diff --git a/builtin/mv.c b/builtin/mv.c index 563d05ba1af21c..d1d43168ae79d0 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -12,7 +12,7 @@ #include "submodule.h" static const char * const builtin_mv_usage[] = { - N_("git mv [options] ... "), + N_("git mv [] ... "), NULL }; diff --git a/builtin/name-rev.c b/builtin/name-rev.c index 3c8f319be675d1..9736d4452f2872 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -252,9 +252,9 @@ static void show_name(const struct object *obj, } static char const * const name_rev_usage[] = { - N_("git name-rev [options] ..."), - N_("git name-rev [options] --all"), - N_("git name-rev [options] --stdin"), + N_("git name-rev [] ..."), + N_("git name-rev [] --all"), + N_("git name-rev [] --stdin"), NULL }; diff --git a/builtin/notes.c b/builtin/notes.c index a9f37d04564123..63f95fc5543906 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -21,18 +21,18 @@ #include "notes-utils.h" static const char * const git_notes_usage[] = { - N_("git notes [--ref ] [list []]"), - N_("git notes [--ref ] add [-f] [--allow-empty] [-m | -F | (-c | -C) ] []"), - N_("git notes [--ref ] copy [-f] "), - N_("git notes [--ref ] append [--allow-empty] [-m | -F | (-c | -C) ] []"), - N_("git notes [--ref ] edit [--allow-empty] []"), - N_("git notes [--ref ] show []"), - N_("git notes [--ref ] merge [-v | -q] [-s ] "), + N_("git notes [--ref ] [list []]"), + N_("git notes [--ref ] add [-f] [--allow-empty] [-m | -F | (-c | -C) ] []"), + N_("git notes [--ref ] copy [-f] "), + N_("git notes [--ref ] append [--allow-empty] [-m | -F | (-c | -C) ] []"), + N_("git notes [--ref ] edit [--allow-empty] []"), + N_("git notes [--ref ] show []"), + N_("git notes [--ref ] merge [-v | -q] [-s ] "), N_("git notes merge --commit [-v | -q]"), N_("git notes merge --abort [-v | -q]"), - N_("git notes [--ref ] remove [...]"), - N_("git notes [--ref ] prune [-n | -v]"), - N_("git notes [--ref ] get-ref"), + N_("git notes [--ref ] remove [...]"), + N_("git notes [--ref ] prune [-n | -v]"), + N_("git notes [--ref ] get-ref"), NULL }; @@ -68,7 +68,7 @@ static const char * const git_notes_show_usage[] = { }; static const char * const git_notes_merge_usage[] = { - N_("git notes merge [] "), + N_("git notes merge [] "), N_("git notes merge --commit []"), N_("git notes merge --abort []"), NULL @@ -951,7 +951,7 @@ int cmd_notes(int argc, const char **argv, const char *prefix) const char *override_notes_ref = NULL; struct option options[] = { OPT_STRING(0, "ref", &override_notes_ref, N_("notes-ref"), - N_("use notes from ")), + N_("use notes from ")), OPT_END() }; diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c index 649c3aaa93ccda..d0532f66b1d4a4 100644 --- a/builtin/pack-redundant.c +++ b/builtin/pack-redundant.c @@ -11,7 +11,7 @@ #define BLKSIZE 512 static const char pack_redundant_usage[] = -"git pack-redundant [ --verbose ] [ --alt-odb ] < --all | <.pack filename> ...>"; +"git pack-redundant [--verbose] [--alt-odb] (--all | ...)"; static int load_all_packs, verbose, alt_odb; diff --git a/builtin/pack-refs.c b/builtin/pack-refs.c index b20b1ec4c117f7..39f9a55d16736d 100644 --- a/builtin/pack-refs.c +++ b/builtin/pack-refs.c @@ -3,7 +3,7 @@ #include "refs.h" static char const * const pack_refs_usage[] = { - N_("git pack-refs [options]"), + N_("git pack-refs []"), NULL }; diff --git a/builtin/prune-packed.c b/builtin/prune-packed.c index f24a2c2bdca81f..7cf900ea0765e3 100644 --- a/builtin/prune-packed.c +++ b/builtin/prune-packed.c @@ -4,7 +4,7 @@ #include "parse-options.h" static const char * const prune_packed_usage[] = { - N_("git prune-packed [-n|--dry-run] [-q|--quiet]"), + N_("git prune-packed [-n | --dry-run] [-q | --quiet]"), NULL }; diff --git a/builtin/push.c b/builtin/push.c index 12f5e69393bc29..fc771a9f6f83a4 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -487,6 +487,7 @@ int cmd_push(int argc, const char **argv, const char *prefix) int flags = 0; int tags = 0; int rc; + int atomic = 0; const char *repo = NULL; /* default repository */ struct option options[] = { OPT__VERBOSITY(&verbosity), @@ -518,6 +519,7 @@ int cmd_push(int argc, const char **argv, const char *prefix) OPT_BIT(0, "follow-tags", &flags, N_("push missing but relevant tags"), TRANSPORT_PUSH_FOLLOW_TAGS), OPT_BIT(0, "signed", &flags, N_("GPG sign the push"), TRANSPORT_PUSH_CERT), + OPT_BOOL(0, "atomic", &atomic, N_("request atomic transaction on remote side")), OPT_END() }; @@ -533,6 +535,9 @@ int cmd_push(int argc, const char **argv, const char *prefix) if (tags) add_refspec("refs/tags/*"); + if (atomic) + flags |= TRANSPORT_PUSH_ATOMIC; + if (argc > 0) { repo = argv[0]; set_refspecs(argv + 1, argc - 1, repo); diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 8266c1fccf0c0b..e0ce78e5a06967 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -38,9 +38,11 @@ static int receive_fsck_objects = -1; static int transfer_fsck_objects = -1; static int receive_unpack_limit = -1; static int transfer_unpack_limit = -1; +static int advertise_atomic_push = 1; static int unpack_limit = 100; static int report_status; static int use_sideband; +static int use_atomic; static int quiet; static int prefer_ofs_delta = 1; static int auto_update_server_info; @@ -67,6 +69,7 @@ static const char *NONCE_SLOP = "SLOP"; static const char *nonce_status; static long nonce_stamp_slop; static unsigned long nonce_stamp_slop_limit; +static struct ref_transaction *transaction; static enum deny_action parse_deny_action(const char *var, const char *value) { @@ -160,6 +163,11 @@ static int receive_pack_config(const char *var, const char *value, void *cb) return 0; } + if (strcmp(var, "receive.advertiseatomic") == 0) { + advertise_atomic_push = git_config_bool(var, value); + return 0; + } + return git_default_config(var, value, cb); } @@ -175,6 +183,8 @@ static void show_ref(const char *path, const unsigned char *sha1) strbuf_addstr(&cap, "report-status delete-refs side-band-64k quiet"); + if (advertise_atomic_push) + strbuf_addstr(&cap, " atomic"); if (prefer_ofs_delta) strbuf_addstr(&cap, " ofs-delta"); if (push_cert_nonce) @@ -733,7 +743,9 @@ static int update_shallow_ref(struct command *cmd, struct shallow_info *si) return 0; } -static const char *update_worktree(unsigned char *sha1) +static const char *push_to_deploy(unsigned char *sha1, + struct argv_array *env, + const char *work_tree) { const char *update_refresh[] = { "update-index", "-q", "--ignore-submodules", "--refresh", NULL @@ -748,69 +760,87 @@ static const char *update_worktree(unsigned char *sha1) const char *read_tree[] = { "read-tree", "-u", "-m", NULL, NULL }; - const char *work_tree = git_work_tree_cfg ? git_work_tree_cfg : ".."; - struct argv_array env = ARGV_ARRAY_INIT; struct child_process child = CHILD_PROCESS_INIT; - if (is_bare_repository()) - return "denyCurrentBranch = updateInstead needs a worktree"; - - argv_array_pushf(&env, "GIT_DIR=%s", absolute_path(get_git_dir())); - child.argv = update_refresh; - child.env = env.argv; + child.env = env->argv; child.dir = work_tree; child.no_stdin = 1; child.stdout_to_stderr = 1; child.git_cmd = 1; - if (run_command(&child)) { - argv_array_clear(&env); + if (run_command(&child)) return "Up-to-date check failed"; - } /* run_command() does not clean up completely; reinitialize */ child_process_init(&child); child.argv = diff_files; - child.env = env.argv; + child.env = env->argv; child.dir = work_tree; child.no_stdin = 1; child.stdout_to_stderr = 1; child.git_cmd = 1; - if (run_command(&child)) { - argv_array_clear(&env); + if (run_command(&child)) return "Working directory has unstaged changes"; - } child_process_init(&child); child.argv = diff_index; - child.env = env.argv; + child.env = env->argv; child.no_stdin = 1; child.no_stdout = 1; child.stdout_to_stderr = 0; child.git_cmd = 1; - if (run_command(&child)) { - argv_array_clear(&env); + if (run_command(&child)) return "Working directory has staged changes"; - } read_tree[3] = sha1_to_hex(sha1); child_process_init(&child); child.argv = read_tree; - child.env = env.argv; + child.env = env->argv; child.dir = work_tree; child.no_stdin = 1; child.no_stdout = 1; child.stdout_to_stderr = 0; child.git_cmd = 1; - if (run_command(&child)) { - argv_array_clear(&env); + if (run_command(&child)) return "Could not update working tree to new HEAD"; - } - argv_array_clear(&env); return NULL; } +static const char *push_to_checkout_hook = "push-to-checkout"; + +static const char *push_to_checkout(unsigned char *sha1, + struct argv_array *env, + const char *work_tree) +{ + argv_array_pushf(env, "GIT_WORK_TREE=%s", absolute_path(work_tree)); + if (run_hook_le(env->argv, push_to_checkout_hook, + sha1_to_hex(sha1), NULL)) + return "push-to-checkout hook declined"; + else + return NULL; +} + +static const char *update_worktree(unsigned char *sha1) +{ + const char *retval; + const char *work_tree = git_work_tree_cfg ? git_work_tree_cfg : ".."; + struct argv_array env = ARGV_ARRAY_INIT; + + if (is_bare_repository()) + return "denyCurrentBranch = updateInstead needs a worktree"; + + argv_array_pushf(&env, "GIT_DIR=%s", absolute_path(get_git_dir())); + + if (!find_hook(push_to_checkout_hook)) + retval = push_to_deploy(sha1, &env, work_tree); + else + retval = push_to_checkout(sha1, &env, work_tree); + + argv_array_clear(&env); + return retval; +} + static const char *update(struct command *cmd, struct shallow_info *si) { const char *name = cmd->ref_name; @@ -910,6 +940,7 @@ static const char *update(struct command *cmd, struct shallow_info *si) } if (is_null_sha1(new_sha1)) { + struct strbuf err = STRBUF_INIT; if (!parse_object(old_sha1)) { old_sha1 = NULL; if (ref_exists(name)) { @@ -919,35 +950,36 @@ static const char *update(struct command *cmd, struct shallow_info *si) cmd->did_not_exist = 1; } } - if (delete_ref(namespaced_name, old_sha1, 0)) { - rp_error("failed to delete %s", name); + if (ref_transaction_delete(transaction, + namespaced_name, + old_sha1, + 0, old_sha1 != NULL, + "push", &err)) { + rp_error("%s", err.buf); + strbuf_release(&err); return "failed to delete"; } + strbuf_release(&err); return NULL; /* good */ } else { struct strbuf err = STRBUF_INIT; - struct ref_transaction *transaction; - if (shallow_update && si->shallow_ref[cmd->index] && update_shallow_ref(cmd, si)) return "shallow error"; - transaction = ref_transaction_begin(&err); - if (!transaction || - ref_transaction_update(transaction, namespaced_name, - new_sha1, old_sha1, 0, 1, "push", - &err) || - ref_transaction_commit(transaction, &err)) { - ref_transaction_free(transaction); - + if (ref_transaction_update(transaction, + namespaced_name, + new_sha1, old_sha1, + 0, 1, "push", + &err)) { rp_error("%s", err.buf); strbuf_release(&err); + return "failed to update ref"; } - - ref_transaction_free(transaction); strbuf_release(&err); + return NULL; /* good */ } } @@ -1131,11 +1163,105 @@ static void reject_updates_to_hidden(struct command *commands) } } +static int should_process_cmd(struct command *cmd) +{ + return !cmd->error_string && !cmd->skip_update; +} + +static void warn_if_skipped_connectivity_check(struct command *commands, + struct shallow_info *si) +{ + struct command *cmd; + int checked_connectivity = 1; + + for (cmd = commands; cmd; cmd = cmd->next) { + if (should_process_cmd(cmd) && si->shallow_ref[cmd->index]) { + error("BUG: connectivity check has not been run on ref %s", + cmd->ref_name); + checked_connectivity = 0; + } + } + if (!checked_connectivity) + die("BUG: connectivity check skipped???"); +} + +static void execute_commands_non_atomic(struct command *commands, + struct shallow_info *si) +{ + struct command *cmd; + struct strbuf err = STRBUF_INIT; + + for (cmd = commands; cmd; cmd = cmd->next) { + if (!should_process_cmd(cmd)) + continue; + + transaction = ref_transaction_begin(&err); + if (!transaction) { + rp_error("%s", err.buf); + strbuf_reset(&err); + cmd->error_string = "transaction failed to start"; + continue; + } + + cmd->error_string = update(cmd, si); + + if (!cmd->error_string + && ref_transaction_commit(transaction, &err)) { + rp_error("%s", err.buf); + strbuf_reset(&err); + cmd->error_string = "failed to update ref"; + } + ref_transaction_free(transaction); + } + strbuf_release(&err); +} + +static void execute_commands_atomic(struct command *commands, + struct shallow_info *si) +{ + struct command *cmd; + struct strbuf err = STRBUF_INIT; + const char *reported_error = "atomic push failure"; + + transaction = ref_transaction_begin(&err); + if (!transaction) { + rp_error("%s", err.buf); + strbuf_reset(&err); + reported_error = "transaction failed to start"; + goto failure; + } + + for (cmd = commands; cmd; cmd = cmd->next) { + if (!should_process_cmd(cmd)) + continue; + + cmd->error_string = update(cmd, si); + + if (cmd->error_string) + goto failure; + } + + if (ref_transaction_commit(transaction, &err)) { + rp_error("%s", err.buf); + reported_error = "atomic transaction failed"; + goto failure; + } + goto cleanup; + +failure: + for (cmd = commands; cmd; cmd = cmd->next) + if (!cmd->error_string) + cmd->error_string = reported_error; + +cleanup: + ref_transaction_free(transaction); + strbuf_release(&err); +} + static void execute_commands(struct command *commands, const char *unpacker_error, struct shallow_info *si) { - int checked_connectivity; struct command *cmd; unsigned char sha1[20]; struct iterate_data data; @@ -1166,27 +1292,13 @@ static void execute_commands(struct command *commands, free(head_name_to_free); head_name = head_name_to_free = resolve_refdup("HEAD", 0, sha1, NULL); - checked_connectivity = 1; - for (cmd = commands; cmd; cmd = cmd->next) { - if (cmd->error_string) - continue; - - if (cmd->skip_update) - continue; - - cmd->error_string = update(cmd, si); - if (shallow_update && !cmd->error_string && - si->shallow_ref[cmd->index]) { - error("BUG: connectivity check has not been run on ref %s", - cmd->ref_name); - checked_connectivity = 0; - } - } + if (use_atomic) + execute_commands_atomic(commands, si); + else + execute_commands_non_atomic(commands, si); - if (shallow_update && !checked_connectivity) - error("BUG: run 'git fsck' for safety.\n" - "If there are errors, try to remove " - "the reported refs above"); + if (shallow_update) + warn_if_skipped_connectivity_check(commands, si); } static struct command **queue_command(struct command **tail, @@ -1268,6 +1380,9 @@ static struct command *read_head_info(struct sha1_array *shallow) use_sideband = LARGE_PACKET_MAX; if (parse_feature_request(feature_list, "quiet")) quiet = 1; + if (advertise_atomic_push + && parse_feature_request(feature_list, "atomic")) + use_atomic = 1; } if (!strcmp(line, "push-cert")) { diff --git a/builtin/reflog.c b/builtin/reflog.c index 2d85d260ca66de..49c64f96d8adba 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -22,18 +22,13 @@ static unsigned long default_reflog_expire_unreachable; struct cmd_reflog_expire_cb { struct rev_info revs; - int dry_run; int stalefix; - int rewrite; - int updateref; - int verbose; unsigned long expire_total; unsigned long expire_unreachable; int recno; }; -struct expire_reflog_cb { - FILE *newlog; +struct expire_reflog_policy_cb { enum { UE_NORMAL, UE_ALWAYS, @@ -41,14 +36,16 @@ struct expire_reflog_cb { } unreachable_expire_kind; struct commit_list *mark_list; unsigned long mark_limit; - struct cmd_reflog_expire_cb *cmd; - unsigned char last_kept_sha1[20]; + struct cmd_reflog_expire_cb cmd; + struct commit *tip_commit; + struct commit_list *tips; }; struct collected_reflog { unsigned char sha1[20]; char reflog[FLEX_ARRAY]; }; + struct collect_reflog_cb { struct collected_reflog **e; int alloc; @@ -220,7 +217,7 @@ static int keep_entry(struct commit **it, unsigned char *sha1) * the expire_limit and queue them back, so that the caller can call * us again to restart the traversal with longer expire_limit. */ -static void mark_reachable(struct expire_reflog_cb *cb) +static void mark_reachable(struct expire_reflog_policy_cb *cb) { struct commit *commit; struct commit_list *pending; @@ -259,7 +256,7 @@ static void mark_reachable(struct expire_reflog_cb *cb) cb->mark_list = leftover; } -static int unreachable(struct expire_reflog_cb *cb, struct commit *commit, unsigned char *sha1) +static int unreachable(struct expire_reflog_policy_cb *cb, struct commit *commit, unsigned char *sha1) { /* * We may or may not have the commit yet - if not, look it @@ -288,55 +285,39 @@ static int unreachable(struct expire_reflog_cb *cb, struct commit *commit, unsig return !(commit->object.flags & REACHABLE); } -static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1, - const char *email, unsigned long timestamp, int tz, - const char *message, void *cb_data) +/* + * Return true iff the specified reflog entry should be expired. + */ +static int should_expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1, + const char *email, unsigned long timestamp, int tz, + const char *message, void *cb_data) { - struct expire_reflog_cb *cb = cb_data; + struct expire_reflog_policy_cb *cb = cb_data; struct commit *old, *new; - if (timestamp < cb->cmd->expire_total) - goto prune; - - if (cb->cmd->rewrite) - osha1 = cb->last_kept_sha1; + if (timestamp < cb->cmd.expire_total) + return 1; old = new = NULL; - if (cb->cmd->stalefix && + if (cb->cmd.stalefix && (!keep_entry(&old, osha1) || !keep_entry(&new, nsha1))) - goto prune; + return 1; - if (timestamp < cb->cmd->expire_unreachable) { + if (timestamp < cb->cmd.expire_unreachable) { if (cb->unreachable_expire_kind == UE_ALWAYS) - goto prune; + return 1; if (unreachable(cb, old, osha1) || unreachable(cb, new, nsha1)) - goto prune; + return 1; } - if (cb->cmd->recno && --(cb->cmd->recno) == 0) - goto prune; - - if (cb->newlog) { - char sign = (tz < 0) ? '-' : '+'; - int zone = (tz < 0) ? (-tz) : tz; - fprintf(cb->newlog, "%s %s %s %lu %c%04d\t%s", - sha1_to_hex(osha1), sha1_to_hex(nsha1), - email, timestamp, sign, zone, - message); - hashcpy(cb->last_kept_sha1, nsha1); - } - if (cb->cmd->verbose) - printf("keep %s", message); - return 0; - prune: - if (!cb->newlog) - printf("would prune %s", message); - else if (cb->cmd->verbose) - printf("prune %s", message); + if (cb->cmd.recno && --(cb->cmd.recno) == 0) + return 1; + return 0; } -static int push_tip_to_list(const char *refname, const unsigned char *sha1, int flags, void *cb_data) +static int push_tip_to_list(const char *refname, const unsigned char *sha1, + int flags, void *cb_data) { struct commit_list **list = cb_data; struct commit *tip_commit; @@ -349,104 +330,56 @@ static int push_tip_to_list(const char *refname, const unsigned char *sha1, int return 0; } -static int expire_reflog(const char *ref, const unsigned char *sha1, int unused, void *cb_data) +static void reflog_expiry_prepare(const char *refname, + const unsigned char *sha1, + void *cb_data) { - struct cmd_reflog_expire_cb *cmd = cb_data; - struct expire_reflog_cb cb; - struct ref_lock *lock; - char *log_file, *newlog_path = NULL; - struct commit *tip_commit; - struct commit_list *tips; - int status = 0; - - memset(&cb, 0, sizeof(cb)); - - /* - * we take the lock for the ref itself to prevent it from - * getting updated. - */ - lock = lock_any_ref_for_update(ref, sha1, 0, NULL); - if (!lock) - return error("cannot lock ref '%s'", ref); - log_file = git_pathdup("logs/%s", ref); - if (!reflog_exists(ref)) - goto finish; - if (!cmd->dry_run) { - newlog_path = git_pathdup("logs/%s.lock", ref); - cb.newlog = fopen(newlog_path, "w"); - } - - cb.cmd = cmd; + struct expire_reflog_policy_cb *cb = cb_data; - if (!cmd->expire_unreachable || !strcmp(ref, "HEAD")) { - tip_commit = NULL; - cb.unreachable_expire_kind = UE_HEAD; + if (!cb->cmd.expire_unreachable || !strcmp(refname, "HEAD")) { + cb->tip_commit = NULL; + cb->unreachable_expire_kind = UE_HEAD; } else { - tip_commit = lookup_commit_reference_gently(sha1, 1); - if (!tip_commit) - cb.unreachable_expire_kind = UE_ALWAYS; + cb->tip_commit = lookup_commit_reference_gently(sha1, 1); + if (!cb->tip_commit) + cb->unreachable_expire_kind = UE_ALWAYS; else - cb.unreachable_expire_kind = UE_NORMAL; + cb->unreachable_expire_kind = UE_NORMAL; } - if (cmd->expire_unreachable <= cmd->expire_total) - cb.unreachable_expire_kind = UE_ALWAYS; + if (cb->cmd.expire_unreachable <= cb->cmd.expire_total) + cb->unreachable_expire_kind = UE_ALWAYS; - cb.mark_list = NULL; - tips = NULL; - if (cb.unreachable_expire_kind != UE_ALWAYS) { - if (cb.unreachable_expire_kind == UE_HEAD) { + cb->mark_list = NULL; + cb->tips = NULL; + if (cb->unreachable_expire_kind != UE_ALWAYS) { + if (cb->unreachable_expire_kind == UE_HEAD) { struct commit_list *elem; - for_each_ref(push_tip_to_list, &tips); - for (elem = tips; elem; elem = elem->next) - commit_list_insert(elem->item, &cb.mark_list); + for_each_ref(push_tip_to_list, &cb->tips); + for (elem = cb->tips; elem; elem = elem->next) + commit_list_insert(elem->item, &cb->mark_list); } else { - commit_list_insert(tip_commit, &cb.mark_list); + commit_list_insert(cb->tip_commit, &cb->mark_list); } - cb.mark_limit = cmd->expire_total; - mark_reachable(&cb); + cb->mark_limit = cb->cmd.expire_total; + mark_reachable(cb); } +} - for_each_reflog_ent(ref, expire_reflog_ent, &cb); +static void reflog_expiry_cleanup(void *cb_data) +{ + struct expire_reflog_policy_cb *cb = cb_data; - if (cb.unreachable_expire_kind != UE_ALWAYS) { - if (cb.unreachable_expire_kind == UE_HEAD) { + if (cb->unreachable_expire_kind != UE_ALWAYS) { + if (cb->unreachable_expire_kind == UE_HEAD) { struct commit_list *elem; - for (elem = tips; elem; elem = elem->next) + for (elem = cb->tips; elem; elem = elem->next) clear_commit_marks(elem->item, REACHABLE); - free_commit_list(tips); + free_commit_list(cb->tips); } else { - clear_commit_marks(tip_commit, REACHABLE); + clear_commit_marks(cb->tip_commit, REACHABLE); } } - finish: - if (cb.newlog) { - if (fclose(cb.newlog)) { - status |= error("%s: %s", strerror(errno), - newlog_path); - unlink(newlog_path); - } else if (cmd->updateref && - (write_in_full(lock->lock_fd, - sha1_to_hex(cb.last_kept_sha1), 40) != 40 || - write_str_in_full(lock->lock_fd, "\n") != 1 || - close_ref(lock) < 0)) { - status |= error("Couldn't write %s", - lock->lk->filename.buf); - unlink(newlog_path); - } else if (rename(newlog_path, log_file)) { - status |= error("cannot rename %s to %s", - newlog_path, log_file); - unlink(newlog_path); - } else if (cmd->updateref && commit_ref(lock)) { - status |= error("Couldn't set %s", lock->ref_name); - } else { - adjust_shared_perm(log_file); - } - } - free(newlog_path); - free(log_file); - unlock_ref(lock); - return status; } static int collect_reflog(const char *ref, const unsigned char *sha1, int unused, void *cb_data) @@ -590,10 +523,11 @@ static void set_reflog_expiry_param(struct cmd_reflog_expire_cb *cb, int slot, c static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) { - struct cmd_reflog_expire_cb cb; + struct expire_reflog_policy_cb cb; unsigned long now = time(NULL); int i, status, do_all; int explicit_expiry = 0; + unsigned int flags = 0; default_reflog_expire_unreachable = now - 30 * 24 * 3600; default_reflog_expire = now - 90 * 24 * 3600; @@ -603,33 +537,33 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) do_all = status = 0; memset(&cb, 0, sizeof(cb)); - cb.expire_total = default_reflog_expire; - cb.expire_unreachable = default_reflog_expire_unreachable; + cb.cmd.expire_total = default_reflog_expire; + cb.cmd.expire_unreachable = default_reflog_expire_unreachable; for (i = 1; i < argc; i++) { const char *arg = argv[i]; if (!strcmp(arg, "--dry-run") || !strcmp(arg, "-n")) - cb.dry_run = 1; + flags |= EXPIRE_REFLOGS_DRY_RUN; else if (starts_with(arg, "--expire=")) { - if (parse_expiry_date(arg + 9, &cb.expire_total)) + if (parse_expiry_date(arg + 9, &cb.cmd.expire_total)) die(_("'%s' is not a valid timestamp"), arg); explicit_expiry |= EXPIRE_TOTAL; } else if (starts_with(arg, "--expire-unreachable=")) { - if (parse_expiry_date(arg + 21, &cb.expire_unreachable)) + if (parse_expiry_date(arg + 21, &cb.cmd.expire_unreachable)) die(_("'%s' is not a valid timestamp"), arg); explicit_expiry |= EXPIRE_UNREACH; } else if (!strcmp(arg, "--stale-fix")) - cb.stalefix = 1; + cb.cmd.stalefix = 1; else if (!strcmp(arg, "--rewrite")) - cb.rewrite = 1; + flags |= EXPIRE_REFLOGS_REWRITE; else if (!strcmp(arg, "--updateref")) - cb.updateref = 1; + flags |= EXPIRE_REFLOGS_UPDATE_REF; else if (!strcmp(arg, "--all")) do_all = 1; else if (!strcmp(arg, "--verbose")) - cb.verbose = 1; + flags |= EXPIRE_REFLOGS_VERBOSE; else if (!strcmp(arg, "--")) { i++; break; @@ -645,12 +579,12 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) * even in older repository. We cannot trust what's reachable * from reflog if the repository was pruned with older git. */ - if (cb.stalefix) { - init_revisions(&cb.revs, prefix); - if (cb.verbose) + if (cb.cmd.stalefix) { + init_revisions(&cb.cmd.revs, prefix); + if (flags & EXPIRE_REFLOGS_VERBOSE) printf("Marking reachable objects..."); - mark_reachable_objects(&cb.revs, 0, 0, NULL); - if (cb.verbose) + mark_reachable_objects(&cb.cmd.revs, 0, 0, NULL); + if (flags & EXPIRE_REFLOGS_VERBOSE) putchar('\n'); } @@ -662,8 +596,12 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) for_each_reflog(collect_reflog, &collected); for (i = 0; i < collected.nr; i++) { struct collected_reflog *e = collected.e[i]; - set_reflog_expiry_param(&cb, explicit_expiry, e->reflog); - status |= expire_reflog(e->reflog, e->sha1, 0, &cb); + set_reflog_expiry_param(&cb.cmd, explicit_expiry, e->reflog); + status |= reflog_expire(e->reflog, e->sha1, flags, + reflog_expiry_prepare, + should_expire_reflog_ent, + reflog_expiry_cleanup, + &cb); free(e); } free(collected.e); @@ -676,8 +614,12 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) status |= error("%s points nowhere!", argv[i]); continue; } - set_reflog_expiry_param(&cb, explicit_expiry, ref); - status |= expire_reflog(ref, sha1, 0, &cb); + set_reflog_expiry_param(&cb.cmd, explicit_expiry, ref); + status |= reflog_expire(ref, sha1, flags, + reflog_expiry_prepare, + should_expire_reflog_ent, + reflog_expiry_cleanup, + &cb); } return status; } @@ -686,29 +628,30 @@ static int count_reflog_ent(unsigned char *osha1, unsigned char *nsha1, const char *email, unsigned long timestamp, int tz, const char *message, void *cb_data) { - struct cmd_reflog_expire_cb *cb = cb_data; - if (!cb->expire_total || timestamp < cb->expire_total) - cb->recno++; + struct expire_reflog_policy_cb *cb = cb_data; + if (!cb->cmd.expire_total || timestamp < cb->cmd.expire_total) + cb->cmd.recno++; return 0; } static int cmd_reflog_delete(int argc, const char **argv, const char *prefix) { - struct cmd_reflog_expire_cb cb; + struct expire_reflog_policy_cb cb; int i, status = 0; + unsigned int flags = 0; memset(&cb, 0, sizeof(cb)); for (i = 1; i < argc; i++) { const char *arg = argv[i]; if (!strcmp(arg, "--dry-run") || !strcmp(arg, "-n")) - cb.dry_run = 1; + flags |= EXPIRE_REFLOGS_DRY_RUN; else if (!strcmp(arg, "--rewrite")) - cb.rewrite = 1; + flags |= EXPIRE_REFLOGS_REWRITE; else if (!strcmp(arg, "--updateref")) - cb.updateref = 1; + flags |= EXPIRE_REFLOGS_UPDATE_REF; else if (!strcmp(arg, "--verbose")) - cb.verbose = 1; + flags |= EXPIRE_REFLOGS_VERBOSE; else if (!strcmp(arg, "--")) { i++; break; @@ -740,15 +683,19 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix) recno = strtoul(spec + 2, &ep, 10); if (*ep == '}') { - cb.recno = -recno; + cb.cmd.recno = -recno; for_each_reflog_ent(ref, count_reflog_ent, &cb); } else { - cb.expire_total = approxidate(spec + 2); + cb.cmd.expire_total = approxidate(spec + 2); for_each_reflog_ent(ref, count_reflog_ent, &cb); - cb.expire_total = 0; + cb.cmd.expire_total = 0; } - status |= expire_reflog(ref, sha1, 0, &cb); + status |= reflog_expire(ref, sha1, flags, + reflog_expiry_prepare, + should_expire_reflog_ent, + reflog_expiry_cleanup, + &cb); free(ref); } return status; diff --git a/builtin/remote.c b/builtin/remote.c index b4ff4689770e40..5d3ab906bc7ef6 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -10,10 +10,10 @@ static const char * const builtin_remote_usage[] = { N_("git remote [-v | --verbose]"), - N_("git remote add [-t ] [-m ] [-f] [--tags|--no-tags] [--mirror=] "), + N_("git remote add [-t ] [-m ] [-f] [--tags | --no-tags] [--mirror=] "), N_("git remote rename "), N_("git remote remove "), - N_("git remote set-head (-a | --auto | -d | --delete |)"), + N_("git remote set-head (-a | --auto | -d | --delete | )"), N_("git remote [-v | --verbose] show [-n] "), N_("git remote prune [-n | --dry-run] "), N_("git remote [-v | --verbose] update [-p | --prune] [( | )...]"), diff --git a/builtin/repack.c b/builtin/repack.c index 3f852f35d1e786..28fbc7099a84c7 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -14,7 +14,7 @@ static int write_bitmaps; static char *packdir, *packtmp; static const char *const git_repack_usage[] = { - N_("git repack [options]"), + N_("git repack []"), NULL }; diff --git a/builtin/replace.c b/builtin/replace.c index 85d39b58d8aa35..b2ea28f9a93846 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -236,7 +236,7 @@ static void import_object(unsigned char *sha1, enum object_type type, die_errno("unable to open %s for reading", filename); if (!raw && type == OBJ_TREE) { - const char *argv[] = { "mktree", NULL }; + const char *argv[] = { "mktree", "--strict", NULL }; struct child_process cmd = CHILD_PROCESS_INIT; struct strbuf result = STRBUF_INIT; @@ -260,7 +260,8 @@ static void import_object(unsigned char *sha1, enum object_type type, strbuf_release(&result); } else { struct stat st; - int flags = HASH_FORMAT_CHECK | HASH_WRITE_OBJECT; + int flags = HASH_FORMAT_CHECK | HASH_FORMAT_STRICT | + HASH_WRITE_OBJECT; if (fstat(fd, &st) < 0) die_errno("unable to fstat %s", filename); diff --git a/builtin/rerere.c b/builtin/rerere.c index 98eb8c5404914e..7afadd2eadd59d 100644 --- a/builtin/rerere.c +++ b/builtin/rerere.c @@ -9,7 +9,7 @@ #include "pathspec.h" static const char * const rerere_usage[] = { - N_("git rerere [clear | forget path... | status | remaining | diff | gc]"), + N_("git rerere [clear | forget ... | status | remaining | diff | gc]"), NULL, }; diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index 95328b80d93026..3626c61da67abb 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -358,7 +358,7 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix) { static int keep_dashdash = 0, stop_at_non_option = 0; static char const * const parseopt_usage[] = { - N_("git rev-parse --parseopt [options] -- [...]"), + N_("git rev-parse --parseopt [] -- [...]"), NULL }; static struct option parseopt_opts[] = { @@ -496,9 +496,9 @@ static void die_no_single_rev(int quiet) } static const char builtin_rev_parse_usage[] = -N_("git rev-parse --parseopt [options] -- [...]\n" +N_("git rev-parse --parseopt [] -- [...]\n" " or: git rev-parse --sq-quote [...]\n" - " or: git rev-parse [options] [...]\n" + " or: git rev-parse [] [...]\n" "\n" "Run \"git rev-parse --parseopt -h\" for more information on the first usage."); diff --git a/builtin/revert.c b/builtin/revert.c index f9ed5bd5d03675..56a2c366698f83 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -19,13 +19,13 @@ */ static const char * const revert_usage[] = { - N_("git revert [options] ..."), + N_("git revert [] ..."), N_("git revert "), NULL }; static const char * const cherry_pick_usage[] = { - N_("git cherry-pick [options] ..."), + N_("git cherry-pick [] ..."), N_("git cherry-pick "), NULL }; diff --git a/builtin/rm.c b/builtin/rm.c index d8a9c86dd135e6..3304bff42a2fb9 100644 --- a/builtin/rm.c +++ b/builtin/rm.c @@ -14,7 +14,7 @@ #include "pathspec.h" static const char * const builtin_rm_usage[] = { - N_("git rm [options] [--] ..."), + N_("git rm [] [--] ..."), NULL }; diff --git a/builtin/send-pack.c b/builtin/send-pack.c index b564a778455c35..b961e5ae785662 100644 --- a/builtin/send-pack.c +++ b/builtin/send-pack.c @@ -13,7 +13,7 @@ #include "sha1-array.h" static const char send_pack_usage[] = -"git send-pack [--all | --mirror] [--dry-run] [--force] [--receive-pack=] [--verbose] [--thin] [:] [...]\n" +"git send-pack [--all | --mirror] [--dry-run] [--force] [--receive-pack=] [--verbose] [--thin] [--atomic] [:] [...]\n" " --all and explicit specification are mutually exclusive."; static struct send_pack_args args; @@ -170,6 +170,10 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix) args.use_thin_pack = 1; continue; } + if (!strcmp(arg, "--atomic")) { + args.atomic = 1; + continue; + } if (!strcmp(arg, "--stateless-rpc")) { args.stateless_rpc = 1; continue; diff --git a/builtin/shortlog.c b/builtin/shortlog.c index 4b7e53623fc9cf..c0bab6aaa9755f 100644 --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@ -10,7 +10,7 @@ #include "parse-options.h" static char const * const shortlog_usage[] = { - N_("git shortlog [] [] [[--] [...]]"), + N_("git shortlog [] [] [[--] [...]]"), NULL }; diff --git a/builtin/show-branch.c b/builtin/show-branch.c index 365228aa8d805b..f3fb5fb2bf2801 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -6,11 +6,11 @@ #include "parse-options.h" static const char* show_branch_usage[] = { - N_("git show-branch [-a|--all] [-r|--remotes] [--topo-order | --date-order]\n" + N_("git show-branch [-a | --all] [-r | --remotes] [--topo-order | --date-order]\n" " [--current] [--color[=] | --no-color] [--sparse]\n" " [--more= | --list | --independent | --merge-base]\n" " [--no-name | --sha1-name] [--topics] [( | )...]"), - N_("git show-branch (-g|--reflog)[=[,]] [--list] []"), + N_("git show-branch (-g | --reflog)[=[,]] [--list] []"), NULL }; diff --git a/builtin/show-ref.c b/builtin/show-ref.c index 5ba1f3083890c6..afb10309d6365a 100644 --- a/builtin/show-ref.c +++ b/builtin/show-ref.c @@ -7,7 +7,7 @@ #include "parse-options.h" static const char * const show_ref_usage[] = { - N_("git show-ref [-q|--quiet] [--verify] [--head] [-d|--dereference] [-s|--hash[=]] [--abbrev[=]] [--tags] [--heads] [--] [pattern*] "), + N_("git show-ref [-q | --quiet] [--verify] [--head] [-d | --dereference] [-s | --hash[=]] [--abbrev[=]] [--tags] [--heads] [--] [...]"), N_("git show-ref --exclude-existing[=pattern] < ref-list"), NULL }; diff --git a/builtin/symbolic-ref.c b/builtin/symbolic-ref.c index 29fb3f1c201682..ce0fde705c0350 100644 --- a/builtin/symbolic-ref.c +++ b/builtin/symbolic-ref.c @@ -4,8 +4,8 @@ #include "parse-options.h" static const char * const git_symbolic_ref_usage[] = { - N_("git symbolic-ref [options] name [ref]"), - N_("git symbolic-ref -d [-q] name"), + N_("git symbolic-ref [] []"), + N_("git symbolic-ref -d [-q] "), NULL }; diff --git a/builtin/tag.c b/builtin/tag.c index e633f4efdbb896..6dc85a9d5e16e9 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -19,9 +19,9 @@ #include "column.h" static const char * const git_tag_usage[] = { - N_("git tag [-a|-s|-u ] [-f] [-m |-F ] []"), + N_("git tag [-a | -s | -u ] [-f] [-m | -F ] []"), N_("git tag -d ..."), - N_("git tag -l [-n[]] [--contains ] [--points-at ] " + N_("git tag -l [-n[]] [--contains ] [--points-at ]" "\n\t\t[...]"), N_("git tag -v ..."), NULL diff --git a/builtin/update-index.c b/builtin/update-index.c index b0e3dc91055ec7..587898624c0550 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -400,7 +400,7 @@ static void read_index_info(int line_termination) } static const char * const update_index_usage[] = { - N_("git update-index [options] [--] [...]"), + N_("git update-index [] [--] [...]"), NULL }; diff --git a/builtin/update-ref.c b/builtin/update-ref.c index 1993529521c0ef..2497ba4303a03f 100644 --- a/builtin/update-ref.c +++ b/builtin/update-ref.c @@ -6,9 +6,9 @@ #include "argv-array.h" static const char * const git_update_ref_usage[] = { - N_("git update-ref [options] -d []"), - N_("git update-ref [options] []"), - N_("git update-ref [options] --stdin [-z]"), + N_("git update-ref [] -d []"), + N_("git update-ref [] []"), + N_("git update-ref [] --stdin [-z]"), NULL }; diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c index b0f85042b234a3..ec0c4e3d836f92 100644 --- a/builtin/verify-commit.c +++ b/builtin/verify-commit.c @@ -14,7 +14,7 @@ #include "gpg-interface.h" static const char * const verify_commit_usage[] = { - N_("git verify-commit [-v|--verbose] ..."), + N_("git verify-commit [-v | --verbose] ..."), NULL }; diff --git a/builtin/verify-pack.c b/builtin/verify-pack.c index 7747537beb72ab..c94e156932c0c8 100644 --- a/builtin/verify-pack.c +++ b/builtin/verify-pack.c @@ -51,7 +51,7 @@ static int verify_one_pack(const char *path, unsigned int flags) } static const char * const verify_pack_usage[] = { - N_("git verify-pack [-v|--verbose] [-s|--stat-only] ..."), + N_("git verify-pack [-v | --verbose] [-s | --stat-only] ..."), NULL }; diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c index 9cdf332333b95b..53c68fce3ac182 100644 --- a/builtin/verify-tag.c +++ b/builtin/verify-tag.c @@ -14,7 +14,7 @@ #include "gpg-interface.h" static const char * const verify_tag_usage[] = { - N_("git verify-tag [-v|--verbose] ..."), + N_("git verify-tag [-v | --verbose] ..."), NULL }; diff --git a/cache.h b/cache.h index f704af5df0984e..513e6ee1925575 100644 --- a/cache.h +++ b/cache.h @@ -536,6 +536,7 @@ extern int ie_modified(const struct index_state *, const struct cache_entry *, s #define HASH_WRITE_OBJECT 1 #define HASH_FORMAT_CHECK 2 +#define HASH_FORMAT_STRICT 4 extern int index_fd(unsigned char *sha1, int fd, struct stat *st, enum object_type type, const char *path, unsigned flags); extern int index_path(unsigned char *sha1, const char *path, struct stat *st, unsigned flags); diff --git a/commit.h b/commit.h index 5cc1e7ec9ee809..9f189cb054266c 100644 --- a/commit.h +++ b/commit.h @@ -254,7 +254,6 @@ extern int for_each_commit_graft(each_commit_graft_fn, void *); extern int is_repository_shallow(void); extern struct commit_list *get_shallow_commits(struct object_array *heads, int depth, int shallow_flag, int not_shallow_flag); -extern void check_shallow_file_for_update(void); extern void set_alternate_shallow_file(const char *path, int override); extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol, const struct sha1_array *extra); diff --git a/config.c b/config.c index 752e2e227f56ed..e5e64dc60fa489 100644 --- a/config.c +++ b/config.c @@ -1340,7 +1340,7 @@ static int configset_add_value(struct config_set *cs, const char *key, const cha string_list_init(&e->value_list, 1); hashmap_add(&cs->config_hash, e); } - si = string_list_append_nodup(&e->value_list, value ? xstrdup(value) : NULL); + si = string_list_append_nodup(&e->value_list, xstrdup_or_null(value)); ALLOC_GROW(cs->list.items, cs->list.nr + 1, cs->list.alloc); l_item = &cs->list.items[cs->list.nr++]; diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 8cfee95f880062..c21190d7510c17 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1425,7 +1425,7 @@ __git_log_gitk_options=" # Options that go well for log and shortlog (not gitk) __git_log_shortlog_options=" --author= --committer= --grep= - --all-match + --all-match --invert-grep " __git_log_pretty_formats="oneline short medium full fuller email raw format:" diff --git a/credential-store.c b/credential-store.c index d435514cbe29aa..925d3f40247d7f 100644 --- a/credential-store.c +++ b/credential-store.c @@ -118,7 +118,7 @@ static int lookup_credential(const char *fn, struct credential *c) int main(int argc, char **argv) { const char * const usage[] = { - "git credential-store [options] ", + "git credential-store [] ", NULL }; const char *op; diff --git a/fsck.c b/fsck.c index 10bcb651516e2c..3e8343fd451aac 100644 --- a/fsck.c +++ b/fsck.c @@ -305,7 +305,7 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer, { unsigned char tree_sha1[20], sha1[20]; struct commit_graft *graft; - unsigned parent_count, parent_line_count = 0; + unsigned parent_line_count = 0; int err; if (require_end_of_header(buffer, size, &commit->object, error_func)) @@ -323,15 +323,17 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer, parent_line_count++; } graft = lookup_commit_graft(commit->object.sha1); - parent_count = commit_list_count(commit->parents); - if (graft) { - if (graft->nr_parent == -1 && !parent_count) - ; /* shallow commit */ - else if (graft->nr_parent != parent_count) - return error_func(&commit->object, FSCK_ERROR, "graft objects missing"); - } else { - if (parent_count != parent_line_count) - return error_func(&commit->object, FSCK_ERROR, "parent objects missing"); + if (commit->object.parsed) { + unsigned parent_count = commit_list_count(commit->parents); + if (graft) { + if (graft->nr_parent == -1 && !parent_count) + ; /* shallow commit */ + else if (graft->nr_parent != parent_count) + return error_func(&commit->object, FSCK_ERROR, "graft objects missing"); + } else { + if (parent_count != parent_line_count) + return error_func(&commit->object, FSCK_ERROR, "parent objects missing"); + } } if (!skip_prefix(buffer, "author ", &buffer)) return error_func(&commit->object, FSCK_ERROR, "invalid format - expected 'author' line"); diff --git a/gettext.h b/gettext.h index 7671d09d04bb87..dc1722dd4bc6b1 100644 --- a/gettext.h +++ b/gettext.h @@ -63,6 +63,30 @@ const char *Q_(const char *msgid, const char *plu, unsigned long n) } /* Mark msgid for translation but do not translate it. */ +#if !USE_PARENS_AROUND_GETTEXT_N #define N_(msgid) msgid +#else +/* + * Strictly speaking, this will lead to invalid C when + * used this way: + * static const char s[] = N_("FOO"); + * which will expand to + * static const char s[] = ("FOO"); + * and in valid C, the initializer on the right hand side must + * be without the parentheses. But many compilers do accept it + * as a language extension and it will allow us to catch mistakes + * like: + * static const char *msgs[] = { + * N_("one") + * N_("two"), + * N_("three"), + * NULL + * }; + * (notice the missing comma on one of the lines) by forcing + * a compilation error, because parenthesised ("one") ("two") + * will not get silently turned into ("onetwo"). + */ +#define N_(msgid) (msgid) +#endif #endif diff --git a/git-bisect.sh b/git-bisect.sh index 2fc07acb0f2421..ae3fec22c48a29 100755 --- a/git-bisect.sh +++ b/git-bisect.sh @@ -127,7 +127,7 @@ bisect_start() { if test "z$mode" != "z--no-checkout" then git checkout "$start_head" -- || - die "$(eval_gettext "Checking out '\$start_head' failed. Try 'git bisect reset '.")" + die "$(eval_gettext "Checking out '\$start_head' failed. Try 'git bisect reset '.")" fi else # Get rev from where we start. diff --git a/git-compat-util.h b/git-compat-util.h index eb9b0ff32829ef..68c07af9d465ce 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -678,6 +678,11 @@ extern char *xgetcwd(void); #define REALLOC_ARRAY(x, alloc) (x) = xrealloc((x), (alloc) * sizeof(*(x))) +static inline char *xstrdup_or_null(const char *str) +{ + return str ? xstrdup(str) : NULL; +} + static inline size_t xsize_t(off_t len) { if (len > (size_t) len) @@ -870,4 +875,8 @@ struct tm *git_gmtime_r(const time_t *, struct tm *); #define gmtime_r git_gmtime_r #endif +#if !defined(USE_PARENS_AROUND_GETTEXT_N) && defined(__GNUC__) +#define USE_PARENS_AROUND_GETTEXT_N 1 +#endif + #endif diff --git a/git-p4.py b/git-p4.py index ff132b2117c5ed..6ff0b76f0da1e4 100755 --- a/git-p4.py +++ b/git-p4.py @@ -1442,7 +1442,7 @@ def applyCommit(self, id): print " " + self.clientPath print print "To submit, use \"p4 submit\" to write a new description," - print "or \"p4 submit -i %s\" to use the one prepared by" \ + print "or \"p4 submit -i <%s\" to use the one prepared by" \ " \"git p4\"." % fileName print "You can delete the file \"%s\" when finished." % fileName @@ -1916,6 +1916,9 @@ def __init__(self): help="Keep entire BRANCH/DIR/SUBDIR prefix during import"), optparse.make_option("--use-client-spec", dest="useClientSpec", action='store_true', help="Only sync files that are included in the Perforce Client Spec") + optparse.make_option("-/", dest="cloneExclude", + action="append", type="string", + help="exclude depot path"), ] self.description = """Imports from Perforce into a git repository.\n example: @@ -1950,6 +1953,12 @@ def __init__(self): if gitConfig("git-p4.syncFromOrigin") == "false": self.syncWithOrigin = False + # This is required for the "append" cloneExclude action + def ensure_value(self, attr, value): + if not hasattr(self, attr) or getattr(self, attr) is None: + setattr(self, attr, value) + return getattr(self, attr) + # Force a checkpoint in fast-import and wait for it to finish def checkpoint(self): self.gitStream.write("checkpoint\n\n") @@ -3101,9 +3110,6 @@ def __init__(self): optparse.make_option("--destination", dest="cloneDestination", action='store', default=None, help="where to leave result of the clone"), - optparse.make_option("-/", dest="cloneExclude", - action="append", type="string", - help="exclude depot path"), optparse.make_option("--bare", dest="cloneBare", action="store_true", default=False), ] @@ -3111,12 +3117,6 @@ def __init__(self): self.needsGit = False self.cloneBare = False - # This is required for the "append" cloneExclude action - def ensure_value(self, attr, value): - if not hasattr(self, attr) or getattr(self, attr) is None: - setattr(self, attr, value) - return getattr(self, attr) - def defaultDestination(self, args): ## TODO: use common prefix of args? depotPath = args[0] diff --git a/git.c b/git.c index 6b5ae6a2ace7ff..8c7ee9c8300076 100644 --- a/git.c +++ b/git.c @@ -6,7 +6,7 @@ const char git_usage_string[] = "git [--version] [--help] [-C ] [-c name=value]\n" " [--exec-path[=]] [--html-path] [--man-path] [--info-path]\n" - " [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]\n" + " [-p | --paginate | --no-pager] [--no-replace-objects] [--bare]\n" " [--git-dir=] [--work-tree=] [--namespace=]\n" " []"; diff --git a/grep.c b/grep.c index 6e085f82973114..b58c7c64342698 100644 --- a/grep.c +++ b/grep.c @@ -1661,8 +1661,8 @@ void grep_source_init(struct grep_source *gs, enum grep_source_type type, const void *identifier) { gs->type = type; - gs->name = name ? xstrdup(name) : NULL; - gs->path = path ? xstrdup(path) : NULL; + gs->name = xstrdup_or_null(name); + gs->path = xstrdup_or_null(path); gs->buf = NULL; gs->size = 0; gs->driver = NULL; diff --git a/http.c b/http.c index 040f362a6a2996..4ecf9e8f7b2ac8 100644 --- a/http.c +++ b/http.c @@ -62,6 +62,9 @@ static const char *user_agent; static struct credential cert_auth = CREDENTIAL_INIT; static int ssl_cert_password_required; +#ifdef LIBCURL_CAN_HANDLE_AUTH_ANY +static unsigned long http_auth_methods = CURLAUTH_ANY; +#endif static struct curl_slist *pragma_header; static struct curl_slist *no_pragma_header; @@ -114,6 +117,37 @@ size_t fwrite_null(char *ptr, size_t eltsize, size_t nmemb, void *strbuf) return eltsize * nmemb; } +static void closedown_active_slot(struct active_request_slot *slot) +{ + active_requests--; + slot->in_use = 0; +} + +static void finish_active_slot(struct active_request_slot *slot) +{ + closedown_active_slot(slot); + curl_easy_getinfo(slot->curl, CURLINFO_HTTP_CODE, &slot->http_code); + + if (slot->finished != NULL) + (*slot->finished) = 1; + + /* Store slot results so they can be read after the slot is reused */ + if (slot->results != NULL) { + slot->results->curl_result = slot->curl_result; + slot->results->http_code = slot->http_code; +#if LIBCURL_VERSION_NUM >= 0x070a08 + curl_easy_getinfo(slot->curl, CURLINFO_HTTPAUTH_AVAIL, + &slot->results->auth_avail); +#else + slot->results->auth_avail = 0; +#endif + } + + /* Run callback if appropriate */ + if (slot->callback_func != NULL) + slot->callback_func(slot->callback_data); +} + #ifdef USE_CURL_MULTI static void process_curl_messages(void) { @@ -580,6 +614,9 @@ struct active_request_slot *get_active_slot(void) curl_easy_setopt(slot->curl, CURLOPT_UPLOAD, 0); curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1); curl_easy_setopt(slot->curl, CURLOPT_FAILONERROR, 1); +#ifdef LIBCURL_CAN_HANDLE_AUTH_ANY + curl_easy_setopt(slot->curl, CURLOPT_HTTPAUTH, http_auth_methods); +#endif if (http_auth.password) init_curl_http_auth(slot->curl); @@ -730,12 +767,6 @@ void run_active_slot(struct active_request_slot *slot) #endif } -static void closedown_active_slot(struct active_request_slot *slot) -{ - active_requests--; - slot->in_use = 0; -} - static void release_active_slot(struct active_request_slot *slot) { closedown_active_slot(slot); @@ -752,31 +783,6 @@ static void release_active_slot(struct active_request_slot *slot) #endif } -void finish_active_slot(struct active_request_slot *slot) -{ - closedown_active_slot(slot); - curl_easy_getinfo(slot->curl, CURLINFO_HTTP_CODE, &slot->http_code); - - if (slot->finished != NULL) - (*slot->finished) = 1; - - /* Store slot results so they can be read after the slot is reused */ - if (slot->results != NULL) { - slot->results->curl_result = slot->curl_result; - slot->results->http_code = slot->http_code; -#if LIBCURL_VERSION_NUM >= 0x070a08 - curl_easy_getinfo(slot->curl, CURLINFO_HTTPAUTH_AVAIL, - &slot->results->auth_avail); -#else - slot->results->auth_avail = 0; -#endif - } - - /* Run callback if appropriate */ - if (slot->callback_func != NULL) - slot->callback_func(slot->callback_data); -} - void finish_all_active_slots(void) { struct active_request_slot *slot = active_queue_head; @@ -839,7 +845,7 @@ char *get_remote_object_url(const char *url, const char *hex, return strbuf_detach(&buf, NULL); } -int handle_curl_result(struct slot_results *results) +static int handle_curl_result(struct slot_results *results) { /* * If we see a failing http code with CURLE_OK, we have turned off @@ -870,6 +876,9 @@ int handle_curl_result(struct slot_results *results) credential_reject(&http_auth); return HTTP_NOAUTH; } else { +#ifdef LIBCURL_CAN_HANDLE_AUTH_ANY + http_auth_methods &= ~CURLAUTH_GSSNEGOTIATE; +#endif return HTTP_REAUTH; } } else { @@ -986,6 +995,7 @@ static void extract_content_type(struct strbuf *raw, struct strbuf *type, strbuf_addstr(charset, "ISO-8859-1"); } + /* http_request() targets */ #define HTTP_REQUEST_STRBUF 0 #define HTTP_REQUEST_FILE 1 diff --git a/http.h b/http.h index 473179b14d5648..49afe39279d027 100644 --- a/http.h +++ b/http.h @@ -85,9 +85,7 @@ extern curlioerr ioctl_buffer(CURL *handle, int cmd, void *clientp); extern struct active_request_slot *get_active_slot(void); extern int start_active_slot(struct active_request_slot *slot); extern void run_active_slot(struct active_request_slot *slot); -extern void finish_active_slot(struct active_request_slot *slot); extern void finish_all_active_slots(void); -extern int handle_curl_result(struct slot_results *results); /* * This will run one slot to completion in a blocking manner, similar to how diff --git a/line-log.c b/line-log.c index b7864ad5869eb0..a490efea07519e 100644 --- a/line-log.c +++ b/line-log.c @@ -237,7 +237,7 @@ static void diff_ranges_release(struct diff_ranges *diff) range_set_release(&diff->target); } -void line_log_data_init(struct line_log_data *r) +static void line_log_data_init(struct line_log_data *r) { memset(r, 0, sizeof(struct line_log_data)); range_set_init(&r->ranges, 0); diff --git a/line-log.h b/line-log.h index a9212d84e49230..7a5c24e2df40c0 100644 --- a/line-log.h +++ b/line-log.h @@ -54,8 +54,6 @@ struct line_log_data { struct diff_ranges diff; }; -extern void line_log_data_init(struct line_log_data *r); - extern void line_log_init(struct rev_info *rev, const char *prefix, struct string_list *args); extern int line_log_filter(struct rev_info *rev); diff --git a/notes.c b/notes.c index c763a21eef5b64..2be4d7f3fd0814 100644 --- a/notes.c +++ b/notes.c @@ -1006,7 +1006,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref, t->root = (struct int_node *) xcalloc(1, sizeof(struct int_node)); t->first_non_note = NULL; t->prev_non_note = NULL; - t->ref = notes_ref ? xstrdup(notes_ref) : NULL; + t->ref = xstrdup_or_null(notes_ref); t->combine_notes = combine_notes; t->initialized = 1; t->dirty = 0; diff --git a/pack-bitmap.c b/pack-bitmap.c index 6a818419ca46f8..365f9d92ed8b57 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -60,7 +60,7 @@ static struct bitmap_index { struct ewah_bitmap *blobs; struct ewah_bitmap *tags; - /* Map from SHA1 -> `stored_bitmap` for all the bitmapped comits */ + /* Map from SHA1 -> `stored_bitmap` for all the bitmapped commits */ khash_sha1 *bitmaps; /* Number of bitmapped commits */ @@ -252,6 +252,20 @@ static int load_bitmap_entries_v1(struct bitmap_index *index) return 0; } +static char *pack_bitmap_filename(struct packed_git *p) +{ + char *idx_name; + int len; + + len = strlen(p->pack_name) - strlen(".pack"); + idx_name = xmalloc(len + strlen(".bitmap") + 1); + + memcpy(idx_name, p->pack_name, len); + memcpy(idx_name + len, ".bitmap", strlen(".bitmap") + 1); + + return idx_name; +} + static int open_pack_bitmap_1(struct packed_git *packfile) { int fd; @@ -322,20 +336,6 @@ static int load_pack_bitmap(void) return -1; } -char *pack_bitmap_filename(struct packed_git *p) -{ - char *idx_name; - int len; - - len = strlen(p->pack_name) - strlen(".pack"); - idx_name = xmalloc(len + strlen(".bitmap") + 1); - - memcpy(idx_name, p->pack_name, len); - memcpy(idx_name + len, ".bitmap", strlen(".bitmap") + 1); - - return idx_name; -} - static int open_pack_bitmap(void) { struct packed_git *p; diff --git a/pack-bitmap.h b/pack-bitmap.h index 487600b18c79be..0adcef77b58cc1 100644 --- a/pack-bitmap.h +++ b/pack-bitmap.h @@ -38,7 +38,6 @@ int prepare_bitmap_git(void); void count_bitmap_commit_list(uint32_t *commits, uint32_t *trees, uint32_t *blobs, uint32_t *tags); void traverse_bitmap_commit_list(show_reachable_fn show_reachable); void test_bitmap_walk(struct rev_info *revs); -char *pack_bitmap_filename(struct packed_git *p); int prepare_bitmap_walk(struct rev_info *revs); int reuse_partial_packfile_from_bitmap(struct packed_git **packfile, uint32_t *entries, off_t *up_to); int rebuild_existing_bitmaps(struct packing_data *mapping, khash_sha1 *reused_bitmaps, int show_progress); diff --git a/prompt.c b/prompt.c index 8181eebbfcd008..75406390c6fdab 100644 --- a/prompt.c +++ b/prompt.c @@ -73,8 +73,3 @@ char *git_prompt(const char *prompt, int flags) } return r; } - -char *git_getpass(const char *prompt) -{ - return git_prompt(prompt, PROMPT_ASKPASS); -} diff --git a/prompt.h b/prompt.h index 04f321a781d37a..e04cced030ca4d 100644 --- a/prompt.h +++ b/prompt.h @@ -5,6 +5,5 @@ #define PROMPT_ECHO (1<<1) char *git_prompt(const char *prompt, int flags); -char *git_getpass(const char *prompt); #endif /* PROMPT_H */ diff --git a/refs.c b/refs.c index ed3b2cb405cc57..ab2f2a92cd9119 100644 --- a/refs.c +++ b/refs.c @@ -6,6 +6,15 @@ #include "dir.h" #include "string-list.h" +struct ref_lock { + char *ref_name; + char *orig_ref_name; + struct lock_file *lk; + unsigned char old_sha1[20]; + int lock_fd; + int force_write; +}; + /* * How to handle various characters in refnames: * 0: An acceptable character for refs @@ -1618,8 +1627,7 @@ const char *resolve_ref_unsafe(const char *refname, int resolve_flags, unsigned char *resolve_refdup(const char *ref, int resolve_flags, unsigned char *sha1, int *flags) { - const char *ret = resolve_ref_unsafe(ref, resolve_flags, sha1, flags); - return ret ? xstrdup(ret) : NULL; + return xstrdup_or_null(resolve_ref_unsafe(ref, resolve_flags, sha1, flags)); } /* The argument to filter_refs */ @@ -2094,6 +2102,16 @@ int refname_match(const char *abbrev_name, const char *full_name) return 0; } +static void unlock_ref(struct ref_lock *lock) +{ + /* Do not free lock->lk -- atexit() still looks at them */ + if (lock->lk) + rollback_lock_file(lock->lk); + free(lock->ref_name); + free(lock->orig_ref_name); + free(lock); +} + /* This function should make sure errno is meaningful on error */ static struct ref_lock *verify_lock(struct ref_lock *lock, const unsigned char *old_sha1, int mustexist) @@ -2346,13 +2364,6 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname, return NULL; } -struct ref_lock *lock_any_ref_for_update(const char *refname, - const unsigned char *old_sha1, - int flags, int *type_p) -{ - return lock_ref_sha1_basic(refname, old_sha1, NULL, flags, type_p); -} - /* * Write an entry to the packed-refs file for the specified refname. * If peeled is non-NULL, write it as the entry's peeled value. @@ -2901,7 +2912,7 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms return 1; } -int close_ref(struct ref_lock *lock) +static int close_ref(struct ref_lock *lock) { if (close_lock_file(lock->lk)) return -1; @@ -2909,7 +2920,7 @@ int close_ref(struct ref_lock *lock) return 0; } -int commit_ref(struct ref_lock *lock) +static int commit_ref(struct ref_lock *lock) { if (commit_lock_file(lock->lk)) return -1; @@ -2917,16 +2928,6 @@ int commit_ref(struct ref_lock *lock) return 0; } -void unlock_ref(struct ref_lock *lock) -{ - /* Do not free lock->lk -- atexit() still looks at them */ - if (lock->lk) - rollback_lock_file(lock->lk); - free(lock->ref_name); - free(lock->orig_ref_name); - free(lock); -} - /* * copy the reflog message msg to buf, which has been allocated sufficiently * large, while cleaning up the whitespaces. Especially, convert LF to space, @@ -3003,15 +3004,37 @@ int log_ref_setup(const char *refname, char *logfile, int bufsize) return 0; } +static int log_ref_write_fd(int fd, const unsigned char *old_sha1, + const unsigned char *new_sha1, + const char *committer, const char *msg) +{ + int msglen, written; + unsigned maxlen, len; + char *logrec; + + msglen = msg ? strlen(msg) : 0; + maxlen = strlen(committer) + msglen + 100; + logrec = xmalloc(maxlen); + len = sprintf(logrec, "%s %s %s\n", + sha1_to_hex(old_sha1), + sha1_to_hex(new_sha1), + committer); + if (msglen) + len += copy_msg(logrec + len - 1, msg) - 1; + + written = len <= maxlen ? write_in_full(fd, logrec, len) : -1; + free(logrec); + if (written != len) + return -1; + + return 0; +} + static int log_ref_write(const char *refname, const unsigned char *old_sha1, const unsigned char *new_sha1, const char *msg) { - int logfd, result, written, oflags = O_APPEND | O_WRONLY; - unsigned maxlen, len; - int msglen; + int logfd, result, oflags = O_APPEND | O_WRONLY; char log_file[PATH_MAX]; - char *logrec; - const char *committer; if (log_all_ref_updates < 0) log_all_ref_updates = !is_bare_repository(); @@ -3023,19 +3046,9 @@ static int log_ref_write(const char *refname, const unsigned char *old_sha1, logfd = open(log_file, oflags); if (logfd < 0) return 0; - msglen = msg ? strlen(msg) : 0; - committer = git_committer_info(0); - maxlen = strlen(committer) + msglen + 100; - logrec = xmalloc(maxlen); - len = sprintf(logrec, "%s %s %s\n", - sha1_to_hex(old_sha1), - sha1_to_hex(new_sha1), - committer); - if (msglen) - len += copy_msg(logrec + len - 1, msg) - 1; - written = len <= maxlen ? write_in_full(logfd, logrec, len) : -1; - free(logrec); - if (written != len) { + result = log_ref_write_fd(logfd, old_sha1, new_sha1, + git_committer_info(0), msg); + if (result) { int save_errno = errno; close(logfd); error("Unable to append to %s", log_file); @@ -3661,31 +3674,8 @@ int ref_transaction_create(struct ref_transaction *transaction, int flags, const char *msg, struct strbuf *err) { - struct ref_update *update; - - assert(err); - - if (transaction->state != REF_TRANSACTION_OPEN) - die("BUG: create called for transaction that is not open"); - - if (!new_sha1 || is_null_sha1(new_sha1)) - die("BUG: create ref with null new_sha1"); - - if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) { - strbuf_addf(err, "refusing to create ref with bad name %s", - refname); - return -1; - } - - update = add_update(transaction, refname); - - hashcpy(update->new_sha1, new_sha1); - hashclr(update->old_sha1); - update->flags = flags; - update->have_old = 1; - if (msg) - update->msg = xstrdup(msg); - return 0; + return ref_transaction_update(transaction, refname, new_sha1, + null_sha1, flags, 1, msg, err); } int ref_transaction_delete(struct ref_transaction *transaction, @@ -3694,26 +3684,8 @@ int ref_transaction_delete(struct ref_transaction *transaction, int flags, int have_old, const char *msg, struct strbuf *err) { - struct ref_update *update; - - assert(err); - - if (transaction->state != REF_TRANSACTION_OPEN) - die("BUG: delete called for transaction that is not open"); - - if (have_old && !old_sha1) - die("BUG: have_old is true but old_sha1 is NULL"); - - update = add_update(transaction, refname); - update->flags = flags; - update->have_old = have_old; - if (have_old) { - assert(!is_null_sha1(old_sha1)); - hashcpy(update->old_sha1, old_sha1); - } - if (msg) - update->msg = xstrdup(msg); - return 0; + return ref_transaction_update(transaction, refname, null_sha1, + old_sha1, flags, have_old, msg, err); } int update_ref(const char *action, const char *refname, @@ -4009,3 +3981,129 @@ int ref_is_hidden(const char *refname) } return 0; } + +struct expire_reflog_cb { + unsigned int flags; + reflog_expiry_should_prune_fn *should_prune_fn; + void *policy_cb; + FILE *newlog; + unsigned char last_kept_sha1[20]; +}; + +static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1, + const char *email, unsigned long timestamp, int tz, + const char *message, void *cb_data) +{ + struct expire_reflog_cb *cb = cb_data; + struct expire_reflog_policy_cb *policy_cb = cb->policy_cb; + + if (cb->flags & EXPIRE_REFLOGS_REWRITE) + osha1 = cb->last_kept_sha1; + + if ((*cb->should_prune_fn)(osha1, nsha1, email, timestamp, tz, + message, policy_cb)) { + if (!cb->newlog) + printf("would prune %s", message); + else if (cb->flags & EXPIRE_REFLOGS_VERBOSE) + printf("prune %s", message); + } else { + if (cb->newlog) { + fprintf(cb->newlog, "%s %s %s %lu %+05d\t%s", + sha1_to_hex(osha1), sha1_to_hex(nsha1), + email, timestamp, tz, message); + hashcpy(cb->last_kept_sha1, nsha1); + } + if (cb->flags & EXPIRE_REFLOGS_VERBOSE) + printf("keep %s", message); + } + return 0; +} + +int reflog_expire(const char *refname, const unsigned char *sha1, + unsigned int flags, + reflog_expiry_prepare_fn prepare_fn, + reflog_expiry_should_prune_fn should_prune_fn, + reflog_expiry_cleanup_fn cleanup_fn, + void *policy_cb_data) +{ + static struct lock_file reflog_lock; + struct expire_reflog_cb cb; + struct ref_lock *lock; + char *log_file; + int status = 0; + + memset(&cb, 0, sizeof(cb)); + cb.flags = flags; + cb.policy_cb = policy_cb_data; + cb.should_prune_fn = should_prune_fn; + + /* + * The reflog file is locked by holding the lock on the + * reference itself, plus we might need to update the + * reference if --updateref was specified: + */ + lock = lock_ref_sha1_basic(refname, sha1, NULL, 0, NULL); + if (!lock) + return error("cannot lock ref '%s'", refname); + if (!reflog_exists(refname)) { + unlock_ref(lock); + return 0; + } + + log_file = git_pathdup("logs/%s", refname); + if (!(flags & EXPIRE_REFLOGS_DRY_RUN)) { + /* + * Even though holding $GIT_DIR/logs/$reflog.lock has + * no locking implications, we use the lock_file + * machinery here anyway because it does a lot of the + * work we need, including cleaning up if the program + * exits unexpectedly. + */ + if (hold_lock_file_for_update(&reflog_lock, log_file, 0) < 0) { + struct strbuf err = STRBUF_INIT; + unable_to_lock_message(log_file, errno, &err); + error("%s", err.buf); + strbuf_release(&err); + goto failure; + } + cb.newlog = fdopen_lock_file(&reflog_lock, "w"); + if (!cb.newlog) { + error("cannot fdopen %s (%s)", + reflog_lock.filename.buf, strerror(errno)); + goto failure; + } + } + + (*prepare_fn)(refname, sha1, cb.policy_cb); + for_each_reflog_ent(refname, expire_reflog_ent, &cb); + (*cleanup_fn)(cb.policy_cb); + + if (!(flags & EXPIRE_REFLOGS_DRY_RUN)) { + if (close_lock_file(&reflog_lock)) { + status |= error("couldn't write %s: %s", log_file, + strerror(errno)); + } else if ((flags & EXPIRE_REFLOGS_UPDATE_REF) && + (write_in_full(lock->lock_fd, + sha1_to_hex(cb.last_kept_sha1), 40) != 40 || + write_str_in_full(lock->lock_fd, "\n") != 1 || + close_ref(lock) < 0)) { + status |= error("couldn't write %s", + lock->lk->filename.buf); + rollback_lock_file(&reflog_lock); + } else if (commit_lock_file(&reflog_lock)) { + status |= error("unable to commit reflog '%s' (%s)", + log_file, strerror(errno)); + } else if ((flags & EXPIRE_REFLOGS_UPDATE_REF) && commit_ref(lock)) { + status |= error("couldn't set %s", lock->ref_name); + } + } + free(log_file); + unlock_ref(lock); + return status; + + failure: + rollback_lock_file(&reflog_lock); + free(log_file); + unlock_ref(lock); + return -1; +} diff --git a/refs.h b/refs.h index 405c6572f1135d..afa3c4decd5562 100644 --- a/refs.h +++ b/refs.h @@ -1,15 +1,6 @@ #ifndef REFS_H #define REFS_H -struct ref_lock { - char *ref_name; - char *orig_ref_name; - struct lock_file *lk; - unsigned char old_sha1[20]; - int lock_fd; - int force_write; -}; - /* * A ref_transaction represents a collection of ref updates * that should succeed or fail together. @@ -189,8 +180,7 @@ extern int is_branch(const char *refname); extern int peel_ref(const char *refname, unsigned char *sha1); /* - * Flags controlling lock_any_ref_for_update(), ref_transaction_update(), - * ref_transaction_create(), etc. + * Flags controlling ref_transaction_update(), ref_transaction_create(), etc. * REF_NODEREF: act on the ref directly, instead of dereferencing * symbolic references. * REF_DELETING: tolerate broken refs @@ -199,21 +189,6 @@ extern int peel_ref(const char *refname, unsigned char *sha1); */ #define REF_NODEREF 0x01 #define REF_DELETING 0x02 -/* - * This function sets errno to something meaningful on failure. - */ -extern struct ref_lock *lock_any_ref_for_update(const char *refname, - const unsigned char *old_sha1, - int flags, int *type_p); - -/** Close the file descriptor owned by a lock and return the status */ -extern int close_ref(struct ref_lock *lock); - -/** Close and commit the ref locked by the lock */ -extern int commit_ref(struct ref_lock *lock); - -/** Release any lock taken but not written. **/ -extern void unlock_ref(struct ref_lock *lock); /* * Setup reflog before using. Set errno to something meaningful on failure. @@ -291,7 +266,7 @@ struct ref_transaction *ref_transaction_begin(struct strbuf *err); /* * Add a reference update to transaction. new_sha1 is the value that - * the reference should have after the update, or zeros if it should + * the reference should have after the update, or null_sha1 if it should * be deleted. If have_old is true, then old_sha1 holds the value * that the reference should have had before the update, or zeros if * it must not have existed beforehand. @@ -361,4 +336,50 @@ int update_ref(const char *action, const char *refname, extern int parse_hide_refs_config(const char *var, const char *value, const char *); extern int ref_is_hidden(const char *); +enum expire_reflog_flags { + EXPIRE_REFLOGS_DRY_RUN = 1 << 0, + EXPIRE_REFLOGS_UPDATE_REF = 1 << 1, + EXPIRE_REFLOGS_VERBOSE = 1 << 2, + EXPIRE_REFLOGS_REWRITE = 1 << 3 +}; + +/* + * The following interface is used for reflog expiration. The caller + * calls reflog_expire(), supplying it with three callback functions, + * of the following types. The callback functions define the + * expiration policy that is desired. + * + * reflog_expiry_prepare_fn -- Called once after the reference is + * locked. + * + * reflog_expiry_should_prune_fn -- Called once for each entry in the + * existing reflog. It should return true iff that entry should be + * pruned. + * + * reflog_expiry_cleanup_fn -- Called once before the reference is + * unlocked again. + */ +typedef void reflog_expiry_prepare_fn(const char *refname, + const unsigned char *sha1, + void *cb_data); +typedef int reflog_expiry_should_prune_fn(unsigned char *osha1, + unsigned char *nsha1, + const char *email, + unsigned long timestamp, int tz, + const char *message, void *cb_data); +typedef void reflog_expiry_cleanup_fn(void *cb_data); + +/* + * Expire reflog entries for the specified reference. sha1 is the old + * value of the reference. flags is a combination of the constants in + * enum expire_reflog_flags. The three function pointers are described + * above. On success, return zero. + */ +extern int reflog_expire(const char *refname, const unsigned char *sha1, + unsigned int flags, + reflog_expiry_prepare_fn prepare_fn, + reflog_expiry_should_prune_fn should_prune_fn, + reflog_expiry_cleanup_fn cleanup_fn, + void *policy_cb_data); + #endif /* REFS_H */ diff --git a/remote.c b/remote.c index 5b9c6931c1e66a..68901b0070d257 100644 --- a/remote.c +++ b/remote.c @@ -975,8 +975,8 @@ struct ref *copy_ref(const struct ref *ref) cpy = xmalloc(sizeof(struct ref) + len + 1); memcpy(cpy, ref, sizeof(struct ref) + len + 1); cpy->next = NULL; - cpy->symref = ref->symref ? xstrdup(ref->symref) : NULL; - cpy->remote_status = ref->remote_status ? xstrdup(ref->remote_status) : NULL; + cpy->symref = xstrdup_or_null(ref->symref); + cpy->remote_status = xstrdup_or_null(ref->remote_status); cpy->peer_ref = copy_ref(ref->peer_ref); return cpy; } @@ -2156,7 +2156,7 @@ struct ref *get_stale_heads(struct refspec *refs, int ref_count, struct ref *fet /* * Compare-and-swap */ -void clear_cas_option(struct push_cas_option *cas) +static void clear_cas_option(struct push_cas_option *cas) { int i; diff --git a/remote.h b/remote.h index 8b62efd2adcb74..02d66ceff5c962 100644 --- a/remote.h +++ b/remote.h @@ -115,7 +115,8 @@ struct ref { REF_STATUS_REJECT_SHALLOW, REF_STATUS_UPTODATE, REF_STATUS_REMOTE_REJECT, - REF_STATUS_EXPECTING_REPORT + REF_STATUS_EXPECTING_REPORT, + REF_STATUS_ATOMIC_PUSH_FAILED } status; char *remote_status; struct ref *peer_ref; /* when renaming */ @@ -260,7 +261,6 @@ struct push_cas_option { extern int parseopt_push_cas_option(const struct option *, const char *arg, int unset); extern int parse_push_cas_option(struct push_cas_option *, const char *arg, int unset); -extern void clear_cas_option(struct push_cas_option *); extern int is_empty_cas(const struct push_cas_option *); void apply_push_cas(struct push_cas_option *, struct remote *, struct ref *); diff --git a/rerere.c b/rerere.c index 1b0555f1a5a023..31644dec04fe4a 100644 --- a/rerere.c +++ b/rerere.c @@ -477,27 +477,23 @@ static int merge(const char *name, const char *path) static struct lock_file index_lock; -static int update_paths(struct string_list *update) +static void update_paths(struct string_list *update) { int i; - int fd = hold_locked_index(&index_lock, 0); - int status = 0; - if (fd < 0) - return -1; + hold_locked_index(&index_lock, 1); for (i = 0; i < update->nr; i++) { struct string_list_item *item = &update->items[i]; - if (add_file_to_cache(item->string, ADD_CACHE_IGNORE_ERRORS)) - status = -1; + if (add_file_to_cache(item->string, 0)) + exit(128); } - if (!status && active_cache_changed) { + if (active_cache_changed) { if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK)) die("Unable to write new index file"); - } else if (fd >= 0) + } else rollback_lock_file(&index_lock); - return status; } static int do_plain_rerere(struct string_list *rr, int fd) diff --git a/revision.c b/revision.c index 86406a26a2d459..66520c671ee114 100644 --- a/revision.c +++ b/revision.c @@ -2017,6 +2017,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg grep_set_pattern_type_option(GREP_PATTERN_TYPE_PCRE, &revs->grep_filter); } else if (!strcmp(arg, "--all-match")) { revs->grep_filter.all_match = 1; + } else if (!strcmp(arg, "--invert-grep")) { + revs->invert_grep = 1; } else if ((argcount = parse_long_opt("encoding", argv, &optarg))) { if (strcmp(optarg, "none")) git_log_output_encoding = xstrdup(optarg); @@ -2915,7 +2917,7 @@ static int commit_match(struct commit *commit, struct rev_info *opt) (char *)message, strlen(message)); strbuf_release(&buf); unuse_commit_buffer(commit, message); - return retval; + return opt->invert_grep ? !retval : retval; } static inline int want_ancestry(const struct rev_info *revs) @@ -2968,6 +2970,61 @@ enum commit_action get_commit_action(struct rev_info *revs, struct commit *commi return commit_show; } +define_commit_slab(saved_parents, struct commit_list *); + +#define EMPTY_PARENT_LIST ((struct commit_list *)-1) + +/* + * You may only call save_parents() once per commit (this is checked + * for non-root commits). + */ +static void save_parents(struct rev_info *revs, struct commit *commit) +{ + struct commit_list **pp; + + if (!revs->saved_parents_slab) { + revs->saved_parents_slab = xmalloc(sizeof(struct saved_parents)); + init_saved_parents(revs->saved_parents_slab); + } + + pp = saved_parents_at(revs->saved_parents_slab, commit); + + /* + * When walking with reflogs, we may visit the same commit + * several times: once for each appearance in the reflog. + * + * In this case, save_parents() will be called multiple times. + * We want to keep only the first set of parents. We need to + * store a sentinel value for an empty (i.e., NULL) parent + * list to distinguish it from a not-yet-saved list, however. + */ + if (*pp) + return; + if (commit->parents) + *pp = copy_commit_list(commit->parents); + else + *pp = EMPTY_PARENT_LIST; +} + +static void free_saved_parents(struct rev_info *revs) +{ + if (revs->saved_parents_slab) + clear_saved_parents(revs->saved_parents_slab); +} + +struct commit_list *get_saved_parents(struct rev_info *revs, const struct commit *commit) +{ + struct commit_list *parents; + + if (!revs->saved_parents_slab) + return commit->parents; + + parents = *saved_parents_at(revs->saved_parents_slab, commit); + if (parents == EMPTY_PARENT_LIST) + return NULL; + return parents; +} + enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit) { enum commit_action action = get_commit_action(revs, commit); @@ -3267,54 +3324,3 @@ void put_revision_mark(const struct rev_info *revs, const struct commit *commit) fputs(mark, stdout); putchar(' '); } - -define_commit_slab(saved_parents, struct commit_list *); - -#define EMPTY_PARENT_LIST ((struct commit_list *)-1) - -void save_parents(struct rev_info *revs, struct commit *commit) -{ - struct commit_list **pp; - - if (!revs->saved_parents_slab) { - revs->saved_parents_slab = xmalloc(sizeof(struct saved_parents)); - init_saved_parents(revs->saved_parents_slab); - } - - pp = saved_parents_at(revs->saved_parents_slab, commit); - - /* - * When walking with reflogs, we may visit the same commit - * several times: once for each appearance in the reflog. - * - * In this case, save_parents() will be called multiple times. - * We want to keep only the first set of parents. We need to - * store a sentinel value for an empty (i.e., NULL) parent - * list to distinguish it from a not-yet-saved list, however. - */ - if (*pp) - return; - if (commit->parents) - *pp = copy_commit_list(commit->parents); - else - *pp = EMPTY_PARENT_LIST; -} - -struct commit_list *get_saved_parents(struct rev_info *revs, const struct commit *commit) -{ - struct commit_list *parents; - - if (!revs->saved_parents_slab) - return commit->parents; - - parents = *saved_parents_at(revs->saved_parents_slab, commit); - if (parents == EMPTY_PARENT_LIST) - return NULL; - return parents; -} - -void free_saved_parents(struct rev_info *revs) -{ - if (revs->saved_parents_slab) - clear_saved_parents(revs->saved_parents_slab); -} diff --git a/revision.h b/revision.h index 033a24460e71b7..0ea8b4e25555e3 100644 --- a/revision.h +++ b/revision.h @@ -169,6 +169,8 @@ struct rev_info { /* Filter by commit log message */ struct grep_opt grep_filter; + /* Negate the match of grep_filter */ + int invert_grep; /* Display history graph */ struct git_graph *graph; @@ -298,18 +300,14 @@ extern int rewrite_parents(struct rev_info *revs, struct commit *commit, rewrite_parent_fn_t rewrite_parent); /* - * Save a copy of the parent list, and return the saved copy. This is - * used by the log machinery to retrieve the original parents when - * commit->parents has been modified by history simpification. - * - * You may only call save_parents() once per commit (this is checked - * for non-root commits). + * The log machinery saves the original parent list so that + * get_saved_parents() can later tell what the real parents of the + * commits are, when commit->parents has been modified by history + * simpification. * * get_saved_parents() will transparently return commit->parents if * history simplification is off. */ -extern void save_parents(struct rev_info *revs, struct commit *commit); extern struct commit_list *get_saved_parents(struct rev_info *revs, const struct commit *commit); -extern void free_saved_parents(struct rev_info *revs); #endif diff --git a/send-pack.c b/send-pack.c index 25947d7df9dd3a..9d2b0c52ed8235 100644 --- a/send-pack.c +++ b/send-pack.c @@ -193,10 +193,13 @@ static void advertise_shallow_grafts_buf(struct strbuf *sb) for_each_commit_graft(advertise_shallow_grafts_cb, sb); } -static int ref_update_to_be_sent(const struct ref *ref, const struct send_pack_args *args) +#define CHECK_REF_NO_PUSH -1 +#define CHECK_REF_STATUS_REJECTED -2 +#define CHECK_REF_UPTODATE -3 +static int check_to_send_update(const struct ref *ref, const struct send_pack_args *args) { if (!ref->peer_ref && !args->send_mirror) - return 0; + return CHECK_REF_NO_PUSH; /* Check for statuses set by set_ref_status_for_push() */ switch (ref->status) { @@ -206,10 +209,11 @@ static int ref_update_to_be_sent(const struct ref *ref, const struct send_pack_a case REF_STATUS_REJECT_NEEDS_FORCE: case REF_STATUS_REJECT_STALE: case REF_STATUS_REJECT_NODELETE: + return CHECK_REF_STATUS_REJECTED; case REF_STATUS_UPTODATE: - return 0; + return CHECK_REF_UPTODATE; default: - return 1; + return 0; } } @@ -253,7 +257,7 @@ static int generate_push_cert(struct strbuf *req_buf, strbuf_addstr(&cert, "\n"); for (ref = remote_refs; ref; ref = ref->next) { - if (!ref_update_to_be_sent(ref, args)) + if (check_to_send_update(ref, args) < 0) continue; update_seen = 1; strbuf_addf(&cert, "%s %s %s\n", @@ -281,6 +285,29 @@ static int generate_push_cert(struct strbuf *req_buf, return update_seen; } + +static int atomic_push_failure(struct send_pack_args *args, + struct ref *remote_refs, + struct ref *failing_ref) +{ + struct ref *ref; + /* Mark other refs as failed */ + for (ref = remote_refs; ref; ref = ref->next) { + if (!ref->peer_ref && !args->send_mirror) + continue; + + switch (ref->status) { + case REF_STATUS_EXPECTING_REPORT: + ref->status = REF_STATUS_ATOMIC_PUSH_FAILED; + continue; + default: + break; /* do nothing */ + } + } + return error("atomic push failed for ref %s. status: %d\n", + failing_ref->name, failing_ref->status); +} + int send_pack(struct send_pack_args *args, int fd[], struct child_process *conn, struct ref *remote_refs, @@ -297,6 +324,8 @@ int send_pack(struct send_pack_args *args, int use_sideband = 0; int quiet_supported = 0; int agent_supported = 0; + int use_atomic = 0; + int atomic_supported = 0; unsigned cmds_sent = 0; int ret; struct async demux; @@ -317,6 +346,8 @@ int send_pack(struct send_pack_args *args, agent_supported = 1; if (server_supports("no-thin")) args->use_thin_pack = 0; + if (server_supports("atomic")) + atomic_supported = 1; if (args->push_cert) { int len; @@ -331,6 +362,10 @@ int send_pack(struct send_pack_args *args, "Perhaps you should specify a branch such as 'master'.\n"); return 0; } + if (args->atomic && !atomic_supported) + die(_("server does not support --atomic push")); + + use_atomic = atomic_supported && args->atomic; if (status_report) strbuf_addstr(&cap_buf, " report-status"); @@ -338,6 +373,8 @@ int send_pack(struct send_pack_args *args, strbuf_addstr(&cap_buf, " side-band-64k"); if (quiet_supported && (args->quiet || !args->progress)) strbuf_addstr(&cap_buf, " quiet"); + if (use_atomic) + strbuf_addstr(&cap_buf, " atomic"); if (agent_supported) strbuf_addf(&cap_buf, " agent=%s", git_user_agent_sanitized()); @@ -362,9 +399,21 @@ int send_pack(struct send_pack_args *args, * the pack data. */ for (ref = remote_refs; ref; ref = ref->next) { - if (!ref_update_to_be_sent(ref, args)) + switch (check_to_send_update(ref, args)) { + case 0: /* no error */ + break; + case CHECK_REF_STATUS_REJECTED: + /* + * When we know the server would reject a ref update if + * we were to send it and we're trying to send the refs + * atomically, abort the whole operation. + */ + if (use_atomic) + return atomic_push_failure(args, remote_refs, ref); + /* Fallthrough for non atomic case. */ + default: continue; - + } if (!ref->deletion) need_pack_data = 1; @@ -383,7 +432,7 @@ int send_pack(struct send_pack_args *args, if (args->dry_run || args->push_cert) continue; - if (!ref_update_to_be_sent(ref, args)) + if (check_to_send_update(ref, args) < 0) continue; old_hex = sha1_to_hex(ref->old_sha1); diff --git a/send-pack.h b/send-pack.h index 56354577467acf..b6646488aaf938 100644 --- a/send-pack.h +++ b/send-pack.h @@ -13,7 +13,8 @@ struct send_pack_args { use_ofs_delta:1, dry_run:1, push_cert:1, - stateless_rpc:1; + stateless_rpc:1, + atomic:1; }; int send_pack(struct send_pack_args *args, diff --git a/sha1_file.c b/sha1_file.c index 30995e61b38fbf..fa2ae7466899ba 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -23,6 +23,7 @@ #include "bulk-checkin.h" #include "streaming.h" #include "dir.h" +#include "fsck.h" #ifndef O_NOATIME #if defined(__linux__) && (defined(__i386__) || defined(__PPC__)) @@ -3117,11 +3118,21 @@ static int index_mem(unsigned char *sha1, void *buf, size_t size, } } if (flags & HASH_FORMAT_CHECK) { - if (type == OBJ_TREE) + if (flags & HASH_FORMAT_STRICT) { + struct object object; + + memset(&object, 0, sizeof(object)); + object.type = type; + memcpy(object.sha1, sha1, 20); + if (fsck_object(&object, buf, size, 1, + fsck_error_function)) + exit(1); + } + else if (type == OBJ_TREE) check_tree(buf, size); - if (type == OBJ_COMMIT) + else if (type == OBJ_COMMIT) check_commit(buf, size); - if (type == OBJ_TAG) + else if (type == OBJ_TAG) check_tag(buf, size); } diff --git a/shallow.c b/shallow.c index cdd07751461e69..d8bf40ad4bed3b 100644 --- a/shallow.c +++ b/shallow.c @@ -22,7 +22,7 @@ void set_alternate_shallow_file(const char *path, int override) if (alternate_shallow_file && !override) return; free(alternate_shallow_file); - alternate_shallow_file = path ? xstrdup(path) : NULL; + alternate_shallow_file = xstrdup_or_null(path); } int register_shallow(const unsigned char *sha1) @@ -137,7 +137,7 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth, return result; } -void check_shallow_file_for_update(void) +static void check_shallow_file_for_update(void) { if (is_shallow == -1) die("BUG: shallow must be initialized by now"); diff --git a/t/lib-terminal.sh b/t/lib-terminal.sh index 51845491bb42ee..cd220e378e201f 100644 --- a/t/lib-terminal.sh +++ b/t/lib-terminal.sh @@ -1,7 +1,7 @@ # Helpers for terminal output tests. # Catch tests which should depend on TTY but forgot to. There's no need -# to aditionally check that the TTY prereq is set here. If the test declared +# to additionally check that the TTY prereq is set here. If the test declared # it and we are running the test, then it must have been set. test_terminal () { if ! test_declared_prereq TTY diff --git a/t/t1007-hash-object.sh b/t/t1007-hash-object.sh index f83df8eb8b1430..39317ab6e59788 100755 --- a/t/t1007-hash-object.sh +++ b/t/t1007-hash-object.sh @@ -201,4 +201,18 @@ test_expect_success 'corrupt tag' ' test_must_fail git hash-object -t tag --stdin bogus-commit < 123459876 +0100 + +This commit message intentionally left blank +EOF + +test_expect_success 'hash-object --strict' ' + test_must_fail git hash-object \ + --strict -t commit --stdin -w actual ' +test_expect_success '`mktree --strict` validates before writing' ' + printf "40000 tree %s\t.\n" $(git rev-parse HEAD:) > bogus-tree && + test_must_fail git mktree --strict expect << EOF +second +initial +EOF +test_expect_success 'log --invert-grep --grep' ' + git log --pretty="tformat:%s" --invert-grep --grep=th --grep=Sec >actual && + test_cmp expect actual +' + +test_expect_success 'log --invert-grep --grep -i' ' + echo initial >expect && + git log --pretty="tformat:%s" --invert-grep -i --grep=th --grep=Sec >actual && + test_cmp expect actual +' + test_expect_success 'log --grep option parsing' ' echo second >expect && git log -1 --pretty="tformat:%s" --grep sec >actual && diff --git a/t/t4255-am-submodule.sh b/t/t4255-am-submodule.sh index 8bde7dbb6dba8f..0ba8194403f674 100755 --- a/t/t4255-am-submodule.sh +++ b/t/t4255-am-submodule.sh @@ -18,4 +18,76 @@ am_3way () { KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1 test_submodule_switch "am_3way" +test_expect_success 'setup diff.submodule' ' + test_commit one && + INITIAL=$(git rev-parse HEAD) && + + git init submodule && + ( + cd submodule && + test_commit two && + git rev-parse HEAD >../initial-submodule + ) && + git submodule add ./submodule && + git commit -m first && + + ( + cd submodule && + test_commit three && + git rev-parse HEAD >../first-submodule + ) && + git add submodule && + git commit -m second && + SECOND=$(git rev-parse HEAD) && + + ( + cd submodule && + git mv two.t four.t && + git commit -m "second submodule" && + git rev-parse HEAD >../second-submodule + ) && + test_commit four && + git add submodule && + git commit --amend --no-edit && + THIRD=$(git rev-parse HEAD) && + git submodule update --init +' + +run_test() { + START_COMMIT=$1 && + EXPECT=$2 && + # Abort any merges in progress: the previous + # test may have failed, and we should clean up. + test_might_fail git am --abort && + git reset --hard $START_COMMIT && + rm -f *.patch && + git format-patch -1 && + git reset --hard $START_COMMIT^ && + git submodule update && + git am *.patch && + git submodule update && + git -C submodule rev-parse HEAD >actual && + test_cmp $EXPECT actual +} + +test_expect_success 'diff.submodule unset' ' + test_unconfig diff.submodule && + run_test $SECOND first-submodule +' + +test_expect_success 'diff.submodule unset with extra file' ' + test_unconfig diff.submodule && + run_test $THIRD second-submodule +' + +test_expect_success 'diff.submodule=log' ' + test_config diff.submodule log && + run_test $SECOND first-submodule +' + +test_expect_success 'diff.submodule=log with extra file' ' + test_config diff.submodule log && + run_test $THIRD second-submodule +' + test_done diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index 85c7fecd22a37d..e4436c170088a6 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -1434,4 +1434,67 @@ test_expect_success 'receive.denyCurrentBranch = updateInstead' ' ' +test_expect_success 'updateInstead with push-to-checkout hook' ' + rm -fr testrepo && + git init testrepo && + ( + cd testrepo && + git pull .. master && + git reset --hard HEAD^^ && + git tag initial && + git config receive.denyCurrentBranch updateInstead && + write_script .git/hooks/push-to-checkout <<-\EOF + echo >&2 updating from $(git rev-parse HEAD) + echo >&2 updating to "$1" + + git update-index -q --refresh && + git read-tree -u -m HEAD "$1" || { + status=$? + echo >&2 read-tree failed + exit $status + } + EOF + ) && + + # Try pushing into a pristine + git push testrepo master && + ( + cd testrepo && + git diff --quiet && + git diff HEAD --quiet && + test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD) + ) && + + # Try pushing into a repository with conflicting change + ( + cd testrepo && + git reset --hard initial && + echo conflicting >path2 + ) && + test_must_fail git push testrepo master && + ( + cd testrepo && + test $(git rev-parse initial) = $(git rev-parse HEAD) && + test conflicting = "$(cat path2)" && + git diff-index --quiet --cached HEAD + ) && + + # Try pushing into a repository with unrelated change + ( + cd testrepo && + git reset --hard initial && + echo unrelated >path1 && + echo irrelevant >path5 && + git add path5 + ) && + git push testrepo master && + ( + cd testrepo && + test "$(cat path1)" = unrelated && + test "$(cat path5)" = irrelevant && + test "$(git diff --name-only --cached HEAD)" = path5 && + test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD) + ) +' + test_done diff --git a/t/t5543-atomic-push.sh b/t/t5543-atomic-push.sh new file mode 100755 index 00000000000000..3480b33007de4d --- /dev/null +++ b/t/t5543-atomic-push.sh @@ -0,0 +1,194 @@ +#!/bin/sh + +test_description='pushing to a repository using the atomic push option' + +. ./test-lib.sh + +mk_repo_pair () { + rm -rf workbench upstream && + test_create_repo upstream && + test_create_repo workbench && + ( + cd upstream && + git config receive.denyCurrentBranch warn + ) && + ( + cd workbench && + git remote add up ../upstream + ) +} + +# Compare the ref ($1) in upstream with a ref value from workbench ($2) +# i.e. test_refs second HEAD@{2} +test_refs () { + test $# = 2 && + git -C upstream rev-parse --verify "$1" >expect && + git -C workbench rev-parse --verify "$2" >actual && + test_cmp expect actual +} + +test_expect_success 'atomic push works for a single branch' ' + mk_repo_pair && + ( + cd workbench && + test_commit one && + git push --mirror up && + test_commit two && + git push --atomic up master + ) && + test_refs master master +' + +test_expect_success 'atomic push works for two branches' ' + mk_repo_pair && + ( + cd workbench && + test_commit one && + git branch second && + git push --mirror up && + test_commit two && + git checkout second && + test_commit three && + git push --atomic up master second + ) && + test_refs master master && + test_refs second second +' + +test_expect_success 'atomic push works in combination with --mirror' ' + mk_repo_pair && + ( + cd workbench && + test_commit one && + git checkout -b second && + test_commit two && + git push --atomic --mirror up + ) && + test_refs master master && + test_refs second second +' + +test_expect_success 'atomic push works in combination with --force' ' + mk_repo_pair && + ( + cd workbench && + test_commit one && + git branch second master && + test_commit two_a && + git checkout second && + test_commit two_b && + test_commit three_b && + test_commit four && + git push --mirror up && + # The actual test is below + git checkout master && + test_commit three_a && + git checkout second && + git reset --hard HEAD^ && + git push --force --atomic up master second + ) && + test_refs master master && + test_refs second second +' + +# set up two branches where master can be pushed but second can not +# (non-fast-forward). Since second can not be pushed the whole operation +# will fail and leave master untouched. +test_expect_success 'atomic push fails if one branch fails' ' + mk_repo_pair && + ( + cd workbench && + test_commit one && + git checkout -b second master && + test_commit two && + test_commit three && + test_commit four && + git push --mirror up && + git reset --hard HEAD~2 && + test_commit five && + git checkout master && + test_commit six && + test_must_fail git push --atomic --all up + ) && + test_refs master HEAD@{7} && + test_refs second HEAD@{4} +' + +test_expect_success 'atomic push fails if one tag fails remotely' ' + # prepare the repo + mk_repo_pair && + ( + cd workbench && + test_commit one && + git checkout -b second master && + test_commit two && + git push --mirror up + ) && + # a third party modifies the server side: + ( + cd upstream && + git checkout second && + git tag test_tag second + ) && + # see if we can now push both branches. + ( + cd workbench && + git checkout master && + test_commit three && + git checkout second && + test_commit four && + git tag test_tag && + test_must_fail git push --tags --atomic up master second + ) && + test_refs master HEAD@{3} && + test_refs second HEAD@{1} +' + +test_expect_success 'atomic push obeys update hook preventing a branch to be pushed' ' + mk_repo_pair && + ( + cd workbench && + test_commit one && + git checkout -b second master && + test_commit two && + git push --mirror up + ) && + ( + cd upstream && + HOOKDIR="$(git rev-parse --git-dir)/hooks" && + HOOK="$HOOKDIR/update" && + mkdir -p "$HOOKDIR" && + write_script "$HOOK" <<-\EOF + # only allow update to master from now on + test "$1" = "refs/heads/master" + EOF + ) && + ( + cd workbench && + git checkout master && + test_commit three && + git checkout second && + test_commit four && + test_must_fail git push --atomic up master second + ) && + test_refs master HEAD@{3} && + test_refs second HEAD@{1} +' + +test_expect_success 'atomic push is not advertised if configured' ' + mk_repo_pair && + ( + cd upstream + git config receive.advertiseatomic 0 + ) && + ( + cd workbench && + test_commit one && + git push --mirror up && + test_commit two && + test_must_fail git push --atomic up master + ) && + test_refs master HEAD@{1} +' + +test_done diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh index 4d5a25eedfef50..6e2f3b215ad657 100755 --- a/t/t6050-replace.sh +++ b/t/t6050-replace.sh @@ -378,6 +378,17 @@ test_expect_success '--edit and change nothing or command failed' ' git cat-file commit "$PARA3" | grep "A fake Thor" ' +test_expect_success 'setup an intentionally broken fake editor' ' + write_script fakeeditor <<-\EOF + tr -d "<>" <"$1" >"$1.new" + mv "$1.new" "$1" + EOF +' + +test_expect_success '--edit validates before replacing the object' ' + test_must_fail env GIT_EDITOR=./fakeeditor git replace --edit "$PARA3" +' + test_expect_success 'replace ref cleanup' ' test -n "$(git replace)" && git replace -d $(git replace) && diff --git a/t/t9817-git-p4-exclude.sh b/t/t9817-git-p4-exclude.sh new file mode 100755 index 00000000000000..aac568eadfcab6 --- /dev/null +++ b/t/t9817-git-p4-exclude.sh @@ -0,0 +1,71 @@ +#!/bin/sh + +test_description='git p4 tests for excluded paths during clone and sync' + +. ./lib-git-p4.sh + +test_expect_success 'start p4d' ' + start_p4d +' + +# Create a repo with the structure: +# +# //depot/wanted/foo +# //depot/discard/foo +# +# Check that we can exclude a subdirectory with both +# clone and sync operations. + +test_expect_success 'create exclude repo' ' + ( + cd "$cli" && + mkdir -p wanted discard && + echo wanted >wanted/foo && + echo discard >discard/foo && + p4 add wanted/foo discard/foo && + p4 submit -d "initial revision" + ) +' + +test_expect_success 'check the repo was created correctly' ' + test_when_finished cleanup_git && + git p4 clone --dest="$git" //depot/...@all && + ( + cd "$git" && + test_path_is_file wanted/foo && + test_path_is_file discard/foo + ) +' + +test_expect_success 'clone, excluding part of repo' ' + test_when_finished cleanup_git && + git p4 clone -//depot/discard/... --dest="$git" //depot/...@all && + ( + cd "$git" && + test_path_is_file wanted/foo && + test_path_is_missing discard/foo + ) +' + +test_expect_success 'clone, then sync with exclude' ' + test_when_finished cleanup_git && + git p4 clone -//depot/discard/... --dest="$git" //depot/...@all && + ( + cd "$cli" && + p4 edit wanted/foo discard/foo && + date >>wanted/foo && + date >>discard/foo && + p4 submit -d "updating" && + + cd "$git" && + git p4 sync -//depot/discard/... && + test_path_is_file wanted/foo && + test_path_is_missing discard/foo + ) +' + +test_expect_success 'kill p4d' ' + kill_p4d +' + +test_done diff --git a/transport.c b/transport.c index 08bcd3a4eba42d..0694a7cf3e4a8b 100644 --- a/transport.c +++ b/transport.c @@ -728,6 +728,10 @@ static int print_one_push_status(struct ref *ref, const char *dest, int count, i ref->deletion ? NULL : ref->peer_ref, "remote failed to report status", porcelain); break; + case REF_STATUS_ATOMIC_PUSH_FAILED: + print_ref_status('!', "[rejected]", ref, ref->peer_ref, + "atomic push failed", porcelain); + break; case REF_STATUS_OK: print_ok_ref_status(ref, porcelain); break; @@ -826,6 +830,7 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re args.dry_run = !!(flags & TRANSPORT_PUSH_DRY_RUN); args.porcelain = !!(flags & TRANSPORT_PUSH_PORCELAIN); args.push_cert = !!(flags & TRANSPORT_PUSH_CERT); + args.atomic = !!(flags & TRANSPORT_PUSH_ATOMIC); args.url = transport->url; ret = send_pack(&args, data->fd, data->conn, remote_refs, diff --git a/transport.h b/transport.h index 3e0091eaabe406..18d2cf8275e1f5 100644 --- a/transport.h +++ b/transport.h @@ -125,6 +125,7 @@ struct transport { #define TRANSPORT_PUSH_NO_HOOK 512 #define TRANSPORT_PUSH_FOLLOW_TAGS 1024 #define TRANSPORT_PUSH_CERT 2048 +#define TRANSPORT_PUSH_ATOMIC 4096 #define TRANSPORT_SUMMARY_WIDTH (2 * DEFAULT_ABBREV + 3) #define TRANSPORT_SUMMARY(x) (int)(TRANSPORT_SUMMARY_WIDTH + strlen(x) - gettext_width(x)), (x) diff --git a/urlmatch.c b/urlmatch.c index 618d2164919758..132d342bc12bf7 100644 --- a/urlmatch.c +++ b/urlmatch.c @@ -412,9 +412,9 @@ static size_t url_match_prefix(const char *url, return 0; } -int match_urls(const struct url_info *url, - const struct url_info *url_prefix, - int *exactusermatch) +static int match_urls(const struct url_info *url, + const struct url_info *url_prefix, + int *exactusermatch) { /* * url_prefix matches url if the scheme, host and port of url_prefix diff --git a/urlmatch.h b/urlmatch.h index b461dfd3dfee2c..528862adc55c43 100644 --- a/urlmatch.h +++ b/urlmatch.h @@ -31,7 +31,6 @@ struct url_info { }; extern char *url_normalize(const char *, struct url_info *); -extern int match_urls(const struct url_info *url, const struct url_info *url_prefix, int *exactusermatch); struct urlmatch_item { size_t matched_len; diff --git a/walker.c b/walker.c index f149371e71ebdc..483da4e0fb5771 100644 --- a/walker.c +++ b/walker.c @@ -232,7 +232,7 @@ int walker_targets_stdin(char ***target, const char ***write_ref) REALLOC_ARRAY(*write_ref, targets_alloc); } (*target)[targets] = xstrdup(tg_one); - (*write_ref)[targets] = rf_one ? xstrdup(rf_one) : NULL; + (*write_ref)[targets] = xstrdup_or_null(rf_one); targets++; } strbuf_release(&buf);