From ecde49bb8aa6e5d48e96988cf7f7d5a949893980 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Sat, 5 Oct 2019 21:11:55 +0000 Subject: [PATCH 001/953] t/oid-info: allow looking up hash algorithm name The test_oid function provides a mechanism for looking up hash algorithm information, but it doesn't specify a way to discover the hash algorithm name. Knowing this information is useful if one wants to invoke the test-tool helper for the algorithm in use, such as in our pack generation library. While it's currently possible to inspect the global variable holding this value, in the future we'll allow specifying an algorithm for storage and an algorithm for display, so it's better to abstract this value away. To assist with this, provide a named entry in the algorithm-specific lookup table that prints the algorithm in use. Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- t/oid-info/hash-info | 3 +++ 1 file changed, 3 insertions(+) diff --git a/t/oid-info/hash-info b/t/oid-info/hash-info index ccdbfdf9743d6a..6b5ded0b34b32f 100644 --- a/t/oid-info/hash-info +++ b/t/oid-info/hash-info @@ -6,3 +6,6 @@ hexsz sha256:64 zero sha1:0000000000000000000000000000000000000000 zero sha256:0000000000000000000000000000000000000000000000000000000000000000 + +algo sha1:sha1 +algo sha256:sha256 From 1bcef512040979964816937162bfc9968d414a4d Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Sat, 5 Oct 2019 21:11:56 +0000 Subject: [PATCH 002/953] t/oid-info: add empty tree and empty blob values The testsuite will eventually learn how to run using an algorithm other than SHA-1. In preparation for this, teach the test_oid family of functions how to look up the empty blob and empty tree values so they can be used. Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- t/oid-info/hash-info | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/t/oid-info/hash-info b/t/oid-info/hash-info index 6b5ded0b34b32f..d0736dd1a00d59 100644 --- a/t/oid-info/hash-info +++ b/t/oid-info/hash-info @@ -9,3 +9,9 @@ zero sha256:0000000000000000000000000000000000000000000000000000000000000000 algo sha1:sha1 algo sha256:sha256 + +empty_blob sha1:e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 +empty_blob sha256:473a0f4c3be8a93681a267e3b1e9a7dcda1185436fe141f7749120a303721813 + +empty_tree sha1:4b825dc642cb6eb9a060e54bf8d69288fbee4904 +empty_tree sha256:6ef19b41225c5369f1c104d45d8d85efa9b057b53b14b4b9b939dd74decc5321 From e0479fa07387a7f84dad04a258cd2dc2861c9df9 Mon Sep 17 00:00:00 2001 From: Emily Shaffer Date: Fri, 11 Oct 2019 16:55:54 -0700 Subject: [PATCH 003/953] documentation: add tutorial for object walking Existing documentation on object walks seems to be primarily intended as a reference for those already familiar with the procedure. This tutorial attempts to give an entry-level guide to a couple of bare-bones object walks so that new Git contributors can learn the concepts without having to wade through options parsing or special casing. The target audience is a Git contributor who is just getting started with the concept of object walking. The goal is to prepare this contributor to be able to understand and modify existing commands which perform revision walks more easily, although it will also prepare contributors to create new commands which perform walks. The tutorial covers a basic overview of the structs involved during object walk, setting up a basic commit walk, setting up a basic all-object walk, and adding some configuration changes to both walk types. It intentionally does not cover how to create new commands or search for options from the command line or gitconfigs. There is an associated patchset at https://github.com/nasamuffin/git/tree/revwalk that contains a reference implementation of the code generated by this tutorial. Signed-off-by: Emily Shaffer Helped-by: Eric Sunshine Signed-off-by: Junio C Hamano --- Documentation/Makefile | 1 + Documentation/MyFirstObjectWalk.txt | 906 ++++++++++++++++++++++++++++ 2 files changed, 907 insertions(+) create mode 100644 Documentation/MyFirstObjectWalk.txt diff --git a/Documentation/Makefile b/Documentation/Makefile index 76f2ecfc1b1a42..f267a5b7faea77 100644 --- a/Documentation/Makefile +++ b/Documentation/Makefile @@ -77,6 +77,7 @@ API_DOCS = $(patsubst %.txt,%,$(filter-out technical/api-index-skel.txt technica SP_ARTICLES += $(API_DOCS) TECH_DOCS += MyFirstContribution +TECH_DOCS += MyFirstObjectWalk TECH_DOCS += SubmittingPatches TECH_DOCS += technical/hash-function-transition TECH_DOCS += technical/http-protocol diff --git a/Documentation/MyFirstObjectWalk.txt b/Documentation/MyFirstObjectWalk.txt new file mode 100644 index 00000000000000..4d24daeb9feb1d --- /dev/null +++ b/Documentation/MyFirstObjectWalk.txt @@ -0,0 +1,906 @@ += My First Object Walk + +== What's an Object Walk? + +The object walk is a key concept in Git - this is the process that underpins +operations like object transfer and fsck. Beginning from a given commit, the +list of objects is found by walking parent relationships between commits (commit +X based on commit W) and containment relationships between objects (tree Y is +contained within commit X, and blob Z is located within tree Y, giving our +working tree for commit X something like `y/z.txt`). + +A related concept is the revision walk, which is focused on commit objects and +their parent relationships and does not delve into other object types. The +revision walk is used for operations like `git log`. + +=== Related Reading + +- `Documentation/user-manual.txt` under "Hacking Git" contains some coverage of + the revision walker in its various incarnations. +- `Documentation/technical/api-revision-walking.txt` +- https://eagain.net/articles/git-for-computer-scientists/[Git for Computer Scientists] + gives a good overview of the types of objects in Git and what your object + walk is really describing. + +== Setting Up + +Create a new branch from `master`. + +---- +git checkout -b revwalk origin/master +---- + +We'll put our fiddling into a new command. For fun, let's name it `git walken`. +Open up a new file `builtin/walken.c` and set up the command handler: + +---- +/* + * "git walken" + * + * Part of the "My First Object Walk" tutorial. + */ + +#include "builtin.h" + +int cmd_walken(int argc, const char **argv, const char *prefix) +{ + trace_printf(_("cmd_walken incoming...\n")); + return 0; +} +---- + +NOTE: `trace_printf()` differs from `printf()` in that it can be turned on or +off at runtime. For the purposes of this tutorial, we will write `walken` as +though it is intended for use as a "plumbing" command: that is, a command which +is used primarily in scripts, rather than interactively by humans (a "porcelain" +command). So we will send our debug output to `trace_printf()` instead. When +running, enable trace output by setting the environment variable `GIT_TRACE`. + +Add usage text and `-h` handling, like all subcommands should consistently do +(our test suite will notice and complain if you fail to do so). + +---- +int cmd_walken(int argc, const char **argv, const char *prefix) +{ + const char * const walken_usage[] = { + N_("git walken"), + NULL, + } + struct option options[] = { + OPT_END() + }; + + argc = parse_options(argc, argv, prefix, options, walken_usage, 0); + + ... +} +---- + +Also add the relevant line in `builtin.h` near `cmd_whatchanged()`: + +---- +int cmd_walken(int argc, const char **argv, const char *prefix); +---- + +Include the command in `git.c` in `commands[]` near the entry for `whatchanged`, +maintaining alphabetical ordering: + +---- +{ "walken", cmd_walken, RUN_SETUP }, +---- + +Add it to the `Makefile` near the line for `builtin/worktree.o`: + +---- +BUILTIN_OBJS += builtin/walken.o +---- + +Build and test out your command, without forgetting to ensure the `DEVELOPER` +flag is set, and with `GIT_TRACE` enabled so the debug output can be seen: + +---- +$ echo DEVELOPER=1 >>config.mak +$ make +$ GIT_TRACE=1 ./bin-wrappers/git walken +---- + +NOTE: For a more exhaustive overview of the new command process, take a look at +`Documentation/MyFirstContribution.txt`. + +NOTE: A reference implementation can be found at +https://github.com/nasamuffin/git/tree/revwalk. + +=== `struct rev_cmdline_info` + +The definition of `struct rev_cmdline_info` can be found in `revision.h`. + +This struct is contained within the `rev_info` struct and is used to reflect +parameters provided by the user over the CLI. + +`nr` represents the number of `rev_cmdline_entry` present in the array. + +`alloc` is used by the `ALLOC_GROW` macro. Check +`Documentation/technical/api-allocation-growing.txt` - this variable is used to +track the allocated size of the list. + +Per entry, we find: + +`item` is the object provided upon which to base the object walk. Items in Git +can be blobs, trees, commits, or tags. (See `Documentation/gittutorial-2.txt`.) + +`name` is the object ID (OID) of the object - a hex string you may be familiar +with from using Git to organize your source in the past. Check the tutorial +mentioned above towards the top for a discussion of where the OID can come +from. + +`whence` indicates some information about what to do with the parents of the +specified object. We'll explore this flag more later on; take a look at +`Documentation/revisions.txt` to get an idea of what could set the `whence` +value. + +`flags` are used to hint the beginning of the revision walk and are the first +block under the `#include`s in `revision.h`. The most likely ones to be set in +the `rev_cmdline_info` are `UNINTERESTING` and `BOTTOM`, but these same flags +can be used during the walk, as well. + +=== `struct rev_info` + +This one is quite a bit longer, and many fields are only used during the walk +by `revision.c` - not configuration options. Most of the configurable flags in +`struct rev_info` have a mirror in `Documentation/rev-list-options.txt`. It's a +good idea to take some time and read through that document. + +== Basic Commit Walk + +First, let's see if we can replicate the output of `git log --oneline`. We'll +refer back to the implementation frequently to discover norms when performing +an object walk of our own. + +To do so, we'll first find all the commits, in order, which preceded the current +commit. We'll extract the name and subject of the commit from each. + +Ideally, we will also be able to find out which ones are currently at the tip of +various branches. + +=== Setting Up + +Preparing for your object walk has some distinct stages. + +1. Perform default setup for this mode, and others which may be invoked. +2. Check configuration files for relevant settings. +3. Set up the `rev_info` struct. +4. Tweak the initialized `rev_info` to suit the current walk. +5. Prepare the `rev_info` for the walk. +6. Iterate over the objects, processing each one. + +==== Default Setups + +Before examining configuration files which may modify command behavior, set up +default state for switches or options your command may have. If your command +utilizes other Git components, ask them to set up their default states as well. +For instance, `git log` takes advantage of `grep` and `diff` functionality, so +its `init_log_defaults()` sets its own state (`decoration_style`) and asks +`grep` and `diff` to initialize themselves by calling each of their +initialization functions. + +For our first example within `git walken`, we don't intend to use any other +components within Git, and we don't have any configuration to do. However, we +may want to add some later, so for now, we can add an empty placeholder. Create +a new function in `builtin/walken.c`: + +---- +static void init_walken_defaults(void) +{ + /* + * We don't actually need the same components `git log` does; leave this + * empty for now. + */ +} +---- + +Make sure to add a line invoking it inside of `cmd_walken()`. + +---- +int cmd_walken(int argc, const char **argv, const char *prefix) +{ + init_walken_defaults(); +} +---- + +==== Configuring From `.gitconfig` + +Next, we should have a look at any relevant configuration settings (i.e., +settings readable and settable from `git config`). This is done by providing a +callback to `git_config()`; within that callback, you can also invoke methods +from other components you may need that need to intercept these options. Your +callback will be invoked once per each configuration value which Git knows about +(global, local, worktree, etc.). + +Similarly to the default values, we don't have anything to do here yet +ourselves; however, we should call `git_default_config()` if we aren't calling +any other existing config callbacks. + +Add a new function to `builtin/walken.c`: + +---- +static int git_walken_config(const char *var, const char *value, void *cb) +{ + /* + * For now, we don't have any custom configuration, so fall back to + * the default config. + */ + return git_default_config(var, value, cb); +} +---- + +Make sure to invoke `git_config()` with it in your `cmd_walken()`: + +---- +int cmd_walken(int argc, const char **argv, const char *prefix) +{ + ... + + git_config(git_walken_config, NULL); + + ... +} +---- + +==== Setting Up `rev_info` + +Now that we've gathered external configuration and options, it's time to +initialize the `rev_info` object which we will use to perform the walk. This is +typically done by calling `repo_init_revisions()` with the repository you intend +to target, as well as the `prefix` argument of `cmd_walken` and your `rev_info` +struct. + +Add the `struct rev_info` and the `repo_init_revisions()` call: +---- +int cmd_walken(int argc, const char **argv, const char *prefix) +{ + /* This can go wherever you like in your declarations.*/ + struct rev_info rev; + ... + + /* This should go after the git_config() call. */ + repo_init_revisions(the_repository, &rev, prefix); + + ... +} +---- + +==== Tweaking `rev_info` For the Walk + +We're getting close, but we're still not quite ready to go. Now that `rev` is +initialized, we can modify it to fit our needs. This is usually done within a +helper for clarity, so let's add one: + +---- +static void final_rev_info_setup(struct rev_info *rev) +{ + /* + * We want to mimic the appearance of `git log --oneline`, so let's + * force oneline format. + */ + get_commit_format("oneline", rev); + + /* Start our object walk at HEAD. */ + add_head_to_pending(rev); +} +---- + +[NOTE] +==== +Instead of using the shorthand `add_head_to_pending()`, you could do +something like this: +---- + struct setup_revision_opt opt; + + memset(&opt, 0, sizeof(opt)); + opt.def = "HEAD"; + opt.revarg_opt = REVARG_COMMITTISH; + setup_revisions(argc, argv, rev, &opt); +---- +Using a `setup_revision_opt` gives you finer control over your walk's starting +point. +==== + +Then let's invoke `final_rev_info_setup()` after the call to +`repo_init_revisions()`: + +---- +int cmd_walken(int argc, const char **argv, const char *prefix) +{ + ... + + final_rev_info_setup(&rev); + + ... +} +---- + +Later, we may wish to add more arguments to `final_rev_info_setup()`. But for +now, this is all we need. + +==== Preparing `rev_info` For the Walk + +Now that `rev` is all initialized and configured, we've got one more setup step +before we get rolling. We can do this in a helper, which will both prepare the +`rev_info` for the walk, and perform the walk itself. Let's start the helper +with the call to `prepare_revision_walk()`, which can return an error without +dying on its own: + +---- +static void walken_commit_walk(struct rev_info *rev) +{ + if (prepare_revision_walk(rev)) + die(_("revision walk setup failed")); +} +---- + +NOTE: `die()` prints to `stderr` and exits the program. Since it will print to +`stderr` it's likely to be seen by a human, so we will localize it. + +==== Performing the Walk! + +Finally! We are ready to begin the walk itself. Now we can see that `rev_info` +can also be used as an iterator; we move to the next item in the walk by using +`get_revision()` repeatedly. Add the listed variable declarations at the top and +the walk loop below the `prepare_revision_walk()` call within your +`walken_commit_walk()`: + +---- +static void walken_commit_walk(struct rev_info *rev) +{ + struct commit *commit; + struct strbuf prettybuf = STRBUF_INIT; + + ... + + while ((commit = get_revision(rev))) { + if (!commit) + continue; + + strbuf_reset(&prettybuf); + pp_commit_easy(CMIT_FMT_ONELINE, commit, &prettybuf); + puts(prettybuf.buf); + } + strbuf_release(&prettybuf); +} +---- + +NOTE: `puts()` prints a `char*` to `stdout`. Since this is the part of the +command we expect to be machine-parsed, we're sending it directly to stdout. + +Give it a shot. + +---- +$ make +$ ./bin-wrappers/git walken +---- + +You should see all of the subject lines of all the commits in +your tree's history, in order, ending with the initial commit, "Initial revision +of "git", the information manager from hell". Congratulations! You've written +your first revision walk. You can play with printing some additional fields +from each commit if you're curious; have a look at the functions available in +`commit.h`. + +=== Adding a Filter + +Next, let's try to filter the commits we see based on their author. This is +equivalent to running `git log --author=`. We can add a filter by +modifying `rev_info.grep_filter`, which is a `struct grep_opt`. + +First some setup. Add `init_grep_defaults()` to `init_walken_defaults()` and add +`grep_config()` to `git_walken_config()`: + +---- +static void init_walken_defaults(void) +{ + init_grep_defaults(the_repository); +} + +... + +static int git_walken_config(const char *var, const char *value, void *cb) +{ + grep_config(var, value, cb); + return git_default_config(var, value, cb); +} +---- + +Next, we can modify the `grep_filter`. This is done with convenience functions +found in `grep.h`. For fun, we're filtering to only commits from folks using a +`gmail.com` email address - a not-very-precise guess at who may be working on +Git as a hobby. Since we're checking the author, which is a specific line in the +header, we'll use the `append_header_grep_pattern()` helper. We can use +the `enum grep_header_field` to indicate which part of the commit header we want +to search. + +In `final_rev_info_setup()`, add your filter line: + +---- +static void final_rev_info_setup(int argc, const char **argv, + const char *prefix, struct rev_info *rev) +{ + ... + + append_header_grep_pattern(&rev->grep_filter, GREP_HEADER_AUTHOR, + "gmail"); + compile_grep_patterns(&rev->grep_filter); + + ... +} +---- + +`append_header_grep_pattern()` adds your new "gmail" pattern to `rev_info`, but +it won't work unless we compile it with `compile_grep_patterns()`. + +NOTE: If you are using `setup_revisions()` (for example, if you are passing a +`setup_revision_opt` instead of using `add_head_to_pending()`), you don't need +to call `compile_grep_patterns()` because `setup_revisions()` calls it for you. + +NOTE: We could add the same filter via the `append_grep_pattern()` helper if we +wanted to, but `append_header_grep_pattern()` adds the `enum grep_context` and +`enum grep_pat_token` for us. + +=== Changing the Order + +There are a few ways that we can change the order of the commits during a +revision walk. Firstly, we can use the `enum rev_sort_order` to choose from some +typical orderings. + +`topo_order` is the same as `git log --topo-order`: we avoid showing a parent +before all of its children have been shown, and we avoid mixing commits which +are in different lines of history. (`git help log`'s section on `--topo-order` +has a very nice diagram to illustrate this.) + +Let's see what happens when we run with `REV_SORT_BY_COMMIT_DATE` as opposed to +`REV_SORT_BY_AUTHOR_DATE`. Add the following: + +---- +static void final_rev_info_setup(int argc, const char **argv, + const char *prefix, struct rev_info *rev) +{ + ... + + rev->topo_order = 1; + rev->sort_order = REV_SORT_BY_COMMIT_DATE; + + ... +} +---- + +Let's output this into a file so we can easily diff it with the walk sorted by +author date. + +---- +$ make +$ ./bin-wrappers/git walken > commit-date.txt +---- + +Then, let's sort by author date and run it again. + +---- +static void final_rev_info_setup(int argc, const char **argv, + const char *prefix, struct rev_info *rev) +{ + ... + + rev->topo_order = 1; + rev->sort_order = REV_SORT_BY_AUTHOR_DATE; + + ... +} +---- + +---- +$ make +$ ./bin-wrappers/git walken > author-date.txt +---- + +Finally, compare the two. This is a little less helpful without object names or +dates, but hopefully we get the idea. + +---- +$ diff -u commit-date.txt author-date.txt +---- + +This display indicates that commits can be reordered after they're written, for +example with `git rebase`. + +Let's try one more reordering of commits. `rev_info` exposes a `reverse` flag. +Set that flag somewhere inside of `final_rev_info_setup()`: + +---- +static void final_rev_info_setup(int argc, const char **argv, const char *prefix, + struct rev_info *rev) +{ + ... + + rev->reverse = 1; + + ... +} +---- + +Run your walk again and note the difference in order. (If you remove the grep +pattern, you should see the last commit this call gives you as your current +HEAD.) + +== Basic Object Walk + +So far we've been walking only commits. But Git has more types of objects than +that! Let's see if we can walk _all_ objects, and find out some information +about each one. + +We can base our work on an example. `git pack-objects` prepares all kinds of +objects for packing into a bitmap or packfile. The work we are interested in +resides in `builtins/pack-objects.c:get_object_list()`; examination of that +function shows that the all-object walk is being performed by +`traverse_commit_list()` or `traverse_commit_list_filtered()`. Those two +functions reside in `list-objects.c`; examining the source shows that, despite +the name, these functions traverse all kinds of objects. Let's have a look at +the arguments to `traverse_commit_list_filtered()`, which are a superset of the +arguments to the unfiltered version. + +- `struct list_objects_filter_options *filter_options`: This is a struct which + stores a filter-spec as outlined in `Documentation/rev-list-options.txt`. +- `struct rev_info *revs`: This is the `rev_info` used for the walk. +- `show_commit_fn show_commit`: A callback which will be used to handle each + individual commit object. +- `show_object_fn show_object`: A callback which will be used to handle each + non-commit object (so each blob, tree, or tag). +- `void *show_data`: A context buffer which is passed in turn to `show_commit` + and `show_object`. +- `struct oidset *omitted`: A linked-list of object IDs which the provided + filter caused to be omitted. + +It looks like this `traverse_commit_list_filtered()` uses callbacks we provide +instead of needing us to call it repeatedly ourselves. Cool! Let's add the +callbacks first. + +For the sake of this tutorial, we'll simply keep track of how many of each kind +of object we find. At file scope in `builtin/walken.c` add the following +tracking variables: + +---- +static int commit_count; +static int tag_count; +static int blob_count; +static int tree_count; +---- + +Commits are handled by a different callback than other objects; let's do that +one first: + +---- +static void walken_show_commit(struct commit *cmt, void *buf) +{ + commit_count++; +} +---- + +The `cmt` argument is fairly self-explanatory. But it's worth mentioning that +the `buf` argument is actually the context buffer that we can provide to the +traversal calls - `show_data`, which we mentioned a moment ago. + +Since we have the `struct commit` object, we can look at all the same parts that +we looked at in our earlier commit-only walk. For the sake of this tutorial, +though, we'll just increment the commit counter and move on. + +The callback for non-commits is a little different, as we'll need to check +which kind of object we're dealing with: + +---- +static void walken_show_object(struct object *obj, const char *str, void *buf) +{ + switch (obj->type) { + case OBJ_TREE: + tree_count++; + break; + case OBJ_BLOB: + blob_count++; + break; + case OBJ_TAG: + tag_count++; + break; + case OBJ_COMMIT: + BUG("unexpected commit object in walken_show_object\n"); + default: + BUG("unexpected object type %s in walken_show_object\n", + type_name(obj->type)); + } +} +---- + +Again, `obj` is fairly self-explanatory, and we can guess that `buf` is the same +context pointer that `walken_show_commit()` receives: the `show_data` argument +to `traverse_commit_list()` and `traverse_commit_list_filtered()`. Finally, +`str` contains the name of the object, which ends up being something like +`foo.txt` (blob), `bar/baz` (tree), or `v1.2.3` (tag). + +To help assure us that we aren't double-counting commits, we'll include some +complaining if a commit object is routed through our non-commit callback; we'll +also complain if we see an invalid object type. Since those two cases should be +unreachable, and would only change in the event of a semantic change to the Git +codebase, we complain by using `BUG()` - which is a signal to a developer that +the change they made caused unintended consequences, and the rest of the +codebase needs to be updated to understand that change. `BUG()` is not intended +to be seen by the public, so it is not localized. + +Our main object walk implementation is substantially different from our commit +walk implementation, so let's make a new function to perform the object walk. We +can perform setup which is applicable to all objects here, too, to keep separate +from setup which is applicable to commit-only walks. + +We'll start by enabling all types of objects in the `struct rev_info`. We'll +also turn on `tree_blobs_in_commit_order`, which means that we will walk a +commit's tree and everything it points to immediately after we find each commit, +as opposed to waiting for the end and walking through all trees after the commit +history has been discovered. With the appropriate settings configured, we are +ready to call `prepare_revision_walk()`. + +---- +static void walken_object_walk(struct rev_info *rev) +{ + rev->tree_objects = 1; + rev->blob_objects = 1; + rev->tag_objects = 1; + rev->tree_blobs_in_commit_order = 1; + + if (prepare_revision_walk(rev)) + die(_("revision walk setup failed")); + + commit_count = 0; + tag_count = 0; + blob_count = 0; + tree_count = 0; +---- + +Let's start by calling just the unfiltered walk and reporting our counts. +Complete your implementation of `walken_object_walk()`: + +---- + traverse_commit_list(rev, walken_show_commit, walken_show_object, NULL); + + printf("commits %d\nblobs %d\ntags %d\ntrees %d\n", commit_count, + blob_count, tag_count, tree_count); +} +---- + +NOTE: This output is intended to be machine-parsed. Therefore, we are not +sending it to `trace_printf()`, and we are not localizing it - we need scripts +to be able to count on the formatting to be exactly the way it is shown here. +If we were intending this output to be read by humans, we would need to localize +it with `_()`. + +Finally, we'll ask `cmd_walken()` to use the object walk instead. Discussing +command line options is out of scope for this tutorial, so we'll just hardcode +a branch we can change at compile time. Where you call `final_rev_info_setup()` +and `walken_commit_walk()`, instead branch like so: + +---- + if (1) { + add_head_to_pending(&rev); + walken_object_walk(&rev); + } else { + final_rev_info_setup(argc, argv, prefix, &rev); + walken_commit_walk(&rev); + } +---- + +NOTE: For simplicity, we've avoided all the filters and sorts we applied in +`final_rev_info_setup()` and simply added `HEAD` to our pending queue. If you +want, you can certainly use the filters we added before by moving +`final_rev_info_setup()` out of the conditional and removing the call to +`add_head_to_pending()`. + +Now we can try to run our command! It should take noticeably longer than the +commit walk, but an examination of the output will give you an idea why. Your +output should look similar to this example, but with different counts: + +---- +Object walk completed. Found 55733 commits, 100274 blobs, 0 tags, and 104210 trees. +---- + +This makes sense. We have more trees than commits because the Git project has +lots of subdirectories which can change, plus at least one tree per commit. We +have no tags because we started on a commit (`HEAD`) and while tags can point to +commits, commits can't point to tags. + +NOTE: You will have different counts when you run this yourself! The number of +objects grows along with the Git project. + +=== Adding a Filter + +There are a handful of filters that we can apply to the object walk laid out in +`Documentation/rev-list-options.txt`. These filters are typically useful for +operations such as creating packfiles or performing a partial clone. They are +defined in `list-objects-filter-options.h`. For the purposes of this tutorial we +will use the "tree:1" filter, which causes the walk to omit all trees and blobs +which are not directly referenced by commits reachable from the commit in +`pending` when the walk begins. (`pending` is the list of objects which need to +be traversed during a walk; you can imagine a breadth-first tree traversal to +help understand. In our case, that means we omit trees and blobs not directly +referenced by `HEAD` or `HEAD`'s history, because we begin the walk with only +`HEAD` in the `pending` list.) + +First, we'll need to `#include "list-objects-filter-options.h`" and set up the +`struct list_objects_filter_options` at the top of the function. + +---- +static void walken_object_walk(struct rev_info *rev) +{ + struct list_objects_filter_options filter_options = {}; + + ... +---- + +For now, we are not going to track the omitted objects, so we'll replace those +parameters with `NULL`. For the sake of simplicity, we'll add a simple +build-time branch to use our filter or not. Replace the line calling +`traverse_commit_list()` with the following, which will remind us which kind of +walk we've just performed: + +---- + if (0) { + /* Unfiltered: */ + trace_printf(_("Unfiltered object walk.\n")); + traverse_commit_list(rev, walken_show_commit, + walken_show_object, NULL); + } else { + trace_printf( + _("Filtered object walk with filterspec 'tree:1'.\n")); + parse_list_objects_filter(&filter_options, "tree:1"); + + traverse_commit_list_filtered(&filter_options, rev, + walken_show_commit, walken_show_object, NULL, NULL); + } +---- + +`struct list_objects_filter_options` is usually built directly from a command +line argument, so the module provides an easy way to build one from a string. +Even though we aren't taking user input right now, we can still build one with +a hardcoded string using `parse_list_objects_filter()`. + +With the filter spec "tree:1", we are expecting to see _only_ the root tree for +each commit; therefore, the tree object count should be less than or equal to +the number of commits. (For an example of why that's true: `git commit --revert` +points to the same tree object as its grandparent.) + +=== Counting Omitted Objects + +We also have the capability to enumerate all objects which were omitted by a +filter, like with `git log --filter= --filter-print-omitted`. Asking +`traverse_commit_list_filtered()` to populate the `omitted` list means that our +object walk does not perform any better than an unfiltered object walk; all +reachable objects are walked in order to populate the list. + +First, add the `struct oidset` and related items we will use to iterate it: + +---- +static void walken_object_walk( + ... + + struct oidset omitted; + struct oidset_iter oit; + struct object_id *oid = NULL; + int omitted_count = 0; + oidset_init(&omitted, 0); + + ... +---- + +Modify the call to `traverse_commit_list_filtered()` to include your `omitted` +object: + +---- + ... + + traverse_commit_list_filtered(&filter_options, rev, + walken_show_commit, walken_show_object, NULL, &omitted); + + ... +---- + +Then, after your traversal, the `oidset` traversal is pretty straightforward. +Count all the objects within and modify the print statement: + +---- + /* Count the omitted objects. */ + oidset_iter_init(&omitted, &oit); + + while ((oid = oidset_iter_next(&oit))) + omitted_count++; + + printf("commits %d\nblobs %d\ntags %d\ntrees%d\nomitted %d\n", + commit_count, blob_count, tag_count, tree_count, omitted_count); +---- + +By running your walk with and without the filter, you should find that the total +object count in each case is identical. You can also time each invocation of +the `walken` subcommand, with and without `omitted` being passed in, to confirm +to yourself the runtime impact of tracking all omitted objects. + +=== Changing the Order + +Finally, let's demonstrate that you can also reorder walks of all objects, not +just walks of commits. First, we'll make our handlers chattier - modify +`walken_show_commit()` and `walken_show_object()` to print the object as they +go: + +---- +static void walken_show_commit(struct commit *cmt, void *buf) +{ + trace_printf("commit: %s\n", oid_to_hex(&cmt->object.oid)); + commit_count++; +} + +static void walken_show_object(struct object *obj, const char *str, void *buf) +{ + trace_printf("%s: %s\n", type_name(obj->type), oid_to_hex(&obj->oid)); + + ... +} +---- + +NOTE: Since we will be examining this output directly as humans, we'll use +`trace_printf()` here. Additionally, since this change introduces a significant +number of printed lines, using `trace_printf()` will allow us to easily silence +those lines without having to recompile. + +(Leave the counter increment logic in place.) + +With only that change, run again (but save yourself some scrollback): + +---- +$ GIT_TRACE=1 ./bin-wrappers/git walken | head -n 10 +---- + +Take a look at the top commit with `git show` and the object ID you printed; it +should be the same as the output of `git show HEAD`. + +Next, let's change a setting on our `struct rev_info` within +`walken_object_walk()`. Find where you're changing the other settings on `rev`, +such as `rev->tree_objects` and `rev->tree_blobs_in_commit_order`, and add the +`reverse` setting at the bottom: + +---- + ... + + rev->tree_objects = 1; + rev->blob_objects = 1; + rev->tag_objects = 1; + rev->tree_blobs_in_commit_order = 1; + rev->reverse = 1; + + ... +---- + +Now, run again, but this time, let's grab the last handful of objects instead +of the first handful: + +---- +$ make +$ GIT_TRACE=1 ./bin-wrappers git walken | tail -n 10 +---- + +The last commit object given should have the same OID as the one we saw at the +top before, and running `git show ` with that OID should give you again +the same results as `git show HEAD`. Furthermore, if you run and examine the +first ten lines again (with `head` instead of `tail` like we did before applying +the `reverse` setting), you should see that now the first commit printed is the +initial commit, `e83c5163`. + +== Wrapping Up + +Let's review. In this tutorial, we: + +- Built a commit walk from the ground up +- Enabled a grep filter for that commit walk +- Changed the sort order of that filtered commit walk +- Built an object walk (tags, commits, trees, and blobs) from the ground up +- Learned how to add a filter-spec to an object walk +- Changed the display order of the filtered object walk From 46273df7bfdd43e5f8a190d0a80a078ca55ce5ff Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Tue, 15 Oct 2019 02:06:35 -0700 Subject: [PATCH 004/953] format-patch: replace erroneous and condition Commit 30984ed2e9 (format-patch: support deep threading, 2009-02-19), introduced the following lines: #define THREAD_SHALLOW 1 [...] thread = git_config_bool(var, value) && THREAD_SHALLOW; Since git_config_bool() returns a bool, the trailing `&& THREAD_SHALLOW` is a no-op. Replace this errorneous and condition with a ternary statement so that it is clear what the configured value is when a boolean is given. Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano --- builtin/log.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/log.c b/builtin/log.c index 44b10b3415414c..351f4ffcfd96de 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -835,7 +835,7 @@ static int git_format_config(const char *var, const char *value, void *cb) thread = THREAD_SHALLOW; return 0; } - thread = git_config_bool(var, value) && THREAD_SHALLOW; + thread = git_config_bool(var, value) ? THREAD_SHALLOW : THREAD_UNSET; return 0; } if (!strcmp(var, "format.signoff")) { From a92331df18112199d6aa7bee132ecf928509621c Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Tue, 15 Oct 2019 02:06:37 -0700 Subject: [PATCH 005/953] format-patch: use enum variables Before, `thread` and `config_cover_letter` were defined as ints even though they behaved as enums. Define actual enums and change these variables to use these new definitions. Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano --- builtin/log.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/builtin/log.c b/builtin/log.c index 351f4ffcfd96de..d212a8305d32c8 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -764,24 +764,28 @@ static void add_header(const char *value) item->string[len] = '\0'; } -#define THREAD_SHALLOW 1 -#define THREAD_DEEP 2 -static int thread; +enum cover_setting { + COVER_UNSET, + COVER_OFF, + COVER_ON, + COVER_AUTO +}; + +enum thread_level { + THREAD_UNSET, + THREAD_SHALLOW, + THREAD_DEEP +}; + +static enum thread_level thread; static int do_signoff; static int base_auto; static char *from; static const char *signature = git_version_string; static const char *signature_file; -static int config_cover_letter; +static enum cover_setting config_cover_letter; static const char *config_output_directory; -enum { - COVER_UNSET, - COVER_OFF, - COVER_ON, - COVER_AUTO -}; - static int git_format_config(const char *var, const char *value, void *cb) { struct rev_info *rev = cb; @@ -1248,9 +1252,9 @@ static int output_directory_callback(const struct option *opt, const char *arg, static int thread_callback(const struct option *opt, const char *arg, int unset) { - int *thread = (int *)opt->value; + enum thread_level *thread = (enum thread_level *)opt->value; if (unset) - *thread = 0; + *thread = THREAD_UNSET; else if (!arg || !strcmp(arg, "shallow")) *thread = THREAD_SHALLOW; else if (!strcmp(arg, "deep")) From bf8e65b30b77308710f14d523782f99a4a23eb55 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Tue, 15 Oct 2019 02:06:40 -0700 Subject: [PATCH 006/953] format-patch: teach --cover-from-description option Before, when format-patch generated a cover letter, only the body would be populated with a branch's description while the subject would be populated with placeholder text. However, users may want to have the subject of their cover letter automatically populated in the same way. Teach format-patch to accept the `--cover-from-description` option and corresponding `format.coverFromDescription` config, allowing users to populate different parts of the cover letter (including the subject now). Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano --- Documentation/config/format.txt | 6 + Documentation/git-format-patch.txt | 22 ++++ builtin/log.c | 95 ++++++++++++---- t/t4014-format-patch.sh | 172 +++++++++++++++++++++++++++++ t/t9902-completion.sh | 5 +- 5 files changed, 279 insertions(+), 21 deletions(-) diff --git a/Documentation/config/format.txt b/Documentation/config/format.txt index cb629fa769b7ff..735dfcf8275c1b 100644 --- a/Documentation/config/format.txt +++ b/Documentation/config/format.txt @@ -36,6 +36,12 @@ format.subjectPrefix:: The default for format-patch is to output files with the '[PATCH]' subject prefix. Use this variable to change that prefix. +format.coverFromDescription:: + The default mode for format-patch to determine which parts of + the cover letter will be populated using the branch's + description. See the `--cover-from-description` option in + linkgit:git-format-patch[1]. + format.signature:: The default for format-patch is to output a signature containing the Git version number. Use this variable to change that default. diff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt index 0ac56f4b7080bc..6800e1ab9a3b34 100644 --- a/Documentation/git-format-patch.txt +++ b/Documentation/git-format-patch.txt @@ -19,6 +19,7 @@ SYNOPSIS [--start-number ] [--numbered-files] [--in-reply-to=] [--suffix=.] [--ignore-if-in-upstream] + [--cover-from-description=] [--rfc] [--subject-prefix=] [(--reroll-count|-v) ] [--to=] [--cc=] @@ -171,6 +172,26 @@ will want to ensure that threading is disabled for `git send-email`. patches being generated, and any patch that matches is ignored. +--cover-from-description=:: + Controls which parts of the cover letter will be automatically + populated using the branch's description. ++ +If `` is `message` or `default`, the cover letter subject will be +populated with placeholder text. The body of the cover letter will be +populated with the branch's description. This is the default mode when +no configuration nor command line option is specified. ++ +If `` is `subject`, the first paragraph of the branch description will +populate the cover letter subject. The remainder of the description will +populate the body of the cover letter. ++ +If `` is `auto`, if the first paragraph of the branch description +is greater than 100 bytes, then the mode will be `message`, otherwise +`subject` will be used. ++ +If `` is `none`, both the cover letter subject and body will be +populated with placeholder text. + --subject-prefix=:: Instead of the standard '[PATCH]' prefix in the subject line, instead use '[]'. This @@ -347,6 +368,7 @@ with configuration variables. signOff = true outputDirectory = coverLetter = auto + coverFromDescription = auto ------------ diff --git a/builtin/log.c b/builtin/log.c index d212a8305d32c8..04be559bd23f57 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -37,6 +37,7 @@ #include "range-diff.h" #define MAIL_DEFAULT_WRAP 72 +#define COVER_FROM_AUTO_MAX_SUBJECT_LEN 100 /* Set a default date-time format for git log ("log.date" config variable) */ static const char *default_date_mode = NULL; @@ -777,6 +778,13 @@ enum thread_level { THREAD_DEEP }; +enum cover_from_description { + COVER_FROM_NONE, + COVER_FROM_MESSAGE, + COVER_FROM_SUBJECT, + COVER_FROM_AUTO +}; + static enum thread_level thread; static int do_signoff; static int base_auto; @@ -785,6 +793,23 @@ static const char *signature = git_version_string; static const char *signature_file; static enum cover_setting config_cover_letter; static const char *config_output_directory; +static enum cover_from_description cover_from_description_mode = COVER_FROM_MESSAGE; + +static enum cover_from_description parse_cover_from_description(const char *arg) +{ + if (!arg || !strcmp(arg, "default")) + return COVER_FROM_MESSAGE; + else if (!strcmp(arg, "none")) + return COVER_FROM_NONE; + else if (!strcmp(arg, "message")) + return COVER_FROM_MESSAGE; + else if (!strcmp(arg, "subject")) + return COVER_FROM_SUBJECT; + else if (!strcmp(arg, "auto")) + return COVER_FROM_AUTO; + else + die(_("%s: invalid cover from description mode"), arg); +} static int git_format_config(const char *var, const char *value, void *cb) { @@ -891,6 +916,10 @@ static int git_format_config(const char *var, const char *value, void *cb) } return 0; } + if (!strcmp(var, "format.coverfromdescription")) { + cover_from_description_mode = parse_cover_from_description(value); + return 0; + } return git_log_config(var, value, cb); } @@ -997,20 +1026,6 @@ static void print_signature(FILE *file) putc('\n', file); } -static void add_branch_description(struct strbuf *buf, const char *branch_name) -{ - struct strbuf desc = STRBUF_INIT; - if (!branch_name || !*branch_name) - return; - read_branch_desc(&desc, branch_name); - if (desc.len) { - strbuf_addch(buf, '\n'); - strbuf_addbuf(buf, &desc); - strbuf_addch(buf, '\n'); - } - strbuf_release(&desc); -} - static char *find_branch_name(struct rev_info *rev) { int i, positive = -1; @@ -1057,6 +1072,44 @@ static void show_diffstat(struct rev_info *rev, fprintf(rev->diffopt.file, "\n"); } +static void prepare_cover_text(struct pretty_print_context *pp, + const char *branch_name, + struct strbuf *sb, + const char *encoding, + int need_8bit_cte) +{ + const char *subject = "*** SUBJECT HERE ***"; + const char *body = "*** BLURB HERE ***"; + struct strbuf description_sb = STRBUF_INIT; + struct strbuf subject_sb = STRBUF_INIT; + + if (cover_from_description_mode == COVER_FROM_NONE) + goto do_pp; + + if (branch_name && *branch_name) + read_branch_desc(&description_sb, branch_name); + if (!description_sb.len) + goto do_pp; + + if (cover_from_description_mode == COVER_FROM_SUBJECT || + cover_from_description_mode == COVER_FROM_AUTO) + body = format_subject(&subject_sb, description_sb.buf, " "); + + if (cover_from_description_mode == COVER_FROM_MESSAGE || + (cover_from_description_mode == COVER_FROM_AUTO && + subject_sb.len > COVER_FROM_AUTO_MAX_SUBJECT_LEN)) + body = description_sb.buf; + else + subject = subject_sb.buf; + +do_pp: + pp_title_line(pp, &subject, sb, encoding, need_8bit_cte); + pp_remainder(pp, &body, sb, 0); + + strbuf_release(&description_sb); + strbuf_release(&subject_sb); +} + static void make_cover_letter(struct rev_info *rev, int use_stdout, struct commit *origin, int nr, struct commit **list, @@ -1064,8 +1117,6 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout, int quiet) { const char *committer; - const char *body = "*** SUBJECT HERE ***\n\n*** BLURB HERE ***\n"; - const char *msg; struct shortlog log; struct strbuf sb = STRBUF_INIT; int i; @@ -1095,15 +1146,12 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout, if (!branch_name) branch_name = find_branch_name(rev); - msg = body; pp.fmt = CMIT_FMT_EMAIL; pp.date_mode.type = DATE_RFC2822; pp.rev = rev; pp.print_email_subject = 1; pp_user_info(&pp, NULL, &sb, committer, encoding); - pp_title_line(&pp, &msg, &sb, encoding, need_8bit_cte); - pp_remainder(&pp, &msg, &sb, 0); - add_branch_description(&sb, branch_name); + prepare_cover_text(&pp, branch_name, &sb, encoding, need_8bit_cte); fprintf(rev->diffopt.file, "%s\n", sb.buf); strbuf_release(&sb); @@ -1545,6 +1593,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) int use_patch_format = 0; int quiet = 0; int reroll_count = -1; + char *cover_from_description_arg = NULL; char *branch_name = NULL; char *base_commit = NULL; struct base_tree_info bases; @@ -1581,6 +1630,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) { OPTION_CALLBACK, 0, "rfc", &rev, NULL, N_("Use [RFC PATCH] instead of [PATCH]"), PARSE_OPT_NOARG | PARSE_OPT_NONEG, rfc_callback }, + OPT_STRING(0, "cover-from-description", &cover_from_description_arg, + N_("cover-from-description-mode"), + N_("generate parts of a cover letter based on a branch's description")), { OPTION_CALLBACK, 0, "subject-prefix", &rev, N_("prefix"), N_("Use [] instead of [PATCH]"), PARSE_OPT_NONEG, subject_prefix_callback }, @@ -1672,6 +1724,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN | PARSE_OPT_KEEP_DASHDASH); + if (cover_from_description_arg) + cover_from_description_mode = parse_cover_from_description(cover_from_description_arg); + if (0 < reroll_count) { struct strbuf sprefix = STRBUF_INIT; strbuf_addf(&sprefix, "%s v%d", diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index 72b09896cf51a8..88db01308a3f09 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -1517,6 +1517,178 @@ test_expect_success 'format patch ignores color.ui' ' test_cmp expect actual ' +test_expect_success 'cover letter with invalid --cover-from-description and config' ' + test_config branch.rebuild-1.description "config subject + +body" && + test_must_fail git format-patch --cover-letter --cover-from-description garbage master && + test_config format.coverFromDescription garbage && + test_must_fail git format-patch --cover-letter master +' + +test_expect_success 'cover letter with format.coverFromDescription = default' ' + test_config branch.rebuild-1.description "config subject + +body" && + test_config format.coverFromDescription default && + git checkout rebuild-1 && + git format-patch --stdout --cover-letter master >actual && + grep "^Subject: \[PATCH 0/2\] \*\*\* SUBJECT HERE \*\*\*$" actual && + ! grep "^\*\*\* BLURB HERE \*\*\*$" actual && + grep "^config subject$" actual && + grep "^body$" actual +' + +test_expect_success 'cover letter with --cover-from-description default' ' + test_config branch.rebuild-1.description "config subject + +body" && + git checkout rebuild-1 && + git format-patch --stdout --cover-letter --cover-from-description default master >actual && + grep "^Subject: \[PATCH 0/2\] \*\*\* SUBJECT HERE \*\*\*$" actual && + ! grep "^\*\*\* BLURB HERE \*\*\*$" actual && + grep "^config subject$" actual && + grep "^body$" actual +' + +test_expect_success 'cover letter with format.coverFromDescription = none' ' + test_config branch.rebuild-1.description "config subject + +body" && + test_config format.coverFromDescription none && + git checkout rebuild-1 && + git format-patch --stdout --cover-letter master >actual && + grep "^Subject: \[PATCH 0/2\] \*\*\* SUBJECT HERE \*\*\*$" actual && + grep "^\*\*\* BLURB HERE \*\*\*$" actual && + ! grep "^config subject$" actual && + ! grep "^body$" actual +' + +test_expect_success 'cover letter with --cover-from-description none' ' + test_config branch.rebuild-1.description "config subject + +body" && + git checkout rebuild-1 && + git format-patch --stdout --cover-letter --cover-from-description none master >actual && + grep "^Subject: \[PATCH 0/2\] \*\*\* SUBJECT HERE \*\*\*$" actual && + grep "^\*\*\* BLURB HERE \*\*\*$" actual && + ! grep "^config subject$" actual && + ! grep "^body$" actual +' + +test_expect_success 'cover letter with format.coverFromDescription = message' ' + test_config branch.rebuild-1.description "config subject + +body" && + test_config format.coverFromDescription message && + git checkout rebuild-1 && + git format-patch --stdout --cover-letter master >actual && + grep "^Subject: \[PATCH 0/2\] \*\*\* SUBJECT HERE \*\*\*$" actual && + ! grep "^\*\*\* BLURB HERE \*\*\*$" actual && + grep "^config subject$" actual && + grep "^body$" actual +' + +test_expect_success 'cover letter with --cover-from-description message' ' + test_config branch.rebuild-1.description "config subject + +body" && + git checkout rebuild-1 && + git format-patch --stdout --cover-letter --cover-from-description message master >actual && + grep "^Subject: \[PATCH 0/2\] \*\*\* SUBJECT HERE \*\*\*$" actual && + ! grep "^\*\*\* BLURB HERE \*\*\*$" actual && + grep "^config subject$" actual && + grep "^body$" actual +' + +test_expect_success 'cover letter with format.coverFromDescription = subject' ' + test_config branch.rebuild-1.description "config subject + +body" && + test_config format.coverFromDescription subject && + git checkout rebuild-1 && + git format-patch --stdout --cover-letter master >actual && + grep "^Subject: \[PATCH 0/2\] config subject$" actual && + ! grep "^\*\*\* BLURB HERE \*\*\*$" actual && + ! grep "^config subject$" actual && + grep "^body$" actual +' + +test_expect_success 'cover letter with --cover-from-description subject' ' + test_config branch.rebuild-1.description "config subject + +body" && + git checkout rebuild-1 && + git format-patch --stdout --cover-letter --cover-from-description subject master >actual && + grep "^Subject: \[PATCH 0/2\] config subject$" actual && + ! grep "^\*\*\* BLURB HERE \*\*\*$" actual && + ! grep "^config subject$" actual && + grep "^body$" actual +' + +test_expect_success 'cover letter with format.coverFromDescription = auto (short subject line)' ' + test_config branch.rebuild-1.description "config subject + +body" && + test_config format.coverFromDescription auto && + git checkout rebuild-1 && + git format-patch --stdout --cover-letter master >actual && + grep "^Subject: \[PATCH 0/2\] config subject$" actual && + ! grep "^\*\*\* BLURB HERE \*\*\*$" actual && + ! grep "^config subject$" actual && + grep "^body$" actual +' + +test_expect_success 'cover letter with --cover-from-description auto (short subject line)' ' + test_config branch.rebuild-1.description "config subject + +body" && + git checkout rebuild-1 && + git format-patch --stdout --cover-letter --cover-from-description auto master >actual && + grep "^Subject: \[PATCH 0/2\] config subject$" actual && + ! grep "^\*\*\* BLURB HERE \*\*\*$" actual && + ! grep "^config subject$" actual && + grep "^body$" actual +' + +test_expect_success 'cover letter with format.coverFromDescription = auto (long subject line)' ' + test_config branch.rebuild-1.description "this is a really long first line and it is over 100 characters long which is the threshold for long subjects + +body" && + test_config format.coverFromDescription auto && + git checkout rebuild-1 && + git format-patch --stdout --cover-letter master >actual && + grep "^Subject: \[PATCH 0/2\] \*\*\* SUBJECT HERE \*\*\*$" actual && + ! grep "^\*\*\* BLURB HERE \*\*\*$" actual && + grep "^this is a really long first line and it is over 100 characters long which is the threshold for long subjects$" actual && + grep "^body$" actual +' + +test_expect_success 'cover letter with --cover-from-description auto (long subject line)' ' + test_config branch.rebuild-1.description "this is a really long first line and it is over 100 characters long which is the threshold for long subjects + +body" && + git checkout rebuild-1 && + git format-patch --stdout --cover-letter --cover-from-description auto master >actual && + grep "^Subject: \[PATCH 0/2\] \*\*\* SUBJECT HERE \*\*\*$" actual && + ! grep "^\*\*\* BLURB HERE \*\*\*$" actual && + grep "^this is a really long first line and it is over 100 characters long which is the threshold for long subjects$" actual && + grep "^body$" actual +' + +test_expect_success 'cover letter with command-line --cover-from-description overrides config' ' + test_config branch.rebuild-1.description "config subject + +body" && + test_config format.coverFromDescription none && + git checkout rebuild-1 && + git format-patch --stdout --cover-letter --cover-from-description subject master >actual && + grep "^Subject: \[PATCH 0/2\] config subject$" actual && + ! grep "^\*\*\* BLURB HERE \*\*\*$" actual && + ! grep "^config subject$" actual && + grep "^body$" actual +' + test_expect_success 'cover letter using branch description (1)' ' git checkout rebuild-1 && test_config branch.rebuild-1.description hello && diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 75512c340366f3..5187e2ede581f1 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -1548,7 +1548,10 @@ test_expect_success 'complete tree filename with metacharacters' ' ' test_expect_success PERL 'send-email' ' - test_completion "git send-email --cov" "--cover-letter " && + test_completion "git send-email --cov" <<-\EOF && + --cover-from-description=Z + --cover-letter Z + EOF test_completion "git send-email ma" "master " ' From 88a92b6c7372756c862e409a74a22e1ec660b76a Mon Sep 17 00:00:00 2001 From: Phillip Wood Date: Tue, 15 Oct 2019 10:25:27 +0000 Subject: [PATCH 007/953] t3404: remove unnecessary subshell Neither of the commands executed in the subshell change any shell variables or the current directory so there is no need for them to be executed in a subshell. Signed-off-by: Phillip Wood Signed-off-by: Junio C Hamano --- t/t3404-rebase-interactive.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index d2f1d5bd235fd5..c26b3362ef5e9d 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -945,10 +945,8 @@ test_expect_success C_LOCALE_OUTPUT 'rebase -ix with --autosquash' ' git add bis.txt && git commit -m "fixup! two_exec" && set_fake_editor && - ( - git checkout -b autosquash_actual && - git rebase -i --exec "git show HEAD" --autosquash HEAD~4 >actual - ) && + git checkout -b autosquash_actual && + git rebase -i --exec "git show HEAD" --autosquash HEAD~4 >actual && git checkout autosquash && ( git checkout -b autosquash_expected && From b2dbacbddfc40e9715d928dafe3256bb56d91dde Mon Sep 17 00:00:00 2001 From: Phillip Wood Date: Tue, 15 Oct 2019 10:25:28 +0000 Subject: [PATCH 008/953] t3404: set $EDITOR in subshell As $EDITOR is exported setting it in one test affects all subsequent tests. Avoid this by always setting it in a subshell. This commit leaves 20 calls to set_fake_editor that are not in subshells as they can safely be removed in the next commit once all the other editor setting is done inside subshells. I have moved the call to set_fake_editor in some tests so it comes immediately before the call to 'git rebase' to avoid moving unrelated commands into the subshell. In one case ('rebase -ix with --autosquash') the call to set_fake_editor is moved past an invocation of 'git rebase'. This is safe as that invocation of 'git rebase' requires EDITOR=: or EDITOR=fake-editor.sh without FAKE_LINES being set which will be the case as the preceding tests either set their editor in a subshell or call set_fake_editor without setting FAKE_LINES. In a one test ('auto-amend only edited commits after "edit"') a call to test_tick are now in a subshell. I think this is OK as it is there to set the date for the next commit which is executed in the same subshell rather than updating GIT_COMMITTER_DATE for later tests (the next test calls test_tick before doing anything else). Signed-off-by: Phillip Wood Signed-off-by: Junio C Hamano --- t/t3404-rebase-interactive.sh | 546 +++++++++++++++++++++------------- 1 file changed, 342 insertions(+), 204 deletions(-) diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index c26b3362ef5e9d..cb9b210000a6bd 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -79,8 +79,11 @@ test_expect_success 'rebase -i with empty HEAD' ' cat >expect <<-\EOF && error: nothing to do EOF - set_fake_editor && - test_must_fail env FAKE_LINES="1 exec_true" git rebase -i HEAD^ >actual 2>&1 && + ( + set_fake_editor && + test_must_fail env FAKE_LINES="1 exec_true" \ + git rebase -i HEAD^ >actual 2>&1 + ) && test_i18ncmp expect actual ' @@ -139,8 +142,11 @@ test_expect_success 'rebase -i sets work tree properly' ' test_expect_success 'rebase -i with the exec command checks tree cleanness' ' git checkout master && - set_fake_editor && - test_must_fail env FAKE_LINES="exec_echo_foo_>file1 1" git rebase -i HEAD^ && + ( + set_fake_editor && + test_must_fail env FAKE_LINES="exec_echo_foo_>file1 1" \ + git rebase -i HEAD^ + ) && test_cmp_rev master^ HEAD && git reset --hard && git rebase --continue @@ -168,9 +174,11 @@ test_expect_success 'rebase -x with newline in command fails' ' test_expect_success 'rebase -i with exec of inexistent command' ' git checkout master && test_when_finished "git rebase --abort" && - set_fake_editor && - test_must_fail env FAKE_LINES="exec_this-command-does-not-exist 1" \ - git rebase -i HEAD^ >actual 2>&1 && + ( + set_fake_editor && + test_must_fail env FAKE_LINES="exec_this-command-does-not-exist 1" \ + git rebase -i HEAD^ >actual 2>&1 + ) && ! grep "Maybe git-rebase is broken" actual ' @@ -230,8 +238,10 @@ test_expect_success 'reflog for the branch shows correct finish message' ' ' test_expect_success 'exchange two commits' ' - set_fake_editor && - FAKE_LINES="2 1" git rebase -i HEAD~2 && + ( + set_fake_editor && + FAKE_LINES="2 1" git rebase -i HEAD~2 + ) && test H = $(git cat-file commit HEAD^ | sed -ne \$p) && test G = $(git cat-file commit HEAD | sed -ne \$p) ' @@ -332,9 +342,11 @@ test_expect_success 'squash' ' test_tick && GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 && echo "******************************" && - set_fake_editor && - FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=2 \ - git rebase -i --onto master HEAD~2 && + ( + set_fake_editor && + FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=2 \ + git rebase -i --onto master HEAD~2 + ) && test B = $(cat file7) && test $(git rev-parse HEAD^) = $(git rev-parse master) ' @@ -355,8 +367,10 @@ test_expect_success REBASE_P '-p handles "no changes" gracefully' ' test_expect_failure REBASE_P 'exchange two commits with -p' ' git checkout H && - set_fake_editor && - FAKE_LINES="2 1" git rebase -i -p HEAD~2 && + ( + set_fake_editor && + FAKE_LINES="2 1" git rebase -i -p HEAD~2 + ) && test H = $(git cat-file commit HEAD^ | sed -ne \$p) && test G = $(git cat-file commit HEAD | sed -ne \$p) ' @@ -405,8 +419,10 @@ test_expect_success REBASE_P 'preserve merges with -p' ' ' test_expect_success REBASE_P 'edit ancestor with -p' ' - set_fake_editor && - FAKE_LINES="1 2 edit 3 4" git rebase -i -p HEAD~3 && + ( + set_fake_editor && + FAKE_LINES="1 2 edit 3 4" git rebase -i -p HEAD~3 + ) && echo 2 > unrelated-file && test_tick && git commit -m L2-modified --amend unrelated-file && @@ -420,11 +436,13 @@ test_expect_success REBASE_P 'edit ancestor with -p' ' test_expect_success '--continue tries to commit' ' git reset --hard D && test_tick && - set_fake_editor && - test_must_fail git rebase -i --onto new-branch1 HEAD^ && - echo resolved > file1 && - git add file1 && - FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue && + ( + set_fake_editor && + test_must_fail git rebase -i --onto new-branch1 HEAD^ && + echo resolved > file1 && + git add file1 && + FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue + ) && test $(git rev-parse HEAD^) = $(git rev-parse new-branch1) && git show HEAD | grep chouette ' @@ -442,10 +460,13 @@ test_expect_success 'verbose flag is heeded, even after --continue' ' test_expect_success C_LOCALE_OUTPUT 'multi-squash only fires up editor once' ' base=$(git rev-parse HEAD~4) && - set_fake_editor && - FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 squash 2 squash 3 squash 4" \ - EXPECT_HEADER_COUNT=4 \ - git rebase -i $base && + ( + set_fake_editor && + FAKE_COMMIT_AMEND="ONCE" \ + FAKE_LINES="1 squash 2 squash 3 squash 4" \ + EXPECT_HEADER_COUNT=4 \ + git rebase -i $base + ) && test $base = $(git rev-parse HEAD^) && test 1 = $(git show | grep ONCE | wc -l) ' @@ -453,9 +474,12 @@ test_expect_success C_LOCALE_OUTPUT 'multi-squash only fires up editor once' ' test_expect_success C_LOCALE_OUTPUT 'multi-fixup does not fire up editor' ' git checkout -b multi-fixup E && base=$(git rev-parse HEAD~4) && - set_fake_editor && - FAKE_COMMIT_AMEND="NEVER" FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \ - git rebase -i $base && + ( + set_fake_editor && + FAKE_COMMIT_AMEND="NEVER" \ + FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \ + git rebase -i $base + ) && test $base = $(git rev-parse HEAD^) && test 0 = $(git show | grep NEVER | wc -l) && git checkout @{-1} && @@ -465,12 +489,15 @@ test_expect_success C_LOCALE_OUTPUT 'multi-fixup does not fire up editor' ' test_expect_success 'commit message used after conflict' ' git checkout -b conflict-fixup conflict-branch && base=$(git rev-parse HEAD~4) && - set_fake_editor && - test_must_fail env FAKE_LINES="1 fixup 3 fixup 4" git rebase -i $base && - echo three > conflict && - git add conflict && - FAKE_COMMIT_AMEND="ONCE" EXPECT_HEADER_COUNT=2 \ - git rebase --continue && + ( + set_fake_editor && + test_must_fail env FAKE_LINES="1 fixup 3 fixup 4" \ + git rebase -i $base && + echo three > conflict && + git add conflict && + FAKE_COMMIT_AMEND="ONCE" EXPECT_HEADER_COUNT=2 \ + git rebase --continue + ) && test $base = $(git rev-parse HEAD^) && test 1 = $(git show | grep ONCE | wc -l) && git checkout @{-1} && @@ -480,12 +507,15 @@ test_expect_success 'commit message used after conflict' ' test_expect_success 'commit message retained after conflict' ' git checkout -b conflict-squash conflict-branch && base=$(git rev-parse HEAD~4) && - set_fake_editor && - test_must_fail env FAKE_LINES="1 fixup 3 squash 4" git rebase -i $base && - echo three > conflict && - git add conflict && - FAKE_COMMIT_AMEND="TWICE" EXPECT_HEADER_COUNT=2 \ - git rebase --continue && + ( + set_fake_editor && + test_must_fail env FAKE_LINES="1 fixup 3 squash 4" \ + git rebase -i $base && + echo three > conflict && + git add conflict && + FAKE_COMMIT_AMEND="TWICE" EXPECT_HEADER_COUNT=2 \ + git rebase --continue + ) && test $base = $(git rev-parse HEAD^) && test 2 = $(git show | grep TWICE | wc -l) && git checkout @{-1} && @@ -502,10 +532,13 @@ test_expect_success C_LOCALE_OUTPUT 'squash and fixup generate correct log messa EOF git checkout -b squash-fixup E && base=$(git rev-parse HEAD~4) && - set_fake_editor && - FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 fixup 2 squash 3 fixup 4" \ - EXPECT_HEADER_COUNT=4 \ - git rebase -i $base && + ( + set_fake_editor && + FAKE_COMMIT_AMEND="ONCE" \ + FAKE_LINES="1 fixup 2 squash 3 fixup 4" \ + EXPECT_HEADER_COUNT=4 \ + git rebase -i $base + ) && git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup && test_cmp expect-squash-fixup actual-squash-fixup && git cat-file commit HEAD@{2} | @@ -519,10 +552,13 @@ test_expect_success C_LOCALE_OUTPUT 'squash and fixup generate correct log messa test_expect_success C_LOCALE_OUTPUT 'squash ignores comments' ' git checkout -b skip-comments E && base=$(git rev-parse HEAD~4) && - set_fake_editor && - FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \ - EXPECT_HEADER_COUNT=4 \ - git rebase -i $base && + ( + set_fake_editor && + FAKE_COMMIT_AMEND="ONCE" \ + FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \ + EXPECT_HEADER_COUNT=4 \ + git rebase -i $base + ) && test $base = $(git rev-parse HEAD^) && test 1 = $(git show | grep ONCE | wc -l) && git checkout @{-1} && @@ -532,10 +568,13 @@ test_expect_success C_LOCALE_OUTPUT 'squash ignores comments' ' test_expect_success C_LOCALE_OUTPUT 'squash ignores blank lines' ' git checkout -b skip-blank-lines E && base=$(git rev-parse HEAD~4) && - set_fake_editor && - FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \ - EXPECT_HEADER_COUNT=4 \ - git rebase -i $base && + ( + set_fake_editor && + FAKE_COMMIT_AMEND="ONCE" \ + FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \ + EXPECT_HEADER_COUNT=4 \ + git rebase -i $base + ) && test $base = $(git rev-parse HEAD^) && test 1 = $(git show | grep ONCE | wc -l) && git checkout @{-1} && @@ -545,17 +584,21 @@ test_expect_success C_LOCALE_OUTPUT 'squash ignores blank lines' ' test_expect_success 'squash works as expected' ' git checkout -b squash-works no-conflict-branch && one=$(git rev-parse HEAD~3) && - set_fake_editor && - FAKE_LINES="1 s 3 2" EXPECT_HEADER_COUNT=2 \ - git rebase -i HEAD~3 && + ( + set_fake_editor && + FAKE_LINES="1 s 3 2" EXPECT_HEADER_COUNT=2 git rebase -i HEAD~3 + ) && test $one = $(git rev-parse HEAD~2) ' test_expect_success 'interrupted squash works as expected' ' git checkout -b interrupted-squash conflict-branch && one=$(git rev-parse HEAD~3) && - set_fake_editor && - test_must_fail env FAKE_LINES="1 squash 3 2" git rebase -i HEAD~3 && + ( + set_fake_editor && + test_must_fail env FAKE_LINES="1 squash 3 2" \ + git rebase -i HEAD~3 + ) && test_write_lines one two four > conflict && git add conflict && test_must_fail git rebase --continue && @@ -568,8 +611,11 @@ test_expect_success 'interrupted squash works as expected' ' test_expect_success 'interrupted squash works as expected (case 2)' ' git checkout -b interrupted-squash2 conflict-branch && one=$(git rev-parse HEAD~3) && - set_fake_editor && - test_must_fail env FAKE_LINES="3 squash 1 2" git rebase -i HEAD~3 && + ( + set_fake_editor && + test_must_fail env FAKE_LINES="3 squash 1 2" \ + git rebase -i HEAD~3 + ) && test_write_lines one four > conflict && git add conflict && test_must_fail git rebase --continue && @@ -589,11 +635,13 @@ test_expect_success '--continue tries to commit, even for "edit"' ' git commit -m "unrelated change" && parent=$(git rev-parse HEAD^) && test_tick && - set_fake_editor && - FAKE_LINES="edit 1" git rebase -i HEAD^ && - echo edited > file7 && - git add file7 && - FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue && + ( + set_fake_editor && + FAKE_LINES="edit 1" git rebase -i HEAD^ && + echo edited > file7 && + git add file7 && + FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue + ) && test edited = $(git show HEAD:file7) && git show HEAD | grep chouette && test $parent = $(git rev-parse HEAD^) @@ -602,34 +650,41 @@ test_expect_success '--continue tries to commit, even for "edit"' ' test_expect_success 'aborted --continue does not squash commits after "edit"' ' old=$(git rev-parse HEAD) && test_tick && - set_fake_editor && - FAKE_LINES="edit 1" git rebase -i HEAD^ && - echo "edited again" > file7 && - git add file7 && - test_must_fail env FAKE_COMMIT_MESSAGE=" " git rebase --continue && + ( + set_fake_editor && + FAKE_LINES="edit 1" git rebase -i HEAD^ && + echo "edited again" > file7 && + git add file7 && + test_must_fail env FAKE_COMMIT_MESSAGE=" " git rebase --continue + ) && test $old = $(git rev-parse HEAD) && git rebase --abort ' test_expect_success 'auto-amend only edited commits after "edit"' ' test_tick && - set_fake_editor && - FAKE_LINES="edit 1" git rebase -i HEAD^ && - echo "edited again" > file7 && - git add file7 && - FAKE_COMMIT_MESSAGE="edited file7 again" git commit && - echo "and again" > file7 && - git add file7 && - test_tick && - test_must_fail env FAKE_COMMIT_MESSAGE="and again" git rebase --continue && + ( + set_fake_editor && + FAKE_LINES="edit 1" git rebase -i HEAD^ && + echo "edited again" > file7 && + git add file7 && + FAKE_COMMIT_MESSAGE="edited file7 again" git commit && + echo "and again" > file7 && + git add file7 && + test_tick && + test_must_fail env FAKE_COMMIT_MESSAGE="and again" \ + git rebase --continue + ) && git rebase --abort ' test_expect_success 'clean error after failed "exec"' ' test_tick && test_when_finished "git rebase --abort || :" && - set_fake_editor && - test_must_fail env FAKE_LINES="1 exec_false" git rebase -i HEAD^ && + ( + set_fake_editor && + test_must_fail env FAKE_LINES="1 exec_false" git rebase -i HEAD^ + ) && echo "edited again" > file7 && git add file7 && test_must_fail git rebase --continue 2>error && @@ -640,8 +695,10 @@ test_expect_success 'rebase a detached HEAD' ' grandparent=$(git rev-parse HEAD~2) && git checkout $(git rev-parse HEAD) && test_tick && - set_fake_editor && - FAKE_LINES="2 1" git rebase -i HEAD~2 && + ( + set_fake_editor && + FAKE_LINES="2 1" git rebase -i HEAD~2 + ) && test $grandparent = $(git rev-parse HEAD~2) ' @@ -656,9 +713,10 @@ test_expect_success 'rebase a commit violating pre-commit' ' test_must_fail git commit -m doesnt-verify file1 && git commit -m doesnt-verify --no-verify file1 && test_tick && - set_fake_editor && - FAKE_LINES=2 git rebase -i HEAD~2 - + ( + set_fake_editor && + FAKE_LINES=2 git rebase -i HEAD~2 + ) ' test_expect_success 'rebase with a file named HEAD in worktree' ' @@ -678,8 +736,10 @@ test_expect_success 'rebase with a file named HEAD in worktree' ' git commit -m "Add body" ) && - set_fake_editor && - FAKE_LINES="1 squash 2" git rebase -i @{-1} && + ( + set_fake_editor && + FAKE_LINES="1 squash 2" git rebase -i @{-1} + ) && test "$(git show -s --pretty=format:%an)" = "Squashed Away" ' @@ -720,8 +780,10 @@ test_expect_success 'submodule rebase setup' ' ' test_expect_success 'submodule rebase -i' ' - set_fake_editor && - FAKE_LINES="1 squash 2 3" git rebase -i A + ( + set_fake_editor && + FAKE_LINES="1 squash 2 3" git rebase -i A + ) ' test_expect_success 'submodule conflict setup' ' @@ -770,16 +832,22 @@ test_expect_success 'avoid unnecessary reset' ' test_expect_success 'reword' ' git checkout -b reword-branch master && - set_fake_editor && - FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" git rebase -i A && - git show HEAD | grep "E changed" && - test $(git rev-parse master) != $(git rev-parse HEAD) && - test $(git rev-parse master^) = $(git rev-parse HEAD^) && - FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" git rebase -i A && - git show HEAD^ | grep "D changed" && - FAKE_LINES="reword 1 2 3 4" FAKE_COMMIT_MESSAGE="B changed" git rebase -i A && - git show HEAD~3 | grep "B changed" && - FAKE_LINES="1 r 2 pick 3 p 4" FAKE_COMMIT_MESSAGE="C changed" git rebase -i A && + ( + set_fake_editor && + FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" \ + git rebase -i A && + git show HEAD | grep "E changed" && + test $(git rev-parse master) != $(git rev-parse HEAD) && + test $(git rev-parse master^) = $(git rev-parse HEAD^) && + FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" \ + git rebase -i A && + git show HEAD^ | grep "D changed" && + FAKE_LINES="reword 1 2 3 4" FAKE_COMMIT_MESSAGE="B changed" \ + git rebase -i A && + git show HEAD~3 | grep "B changed" && + FAKE_LINES="1 r 2 pick 3 p 4" FAKE_COMMIT_MESSAGE="C changed" \ + git rebase -i A + ) && git show HEAD~2 | grep "C changed" ' @@ -803,8 +871,11 @@ test_expect_success 'rebase -i can copy notes over a fixup' ' EOF git reset --hard n3 && git notes add -m"an earlier note" n2 && - set_fake_editor && - GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 f 2" git rebase -i n1 && + ( + set_fake_editor && + GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 f 2" \ + git rebase -i n1 + ) && git notes show > output && test_cmp expect output ' @@ -813,8 +884,10 @@ test_expect_success 'rebase while detaching HEAD' ' git symbolic-ref HEAD && grandparent=$(git rev-parse HEAD~2) && test_tick && - set_fake_editor && - FAKE_LINES="2 1" git rebase -i HEAD~2 HEAD^0 && + ( + set_fake_editor && + FAKE_LINES="2 1" git rebase -i HEAD~2 HEAD^0 + ) && test $grandparent = $(git rev-parse HEAD~2) && test_must_fail git symbolic-ref HEAD ' @@ -855,8 +928,10 @@ test_expect_success 'set up commits with funny messages' ' test_expect_success 'rebase-i history with funny messages' ' git rev-list A..funny >expect && test_tick && - set_fake_editor && - FAKE_LINES="1 2 3 4" git rebase -i A && + ( + set_fake_editor && + FAKE_LINES="1 2 3 4" git rebase -i A + ) && git rev-list A.. >actual && test_cmp expect actual ' @@ -870,9 +945,9 @@ test_expect_success 'prepare for rebase -i --exec' ' ' test_expect_success 'running "git rebase -i --exec git show HEAD"' ' - set_fake_editor && - git rebase -i --exec "git show HEAD" HEAD~2 >actual && ( + set_fake_editor && + git rebase -i --exec "git show HEAD" HEAD~2 >actual && FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" && export FAKE_LINES && git rebase -i HEAD~2 >expect @@ -883,9 +958,9 @@ test_expect_success 'running "git rebase -i --exec git show HEAD"' ' test_expect_success 'running "git rebase --exec git show HEAD -i"' ' git reset --hard execute && - set_fake_editor && - git rebase --exec "git show HEAD" -i HEAD~2 >actual && ( + set_fake_editor && + git rebase --exec "git show HEAD" -i HEAD~2 >actual && FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" && export FAKE_LINES && git rebase -i HEAD~2 >expect @@ -896,9 +971,9 @@ test_expect_success 'running "git rebase --exec git show HEAD -i"' ' test_expect_success 'running "git rebase -ix git show HEAD"' ' git reset --hard execute && - set_fake_editor && - git rebase -ix "git show HEAD" HEAD~2 >actual && ( + set_fake_editor && + git rebase -ix "git show HEAD" HEAD~2 >actual && FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" && export FAKE_LINES && git rebase -i HEAD~2 >expect @@ -910,9 +985,9 @@ test_expect_success 'running "git rebase -ix git show HEAD"' ' test_expect_success 'rebase -ix with several ' ' git reset --hard execute && - set_fake_editor && - git rebase -ix "git show HEAD; pwd" HEAD~2 >actual && ( + set_fake_editor && + git rebase -ix "git show HEAD; pwd" HEAD~2 >actual && FAKE_LINES="1 exec_git_show_HEAD;_pwd 2 exec_git_show_HEAD;_pwd" && export FAKE_LINES && git rebase -i HEAD~2 >expect @@ -923,9 +998,9 @@ test_expect_success 'rebase -ix with several ' ' test_expect_success 'rebase -ix with several instances of --exec' ' git reset --hard execute && - set_fake_editor && - git rebase -i --exec "git show HEAD" --exec "pwd" HEAD~2 >actual && ( + set_fake_editor && + git rebase -i --exec "git show HEAD" --exec "pwd" HEAD~2 >actual && FAKE_LINES="1 exec_git_show_HEAD exec_pwd 2 exec_git_show_HEAD exec_pwd" && export FAKE_LINES && @@ -944,11 +1019,11 @@ test_expect_success C_LOCALE_OUTPUT 'rebase -ix with --autosquash' ' echo bis >bis.txt && git add bis.txt && git commit -m "fixup! two_exec" && - set_fake_editor && git checkout -b autosquash_actual && git rebase -i --exec "git show HEAD" --autosquash HEAD~4 >actual && git checkout autosquash && ( + set_fake_editor && git checkout -b autosquash_expected && FAKE_LINES="1 fixup 3 fixup 4 exec_git_show_HEAD 2 exec_git_show_HEAD" && export FAKE_LINES && @@ -977,8 +1052,10 @@ test_expect_success 'rebase -i --exec without ' ' test_expect_success 'rebase -i --root re-order and drop commits' ' git checkout E && - set_fake_editor && - FAKE_LINES="3 1 2 5" git rebase -i --root && + ( + set_fake_editor && + FAKE_LINES="3 1 2 5" git rebase -i --root + ) && test E = $(git cat-file commit HEAD | sed -ne \$p) && test B = $(git cat-file commit HEAD^ | sed -ne \$p) && test A = $(git cat-file commit HEAD^^ | sed -ne \$p) && @@ -991,24 +1068,30 @@ test_expect_success 'rebase -i --root retain root commit author and message' ' echo B >file7 && git add file7 && GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" && - set_fake_editor && - FAKE_LINES="2" git rebase -i --root && + ( + set_fake_editor && + FAKE_LINES="2" git rebase -i --root + ) && git cat-file commit HEAD | grep -q "^author Twerp Snog" && git cat-file commit HEAD | grep -q "^different author$" ' test_expect_success 'rebase -i --root temporary sentinel commit' ' git checkout B && - set_fake_editor && - test_must_fail env FAKE_LINES="2" git rebase -i --root && + ( + set_fake_editor && + test_must_fail env FAKE_LINES="2" git rebase -i --root + ) && git cat-file commit HEAD | grep "^tree 4b825dc642cb" && git rebase --abort ' test_expect_success 'rebase -i --root fixup root commit' ' git checkout B && - set_fake_editor && - FAKE_LINES="1 fixup 2" git rebase -i --root && + ( + set_fake_editor && + FAKE_LINES="1 fixup 2" git rebase -i --root + ) && test A = $(git cat-file commit HEAD | sed -ne \$p) && test B = $(git show HEAD:file1) && test 0 = $(git cat-file commit HEAD | grep -c ^parent\ ) @@ -1017,9 +1100,11 @@ test_expect_success 'rebase -i --root fixup root commit' ' test_expect_success 'rebase -i --root reword original root commit' ' test_when_finished "test_might_fail git rebase --abort" && git checkout -b reword-original-root-branch master && - set_fake_editor && - FAKE_LINES="reword 1 2" FAKE_COMMIT_MESSAGE="A changed" \ - git rebase -i --root && + ( + set_fake_editor && + FAKE_LINES="reword 1 2" FAKE_COMMIT_MESSAGE="A changed" \ + git rebase -i --root + ) && git show HEAD^ | grep "A changed" && test -z "$(git show -s --format=%p HEAD^)" ' @@ -1027,9 +1112,11 @@ test_expect_success 'rebase -i --root reword original root commit' ' test_expect_success 'rebase -i --root reword new root commit' ' test_when_finished "test_might_fail git rebase --abort" && git checkout -b reword-now-root-branch master && - set_fake_editor && - FAKE_LINES="reword 3 1" FAKE_COMMIT_MESSAGE="C changed" \ - git rebase -i --root && + ( + set_fake_editor && + FAKE_LINES="reword 3 1" FAKE_COMMIT_MESSAGE="C changed" \ + git rebase -i --root + ) && git show HEAD^ | grep "C changed" && test -z "$(git show -s --format=%p HEAD^)" ' @@ -1041,8 +1128,10 @@ test_expect_success 'rebase -i --root when root has untracked file conflict' ' git rm file1 && git commit -m "remove file 1 add file 2" && echo z >file1 && - set_fake_editor && - test_must_fail env FAKE_LINES="1 2" git rebase -i --root && + ( + set_fake_editor && + test_must_fail env FAKE_LINES="1 2" git rebase -i --root + ) && rm file1 && git rebase --continue && test "$(git log -1 --format=%B)" = "remove file 1 add file 2" && @@ -1052,11 +1141,13 @@ test_expect_success 'rebase -i --root when root has untracked file conflict' ' test_expect_success 'rebase -i --root reword root when root has untracked file conflict' ' test_when_finished "reset_rebase" && echo z>file1 && - set_fake_editor && - test_must_fail env FAKE_LINES="reword 1 2" \ - FAKE_COMMIT_MESSAGE="Modified A" git rebase -i --root && - rm file1 && - FAKE_COMMIT_MESSAGE="Reworded A" git rebase --continue && + ( + set_fake_editor && + test_must_fail env FAKE_LINES="reword 1 2" \ + FAKE_COMMIT_MESSAGE="Modified A" git rebase -i --root && + rm file1 && + FAKE_COMMIT_MESSAGE="Reworded A" git rebase --continue + ) && test "$(git log -1 --format=%B HEAD^)" = "Reworded A" && test "$(git rev-list --count HEAD)" = 2 ' @@ -1065,19 +1156,23 @@ test_expect_success C_LOCALE_OUTPUT 'rebase --edit-todo does not work on non-int git checkout reword-original-root-branch && git reset --hard && git checkout conflict-branch && - set_fake_editor && - test_must_fail git rebase --onto HEAD~2 HEAD~ && - test_must_fail git rebase --edit-todo && + ( + set_fake_editor && + test_must_fail git rebase --onto HEAD~2 HEAD~ && + test_must_fail git rebase --edit-todo + ) && git rebase --abort ' test_expect_success 'rebase --edit-todo can be used to modify todo' ' git reset --hard && git checkout no-conflict-branch^0 && - set_fake_editor && - FAKE_LINES="edit 1 2 3" git rebase -i HEAD~3 && - FAKE_LINES="2 1" git rebase --edit-todo && - git rebase --continue && + ( + set_fake_editor && + FAKE_LINES="edit 1 2 3" git rebase -i HEAD~3 && + FAKE_LINES="2 1" git rebase --edit-todo && + git rebase --continue + ) && test M = $(git cat-file commit HEAD^ | sed -ne \$p) && test L = $(git cat-file commit HEAD | sed -ne \$p) ' @@ -1106,8 +1201,10 @@ test_expect_success 'rebase -i respects core.commentchar' ' sed -e "2,\$s/^/\\\\/" "$1" >"$1.tmp" && mv "$1.tmp" "$1" EOF - test_set_editor "$(pwd)/remove-all-but-first.sh" && - git rebase -i B && + ( + test_set_editor "$(pwd)/remove-all-but-first.sh" && + git rebase -i B + ) && test B = $(git cat-file commit HEAD^ | sed -ne \$p) ' @@ -1116,9 +1213,11 @@ test_expect_success 'rebase -i respects core.commentchar=auto' ' write_script copy-edit-script.sh <<-\EOF && cp "$1" edit-script EOF - test_set_editor "$(pwd)/copy-edit-script.sh" && test_when_finished "git rebase --abort || :" && - git rebase -i HEAD^ && + ( + test_set_editor "$(pwd)/copy-edit-script.sh" && + git rebase -i HEAD^ + ) && test -z "$(grep -ve "^#" -e "^\$" -e "^pick" edit-script)" ' @@ -1153,8 +1252,11 @@ test_expect_success 'interrupted rebase -i with --strategy and -X' ' echo five >conflict && echo Z >file1 && git commit -a -m "one file conflict" && - set_fake_editor && - FAKE_LINES="edit 1 2" git rebase -i --strategy=recursive -Xours conflict-branch && + ( + set_fake_editor && + FAKE_LINES="edit 1 2" git rebase -i --strategy=recursive \ + -Xours conflict-branch + ) && git rebase --continue && test $(git show conflict-branch:conflict) = $(cat conflict) && test $(cat file1) = Z @@ -1195,8 +1297,10 @@ test_expect_success 'short SHA-1 collide' ' test_expect_success 'respect core.abbrev' ' git config core.abbrev 12 && - set_cat_todo_editor && - test_must_fail git rebase -i HEAD~4 >todo-list && + ( + set_cat_todo_editor && + test_must_fail git rebase -i HEAD~4 >todo-list + ) && test 4 = $(grep -c "pick [0-9a-f]\{12,\}" todo-list) ' @@ -1204,16 +1308,20 @@ test_expect_success 'todo count' ' write_script dump-raw.sh <<-\EOF && cat "$1" EOF - test_set_editor "$(pwd)/dump-raw.sh" && - git rebase -i HEAD~4 >actual && + ( + test_set_editor "$(pwd)/dump-raw.sh" && + git rebase -i HEAD~4 >actual + ) && test_i18ngrep "^# Rebase ..* onto ..* ([0-9]" actual ' test_expect_success 'rebase -i commits that overwrite untracked files (pick)' ' git checkout --force branch2 && git clean -f && - set_fake_editor && - FAKE_LINES="edit 1 2" git rebase -i A && + ( + set_fake_editor && + FAKE_LINES="edit 1 2" git rebase -i A + ) && test_cmp_rev HEAD F && test_path_is_missing file6 && >file6 && @@ -1228,8 +1336,10 @@ test_expect_success 'rebase -i commits that overwrite untracked files (squash)' git checkout --force branch2 && git clean -f && git tag original-branch2 && - set_fake_editor && - FAKE_LINES="edit 1 squash 2" git rebase -i A && + ( + set_fake_editor && + FAKE_LINES="edit 1 squash 2" git rebase -i A + ) && test_cmp_rev HEAD F && test_path_is_missing file6 && >file6 && @@ -1244,8 +1354,10 @@ test_expect_success 'rebase -i commits that overwrite untracked files (squash)' test_expect_success 'rebase -i commits that overwrite untracked files (no ff)' ' git checkout --force branch2 && git clean -f && - set_fake_editor && - FAKE_LINES="edit 1 2" git rebase -i --no-ff A && + ( + set_fake_editor && + FAKE_LINES="edit 1 2" git rebase -i --no-ff A + ) && test $(git cat-file commit HEAD | sed -ne \$p) = F && test_path_is_missing file6 && >file6 && @@ -1268,8 +1380,10 @@ test_expect_success 'rebase --continue removes CHERRY_PICK_HEAD' ' git tag seq-onto && git reset --hard HEAD~2 && git cherry-pick seq-onto && - set_fake_editor && - test_must_fail env FAKE_LINES= git rebase -i seq-onto && + ( + set_fake_editor && + test_must_fail env FAKE_LINES= git rebase -i seq-onto + ) && test -d .git/rebase-merge && git rebase --continue && git diff --exit-code seq-onto && @@ -1288,8 +1402,10 @@ rebase_setup_and_clean () { test_expect_success 'drop' ' rebase_setup_and_clean drop-test && - set_fake_editor && - FAKE_LINES="1 drop 2 3 d 4 5" git rebase -i --root && + ( + set_fake_editor && + FAKE_LINES="1 drop 2 3 d 4 5" git rebase -i --root + ) && test E = $(git cat-file commit HEAD | sed -ne \$p) && test C = $(git cat-file commit HEAD^ | sed -ne \$p) && test A = $(git cat-file commit HEAD^^ | sed -ne \$p) @@ -1298,9 +1414,10 @@ test_expect_success 'drop' ' test_expect_success 'rebase -i respects rebase.missingCommitsCheck = ignore' ' test_config rebase.missingCommitsCheck ignore && rebase_setup_and_clean missing-commit && - set_fake_editor && - FAKE_LINES="1 2 3 4" \ - git rebase -i --root 2>actual && + ( + set_fake_editor && + FAKE_LINES="1 2 3 4" git rebase -i --root 2>actual + ) && test D = $(git cat-file commit HEAD | sed -ne \$p) && test_i18ngrep \ "Successfully rebased and updated refs/heads/missing-commit" \ @@ -1316,9 +1433,10 @@ test_expect_success 'rebase -i respects rebase.missingCommitsCheck = warn' ' EOF test_config rebase.missingCommitsCheck warn && rebase_setup_and_clean missing-commit && - set_fake_editor && - FAKE_LINES="1 2 3 4" \ - git rebase -i --root 2>actual.2 && + ( + set_fake_editor && + FAKE_LINES="1 2 3 4" git rebase -i --root 2>actual.2 + ) && head -n4 actual.2 >actual && test_i18ncmp expect actual && test D = $(git cat-file commit HEAD | sed -ne \$p) @@ -1340,14 +1458,15 @@ test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' ' EOF test_config rebase.missingCommitsCheck error && rebase_setup_and_clean missing-commit && - set_fake_editor && - test_must_fail env FAKE_LINES="1 2 4" \ - git rebase -i --root 2>actual && - test_i18ncmp expect actual && - cp .git/rebase-merge/git-rebase-todo.backup \ - .git/rebase-merge/git-rebase-todo && - FAKE_LINES="1 2 drop 3 4 drop 5" \ - git rebase --edit-todo && + ( + set_fake_editor && + test_must_fail env FAKE_LINES="1 2 4" \ + git rebase -i --root 2>actual && + test_i18ncmp expect actual && + cp .git/rebase-merge/git-rebase-todo.backup \ + .git/rebase-merge/git-rebase-todo && + FAKE_LINES="1 2 drop 3 4 drop 5" git rebase --edit-todo + ) && git rebase --continue && test D = $(git cat-file commit HEAD | sed -ne \$p) && test B = $(git cat-file commit HEAD^ | sed -ne \$p) @@ -1368,21 +1487,27 @@ test_expect_success 'respects rebase.abbreviateCommands with fixup, squash and e x git show HEAD EOF git checkout abbrevcmd && - set_cat_todo_editor && test_config rebase.abbreviateCommands true && - test_must_fail git rebase -i --exec "git show HEAD" \ - --autosquash master >actual && + ( + set_cat_todo_editor && + test_must_fail git rebase -i --exec "git show HEAD" \ + --autosquash master >actual + ) && test_cmp expected actual ' test_expect_success 'static check of bad command' ' rebase_setup_and_clean bad-cmd && - set_fake_editor && - test_must_fail env FAKE_LINES="1 2 3 bad 4 5" \ + ( + set_fake_editor && + test_must_fail env FAKE_LINES="1 2 3 bad 4 5" \ git rebase -i --root 2>actual && - test_i18ngrep "badcmd $(git rev-list --oneline -1 master~1)" actual && - test_i18ngrep "You can fix this with .git rebase --edit-todo.." actual && - FAKE_LINES="1 2 3 drop 4 5" git rebase --edit-todo && + test_i18ngrep "badcmd $(git rev-list --oneline -1 master~1)" \ + actual && + test_i18ngrep "You can fix this with .git rebase --edit-todo.." \ + actual && + FAKE_LINES="1 2 3 drop 4 5" git rebase --edit-todo + ) && git rebase --continue && test E = $(git cat-file commit HEAD | sed -ne \$p) && test C = $(git cat-file commit HEAD^ | sed -ne \$p) @@ -1398,19 +1523,24 @@ test_expect_success 'tabs and spaces are accepted in the todolist' ' ) >"$1.new" mv "$1.new" "$1" EOF - test_set_editor "$(pwd)/add-indent.sh" && - git rebase -i HEAD^^^ && + ( + test_set_editor "$(pwd)/add-indent.sh" && + git rebase -i HEAD^^^ + ) && test E = $(git cat-file commit HEAD | sed -ne \$p) ' test_expect_success 'static check of bad SHA-1' ' rebase_setup_and_clean bad-sha && - set_fake_editor && - test_must_fail env FAKE_LINES="1 2 edit fakesha 3 4 5 #" \ - git rebase -i --root 2>actual && - test_i18ngrep "edit XXXXXXX False commit" actual && - test_i18ngrep "You can fix this with .git rebase --edit-todo.." actual && - FAKE_LINES="1 2 4 5 6" git rebase --edit-todo && + ( + set_fake_editor && + test_must_fail env FAKE_LINES="1 2 edit fakesha 3 4 5 #" \ + git rebase -i --root 2>actual && + test_i18ngrep "edit XXXXXXX False commit" actual && + test_i18ngrep "You can fix this with .git rebase --edit-todo.." \ + actual && + FAKE_LINES="1 2 4 5 6" git rebase --edit-todo + ) && git rebase --continue && test E = $(git cat-file commit HEAD | sed -ne \$p) ' @@ -1430,37 +1560,45 @@ test_expect_success 'editor saves as CR/LF' ' SQ="'" test_expect_success 'rebase -i --gpg-sign=' ' test_when_finished "test_might_fail git rebase --abort" && - set_fake_editor && - FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" HEAD^ \ - >out 2>err && + ( + set_fake_editor && + FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" \ + HEAD^ >out 2>err + ) && test_i18ngrep "$SQ-S\"S I Gner\"$SQ" err ' test_expect_success 'rebase -i --gpg-sign= overrides commit.gpgSign' ' test_when_finished "test_might_fail git rebase --abort" && test_config commit.gpgsign true && - set_fake_editor && - FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" HEAD^ \ - >out 2>err && + ( + set_fake_editor && + FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" \ + HEAD^ >out 2>err + ) && test_i18ngrep "$SQ-S\"S I Gner\"$SQ" err ' test_expect_success 'valid author header after --root swap' ' rebase_setup_and_clean author-header no-conflict-branch && - set_fake_editor && git commit --amend --author="Au ${SQ}thor " --no-edit && git cat-file commit HEAD | grep ^author >expected && - FAKE_LINES="5 1" git rebase -i --root && + ( + set_fake_editor && + FAKE_LINES="5 1" git rebase -i --root + ) && git cat-file commit HEAD^ | grep ^author >actual && test_cmp expected actual ' test_expect_success 'valid author header when author contains single quote' ' rebase_setup_and_clean author-header no-conflict-branch && - set_fake_editor && git commit --amend --author="Au ${SQ}thor " --no-edit && git cat-file commit HEAD | grep ^author >expected && - FAKE_LINES="2" git rebase -i HEAD~2 && + ( + set_fake_editor && + FAKE_LINES="2" git rebase -i HEAD~2 + ) && git cat-file commit HEAD | grep ^author >actual && test_cmp expected actual ' From 6a619ca03ce82988f2039ecdfd3565d54aa4d9ed Mon Sep 17 00:00:00 2001 From: Phillip Wood Date: Tue, 15 Oct 2019 10:25:29 +0000 Subject: [PATCH 009/953] t3404: remove uneeded calls to set_fake_editor Some tests were calling set_fake_editor to ensure they had a sane no-op editor set. Now that all the editor setting is done in subshells these tests can rely on EDITOR=: and so do not need to call set_fake_editor. Also add a test at the end to detect any future additions messing with the exported value of $EDITOR. Signed-off-by: Phillip Wood Signed-off-by: Junio C Hamano --- t/lib-rebase.sh | 28 ++++++++++++++++++++++++++++ t/t3404-rebase-interactive.sh | 25 +++++-------------------- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/t/lib-rebase.sh b/t/lib-rebase.sh index 7ea30e50068be8..e4554db85e23c0 100644 --- a/t/lib-rebase.sh +++ b/t/lib-rebase.sh @@ -118,3 +118,31 @@ make_empty () { git commit --allow-empty -m "$1" && git tag "$1" } + +# Call this (inside test_expect_success) at the end of a test file to +# check that no tests have changed editor related environment +# variables or config settings +test_editor_unchanged () { + # We're only interested in exported variables hence 'sh -c' + sh -c 'cat >actual <<-EOF + EDITOR=$EDITOR + FAKE_COMMIT_AMEND=$FAKE_COMMIT_AMEND + FAKE_COMMIT_MESSAGE=$FAKE_COMMIT_MESSAGE + FAKE_LINES=$FAKE_LINES + GIT_EDITOR=$GIT_EDITOR + GIT_SEQUENCE_EDITOR=$GIT_SEQUENCE_EDITOR + core.editor=$(git config core.editor) + sequence.editor=$(git config sequence.editor) + EOF' + cat >expect <<-\EOF + EDITOR=: + FAKE_COMMIT_AMEND= + FAKE_COMMIT_MESSAGE= + FAKE_LINES= + GIT_EDITOR= + GIT_SEQUENCE_EDITOR= + core.editor= + sequence.editor= + EOF + test_cmp expect actual +} diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index cb9b210000a6bd..c5d0326825af33 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -189,7 +189,6 @@ test_expect_success 'implicit interactive rebase does not invoke sequence editor test_expect_success 'no changes are a nop' ' git checkout branch2 && - set_fake_editor && git rebase -i F && test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" && test $(git rev-parse I) = $(git rev-parse HEAD) @@ -199,7 +198,6 @@ test_expect_success 'test the [branch] option' ' git checkout -b dead-end && git rm file6 && git commit -m "stop here" && - set_fake_editor && git rebase -i F branch2 && test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" && test $(git rev-parse I) = $(git rev-parse branch2) && @@ -208,7 +206,6 @@ test_expect_success 'test the [branch] option' ' test_expect_success 'test --onto ' ' git checkout -b test-onto branch2 && - set_fake_editor && git rebase -i --onto branch1 F && test "$(git symbolic-ref -q HEAD)" = "refs/heads/test-onto" && test $(git rev-parse HEAD^) = $(git rev-parse branch1) && @@ -218,7 +215,6 @@ test_expect_success 'test --onto ' ' test_expect_success 'rebase on top of a non-conflicting commit' ' git checkout branch1 && git tag original-branch1 && - set_fake_editor && git rebase -i branch2 && test file6 = $(git diff --name-only original-branch1) && test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" && @@ -264,7 +260,6 @@ test_expect_success 'stop on conflicting pick' ' >>>>>>> 5d18e54... G EOF git tag new-branch1 && - set_fake_editor && test_must_fail git rebase -i master && test "$(git rev-parse HEAD~3)" = "$(git rev-parse master)" && test_cmp expect .git/rebase-merge/patch && @@ -293,7 +288,6 @@ test_expect_success 'abort' ' test_expect_success 'abort with error when new base cannot be checked out' ' git rm --cached file1 && git commit -m "remove file in base" && - set_fake_editor && test_must_fail git rebase -i master > output 2>&1 && test_i18ngrep "The following untracked working tree files would be overwritten by checkout:" \ output && @@ -308,7 +302,6 @@ test_expect_success 'retain authorship' ' test_tick && GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" && git tag twerp && - set_fake_editor && git rebase -i --onto master HEAD^ && git show HEAD | grep "^Author: Twerp Snog" ' @@ -326,7 +319,6 @@ test_expect_success 'retain authorship w/ conflicts' ' test_commit b conflict b conflict-b && GIT_AUTHOR_NAME=$oGIT_AUTHOR_NAME && - set_fake_editor && test_must_fail git rebase -i conflict-a && echo resolved >conflict && git add conflict && @@ -357,7 +349,6 @@ test_expect_success 'retain authorship when squashing' ' test_expect_success REBASE_P '-p handles "no changes" gracefully' ' HEAD=$(git rev-parse HEAD) && - set_fake_editor && git rebase -i -p HEAD^ && git update-index --refresh && git diff-files --quiet && @@ -404,7 +395,6 @@ test_expect_success REBASE_P 'preserve merges with -p' ' git commit -m M file1 && git checkout -b to-be-rebased && test_tick && - set_fake_editor && git rebase -i -p --onto branch1 master && git update-index --refresh && git diff-files --quiet && @@ -450,7 +440,6 @@ test_expect_success '--continue tries to commit' ' test_expect_success 'verbose flag is heeded, even after --continue' ' git reset --hard master@{1} && test_tick && - set_fake_editor && test_must_fail git rebase -v -i --onto new-branch1 HEAD^ && echo resolved > file1 && git add file1 && @@ -750,7 +739,6 @@ test_expect_success 'do "noop" when there is nothing to cherry-pick' ' GIT_EDITOR=: git commit --amend \ --author="Somebody else " && test $(git rev-parse branch3) != $(git rev-parse branch4) && - set_fake_editor && git rebase -i branch3 && test $(git rev-parse branch3) = $(git rev-parse branch4) @@ -775,7 +763,6 @@ test_expect_success 'submodule rebase setup' ' git commit -a -m "submodule second" ) && test_tick && - set_fake_editor && git commit -a -m "Three changes submodule" ' @@ -800,7 +787,6 @@ test_expect_success 'submodule conflict setup' ' ' test_expect_success 'rebase -i continue with only submodule staged' ' - set_fake_editor && test_must_fail git rebase -i submodule-base && git add sub && git rebase --continue && @@ -810,7 +796,6 @@ test_expect_success 'rebase -i continue with only submodule staged' ' test_expect_success 'rebase -i continue with unstaged submodule' ' git checkout submodule-topic && git reset --hard && - set_fake_editor && test_must_fail git rebase -i submodule-base && git reset && git rebase --continue && @@ -823,7 +808,6 @@ test_expect_success 'avoid unnecessary reset' ' test-tool chmtime =123456789 file3 && git update-index --refresh && HEAD=$(git rev-parse HEAD) && - set_fake_editor && git rebase -i HEAD~4 && test $HEAD = $(git rev-parse HEAD) && MTIME=$(test-tool chmtime --get file3) && @@ -858,7 +842,6 @@ test_expect_success 'rebase -i can copy notes' ' test_commit n2 && test_commit n3 && git notes add -m"a note" n3 && - set_fake_editor && git rebase -i --onto n1 n2 && test "a note" = "$(git notes show HEAD)" ' @@ -896,7 +879,6 @@ test_tick # Ensure that the rebased commits get a different timestamp. test_expect_success 'always cherry-pick with --no-ff' ' git checkout no-ff-branch && git tag original-no-ff-branch && - set_fake_editor && git rebase -i --no-ff A && for p in 0 1 2 do @@ -1044,7 +1026,6 @@ test_expect_success 'rebase --exec works without -i ' ' test_expect_success 'rebase -i --exec without ' ' git reset --hard execute && - set_fake_editor && test_must_fail git rebase -i --exec 2>actual && test_i18ngrep "requires a value" actual && git checkout master @@ -1180,7 +1161,6 @@ test_expect_success 'rebase --edit-todo can be used to modify todo' ' test_expect_success 'rebase -i produces readable reflog' ' git reset --hard && git branch -f branch-reflog-test H && - set_fake_editor && git rebase -i --onto I F branch-reflog-test && cat >expect <<-\EOF && rebase -i (finish): returning to refs/heads/branch-reflog-test @@ -1603,4 +1583,9 @@ test_expect_success 'valid author header when author contains single quote' ' test_cmp expected actual ' +# This must be the last test in this file +test_expect_success '$EDITOR and friends are unchanged' ' + test_editor_unchanged +' + test_done From 12bb7a540a39746fd6f62e4d5ffd016a2178bcf7 Mon Sep 17 00:00:00 2001 From: Phillip Wood Date: Tue, 15 Oct 2019 10:25:30 +0000 Subject: [PATCH 010/953] sequencer.h fix placement of #endif Commit 65850686cf ("rebase -i: rewrite write_basic_state() in C", 2018-08-28) accidentially added new function declarations after the #endif at the end of the include guard. Signed-off-by: Phillip Wood Signed-off-by: Junio C Hamano --- sequencer.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sequencer.h b/sequencer.h index 0c494b83d43e2c..ac66892d7117aa 100644 --- a/sequencer.h +++ b/sequencer.h @@ -195,11 +195,10 @@ void print_commit_summary(struct repository *repo, int read_author_script(const char *path, char **name, char **email, char **date, int allow_missing); -#endif - void parse_strategy_opts(struct replay_opts *opts, char *raw_opts); int write_basic_state(struct replay_opts *opts, const char *head_name, struct commit *onto, const char *orig_head); void sequencer_post_commit_cleanup(struct repository *r); int sequencer_get_last_command(struct repository* r, enum replay_action *action); +#endif /* SEQUENCER_H */ From 49697cb72122cf84b44111124821c9a4bcba3ab6 Mon Sep 17 00:00:00 2001 From: Phillip Wood Date: Tue, 15 Oct 2019 10:25:31 +0000 Subject: [PATCH 011/953] move run_commit_hook() to libgit and use it there This function was declared in commit.h but was implemented in builtin/commit.c so was not part of libgit. Move it to libgit so we can use it in the sequencer. This simplifies the implementation of run_prepare_commit_msg_hook() and will be used in the next commit. Signed-off-by: Phillip Wood Signed-off-by: Junio C Hamano --- builtin/commit.c | 22 ---------------------- commit.c | 24 ++++++++++++++++++++++++ sequencer.c | 23 ++++++++++------------- 3 files changed, 34 insertions(+), 35 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index 192140111747cc..d898a57f5d599b 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1443,28 +1443,6 @@ static int git_commit_config(const char *k, const char *v, void *cb) return git_status_config(k, v, s); } -int run_commit_hook(int editor_is_used, const char *index_file, const char *name, ...) -{ - struct argv_array hook_env = ARGV_ARRAY_INIT; - va_list args; - int ret; - - argv_array_pushf(&hook_env, "GIT_INDEX_FILE=%s", index_file); - - /* - * Let the hook know that no editor will be launched. - */ - if (!editor_is_used) - argv_array_push(&hook_env, "GIT_EDITOR=:"); - - va_start(args, name); - ret = run_hook_ve(hook_env.argv,name, args); - va_end(args); - argv_array_clear(&hook_env); - - return ret; -} - int cmd_commit(int argc, const char **argv, const char *prefix) { const char *argv_gc_auto[] = {"gc", "--auto", NULL}; diff --git a/commit.c b/commit.c index 26ce0770f688eb..7ca8d12174105e 100644 --- a/commit.c +++ b/commit.c @@ -19,6 +19,7 @@ #include "advice.h" #include "refs.h" #include "commit-reach.h" +#include "run-command.h" static struct commit_extra_header *read_commit_extra_header_lines(const char *buf, size_t len, const char **); @@ -1581,3 +1582,26 @@ size_t ignore_non_trailer(const char *buf, size_t len) } return boc ? len - boc : len - cutoff; } + +int run_commit_hook(int editor_is_used, const char *index_file, + const char *name, ...) +{ + struct argv_array hook_env = ARGV_ARRAY_INIT; + va_list args; + int ret; + + argv_array_pushf(&hook_env, "GIT_INDEX_FILE=%s", index_file); + + /* + * Let the hook know that no editor will be launched. + */ + if (!editor_is_used) + argv_array_push(&hook_env, "GIT_EDITOR=:"); + + va_start(args, name); + ret = run_hook_ve(hook_env.argv,name, args); + va_end(args); + argv_array_clear(&hook_env); + + return ret; +} diff --git a/sequencer.c b/sequencer.c index 2adcf5a639c3a7..cdc0d1dfba77d2 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1127,25 +1127,22 @@ static int run_prepare_commit_msg_hook(struct repository *r, struct strbuf *msg, const char *commit) { - struct argv_array hook_env = ARGV_ARRAY_INIT; - int ret; - const char *name; + int ret = 0; + const char *name, *arg1 = NULL, *arg2 = NULL; name = git_path_commit_editmsg(); if (write_message(msg->buf, msg->len, name, 0)) return -1; - argv_array_pushf(&hook_env, "GIT_INDEX_FILE=%s", r->index_file); - argv_array_push(&hook_env, "GIT_EDITOR=:"); - if (commit) - ret = run_hook_le(hook_env.argv, "prepare-commit-msg", name, - "commit", commit, NULL); - else - ret = run_hook_le(hook_env.argv, "prepare-commit-msg", name, - "message", NULL); - if (ret) + if (commit) { + arg1 = "commit"; + arg2 = commit; + } else { + arg1 = "message"; + } + if (run_commit_hook(0, r->index_file, "prepare-commit-msg", name, + arg1, arg2, NULL)) ret = error(_("'prepare-commit-msg' hook failed")); - argv_array_clear(&hook_env); return ret; } From 4627bc777e9ade5e3a85d6b8e8630fc4b6e2f8f6 Mon Sep 17 00:00:00 2001 From: Phillip Wood Date: Tue, 15 Oct 2019 10:25:32 +0000 Subject: [PATCH 012/953] sequencer: run post-commit hook Prior to commit 356ee4659b ("sequencer: try to commit without forking 'git commit'", 2017-11-24) the sequencer would always run the post-commit hook after each pick or revert as it forked `git commit` to create the commit. The conversion to committing without forking `git commit` omitted to call the post-commit hook after creating the commit. Signed-off-by: Phillip Wood Signed-off-by: Junio C Hamano --- sequencer.c | 1 + t/t3404-rebase-interactive.sh | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/sequencer.c b/sequencer.c index cdc0d1dfba77d2..da2decbd3af47f 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1401,6 +1401,7 @@ static int try_to_commit(struct repository *r, goto out; } + run_commit_hook(0, r->index_file, "post-commit", NULL); if (flags & AMEND_MSG) commit_post_rewrite(r, current_head, oid); diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index c5d0326825af33..c573c99069b44c 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -1583,6 +1583,25 @@ test_expect_success 'valid author header when author contains single quote' ' test_cmp expected actual ' +test_expect_success 'post-commit hook is called' ' + test_when_finished "rm -f .git/hooks/post-commit" && + >actual && + mkdir -p .git/hooks && + write_script .git/hooks/post-commit <<-\EOS && + git rev-parse HEAD >>actual + EOS + ( + set_fake_editor && + FAKE_LINES="edit 4 1 reword 2 fixup 3" git rebase -i A E && + echo x>file3 && + git add file3 && + FAKE_COMMIT_MESSAGE=edited git rebase --continue + ) && + git rev-parse HEAD@{5} HEAD@{4} HEAD@{3} HEAD@{2} HEAD@{1} HEAD \ + >expect && + test_cmp expect actual +' + # This must be the last test in this file test_expect_success '$EDITOR and friends are unchanged' ' test_editor_unchanged From 5374a290aa56390f9f44547d52f8f30fb2e866aa Mon Sep 17 00:00:00 2001 From: Jonathan Tan Date: Mon, 14 Oct 2019 17:12:31 -0700 Subject: [PATCH 013/953] fetch-pack: write fetched refs to .promisor The specification of promisor packfiles (in partial-clone.txt) states that the .promisor files that accompany packfiles do not matter (just like .keep files), so whenever a packfile is fetched from the promisor remote, Git has been writing empty .promisor files. But these files could contain more useful information. So instead of writing empty files, write the refs fetched to these files. This makes it easier to debug issues with partial clones, as we can identify what refs (and their associated hashes) were fetched at the time the packfile was downloaded, and if necessary, compare those hashes against what the promisor remote reports now. This is implemented by teaching fetch-pack to write its own non-empty .promisor file whenever it knows the name of the pack's lockfile. This covers the case wherein the user runs "git fetch" with an internal protocol or HTTP protocol v2 (fetch_refs_via_pack() in transport.c sets lock_pack) and with HTTP protocol v0/v1 (fetch_git() in remote-curl.c passes "--lock-pack" to "fetch-pack"). Signed-off-by: Jonathan Tan Acked-by: Josh Steadmon Signed-off-by: Junio C Hamano --- builtin/repack.c | 7 ++++++ fetch-pack.c | 47 ++++++++++++++++++++++++++++++++++++---- t/t5616-partial-clone.sh | 8 +++++++ 3 files changed, 58 insertions(+), 4 deletions(-) diff --git a/builtin/repack.c b/builtin/repack.c index 094c2f8ea48cae..78b23d7a9a31f0 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -233,6 +233,13 @@ static void repack_promisor_objects(const struct pack_objects_args *args, /* * pack-objects creates the .pack and .idx files, but not the * .promisor file. Create the .promisor file, which is empty. + * + * NEEDSWORK: fetch-pack sometimes generates non-empty + * .promisor files containing the ref names and associated + * hashes at the point of generation of the corresponding + * packfile, but this would not preserve their contents. Maybe + * concatenate the contents of all .promisor files instead of + * just creating a new empty file. */ promisor_name = mkpathdup("%s-%s.promisor", packtmp, line.buf); diff --git a/fetch-pack.c b/fetch-pack.c index 947da545de0556..b9e63b52ff4653 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -754,8 +754,33 @@ static int sideband_demux(int in, int out, void *data) return ret; } +static void write_promisor_file(const char *keep_name, + struct ref **sought, int nr_sought) +{ + struct strbuf promisor_name = STRBUF_INIT; + int suffix_stripped; + FILE *output; + int i; + + strbuf_addstr(&promisor_name, keep_name); + suffix_stripped = strbuf_strip_suffix(&promisor_name, ".keep"); + if (!suffix_stripped) + BUG("name of pack lockfile should end with .keep (was '%s')", + keep_name); + strbuf_addstr(&promisor_name, ".promisor"); + + output = xfopen(promisor_name.buf, "w"); + for (i = 0; i < nr_sought; i++) + fprintf(output, "%s %s\n", oid_to_hex(&sought[i]->old_oid), + sought[i]->name); + fclose(output); + + strbuf_release(&promisor_name); +} + static int get_pack(struct fetch_pack_args *args, - int xd[2], char **pack_lockfile) + int xd[2], char **pack_lockfile, + struct ref **sought, int nr_sought) { struct async demux; int do_keep = args->keep_pack; @@ -817,7 +842,13 @@ static int get_pack(struct fetch_pack_args *args, } if (args->check_self_contained_and_connected) argv_array_push(&cmd.args, "--check-self-contained-and-connected"); - if (args->from_promisor) + /* + * If we're obtaining the filename of a lockfile, we'll use + * that filename to write a .promisor file with more + * information below. If not, we need index-pack to do it for + * us. + */ + if (!(do_keep && pack_lockfile) && args->from_promisor) argv_array_push(&cmd.args, "--promisor"); } else { @@ -871,6 +902,14 @@ static int get_pack(struct fetch_pack_args *args, die(_("%s failed"), cmd_name); if (use_sideband && finish_async(&demux)) die(_("error in sideband demultiplexer")); + + /* + * Now that index-pack has succeeded, write the promisor file using the + * obtained .keep filename if necessary + */ + if (do_keep && pack_lockfile && args->from_promisor) + write_promisor_file(*pack_lockfile, sought, nr_sought); + return 0; } @@ -1006,7 +1045,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args, alternate_shallow_file = setup_temporary_shallow(si->shallow); else alternate_shallow_file = NULL; - if (get_pack(args, fd, pack_lockfile)) + if (get_pack(args, fd, pack_lockfile, sought, nr_sought)) die(_("git fetch-pack: fetch failed.")); all_done: @@ -1453,7 +1492,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args, /* get the pack */ process_section_header(&reader, "packfile", 0); - if (get_pack(args, fd, pack_lockfile)) + if (get_pack(args, fd, pack_lockfile, sought, nr_sought)) die(_("git fetch-pack: fetch failed.")); state = FETCH_DONE; diff --git a/t/t5616-partial-clone.sh b/t/t5616-partial-clone.sh index 79f7b65f8c4eee..eaa33a852bad16 100755 --- a/t/t5616-partial-clone.sh +++ b/t/t5616-partial-clone.sh @@ -46,6 +46,14 @@ test_expect_success 'do partial clone 1' ' test "$(git -C pc1 config --local remote.origin.partialclonefilter)" = "blob:none" ' +test_expect_success 'verify that .promisor file contains refs fetched' ' + ls pc1/.git/objects/pack/pack-*.promisor >promisorlist && + test_line_count = 1 promisorlist && + git -C srv.bare rev-list HEAD >headhash && + grep "$(cat headhash) HEAD" $(cat promisorlist) && + grep "$(cat headhash) refs/heads/master" $(cat promisorlist) +' + # checkout master to force dynamic object fetch of blobs at HEAD. test_expect_success 'verify checkout with dynamic object fetch' ' git -C pc1 rev-list --quiet --objects --missing=print HEAD >observed && From fbccf255f9449c2f617d875ebf78b9f1730fae5d Mon Sep 17 00:00:00 2001 From: James Coglan Date: Tue, 15 Oct 2019 23:47:47 +0000 Subject: [PATCH 014/953] graph: automatically track display width of graph lines All the output functions called by `graph_next_line()` currently keep track of how many printable chars they've written to the buffer, before calling `graph_pad_horizontally()` to pad the line with spaces. Some functions do this by incrementing a counter whenever they write to the buffer, and others do it by encoding an assumption about how many chars are written, as in: graph_pad_horizontally(graph, sb, graph->num_columns * 2); This adds a fair amount of noise to the functions' logic and is easily broken if one forgets to increment the right counter or update the calculations used for padding. To make this easier to use, I'm introducing a new struct called `graph_line` that wraps a `strbuf` and keeps count of its display width implicitly. `graph_next_line()` wraps this around the `struct strbuf *` it's given and passes a `struct graph_line *` to the output functions, which use its interface. The `graph_line` interface wraps the `strbuf_addch()`, `strbuf_addchars()` and `strbuf_addstr()` functions, and adds the `graph_line_write_column()` function for adding a single character with color formatting. The `graph_pad_horizontally()` function can then use the `width` field from the struct rather than taking a character count as a parameter. Signed-off-by: James Coglan Signed-off-by: Junio C Hamano --- graph.c | 194 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 99 insertions(+), 95 deletions(-) diff --git a/graph.c b/graph.c index f53135485f565b..2f81a5d23d9561 100644 --- a/graph.c +++ b/graph.c @@ -112,14 +112,42 @@ static const char *column_get_color_code(unsigned short color) return column_colors[color]; } -static void strbuf_write_column(struct strbuf *sb, const struct column *c, - char col_char) +struct graph_line { + struct strbuf *buf; + size_t width; +}; + +static inline void graph_line_addch(struct graph_line *line, int c) +{ + strbuf_addch(line->buf, c); + line->width++; +} + +static inline void graph_line_addchars(struct graph_line *line, int c, size_t n) +{ + strbuf_addchars(line->buf, c, n); + line->width += n; +} + +static inline void graph_line_addstr(struct graph_line *line, const char *s) +{ + strbuf_addstr(line->buf, s); + line->width += strlen(s); +} + +static inline void graph_line_addcolor(struct graph_line *line, unsigned short color) +{ + strbuf_addstr(line->buf, column_get_color_code(color)); +} + +static void graph_line_write_column(struct graph_line *line, const struct column *c, + char col_char) { if (c->color < column_colors_max) - strbuf_addstr(sb, column_get_color_code(c->color)); - strbuf_addch(sb, col_char); + graph_line_addcolor(line, c->color); + graph_line_addch(line, col_char); if (c->color < column_colors_max) - strbuf_addstr(sb, column_get_color_code(column_colors_max)); + graph_line_addcolor(line, column_colors_max); } struct git_graph { @@ -686,8 +714,7 @@ static int graph_is_mapping_correct(struct git_graph *graph) return 1; } -static void graph_pad_horizontally(struct git_graph *graph, struct strbuf *sb, - int chars_written) +static void graph_pad_horizontally(struct git_graph *graph, struct graph_line *line) { /* * Add additional spaces to the end of the strbuf, so that all @@ -696,12 +723,12 @@ static void graph_pad_horizontally(struct git_graph *graph, struct strbuf *sb, * This way, fields printed to the right of the graph will remain * aligned for the entire commit. */ - if (chars_written < graph->width) - strbuf_addchars(sb, ' ', graph->width - chars_written); + if (line->width < graph->width) + graph_line_addchars(line, ' ', graph->width - line->width); } static void graph_output_padding_line(struct git_graph *graph, - struct strbuf *sb) + struct graph_line *line) { int i; @@ -719,11 +746,11 @@ static void graph_output_padding_line(struct git_graph *graph, * Output a padding row, that leaves all branch lines unchanged */ for (i = 0; i < graph->num_new_columns; i++) { - strbuf_write_column(sb, &graph->new_columns[i], '|'); - strbuf_addch(sb, ' '); + graph_line_write_column(line, &graph->new_columns[i], '|'); + graph_line_addch(line, ' '); } - graph_pad_horizontally(graph, sb, graph->num_new_columns * 2); + graph_pad_horizontally(graph, line); } @@ -733,14 +760,14 @@ int graph_width(struct git_graph *graph) } -static void graph_output_skip_line(struct git_graph *graph, struct strbuf *sb) +static void graph_output_skip_line(struct git_graph *graph, struct graph_line *line) { /* * Output an ellipsis to indicate that a portion * of the graph is missing. */ - strbuf_addstr(sb, "..."); - graph_pad_horizontally(graph, sb, 3); + graph_line_addstr(line, "..."); + graph_pad_horizontally(graph, line); if (graph->num_parents >= 3 && graph->commit_index < (graph->num_columns - 1)) @@ -750,11 +777,10 @@ static void graph_output_skip_line(struct git_graph *graph, struct strbuf *sb) } static void graph_output_pre_commit_line(struct git_graph *graph, - struct strbuf *sb) + struct graph_line *line) { int num_expansion_rows; int i, seen_this; - int chars_written; /* * This function formats a row that increases the space around a commit @@ -777,14 +803,12 @@ static void graph_output_pre_commit_line(struct git_graph *graph, * Output the row */ seen_this = 0; - chars_written = 0; for (i = 0; i < graph->num_columns; i++) { struct column *col = &graph->columns[i]; if (col->commit == graph->commit) { seen_this = 1; - strbuf_write_column(sb, col, '|'); - strbuf_addchars(sb, ' ', graph->expansion_row); - chars_written += 1 + graph->expansion_row; + graph_line_write_column(line, col, '|'); + graph_line_addchars(line, ' ', graph->expansion_row); } else if (seen_this && (graph->expansion_row == 0)) { /* * This is the first line of the pre-commit output. @@ -797,22 +821,18 @@ static void graph_output_pre_commit_line(struct git_graph *graph, */ if (graph->prev_state == GRAPH_POST_MERGE && graph->prev_commit_index < i) - strbuf_write_column(sb, col, '\\'); + graph_line_write_column(line, col, '\\'); else - strbuf_write_column(sb, col, '|'); - chars_written++; + graph_line_write_column(line, col, '|'); } else if (seen_this && (graph->expansion_row > 0)) { - strbuf_write_column(sb, col, '\\'); - chars_written++; + graph_line_write_column(line, col, '\\'); } else { - strbuf_write_column(sb, col, '|'); - chars_written++; + graph_line_write_column(line, col, '|'); } - strbuf_addch(sb, ' '); - chars_written++; + graph_line_addch(line, ' '); } - graph_pad_horizontally(graph, sb, chars_written); + graph_pad_horizontally(graph, line); /* * Increment graph->expansion_row, @@ -823,7 +843,7 @@ static void graph_output_pre_commit_line(struct git_graph *graph, graph_update_state(graph, GRAPH_COMMIT); } -static void graph_output_commit_char(struct git_graph *graph, struct strbuf *sb) +static void graph_output_commit_char(struct git_graph *graph, struct graph_line *line) { /* * For boundary commits, print 'o' @@ -831,22 +851,20 @@ static void graph_output_commit_char(struct git_graph *graph, struct strbuf *sb) */ if (graph->commit->object.flags & BOUNDARY) { assert(graph->revs->boundary); - strbuf_addch(sb, 'o'); + graph_line_addch(line, 'o'); return; } /* * get_revision_mark() handles all other cases without assert() */ - strbuf_addstr(sb, get_revision_mark(graph->revs, graph->commit)); + graph_line_addstr(line, get_revision_mark(graph->revs, graph->commit)); } /* - * Draw the horizontal dashes of an octopus merge and return the number of - * characters written. + * Draw the horizontal dashes of an octopus merge. */ -static int graph_draw_octopus_merge(struct git_graph *graph, - struct strbuf *sb) +static void graph_draw_octopus_merge(struct git_graph *graph, struct graph_line *line) { /* * Here dashless_parents represents the number of parents which don't @@ -886,17 +904,16 @@ static int graph_draw_octopus_merge(struct git_graph *graph, int i; for (i = 0; i < dashful_parents; i++) { - strbuf_write_column(sb, &graph->new_columns[i+first_col], '-'); - strbuf_write_column(sb, &graph->new_columns[i+first_col], - i == dashful_parents-1 ? '.' : '-'); + graph_line_write_column(line, &graph->new_columns[i+first_col], '-'); + graph_line_write_column(line, &graph->new_columns[i+first_col], + i == dashful_parents-1 ? '.' : '-'); } - return 2 * dashful_parents; } -static void graph_output_commit_line(struct git_graph *graph, struct strbuf *sb) +static void graph_output_commit_line(struct git_graph *graph, struct graph_line *line) { int seen_this = 0; - int i, chars_written; + int i; /* * Output the row containing this commit @@ -906,7 +923,6 @@ static void graph_output_commit_line(struct git_graph *graph, struct strbuf *sb) * children that we have already processed.) */ seen_this = 0; - chars_written = 0; for (i = 0; i <= graph->num_columns; i++) { struct column *col = &graph->columns[i]; struct commit *col_commit; @@ -920,15 +936,12 @@ static void graph_output_commit_line(struct git_graph *graph, struct strbuf *sb) if (col_commit == graph->commit) { seen_this = 1; - graph_output_commit_char(graph, sb); - chars_written++; + graph_output_commit_char(graph, line); if (graph->num_parents > 2) - chars_written += graph_draw_octopus_merge(graph, - sb); + graph_draw_octopus_merge(graph, line); } else if (seen_this && (graph->num_parents > 2)) { - strbuf_write_column(sb, col, '\\'); - chars_written++; + graph_line_write_column(line, col, '\\'); } else if (seen_this && (graph->num_parents == 2)) { /* * This is a 2-way merge commit. @@ -945,19 +958,16 @@ static void graph_output_commit_line(struct git_graph *graph, struct strbuf *sb) */ if (graph->prev_state == GRAPH_POST_MERGE && graph->prev_commit_index < i) - strbuf_write_column(sb, col, '\\'); + graph_line_write_column(line, col, '\\'); else - strbuf_write_column(sb, col, '|'); - chars_written++; + graph_line_write_column(line, col, '|'); } else { - strbuf_write_column(sb, col, '|'); - chars_written++; + graph_line_write_column(line, col, '|'); } - strbuf_addch(sb, ' '); - chars_written++; + graph_line_addch(line, ' '); } - graph_pad_horizontally(graph, sb, chars_written); + graph_pad_horizontally(graph, line); /* * Update graph->state @@ -981,15 +991,14 @@ static struct column *find_new_column_by_commit(struct git_graph *graph, return NULL; } -static void graph_output_post_merge_line(struct git_graph *graph, struct strbuf *sb) +static void graph_output_post_merge_line(struct git_graph *graph, struct graph_line *line) { int seen_this = 0; - int i, j, chars_written; + int i, j; /* * Output the post-merge row */ - chars_written = 0; for (i = 0; i <= graph->num_columns; i++) { struct column *col = &graph->columns[i]; struct commit *col_commit; @@ -1016,29 +1025,25 @@ static void graph_output_post_merge_line(struct git_graph *graph, struct strbuf par_column = find_new_column_by_commit(graph, parents->item); assert(par_column); - strbuf_write_column(sb, par_column, '|'); - chars_written++; + graph_line_write_column(line, par_column, '|'); for (j = 0; j < graph->num_parents - 1; j++) { parents = next_interesting_parent(graph, parents); assert(parents); par_column = find_new_column_by_commit(graph, parents->item); assert(par_column); - strbuf_write_column(sb, par_column, '\\'); - strbuf_addch(sb, ' '); + graph_line_write_column(line, par_column, '\\'); + graph_line_addch(line, ' '); } - chars_written += j * 2; } else if (seen_this) { - strbuf_write_column(sb, col, '\\'); - strbuf_addch(sb, ' '); - chars_written += 2; + graph_line_write_column(line, col, '\\'); + graph_line_addch(line, ' '); } else { - strbuf_write_column(sb, col, '|'); - strbuf_addch(sb, ' '); - chars_written += 2; + graph_line_write_column(line, col, '|'); + graph_line_addch(line, ' '); } } - graph_pad_horizontally(graph, sb, chars_written); + graph_pad_horizontally(graph, line); /* * Update graph->state @@ -1049,7 +1054,7 @@ static void graph_output_post_merge_line(struct git_graph *graph, struct strbuf graph_update_state(graph, GRAPH_COLLAPSING); } -static void graph_output_collapsing_line(struct git_graph *graph, struct strbuf *sb) +static void graph_output_collapsing_line(struct git_graph *graph, struct graph_line *line) { int i; short used_horizontal = 0; @@ -1159,9 +1164,9 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct strbuf for (i = 0; i < graph->mapping_size; i++) { int target = graph->new_mapping[i]; if (target < 0) - strbuf_addch(sb, ' '); + graph_line_addch(line, ' '); else if (target * 2 == i) - strbuf_write_column(sb, &graph->new_columns[target], '|'); + graph_line_write_column(line, &graph->new_columns[target], '|'); else if (target == horizontal_edge_target && i != horizontal_edge - 1) { /* @@ -1172,16 +1177,16 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct strbuf if (i != (target * 2)+3) graph->new_mapping[i] = -1; used_horizontal = 1; - strbuf_write_column(sb, &graph->new_columns[target], '_'); + graph_line_write_column(line, &graph->new_columns[target], '_'); } else { if (used_horizontal && i < horizontal_edge) graph->new_mapping[i] = -1; - strbuf_write_column(sb, &graph->new_columns[target], '/'); + graph_line_write_column(line, &graph->new_columns[target], '/'); } } - graph_pad_horizontally(graph, sb, graph->mapping_size); + graph_pad_horizontally(graph, line); /* * Swap mapping and new_mapping @@ -1199,24 +1204,26 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct strbuf int graph_next_line(struct git_graph *graph, struct strbuf *sb) { + struct graph_line line = { .buf = sb, .width = 0 }; + switch (graph->state) { case GRAPH_PADDING: - graph_output_padding_line(graph, sb); + graph_output_padding_line(graph, &line); return 0; case GRAPH_SKIP: - graph_output_skip_line(graph, sb); + graph_output_skip_line(graph, &line); return 0; case GRAPH_PRE_COMMIT: - graph_output_pre_commit_line(graph, sb); + graph_output_pre_commit_line(graph, &line); return 0; case GRAPH_COMMIT: - graph_output_commit_line(graph, sb); + graph_output_commit_line(graph, &line); return 1; case GRAPH_POST_MERGE: - graph_output_post_merge_line(graph, sb); + graph_output_post_merge_line(graph, &line); return 0; case GRAPH_COLLAPSING: - graph_output_collapsing_line(graph, sb); + graph_output_collapsing_line(graph, &line); return 0; } @@ -1227,7 +1234,7 @@ int graph_next_line(struct git_graph *graph, struct strbuf *sb) static void graph_padding_line(struct git_graph *graph, struct strbuf *sb) { int i; - int chars_written = 0; + struct graph_line line = { .buf = sb, .width = 0 }; if (graph->state != GRAPH_COMMIT) { graph_next_line(graph, sb); @@ -1244,20 +1251,17 @@ static void graph_padding_line(struct git_graph *graph, struct strbuf *sb) for (i = 0; i < graph->num_columns; i++) { struct column *col = &graph->columns[i]; - strbuf_write_column(sb, col, '|'); - chars_written++; + graph_line_write_column(&line, col, '|'); if (col->commit == graph->commit && graph->num_parents > 2) { int len = (graph->num_parents - 2) * 2; - strbuf_addchars(sb, ' ', len); - chars_written += len; + graph_line_addchars(&line, ' ', len); } else { - strbuf_addch(sb, ' '); - chars_written++; + graph_line_addch(&line, ' '); } } - graph_pad_horizontally(graph, sb, chars_written); + graph_pad_horizontally(graph, &line); /* * Update graph->prev_state since we have output a padding line From 210179a20d585f6a96e0963db69790e590bd9433 Mon Sep 17 00:00:00 2001 From: James Coglan Date: Tue, 15 Oct 2019 23:47:48 +0000 Subject: [PATCH 015/953] graph: handle line padding in `graph_next_line()` Now that the display width of graph lines is implicitly tracked via the `graph_line` interface, the calls to `graph_pad_horizontally()` no longer need to be located inside the individual output functions, where the character counting was previously being done. All the functions called by `graph_next_line()` generate a line of output, then call `graph_pad_horizontally()`, and finally change the graph state if necessary. As padding is the final change to the output done by all these functions, it can be removed from all of them and done in `graph_next_line()` instead. I've also moved the guard in `graph_output_padding_line()` that checks the graph has a commit; this function is only called by `graph_next_line()` and we must not pad the `graph_line` if no commit is set. Signed-off-by: James Coglan Signed-off-by: Junio C Hamano --- graph.c | 49 ++++++++++++++++++++----------------------------- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/graph.c b/graph.c index 2f81a5d23d9561..4c68557b172ea8 100644 --- a/graph.c +++ b/graph.c @@ -732,16 +732,6 @@ static void graph_output_padding_line(struct git_graph *graph, { int i; - /* - * We could conceivable be called with a NULL commit - * if our caller has a bug, and invokes graph_next_line() - * immediately after graph_init(), without first calling - * graph_update(). Return without outputting anything in this - * case. - */ - if (!graph->commit) - return; - /* * Output a padding row, that leaves all branch lines unchanged */ @@ -749,8 +739,6 @@ static void graph_output_padding_line(struct git_graph *graph, graph_line_write_column(line, &graph->new_columns[i], '|'); graph_line_addch(line, ' '); } - - graph_pad_horizontally(graph, line); } @@ -767,7 +755,6 @@ static void graph_output_skip_line(struct git_graph *graph, struct graph_line *l * of the graph is missing. */ graph_line_addstr(line, "..."); - graph_pad_horizontally(graph, line); if (graph->num_parents >= 3 && graph->commit_index < (graph->num_columns - 1)) @@ -832,8 +819,6 @@ static void graph_output_pre_commit_line(struct git_graph *graph, graph_line_addch(line, ' '); } - graph_pad_horizontally(graph, line); - /* * Increment graph->expansion_row, * and move to state GRAPH_COMMIT if necessary @@ -967,8 +952,6 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_line graph_line_addch(line, ' '); } - graph_pad_horizontally(graph, line); - /* * Update graph->state */ @@ -1043,8 +1026,6 @@ static void graph_output_post_merge_line(struct git_graph *graph, struct graph_l } } - graph_pad_horizontally(graph, line); - /* * Update graph->state */ @@ -1186,8 +1167,6 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_l } } - graph_pad_horizontally(graph, line); - /* * Swap mapping and new_mapping */ @@ -1204,31 +1183,43 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_l int graph_next_line(struct git_graph *graph, struct strbuf *sb) { + int shown_commit_line = 0; struct graph_line line = { .buf = sb, .width = 0 }; + /* + * We could conceivable be called with a NULL commit + * if our caller has a bug, and invokes graph_next_line() + * immediately after graph_init(), without first calling + * graph_update(). Return without outputting anything in this + * case. + */ + if (!graph->commit) + return -1; + switch (graph->state) { case GRAPH_PADDING: graph_output_padding_line(graph, &line); - return 0; + break; case GRAPH_SKIP: graph_output_skip_line(graph, &line); - return 0; + break; case GRAPH_PRE_COMMIT: graph_output_pre_commit_line(graph, &line); - return 0; + break; case GRAPH_COMMIT: graph_output_commit_line(graph, &line); - return 1; + shown_commit_line = 1; + break; case GRAPH_POST_MERGE: graph_output_post_merge_line(graph, &line); - return 0; + break; case GRAPH_COLLAPSING: graph_output_collapsing_line(graph, &line); - return 0; + break; } - assert(0); - return 0; + graph_pad_horizontally(graph, &line); + return shown_commit_line; } static void graph_padding_line(struct git_graph *graph, struct strbuf *sb) From 9157a2a032c4c5a154782537b6f1e2f8b7bd7435 Mon Sep 17 00:00:00 2001 From: James Coglan Date: Tue, 15 Oct 2019 23:47:49 +0000 Subject: [PATCH 016/953] graph: reuse `find_new_column_by_commit()` I will shortly be making some changes to `graph_insert_into_new_columns()` and so am trying to simplify it. One possible simplification is that we can extract the loop for finding the element in `new_columns` containing the given commit. `find_new_column_by_commit()` contains a very similar loop but it returns a `struct column *` rather than an `int` offset into the array. Here I'm introducing a version that returns `int` and using that in `graph_insert_into_new_columns()` and `graph_output_post_merge_line()`. Signed-off-by: James Coglan Signed-off-by: Junio C Hamano --- graph.c | 48 +++++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/graph.c b/graph.c index 4c68557b172ea8..c9646d9e006849 100644 --- a/graph.c +++ b/graph.c @@ -460,22 +460,31 @@ static unsigned short graph_find_commit_color(const struct git_graph *graph, return graph_get_current_column_color(graph); } +static int graph_find_new_column_by_commit(struct git_graph *graph, + struct commit *commit) +{ + int i; + for (i = 0; i < graph->num_new_columns; i++) { + if (graph->new_columns[i].commit == commit) + return i; + } + return -1; +} + static void graph_insert_into_new_columns(struct git_graph *graph, struct commit *commit, int *mapping_index) { - int i; + int i = graph_find_new_column_by_commit(graph, commit); /* * If the commit is already in the new_columns list, we don't need to * add it. Just update the mapping correctly. */ - for (i = 0; i < graph->num_new_columns; i++) { - if (graph->new_columns[i].commit == commit) { - graph->mapping[*mapping_index] = i; - *mapping_index += 2; - return; - } + if (i >= 0) { + graph->mapping[*mapping_index] = i; + *mapping_index += 2; + return; } /* @@ -963,17 +972,6 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_line graph_update_state(graph, GRAPH_COLLAPSING); } -static struct column *find_new_column_by_commit(struct git_graph *graph, - struct commit *commit) -{ - int i; - for (i = 0; i < graph->num_new_columns; i++) { - if (graph->new_columns[i].commit == commit) - return &graph->new_columns[i]; - } - return NULL; -} - static void graph_output_post_merge_line(struct git_graph *graph, struct graph_line *line) { int seen_this = 0; @@ -1001,20 +999,20 @@ static void graph_output_post_merge_line(struct git_graph *graph, struct graph_l * edges. */ struct commit_list *parents = NULL; - struct column *par_column; + int par_column; seen_this = 1; parents = first_interesting_parent(graph); assert(parents); - par_column = find_new_column_by_commit(graph, parents->item); - assert(par_column); + par_column = graph_find_new_column_by_commit(graph, parents->item); + assert(par_column >= 0); - graph_line_write_column(line, par_column, '|'); + graph_line_write_column(line, &graph->new_columns[par_column], '|'); for (j = 0; j < graph->num_parents - 1; j++) { parents = next_interesting_parent(graph, parents); assert(parents); - par_column = find_new_column_by_commit(graph, parents->item); - assert(par_column); - graph_line_write_column(line, par_column, '\\'); + par_column = graph_find_new_column_by_commit(graph, parents->item); + assert(par_column >= 0); + graph_line_write_column(line, &graph->new_columns[par_column], '\\'); graph_line_addch(line, ' '); } } else if (seen_this) { From a551fd5efd7b82604c3254e3f7cac08eaaa97ba9 Mon Sep 17 00:00:00 2001 From: James Coglan Date: Tue, 15 Oct 2019 23:47:50 +0000 Subject: [PATCH 017/953] graph: reduce duplication in `graph_insert_into_new_columns()` I will shortly be making some changes to this function and so am trying to simplify it. It currently contains some duplicated logic; both branches the function can take assign the commit's column index into the `mapping` array and increment `mapping_index`. Here I change the function so that the only conditional behaviour is that it appends the commit to `new_columns` if it's not present. All manipulation of `mapping` now happens on a single code path. Signed-off-by: James Coglan Signed-off-by: Junio C Hamano --- graph.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/graph.c b/graph.c index c9646d9e006849..512ae16535b6c2 100644 --- a/graph.c +++ b/graph.c @@ -478,23 +478,17 @@ static void graph_insert_into_new_columns(struct git_graph *graph, int i = graph_find_new_column_by_commit(graph, commit); /* - * If the commit is already in the new_columns list, we don't need to - * add it. Just update the mapping correctly. + * If the commit is not already in the new_columns array, then add it + * and record it as being in the final column. */ - if (i >= 0) { - graph->mapping[*mapping_index] = i; - *mapping_index += 2; - return; + if (i < 0) { + i = graph->num_new_columns++; + graph->new_columns[i].commit = commit; + graph->new_columns[i].color = graph_find_commit_color(graph, commit); } - /* - * This commit isn't already in new_columns. Add it. - */ - graph->new_columns[graph->num_new_columns].commit = commit; - graph->new_columns[graph->num_new_columns].color = graph_find_commit_color(graph, commit); - graph->mapping[*mapping_index] = graph->num_new_columns; + graph->mapping[*mapping_index] = i; *mapping_index += 2; - graph->num_new_columns++; } static void graph_update_width(struct git_graph *graph, From 46ba2abdfa95a26a86714dab386a72a3a5b706a5 Mon Sep 17 00:00:00 2001 From: James Coglan Date: Tue, 15 Oct 2019 23:47:51 +0000 Subject: [PATCH 018/953] graph: remove `mapping_idx` and `graph_update_width()` There's a duplication of logic between `graph_insert_into_new_columns()` and `graph_update_width()`. `graph_insert_into_new_columns()` is called repeatedly by `graph_update_columns()` with an `int *` that tracks the offset into the `mapping` array where we should write the next value. Each call to `graph_insert_into_new_columns()` effectively pushes one column index and one "null" value (-1) onto the `mapping` array and therefore increments `mapping_idx` by 2. `graph_update_width()` duplicates this process: the `width` of the graph is essentially the initial width of the `mapping` array before edges begin collapsing. The `graph_update_width()` function's logic effectively works out how many times `graph_insert_into_new_columns()` was called based on the relationship of the current commit to the rest of the graph. I'm about to make some changes that make the assignment of values into the `mapping` array more complicated. Rather than make `graph_update_width()` more complicated at the same time, we can simply remove this function and use `graph->width` to track the offset into the `mapping` array as we're building it. This removes the duplication and makes sure that `graph->width` is the same as the visual width of the `mapping` array once `graph_update_columns()` is complete. Signed-off-by: James Coglan Signed-off-by: Junio C Hamano --- graph.c | 65 +++++++++------------------------------------------------ 1 file changed, 10 insertions(+), 55 deletions(-) diff --git a/graph.c b/graph.c index 512ae16535b6c2..d724ef25c304ef 100644 --- a/graph.c +++ b/graph.c @@ -472,8 +472,7 @@ static int graph_find_new_column_by_commit(struct git_graph *graph, } static void graph_insert_into_new_columns(struct git_graph *graph, - struct commit *commit, - int *mapping_index) + struct commit *commit) { int i = graph_find_new_column_by_commit(graph, commit); @@ -487,50 +486,14 @@ static void graph_insert_into_new_columns(struct git_graph *graph, graph->new_columns[i].color = graph_find_commit_color(graph, commit); } - graph->mapping[*mapping_index] = i; - *mapping_index += 2; -} - -static void graph_update_width(struct git_graph *graph, - int is_commit_in_existing_columns) -{ - /* - * Compute the width needed to display the graph for this commit. - * This is the maximum width needed for any row. All other rows - * will be padded to this width. - * - * Compute the number of columns in the widest row: - * Count each existing column (graph->num_columns), and each new - * column added by this commit. - */ - int max_cols = graph->num_columns + graph->num_parents; - - /* - * Even if the current commit has no parents to be printed, it - * still takes up a column for itself. - */ - if (graph->num_parents < 1) - max_cols++; - - /* - * We added a column for the current commit as part of - * graph->num_parents. If the current commit was already in - * graph->columns, then we have double counted it. - */ - if (is_commit_in_existing_columns) - max_cols--; - - /* - * Each column takes up 2 spaces - */ - graph->width = max_cols * 2; + graph->mapping[graph->width] = i; + graph->width += 2; } static void graph_update_columns(struct git_graph *graph) { struct commit_list *parent; int max_new_columns; - int mapping_idx; int i, seen_this, is_commit_in_columns; /* @@ -563,6 +526,8 @@ static void graph_update_columns(struct git_graph *graph) for (i = 0; i < graph->mapping_size; i++) graph->mapping[i] = -1; + graph->width = 0; + /* * Populate graph->new_columns and graph->mapping * @@ -573,7 +538,6 @@ static void graph_update_columns(struct git_graph *graph) * supposed to end up after the collapsing is performed. */ seen_this = 0; - mapping_idx = 0; is_commit_in_columns = 1; for (i = 0; i <= graph->num_columns; i++) { struct commit *col_commit; @@ -587,7 +551,6 @@ static void graph_update_columns(struct git_graph *graph) } if (col_commit == graph->commit) { - int old_mapping_idx = mapping_idx; seen_this = 1; graph->commit_index = i; for (parent = first_interesting_parent(graph); @@ -602,21 +565,18 @@ static void graph_update_columns(struct git_graph *graph) !is_commit_in_columns) { graph_increment_column_color(graph); } - graph_insert_into_new_columns(graph, - parent->item, - &mapping_idx); + graph_insert_into_new_columns(graph, parent->item); } /* - * We always need to increment mapping_idx by at + * We always need to increment graph->width by at * least 2, even if it has no interesting parents. * The current commit always takes up at least 2 * spaces. */ - if (mapping_idx == old_mapping_idx) - mapping_idx += 2; + if (graph->num_parents == 0) + graph->width += 2; } else { - graph_insert_into_new_columns(graph, col_commit, - &mapping_idx); + graph_insert_into_new_columns(graph, col_commit); } } @@ -626,11 +586,6 @@ static void graph_update_columns(struct git_graph *graph) while (graph->mapping_size > 1 && graph->mapping[graph->mapping_size - 1] < 0) graph->mapping_size--; - - /* - * Compute graph->width for this commit - */ - graph_update_width(graph, is_commit_in_columns); } void graph_update(struct git_graph *graph, struct commit *commit) From ee7abb5ffaaba8c3fc5f89765609f30d638f63f7 Mon Sep 17 00:00:00 2001 From: James Coglan Date: Tue, 15 Oct 2019 23:47:52 +0000 Subject: [PATCH 019/953] graph: extract logic for moving to GRAPH_PRE_COMMIT state This computation is repeated in a couple of places and I need to add another condition to it to implement a further improvement to the graph rendering, so I'm extracting this into a function. Signed-off-by: James Coglan Signed-off-by: Junio C Hamano --- graph.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/graph.c b/graph.c index d724ef25c304ef..bd7403065ea240 100644 --- a/graph.c +++ b/graph.c @@ -588,6 +588,12 @@ static void graph_update_columns(struct git_graph *graph) graph->mapping_size--; } +static int graph_needs_pre_commit_line(struct git_graph *graph) +{ + return graph->num_parents >= 3 && + graph->commit_index < (graph->num_columns - 1); +} + void graph_update(struct git_graph *graph, struct commit *commit) { struct commit_list *parent; @@ -643,8 +649,7 @@ void graph_update(struct git_graph *graph, struct commit *commit) */ if (graph->state != GRAPH_PADDING) graph->state = GRAPH_SKIP; - else if (graph->num_parents >= 3 && - graph->commit_index < (graph->num_columns - 1)) + else if (graph_needs_pre_commit_line(graph)) graph->state = GRAPH_PRE_COMMIT; else graph->state = GRAPH_COMMIT; @@ -714,8 +719,7 @@ static void graph_output_skip_line(struct git_graph *graph, struct graph_line *l */ graph_line_addstr(line, "..."); - if (graph->num_parents >= 3 && - graph->commit_index < (graph->num_columns - 1)) + if (graph_needs_pre_commit_line(graph)) graph_update_state(graph, GRAPH_PRE_COMMIT); else graph_update_state(graph, GRAPH_COMMIT); From 458152cce1a5544079456675a9cb7df00704c272 Mon Sep 17 00:00:00 2001 From: James Coglan Date: Tue, 15 Oct 2019 23:47:53 +0000 Subject: [PATCH 020/953] graph: example of graph output that can be simplified The commits following this one introduce a series of improvements to the layout of graphs, tidying up a few edge cases, namely: - merge whose first parent fuses with an existing column to the left - merge whose last parent fuses with its immediate neighbor on the right - edges that collapse to the left above and below a commit line This test case exemplifies these cases and provides a motivating example of the kind of history I'm aiming to clear up. The first parent of merge E is the same as the parent of H, so those edges fuse together. * H | | *-. E | |\ \ |/ / / | * B We can "skew" the display of this merge so that it doesn't introduce additional columns that immediately collapse: * H | | * E |/|\ | * B The last parent of E is D, the same as the parent of F which is the edge to the right of the merge. * F | \ *-. \ E |\ \ \ / / / / | / |/ * D The two edges leading to D could be fused sooner: rather than expanding the F edge around the merge and then letting the edges collapse, the F edge could fuse with the E edge in the post-merge line: * F | \ *-. | E |\ \| / / / | * D If this is combined with the "skew" effect above, we get a much cleaner graph display for these edges: * F | * | E /|\| | * D Finally, the edge leading from C to A appears jagged as it passes through the commit line for B: | * | C | |/ * | B |/ * A This can be smoothed out so that such edges are easier to read: | * | C | |/ * / B |/ * A Signed-off-by: James Coglan Signed-off-by: Junio C Hamano --- t/t4215-log-skewed-merges.sh | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 t/t4215-log-skewed-merges.sh diff --git a/t/t4215-log-skewed-merges.sh b/t/t4215-log-skewed-merges.sh new file mode 100755 index 00000000000000..4582ba066af1e6 --- /dev/null +++ b/t/t4215-log-skewed-merges.sh @@ -0,0 +1,43 @@ +#!/bin/sh + +test_description='git log --graph of skewed merges' + +. ./test-lib.sh + +test_expect_success 'log --graph with merge fusing with its left and right neighbors' ' + cat >expect <<-\EOF && + * H + |\ + | * G + | |\ + | | * F + | | | + | | \ + | *-. \ E + | |\ \ \ + |/ / / / + | | | / + | | |/ + | | * D + | * | C + | |/ + * | B + |/ + * A + EOF + + git checkout --orphan _p && + test_commit A && + test_commit B && + git checkout -b _q @^ && test_commit C && + git checkout -b _r @^ && test_commit D && + git checkout _p && git merge --no-ff _q _r -m E && + git checkout _r && test_commit F && + git checkout _p && git merge --no-ff _r -m G && + git checkout @^^ && git merge --no-ff _p -m H && + + git log --graph --pretty=tformat:%s | sed "s/ *$//" >actual && + test_cmp expect actual +' + +test_done From 0f0f389f12029b1c3745f8ed7aacfe6b2fc7a6cc Mon Sep 17 00:00:00 2001 From: James Coglan Date: Tue, 15 Oct 2019 23:47:54 +0000 Subject: [PATCH 021/953] graph: tidy up display of left-skewed merges Currently, when we display a merge whose first parent is already present in a column to the left of the merge commit, we display the first parent as a vertical pipe `|` in the GRAPH_POST_MERGE line and then immediately enter the GRAPH_COLLAPSING state. The first-parent line tracks to the left and all the other parent lines follow it; this creates a "kink" in those lines: | *---. | |\ \ \ |/ / / / | | | * This change tidies the display of such commits such that if the first parent appears to the left of the merge, we render it as a `/` and the second parent as a `|`. This reduces the horizontal and vertical space needed to render the merge, and makes the resulting lines easier to read. | *-. |/|\ \ | | | * If the first parent is separated from the merge by several columns, a horizontal line is drawn in a similar manner to how the GRAPH_COLLAPSING state displays the line. | | | *-. | |_|/|\ \ |/| | | | * This effect is applied to both "normal" two-parent merges, and to octopus merges. It also reduces the vertical space needed for pre-commit lines, as the merge occupies one less column than usual. Before: After: | * | * | |\ | |\ | | \ | * \ | | \ |/|\ \ | *-. \ | |\ \ \ Signed-off-by: James Coglan Signed-off-by: Junio C Hamano --- graph.c | 125 +++++++++++++++++++++++++++-------- t/t4214-log-graph-octopus.sh | 20 +++--- t/t4215-log-skewed-merges.sh | 45 +++++++++++-- 3 files changed, 144 insertions(+), 46 deletions(-) diff --git a/graph.c b/graph.c index bd7403065ea240..e37127f5ab5719 100644 --- a/graph.c +++ b/graph.c @@ -202,6 +202,20 @@ struct git_graph { * previous commit. */ int prev_commit_index; + /* + * Which layout variant to use to display merge commits. If the + * commit's first parent is known to be in a column to the left of the + * merge, then this value is 0 and we use the layout on the left. + * Otherwise, the value is 1 and the layout on the right is used. This + * field tells us how many columns the first parent occupies. + * + * 0) 1) + * + * | | | *-. | | *---. + * | |_|/|\ \ | | |\ \ \ + * |/| | | | | | | | | | * + */ + int merge_layout; /* * The maximum number of columns that can be stored in the columns * and new_columns arrays. This is also half the number of entries @@ -313,6 +327,7 @@ struct git_graph *graph_init(struct rev_info *opt) graph->prev_state = GRAPH_PADDING; graph->commit_index = 0; graph->prev_commit_index = 0; + graph->merge_layout = 0; graph->num_columns = 0; graph->num_new_columns = 0; graph->mapping_size = 0; @@ -472,9 +487,11 @@ static int graph_find_new_column_by_commit(struct git_graph *graph, } static void graph_insert_into_new_columns(struct git_graph *graph, - struct commit *commit) + struct commit *commit, + int idx) { int i = graph_find_new_column_by_commit(graph, commit); + int mapping_idx; /* * If the commit is not already in the new_columns array, then add it @@ -486,8 +503,26 @@ static void graph_insert_into_new_columns(struct git_graph *graph, graph->new_columns[i].color = graph_find_commit_color(graph, commit); } - graph->mapping[graph->width] = i; - graph->width += 2; + if (graph->num_parents > 1 && idx > -1 && graph->merge_layout == -1) { + /* + * If this is the first parent of a merge, choose a layout for + * the merge line based on whether the parent appears in a + * column to the left of the merge + */ + int dist, shift; + + dist = idx - i; + shift = (dist > 1) ? 2 * dist - 3 : 1; + + graph->merge_layout = (dist > 0) ? 0 : 1; + mapping_idx = graph->width + (graph->merge_layout - 1) * shift; + graph->width += 2 * graph->merge_layout; + } else { + mapping_idx = graph->width; + graph->width += 2; + } + + graph->mapping[mapping_idx] = i; } static void graph_update_columns(struct git_graph *graph) @@ -553,6 +588,7 @@ static void graph_update_columns(struct git_graph *graph) if (col_commit == graph->commit) { seen_this = 1; graph->commit_index = i; + graph->merge_layout = -1; for (parent = first_interesting_parent(graph); parent; parent = next_interesting_parent(graph, parent)) { @@ -565,7 +601,7 @@ static void graph_update_columns(struct git_graph *graph) !is_commit_in_columns) { graph_increment_column_color(graph); } - graph_insert_into_new_columns(graph, parent->item); + graph_insert_into_new_columns(graph, parent->item, i); } /* * We always need to increment graph->width by at @@ -576,7 +612,7 @@ static void graph_update_columns(struct git_graph *graph) if (graph->num_parents == 0) graph->width += 2; } else { - graph_insert_into_new_columns(graph, col_commit); + graph_insert_into_new_columns(graph, col_commit, -1); } } @@ -588,10 +624,36 @@ static void graph_update_columns(struct git_graph *graph) graph->mapping_size--; } +static int graph_num_expansion_rows(struct git_graph *graph) +{ + /* + * Normally, we need two expansion rows for each dashed parent line from + * an octopus merge: + * + * | * + * | |\ + * | | \ + * | | \ + * | *-. \ + * | |\ \ \ + * + * If the merge is skewed to the left, then its parents occupy one less + * column, and we don't need as many expansion rows to route around it; + * in some cases that means we don't need any expansion rows at all: + * + * | * + * | |\ + * | * \ + * |/|\ \ + */ + return (graph->num_parents + graph->merge_layout - 3) * 2; +} + static int graph_needs_pre_commit_line(struct git_graph *graph) { return graph->num_parents >= 3 && - graph->commit_index < (graph->num_columns - 1); + graph->commit_index < (graph->num_columns - 1) && + graph->expansion_row < graph_num_expansion_rows(graph); } void graph_update(struct git_graph *graph, struct commit *commit) @@ -728,7 +790,6 @@ static void graph_output_skip_line(struct git_graph *graph, struct graph_line *l static void graph_output_pre_commit_line(struct git_graph *graph, struct graph_line *line) { - int num_expansion_rows; int i, seen_this; /* @@ -739,14 +800,13 @@ static void graph_output_pre_commit_line(struct git_graph *graph, * We need 2 extra rows for every parent over 2. */ assert(graph->num_parents >= 3); - num_expansion_rows = (graph->num_parents - 2) * 2; /* * graph->expansion_row tracks the current expansion row we are on. * It should be in the range [0, num_expansion_rows - 1] */ assert(0 <= graph->expansion_row && - graph->expansion_row < num_expansion_rows); + graph->expansion_row < graph_num_expansion_rows(graph)); /* * Output the row @@ -786,7 +846,7 @@ static void graph_output_pre_commit_line(struct git_graph *graph, * and move to state GRAPH_COMMIT if necessary */ graph->expansion_row++; - if (graph->expansion_row >= num_expansion_rows) + if (!graph_needs_pre_commit_line(graph)) graph_update_state(graph, GRAPH_COMMIT); } @@ -824,7 +884,7 @@ static void graph_draw_octopus_merge(struct git_graph *graph, struct graph_line * x 0 1 2 3 * */ - const int dashless_parents = 2; + const int dashless_parents = 3 - graph->merge_layout; int dashful_parents = graph->num_parents - dashless_parents; /* @@ -832,9 +892,9 @@ static void graph_draw_octopus_merge(struct git_graph *graph, struct graph_line * above) but sometimes the first parent goes into an existing column, * like this: * - * | *---. - * | |\ \ \ - * |/ / / / + * | *-. + * |/|\ \ + * | | | | * x 0 1 2 * * In which case the number of parents will be one greater than the @@ -925,10 +985,15 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_line graph_update_state(graph, GRAPH_COLLAPSING); } +const char merge_chars[] = {'/', '|', '\\'}; + static void graph_output_post_merge_line(struct git_graph *graph, struct graph_line *line) { int seen_this = 0; - int i, j; + int i; + + struct commit_list *first_parent = first_interesting_parent(graph); + int seen_parent = 0; /* * Output the post-merge row @@ -951,30 +1016,34 @@ static void graph_output_post_merge_line(struct git_graph *graph, struct graph_l * new_columns and use those to format the * edges. */ - struct commit_list *parents = NULL; + struct commit_list *parents = first_parent; int par_column; + int idx = graph->merge_layout; + char c; seen_this = 1; - parents = first_interesting_parent(graph); - assert(parents); - par_column = graph_find_new_column_by_commit(graph, parents->item); - assert(par_column >= 0); - - graph_line_write_column(line, &graph->new_columns[par_column], '|'); - for (j = 0; j < graph->num_parents - 1; j++) { - parents = next_interesting_parent(graph, parents); - assert(parents); + + for (; parents; parents = next_interesting_parent(graph, parents)) { par_column = graph_find_new_column_by_commit(graph, parents->item); assert(par_column >= 0); - graph_line_write_column(line, &graph->new_columns[par_column], '\\'); - graph_line_addch(line, ' '); + + c = merge_chars[idx]; + graph_line_write_column(line, &graph->new_columns[par_column], c); + if (idx == 2) + graph_line_addch(line, ' '); + else + idx++; } } else if (seen_this) { graph_line_write_column(line, col, '\\'); graph_line_addch(line, ' '); } else { graph_line_write_column(line, col, '|'); - graph_line_addch(line, ' '); + if (graph->merge_layout != 0 || i != graph->commit_index - 1) + graph_line_addch(line, seen_parent ? '_' : ' '); } + + if (col_commit == first_parent->item) + seen_parent = 1; } /* diff --git a/t/t4214-log-graph-octopus.sh b/t/t4214-log-graph-octopus.sh index 3ae8e51e500269..1b96276894ab51 100755 --- a/t/t4214-log-graph-octopus.sh +++ b/t/t4214-log-graph-octopus.sh @@ -26,9 +26,8 @@ test_expect_success 'set up merge history' ' test_expect_success 'log --graph with tricky octopus merge, no color' ' cat >expect.uncolored <<-\EOF && * left - | *---. octopus-merge - | |\ \ \ - |/ / / / + | *-. octopus-merge + |/|\ \ | | | * 4 | | * | 3 | | |/ @@ -47,9 +46,8 @@ test_expect_success 'log --graph with tricky octopus merge with colors' ' test_config log.graphColors red,green,yellow,blue,magenta,cyan && cat >expect.colors <<-\EOF && * left - | *---. octopus-merge - | |\ \ \ - |/ / / / + | *-. octopus-merge + |/|\ \ | | | * 4 | | * | 3 | | |/ @@ -147,9 +145,8 @@ test_expect_success 'log --graph with tricky octopus merge and its child, no col cat >expect.uncolored <<-\EOF && * left | * after-merge - | *---. octopus-merge - | |\ \ \ - |/ / / / + | *-. octopus-merge + |/|\ \ | | | * 4 | | * | 3 | | |/ @@ -169,9 +166,8 @@ test_expect_failure 'log --graph with tricky octopus merge and its child with co cat >expect.colors <<-\EOF && * left | * after-merge - | *---. octopus-merge - | |\ \ \ - |/ / / / + | *-. octopus-merge + |/|\ \ | | | * 4 | | * | 3 | | |/ diff --git a/t/t4215-log-skewed-merges.sh b/t/t4215-log-skewed-merges.sh index 4582ba066af1e6..dc187b5caf8e90 100755 --- a/t/t4215-log-skewed-merges.sh +++ b/t/t4215-log-skewed-merges.sh @@ -11,12 +11,8 @@ test_expect_success 'log --graph with merge fusing with its left and right neigh | * G | |\ | | * F - | | | - | | \ - | *-. \ E - | |\ \ \ - |/ / / / - | | | / + | * \ E + |/|\ \ | | |/ | | * D | * | C @@ -40,4 +36,41 @@ test_expect_success 'log --graph with merge fusing with its left and right neigh test_cmp expect actual ' +test_expect_success 'log --graph with left-skewed merge' ' + cat >expect <<-\EOF && + *-----. 0_H + |\ \ \ \ + | | | | * 0_G + | |_|_|/| + |/| | | | + | | | * \ 0_F + | |_|/|\ \ + |/| | | |/ + | | | | * 0_E + | |_|_|/ + |/| | | + | | * | 0_D + | | |/ + | | * 0_C + | |/ + |/| + | * 0_B + |/ + * 0_A + EOF + + git checkout --orphan 0_p && test_commit 0_A && + git checkout -b 0_q 0_p && test_commit 0_B && + git checkout -b 0_r 0_p && + test_commit 0_C && + test_commit 0_D && + git checkout -b 0_s 0_p && test_commit 0_E && + git checkout -b 0_t 0_p && git merge --no-ff 0_r^ 0_s -m 0_F && + git checkout 0_p && git merge --no-ff 0_s -m 0_G && + git checkout @^ && git merge --no-ff 0_q 0_r 0_t 0_p -m 0_H && + + git log --graph --pretty=tformat:%s | sed "s/ *$//" >actual && + test_cmp expect actual +' + test_done From d62893ecc125767d44a194279bcaffa0d02d2572 Mon Sep 17 00:00:00 2001 From: James Coglan Date: Tue, 15 Oct 2019 23:47:55 +0000 Subject: [PATCH 022/953] graph: commit and post-merge lines for left-skewed merges Following the introduction of "left-skewed" merges, which are merges whose first parent fuses with another edge to its left, we have some more edge cases to deal with in the display of commit and post-merge lines. The current graph code handles the following cases for edges appearing to the right of the commit (*) on commit lines. A 2-way merge is usually followed by vertical lines: | | | | * | | |\ \ An octopus merge (more than two parents) is always followed by edges sloping to the right: | | \ | | \ | *-. \ | *---. \ | |\ \ \ | |\ \ \ \ A 2-way merge is followed by a right-sloping edge if the commit line immediately follows a post-merge line for a commit that appears in the same column as the current commit, or any column to the left of that: | * | * | | |\ | |\ \ | * \ | | * \ | |\ \ | | |\ \ This commit introduces the following new cases for commit lines. If a 2-way merge skews to the left, then the edges to its right are always vertical lines, even if the commit follows a post-merge line: | | | | |\ | * | | * | |/| | |/| | A commit with 3 parents that skews left is followed by vertical edges: | | | | * | |/|\ \ If a 3-way left-skewed merge commit appears immediately after a post-merge line, then it may be followed the right-sloping edges, just like a 2-way merge that is not skewed. | |\ | * \ |/|\ \ Octopus merges with 4 or more parents that skew to the left will always be followed by right-sloping edges, because the existing columns need to expand around the merge. | | \ | *-. \ |/|\ \ \ On post-merge lines, usually all edges following the current commit slope to the right: | * | | | |\ \ \ However, if the commit is a left-skewed 2-way merge, the edges to its right remain vertical. We also need to display a space after the vertical line descending from the commit marker, whereas this line would normally be followed by a backslash. | * | | |/| | | If a left-skewed merge has more than 2 parents, then the edges to its right are still sloped as they bend around the edges introduced by the merge. | * | | |/|\ \ \ To handle these new cases, we need to know not just how many parents each commit has, but how many new columns it adds to the display; this quantity is recorded in the `edges_added` field for the current commit, and `prev_edges_added` field for the previous commit. Here, "column" refers to visual columns, not the logical columns of the `columns` array. This is because even if all the commit's parents end up fusing with existing edges, they initially introduce distinct edges in the commit and post-merge lines before those edges collapse. For example, a 3-way merge whose 2nd and 3rd parents fuse with existing edges still introduces 2 visual columns that affect the display of edges to their right. | | | \ | | *-. \ | | |\ \ \ | |_|/ / / |/| | / / | | |/ / | |/| | | | | | This merge does not introduce any *logical* columns; there are 4 edges before and after this commit once all edges have collapsed. But it does initially introduce 2 new edges that need to be accommodated by the edges to their right. Signed-off-by: James Coglan Signed-off-by: Junio C Hamano --- graph.c | 63 +++++++++++++-- t/t4215-log-skewed-merges.sh | 147 ++++++++++++++++++++++++++++++++++- 2 files changed, 203 insertions(+), 7 deletions(-) diff --git a/graph.c b/graph.c index e37127f5ab5719..21edad808571a1 100644 --- a/graph.c +++ b/graph.c @@ -216,6 +216,46 @@ struct git_graph { * |/| | | | | | | | | | * */ int merge_layout; + /* + * The number of columns added to the graph by the current commit. For + * 2-way and octopus merges, this is is usually one less than the + * number of parents: + * + * | | | | | \ + * | * | | *---. \ + * | |\ \ | |\ \ \ \ + * | | | | | | | | | | + * + * num_parents: 2 num_parents: 4 + * edges_added: 1 edges_added: 3 + * + * For left-skewed merges, the first parent fuses with its neighbor and + * so one less column is added: + * + * | | | | | \ + * | * | | *-. \ + * |/| | |/|\ \ \ + * | | | | | | | | + * + * num_parents: 2 num_parents: 4 + * edges_added: 0 edges_added: 2 + * + * This number determines how edges to the right of the merge are + * displayed in commit and post-merge lines; if no columns have been + * added then a vertical line should be used where a right-tracking + * line would otherwise be used. + * + * | * \ | * | + * | |\ \ |/| | + * | | * \ | * | + */ + int edges_added; + /* + * The number of columns added by the previous commit, which is used to + * smooth edges appearing to the right of a commit in a commit line + * following a post-merge line. + */ + int prev_edges_added; /* * The maximum number of columns that can be stored in the columns * and new_columns arrays. This is also half the number of entries @@ -328,6 +368,8 @@ struct git_graph *graph_init(struct rev_info *opt) graph->commit_index = 0; graph->prev_commit_index = 0; graph->merge_layout = 0; + graph->edges_added = 0; + graph->prev_edges_added = 0; graph->num_columns = 0; graph->num_new_columns = 0; graph->mapping_size = 0; @@ -689,6 +731,9 @@ void graph_update(struct git_graph *graph, struct commit *commit) */ graph_update_columns(graph); + graph->prev_edges_added = graph->edges_added; + graph->edges_added = graph->num_parents + graph->merge_layout - 2; + graph->expansion_row = 0; /* @@ -947,12 +992,13 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_line if (graph->num_parents > 2) graph_draw_octopus_merge(graph, line); - } else if (seen_this && (graph->num_parents > 2)) { + } else if (seen_this && (graph->edges_added > 1)) { graph_line_write_column(line, col, '\\'); - } else if (seen_this && (graph->num_parents == 2)) { + } else if (seen_this && (graph->edges_added == 1)) { /* - * This is a 2-way merge commit. - * There is no GRAPH_PRE_COMMIT stage for 2-way + * This is either a right-skewed 2-way merge + * commit, or a left-skewed 3-way merge. + * There is no GRAPH_PRE_COMMIT stage for such * merges, so this is the first line of output * for this commit. Check to see what the previous * line of output was. @@ -964,6 +1010,7 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_line * makes the output look nicer. */ if (graph->prev_state == GRAPH_POST_MERGE && + graph->prev_edges_added > 0 && graph->prev_commit_index < i) graph_line_write_column(line, col, '\\'); else @@ -1033,8 +1080,14 @@ static void graph_output_post_merge_line(struct git_graph *graph, struct graph_l else idx++; } + if (graph->edges_added == 0) + graph_line_addch(line, ' '); + } else if (seen_this) { - graph_line_write_column(line, col, '\\'); + if (graph->edges_added > 0) + graph_line_write_column(line, col, '\\'); + else + graph_line_write_column(line, col, '|'); graph_line_addch(line, ' '); } else { graph_line_write_column(line, col, '|'); diff --git a/t/t4215-log-skewed-merges.sh b/t/t4215-log-skewed-merges.sh index dc187b5caf8e90..e673cdb6f7078f 100755 --- a/t/t4215-log-skewed-merges.sh +++ b/t/t4215-log-skewed-merges.sh @@ -11,7 +11,7 @@ test_expect_success 'log --graph with merge fusing with its left and right neigh | * G | |\ | | * F - | * \ E + | * | E |/|\ \ | | |/ | | * D @@ -43,7 +43,7 @@ test_expect_success 'log --graph with left-skewed merge' ' | | | | * 0_G | |_|_|/| |/| | | | - | | | * \ 0_F + | | | * | 0_F | |_|/|\ \ |/| | | |/ | | | | * 0_E @@ -73,4 +73,147 @@ test_expect_success 'log --graph with left-skewed merge' ' test_cmp expect actual ' +test_expect_success 'log --graph with nested left-skewed merge' ' + cat >expect <<-\EOF && + * 1_H + |\ + | * 1_G + | |\ + | | * 1_F + | * | 1_E + |/| | + | * | 1_D + * | | 1_C + |/ / + * | 1_B + |/ + * 1_A + EOF + + git checkout --orphan 1_p && + test_commit 1_A && + test_commit 1_B && + test_commit 1_C && + git checkout -b 1_q @^ && test_commit 1_D && + git checkout 1_p && git merge --no-ff 1_q -m 1_E && + git checkout -b 1_r @~3 && test_commit 1_F && + git checkout 1_p && git merge --no-ff 1_r -m 1_G && + git checkout @^^ && git merge --no-ff 1_p -m 1_H && + + git log --graph --pretty=tformat:%s | sed "s/ *$//" >actual && + test_cmp expect actual +' + +test_expect_success 'log --graph with nested left-skewed merge following normal merge' ' + cat >expect <<-\EOF && + * 2_K + |\ + | * 2_J + | |\ + | | * 2_H + | | |\ + | | * | 2_G + | |/| | + | | * | 2_F + | * | | 2_E + | |/ / + | * | 2_D + * | | 2_C + | |/ + |/| + * | 2_B + |/ + * 2_A + EOF + + git checkout --orphan 2_p && + test_commit 2_A && + test_commit 2_B && + test_commit 2_C && + git checkout -b 2_q @^^ && + test_commit 2_D && + test_commit 2_E && + git checkout -b 2_r @^ && test_commit 2_F && + git checkout 2_q && + git merge --no-ff 2_r -m 2_G && + git merge --no-ff 2_p^ -m 2_H && + git checkout -b 2_s @^^ && git merge --no-ff 2_q -m 2_J && + git checkout 2_p && git merge --no-ff 2_s -m 2_K && + + git log --graph --pretty=tformat:%s | sed "s/ *$//" >actual && + test_cmp expect actual +' + +test_expect_success 'log --graph with nested right-skewed merge following left-skewed merge' ' + cat >expect <<-\EOF && + * 3_J + |\ + | * 3_H + | |\ + | | * 3_G + | * | 3_F + |/| | + | * | 3_E + | |\ \ + | | |/ + | | * 3_D + | * | 3_C + | |/ + | * 3_B + |/ + * 3_A + EOF + + git checkout --orphan 3_p && + test_commit 3_A && + git checkout -b 3_q && + test_commit 3_B && + test_commit 3_C && + git checkout -b 3_r @^ && + test_commit 3_D && + git checkout 3_q && git merge --no-ff 3_r -m 3_E && + git checkout 3_p && git merge --no-ff 3_q -m 3_F && + git checkout 3_r && test_commit 3_G && + git checkout 3_p && git merge --no-ff 3_r -m 3_H && + git checkout @^^ && git merge --no-ff 3_p -m 3_J && + + git log --graph --pretty=tformat:%s | sed "s/ *$//" >actual && + test_cmp expect actual +' + +test_expect_success 'log --graph with right-skewed merge following a left-skewed one' ' + cat >expect <<-\EOF && + * 4_H + |\ + | * 4_G + | |\ + | * | 4_F + |/| | + | * | 4_E + | |\ \ + | | * | 4_D + | |/ / + |/| | + | | * 4_C + | |/ + | * 4_B + |/ + * 4_A + EOF + + git checkout --orphan 4_p && + test_commit 4_A && + test_commit 4_B && + test_commit 4_C && + git checkout -b 4_q @^^ && test_commit 4_D && + git checkout -b 4_r 4_p^ && git merge --no-ff 4_q -m 4_E && + git checkout -b 4_s 4_p^^ && + git merge --no-ff 4_r -m 4_F && + git merge --no-ff 4_p -m 4_G && + git checkout @^^ && git merge --no-ff 4_s -m 4_H && + + git log --graph --date-order --pretty=tformat:%s | sed "s/ *$//" >actual && + test_cmp expect actual +' + test_done From 0195285b956e1b52defa6c259253a7b888fc25df Mon Sep 17 00:00:00 2001 From: James Coglan Date: Tue, 15 Oct 2019 23:47:56 +0000 Subject: [PATCH 023/953] graph: rename `new_mapping` to `old_mapping` The change I'm about to make requires being able to inspect the mapping array that was used to render the last GRAPH_COLLAPSING line while rendering a GRAPH_COMMIT line. The `new_mapping` array currently exists as a pre-allocated space for computing the next `mapping` array during `graph_output_collapsing_line()`, but we can repurpose it to let us see the previous `mapping` state. To support this use it will make more sense if this array is named `old_mapping`, as it will contain the mapping data for the previous line we rendered, at the point we're rendering a commit line. Signed-off-by: James Coglan Signed-off-by: Junio C Hamano --- graph.c | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/graph.c b/graph.c index 21edad808571a1..2315f3604d9a22 100644 --- a/graph.c +++ b/graph.c @@ -259,7 +259,7 @@ struct git_graph { /* * The maximum number of columns that can be stored in the columns * and new_columns arrays. This is also half the number of entries - * that can be stored in the mapping and new_mapping arrays. + * that can be stored in the mapping and old_mapping arrays. */ int column_capacity; /* @@ -302,7 +302,7 @@ struct git_graph { * of the git_graph simply so we don't have to allocate a new * temporary array each time we have to output a collapsing line. */ - int *new_mapping; + int *old_mapping; /* * The current default column color being used. This is * stored as an index into the array column_colors. @@ -388,7 +388,7 @@ struct git_graph *graph_init(struct rev_info *opt) ALLOC_ARRAY(graph->columns, graph->column_capacity); ALLOC_ARRAY(graph->new_columns, graph->column_capacity); ALLOC_ARRAY(graph->mapping, 2 * graph->column_capacity); - ALLOC_ARRAY(graph->new_mapping, 2 * graph->column_capacity); + ALLOC_ARRAY(graph->old_mapping, 2 * graph->column_capacity); /* * The diff output prefix callback, with this we can make @@ -418,7 +418,7 @@ static void graph_ensure_capacity(struct git_graph *graph, int num_columns) REALLOC_ARRAY(graph->columns, graph->column_capacity); REALLOC_ARRAY(graph->new_columns, graph->column_capacity); REALLOC_ARRAY(graph->mapping, graph->column_capacity * 2); - REALLOC_ARRAY(graph->new_mapping, graph->column_capacity * 2); + REALLOC_ARRAY(graph->old_mapping, graph->column_capacity * 2); } /* @@ -1116,13 +1116,18 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_l int horizontal_edge_target = -1; /* - * Clear out the new_mapping array + * Swap the mapping and old_mapping arrays + */ + SWAP(graph->mapping, graph->old_mapping); + + /* + * Clear out the mapping array */ for (i = 0; i < graph->mapping_size; i++) - graph->new_mapping[i] = -1; + graph->mapping[i] = -1; for (i = 0; i < graph->mapping_size; i++) { - int target = graph->mapping[i]; + int target = graph->old_mapping[i]; if (target < 0) continue; @@ -1143,14 +1148,14 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_l * This column is already in the * correct place */ - assert(graph->new_mapping[i] == -1); - graph->new_mapping[i] = target; - } else if (graph->new_mapping[i - 1] < 0) { + assert(graph->mapping[i] == -1); + graph->mapping[i] = target; + } else if (graph->mapping[i - 1] < 0) { /* * Nothing is to the left. * Move to the left by one */ - graph->new_mapping[i - 1] = target; + graph->mapping[i - 1] = target; /* * If there isn't already an edge moving horizontally * select this one. @@ -1166,9 +1171,9 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_l * line. */ for (j = (target * 2)+3; j < (i - 2); j += 2) - graph->new_mapping[j] = target; + graph->mapping[j] = target; } - } else if (graph->new_mapping[i - 1] == target) { + } else if (graph->mapping[i - 1] == target) { /* * There is a branch line to our left * already, and it is our target. We @@ -1176,7 +1181,7 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_l * the same parent commit. * * We don't have to add anything to the - * output or new_mapping, since the + * output or mapping, since the * existing branch line has already taken * care of it. */ @@ -1192,10 +1197,10 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_l * The branch to the left of that space * should be our eventual target. */ - assert(graph->new_mapping[i - 1] > target); - assert(graph->new_mapping[i - 2] < 0); - assert(graph->new_mapping[i - 3] == target); - graph->new_mapping[i - 2] = target; + assert(graph->mapping[i - 1] > target); + assert(graph->mapping[i - 2] < 0); + assert(graph->mapping[i - 3] == target); + graph->mapping[i - 2] = target; /* * Mark this branch as the horizontal edge to * prevent any other edges from moving @@ -1209,14 +1214,14 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_l /* * The new mapping may be 1 smaller than the old mapping */ - if (graph->new_mapping[graph->mapping_size - 1] < 0) + if (graph->mapping[graph->mapping_size - 1] < 0) graph->mapping_size--; /* * Output out a line based on the new mapping info */ for (i = 0; i < graph->mapping_size; i++) { - int target = graph->new_mapping[i]; + int target = graph->mapping[i]; if (target < 0) graph_line_addch(line, ' '); else if (target * 2 == i) @@ -1229,22 +1234,17 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_l * won't continue into the next line. */ if (i != (target * 2)+3) - graph->new_mapping[i] = -1; + graph->mapping[i] = -1; used_horizontal = 1; graph_line_write_column(line, &graph->new_columns[target], '_'); } else { if (used_horizontal && i < horizontal_edge) - graph->new_mapping[i] = -1; + graph->mapping[i] = -1; graph_line_write_column(line, &graph->new_columns[target], '/'); } } - /* - * Swap mapping and new_mapping - */ - SWAP(graph->mapping, graph->new_mapping); - /* * If graph->mapping indicates that all of the branch lines * are already in the correct positions, we are done. From 479db18bc0c38ed610fba56f3cc98abd7977e695 Mon Sep 17 00:00:00 2001 From: James Coglan Date: Tue, 15 Oct 2019 23:47:57 +0000 Subject: [PATCH 024/953] graph: smooth appearance of collapsing edges on commit lines When a graph contains edges that are in the process of collapsing to the left, but those edges cross a commit line, the effect is that the edges have a jagged appearance: * |\ | * | \ *-. \ |\ \ \ | | * | | * | | | |/ / * | | |/ / * | |/ * We already takes steps to smooth edges like this when they're expanding; when an edge appears to the right of a merge commit marker on a GRAPH_COMMIT line immediately following a GRAPH_POST_MERGE line, we render it as a `\`: * \ |\ \ | * \ | |\ \ We can make a similar improvement to collapsing edges, making them easier to follow and giving the overall graph a feeling of increased symmetry: * |\ | * | \ *-. \ |\ \ \ | | * | | * | | | |/ / * / / |/ / * / |/ * To do this, we introduce a new special case for edges on GRAPH_COMMIT lines that immediately follow a GRAPH_COLLAPSING line. By retaining a copy of the `mapping` array used to render the GRAPH_COLLAPSING line in the `old_mapping` array, we can determine that an edge is collapsing through the GRAPH_COMMIT line and should be smoothed. Signed-off-by: James Coglan Signed-off-by: Junio C Hamano --- graph.c | 17 +++++++++--- t/t3430-rebase-merges.sh | 2 +- t/t4202-log.sh | 2 +- t/t4214-log-graph-octopus.sh | 32 +++++++++++----------- t/t4215-log-skewed-merges.sh | 4 +-- t/t6016-rev-list-graph-simplify-history.sh | 4 +-- 6 files changed, 35 insertions(+), 26 deletions(-) diff --git a/graph.c b/graph.c index 2315f3604d9a22..63f8d18baa7d7a 100644 --- a/graph.c +++ b/graph.c @@ -297,10 +297,10 @@ struct git_graph { */ int *mapping; /* - * A temporary array for computing the next mapping state - * while we are outputting a mapping line. This is stored as part - * of the git_graph simply so we don't have to allocate a new - * temporary array each time we have to output a collapsing line. + * A copy of the contents of the mapping array from the last commit, + * which we use to improve the display of columns that are tracking + * from right to left through a commit line. We also use this to + * avoid allocating a fresh array when we compute the next mapping. */ int *old_mapping; /* @@ -1015,6 +1015,10 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_line graph_line_write_column(line, col, '\\'); else graph_line_write_column(line, col, '|'); + } else if (graph->prev_state == GRAPH_COLLAPSING && + graph->old_mapping[2 * i + 1] == i && + graph->mapping[2 * i] < i) { + graph_line_write_column(line, col, '/'); } else { graph_line_write_column(line, col, '|'); } @@ -1211,6 +1215,11 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_l } } + /* + * Copy the current mapping array into old_mapping + */ + COPY_ARRAY(graph->old_mapping, graph->mapping, graph->mapping_size); + /* * The new mapping may be 1 smaller than the old mapping */ diff --git a/t/t3430-rebase-merges.sh b/t/t3430-rebase-merges.sh index 9efcf4808ac92f..a30d27e9f36685 100755 --- a/t/t3430-rebase-merges.sh +++ b/t/t3430-rebase-merges.sh @@ -408,7 +408,7 @@ test_expect_success 'octopus merges' ' | | * three | * | two | |/ - * | one + * / one |/ o before-octopus EOF diff --git a/t/t4202-log.sh b/t/t4202-log.sh index e803ba402e9e22..ab0d0213650a8b 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -667,7 +667,7 @@ cat > expect <<\EOF * | | fifth * | | fourth |/ / -* | third +* / third |/ * second * initial diff --git a/t/t4214-log-graph-octopus.sh b/t/t4214-log-graph-octopus.sh index 1b96276894ab51..21bc600a82d442 100755 --- a/t/t4214-log-graph-octopus.sh +++ b/t/t4214-log-graph-octopus.sh @@ -31,9 +31,9 @@ test_expect_success 'log --graph with tricky octopus merge, no color' ' | | | * 4 | | * | 3 | | |/ - | * | 2 + | * / 2 | |/ - * | 1 + * / 1 |/ * initial EOF @@ -51,9 +51,9 @@ test_expect_success 'log --graph with tricky octopus merge with colors' ' | | | * 4 | | * | 3 | | |/ - | * | 2 + | * / 2 | |/ - * | 1 + * / 1 |/ * initial EOF @@ -72,9 +72,9 @@ test_expect_success 'log --graph with normal octopus merge, no color' ' | | | * 4 | | * | 3 | | |/ - | * | 2 + | * / 2 | |/ - * | 1 + * / 1 |/ * initial EOF @@ -90,9 +90,9 @@ test_expect_success 'log --graph with normal octopus merge with colors' ' | | | * 4 | | * | 3 | | |/ - | * | 2 + | * / 2 | |/ - * | 1 + * / 1 |/ * initial EOF @@ -110,9 +110,9 @@ test_expect_success 'log --graph with normal octopus merge and child, no color' | | | * 4 | | * | 3 | | |/ - | * | 2 + | * / 2 | |/ - * | 1 + * / 1 |/ * initial EOF @@ -129,9 +129,9 @@ test_expect_failure 'log --graph with normal octopus and child merge with colors | | | * 4 | | * | 3 | | |/ - | * | 2 + | * / 2 | |/ - * | 1 + * / 1 |/ * initial EOF @@ -150,9 +150,9 @@ test_expect_success 'log --graph with tricky octopus merge and its child, no col | | | * 4 | | * | 3 | | |/ - | * | 2 + | * / 2 | |/ - * | 1 + * / 1 |/ * initial EOF @@ -171,9 +171,9 @@ test_expect_failure 'log --graph with tricky octopus merge and its child with co | | | * 4 | | * | 3 | | |/ - | * | 2 + | * / 2 | |/ - * | 1 + * / 1 |/ * initial EOF diff --git a/t/t4215-log-skewed-merges.sh b/t/t4215-log-skewed-merges.sh index e673cdb6f7078f..1745b3b64c4071 100755 --- a/t/t4215-log-skewed-merges.sh +++ b/t/t4215-log-skewed-merges.sh @@ -17,7 +17,7 @@ test_expect_success 'log --graph with merge fusing with its left and right neigh | | * D | * | C | |/ - * | B + * / B |/ * A EOF @@ -85,7 +85,7 @@ test_expect_success 'log --graph with nested left-skewed merge' ' | * | 1_D * | | 1_C |/ / - * | 1_B + * / 1_B |/ * 1_A EOF diff --git a/t/t6016-rev-list-graph-simplify-history.sh b/t/t6016-rev-list-graph-simplify-history.sh index f7181d1d6a143c..ca1682f29b4a56 100755 --- a/t/t6016-rev-list-graph-simplify-history.sh +++ b/t/t6016-rev-list-graph-simplify-history.sh @@ -154,7 +154,7 @@ test_expect_success '--graph --full-history -- bar.txt' ' echo "* | $A4" >> expected && echo "|\\ \\ " >> expected && echo "| |/ " >> expected && - echo "* | $A3" >> expected && + echo "* / $A3" >> expected && echo "|/ " >> expected && echo "* $A2" >> expected && git rev-list --graph --full-history --all -- bar.txt > actual && @@ -255,7 +255,7 @@ test_expect_success '--graph --boundary ^C3' ' echo "* | | | $A3" >> expected && echo "o | | | $A2" >> expected && echo "|/ / / " >> expected && - echo "o | | $A1" >> expected && + echo "o / / $A1" >> expected && echo " / / " >> expected && echo "| o $C3" >> expected && echo "|/ " >> expected && From 92beecc136ad51f358baacf948b4c4b734fd5a4c Mon Sep 17 00:00:00 2001 From: James Coglan Date: Tue, 15 Oct 2019 23:47:58 +0000 Subject: [PATCH 025/953] graph: flatten edges that fuse with their right neighbor When a merge commit is printed and its final parent is the same commit that occupies the column to the right of the merge, this results in a kink in the displayed edges: * | |\ \ | |/ | * Graphs containing these shapes can be hard to read, as the expansion to the right followed immediately by collapsing back to the left creates a lot of zig-zagging edges, especially when many columns are present. We can improve this by eliminating the zig-zag and having the merge's final parent edge fuse immediately with its neighbor: * | |\| | * This reduces the horizontal width for the current commit by 2, and requires one less row, making the graph display more compact. Taken in combination with other graph-smoothing enhancements, it greatly compresses the space needed to display certain histories: * |\ | * * | |\ |\ | | * | * | | | | |\ | | \ | | * | *-. \ | * | | |\ \ \ => |/|\| |/ / / / | | * | | | / | * | | | |/ | |/ | | * * / | * | |/ | |/ * * | |/ * One of the test cases here cannot be correctly rendered in Git v2.23.0; it produces this output following commit E: | | *-. \ 5_E | | |\ \ \ | |/ / / / | | | / _ | |_|/ |/| | The new implementation makes sure that the rightmost edge in this history is not left dangling as above. Signed-off-by: James Coglan Signed-off-by: Junio C Hamano --- graph.c | 34 +++++++++---- t/t4215-log-skewed-merges.sh | 56 ++++++++++++++++++---- t/t6016-rev-list-graph-simplify-history.sh | 30 +++++------- 3 files changed, 86 insertions(+), 34 deletions(-) diff --git a/graph.c b/graph.c index 63f8d18baa7d7a..80db74aee6c0aa 100644 --- a/graph.c +++ b/graph.c @@ -557,8 +557,24 @@ static void graph_insert_into_new_columns(struct git_graph *graph, shift = (dist > 1) ? 2 * dist - 3 : 1; graph->merge_layout = (dist > 0) ? 0 : 1; + graph->edges_added = graph->num_parents + graph->merge_layout - 2; + mapping_idx = graph->width + (graph->merge_layout - 1) * shift; graph->width += 2 * graph->merge_layout; + + } else if (graph->edges_added > 0 && i == graph->mapping[graph->width - 2]) { + /* + * If some columns have been added by a merge, but this commit + * was found in the last existing column, then adjust the + * numbers so that the two edges immediately join, i.e.: + * + * * | * | + * |\ \ => |\| + * | |/ | * + * | * + */ + mapping_idx = graph->width - 2; + graph->edges_added = -1; } else { mapping_idx = graph->width; graph->width += 2; @@ -604,6 +620,8 @@ static void graph_update_columns(struct git_graph *graph) graph->mapping[i] = -1; graph->width = 0; + graph->prev_edges_added = graph->edges_added; + graph->edges_added = 0; /* * Populate graph->new_columns and graph->mapping @@ -731,9 +749,6 @@ void graph_update(struct git_graph *graph, struct commit *commit) */ graph_update_columns(graph); - graph->prev_edges_added = graph->edges_added; - graph->edges_added = graph->num_parents + graph->merge_layout - 2; - graph->expansion_row = 0; /* @@ -1041,7 +1056,7 @@ const char merge_chars[] = {'/', '|', '\\'}; static void graph_output_post_merge_line(struct git_graph *graph, struct graph_line *line) { int seen_this = 0; - int i; + int i, j; struct commit_list *first_parent = first_interesting_parent(graph); int seen_parent = 0; @@ -1073,16 +1088,19 @@ static void graph_output_post_merge_line(struct git_graph *graph, struct graph_l char c; seen_this = 1; - for (; parents; parents = next_interesting_parent(graph, parents)) { + for (j = 0; j < graph->num_parents; j++) { par_column = graph_find_new_column_by_commit(graph, parents->item); assert(par_column >= 0); c = merge_chars[idx]; graph_line_write_column(line, &graph->new_columns[par_column], c); - if (idx == 2) - graph_line_addch(line, ' '); - else + if (idx == 2) { + if (graph->edges_added > 0 || j < graph->num_parents - 1) + graph_line_addch(line, ' '); + } else { idx++; + } + parents = next_interesting_parent(graph, parents); } if (graph->edges_added == 0) graph_line_addch(line, ' '); diff --git a/t/t4215-log-skewed-merges.sh b/t/t4215-log-skewed-merges.sh index 1745b3b64c4071..d33c6438d8565d 100755 --- a/t/t4215-log-skewed-merges.sh +++ b/t/t4215-log-skewed-merges.sh @@ -11,9 +11,8 @@ test_expect_success 'log --graph with merge fusing with its left and right neigh | * G | |\ | | * F - | * | E - |/|\ \ - | | |/ + | * | E + |/|\| | | * D | * | C | |/ @@ -43,9 +42,9 @@ test_expect_success 'log --graph with left-skewed merge' ' | | | | * 0_G | |_|_|/| |/| | | | - | | | * | 0_F - | |_|/|\ \ - |/| | | |/ + | | | * | 0_F + | |_|/|\| + |/| | | | | | | | * 0_E | |_|_|/ |/| | | @@ -153,9 +152,8 @@ test_expect_success 'log --graph with nested right-skewed merge following left-s | | * 3_G | * | 3_F |/| | - | * | 3_E - | |\ \ - | | |/ + | * | 3_E + | |\| | | * 3_D | * | 3_C | |/ @@ -216,4 +214,44 @@ test_expect_success 'log --graph with right-skewed merge following a left-skewed test_cmp expect actual ' +test_expect_success 'log --graph with octopus merge with column joining its penultimate parent' ' + cat >expect <<-\EOF && + * 5_H + |\ + | *-. 5_G + | |\ \ + | | | * 5_F + | | * | 5_E + | |/|\ \ + | |_|/ / + |/| | / + | | |/ + * | | 5_D + | | * 5_C + | |/ + |/| + | * 5_B + |/ + * 5_A + EOF + + git checkout --orphan 5_p && + test_commit 5_A && + git branch 5_q && + git branch 5_r && + test_commit 5_B && + git checkout 5_q && test_commit 5_C && + git checkout 5_r && test_commit 5_D && + git checkout 5_p && + git merge --no-ff 5_q 5_r -m 5_E && + git checkout 5_q && test_commit 5_F && + git checkout -b 5_s 5_p^ && + git merge --no-ff 5_p 5_q -m 5_G && + git checkout 5_r && + git merge --no-ff 5_s -m 5_H && + + git log --graph --pretty=tformat:%s | sed "s/ *$//" >actual && + test_cmp expect actual +' + test_done diff --git a/t/t6016-rev-list-graph-simplify-history.sh b/t/t6016-rev-list-graph-simplify-history.sh index ca1682f29b4a56..f5e6e92f5b30cd 100755 --- a/t/t6016-rev-list-graph-simplify-history.sh +++ b/t/t6016-rev-list-graph-simplify-history.sh @@ -67,11 +67,10 @@ test_expect_success '--graph --all' ' echo "| * $C4" >> expected && echo "| * $C3" >> expected && echo "* | $A5" >> expected && - echo "| | " >> expected && - echo "| \\ " >> expected && - echo "*-. \\ $A4" >> expected && - echo "|\\ \\ \\ " >> expected && - echo "| | |/ " >> expected && + echo "| | " >> expected && + echo "| \\ " >> expected && + echo "*-. | $A4" >> expected && + echo "|\\ \\| " >> expected && echo "| | * $C2" >> expected && echo "| | * $C1" >> expected && echo "| * | $B2" >> expected && @@ -97,11 +96,10 @@ test_expect_success '--graph --simplify-by-decoration' ' echo "| * $C4" >> expected && echo "| * $C3" >> expected && echo "* | $A5" >> expected && - echo "| | " >> expected && - echo "| \\ " >> expected && - echo "*-. \\ $A4" >> expected && - echo "|\\ \\ \\ " >> expected && - echo "| | |/ " >> expected && + echo "| | " >> expected && + echo "| \\ " >> expected && + echo "*-. | $A4" >> expected && + echo "|\\ \\| " >> expected && echo "| | * $C2" >> expected && echo "| | * $C1" >> expected && echo "| * | $B2" >> expected && @@ -131,9 +129,8 @@ test_expect_success '--graph --simplify-by-decoration prune branch B' ' echo "| * $C4" >> expected && echo "| * $C3" >> expected && echo "* | $A5" >> expected && - echo "* | $A4" >> expected && - echo "|\\ \\ " >> expected && - echo "| |/ " >> expected && + echo "* | $A4" >> expected && + echo "|\\| " >> expected && echo "| * $C2" >> expected && echo "| * $C1" >> expected && echo "* | $A3" >> expected && @@ -151,10 +148,9 @@ test_expect_success '--graph --full-history -- bar.txt' ' echo "|\\ " >> expected && echo "| * $C4" >> expected && echo "* | $A5" >> expected && - echo "* | $A4" >> expected && - echo "|\\ \\ " >> expected && - echo "| |/ " >> expected && - echo "* / $A3" >> expected && + echo "* | $A4" >> expected && + echo "|\\| " >> expected && + echo "* | $A3" >> expected && echo "|/ " >> expected && echo "* $A2" >> expected && git rev-list --graph --full-history --all -- bar.txt > actual && From bbb13e8188ee37dd3e2318752342622266659620 Mon Sep 17 00:00:00 2001 From: James Coglan Date: Tue, 15 Oct 2019 23:47:59 +0000 Subject: [PATCH 026/953] graph: fix coloring of octopus dashes In 04005834ed ("log: fix coloring of certain octopus merge shapes", 2018-09-01) there is a fix for the coloring of dashes following an octopus merge. It makes a distinction between the case where all parents introduce a new column, versus the case where the first parent collapses into an existing column: | *-. | *-. | |\ \ | |\ \ | | | | |/ / / The latter case means that the columns for the merge parents begin one place to the left in the `new_columns` array compared to the former case. However, the implementation only works if the commit's parents are kept in order as they map onto the visual columns, as we get the colors by iterating over `new_columns` as we print the dashes. In general, the commit's parents can arbitrarily merge with existing columns, and change their ordering in the process. For example, in the following diagram, the number of each column indicates which commit parent appears in each column. | | *---. | | |\ \ \ | | |/ / / | |/| | / | |_|_|/ |/| | | 3 1 0 2 If the columns are colored (red, green, yellow, blue), then the dashes will currently be colored yellow and blue, whereas they should be blue and red. To fix this, we need to look up each column in the `mapping` array, which before the `GRAPH_COLLAPSING` state indicates which logical column is displayed in each visual column. This implementation is simpler as it doesn't have any edge cases, and it also handles how left-skewed first parents are now displayed: | *-. |/|\ \ | | | | 0 1 2 3 The color of the first dashes is always the color found in `mapping` two columns to the right of the commit symbol. Because commits are displayed after all edges have been collapsed together and the visual columns match the logical ones, we can find the visual offset of the commit symbol using `commit_index`. Signed-off-by: James Coglan Signed-off-by: Junio C Hamano --- graph.c | 71 +++++++++++++++++++----------------- t/t4214-log-graph-octopus.sh | 10 ++--- 2 files changed, 42 insertions(+), 39 deletions(-) diff --git a/graph.c b/graph.c index 80db74aee6c0aa..e3fd0ea5f806a2 100644 --- a/graph.c +++ b/graph.c @@ -684,6 +684,11 @@ static void graph_update_columns(struct git_graph *graph) graph->mapping_size--; } +static int graph_num_dashed_parents(struct git_graph *graph) +{ + return graph->num_parents + graph->merge_layout - 3; +} + static int graph_num_expansion_rows(struct git_graph *graph) { /* @@ -706,7 +711,7 @@ static int graph_num_expansion_rows(struct git_graph *graph) * | * \ * |/|\ \ */ - return (graph->num_parents + graph->merge_layout - 3) * 2; + return graph_num_dashed_parents(graph) * 2; } static int graph_needs_pre_commit_line(struct git_graph *graph) @@ -934,47 +939,45 @@ static void graph_output_commit_char(struct git_graph *graph, struct graph_line static void graph_draw_octopus_merge(struct git_graph *graph, struct graph_line *line) { /* - * Here dashless_parents represents the number of parents which don't - * need to have dashes (the edges labeled "0" and "1"). And - * dashful_parents are the remaining ones. + * The parents of a merge commit can be arbitrarily reordered as they + * are mapped onto display columns, for example this is a valid merge: * - * | *---. - * | |\ \ \ - * | | | | | - * x 0 1 2 3 + * | | *---. + * | | |\ \ \ + * | | |/ / / + * | |/| | / + * | |_|_|/ + * |/| | | + * 3 1 0 2 * - */ - const int dashless_parents = 3 - graph->merge_layout; - int dashful_parents = graph->num_parents - dashless_parents; - - /* - * Usually, we add one new column for each parent (like the diagram - * above) but sometimes the first parent goes into an existing column, - * like this: + * The numbers denote which parent of the merge each visual column + * corresponds to; we can't assume that the parents will initially + * display in the order given by new_columns. * - * | *-. - * |/|\ \ - * | | | | - * x 0 1 2 + * To find the right color for each dash, we need to consult the + * mapping array, starting from the column 2 places to the right of the + * merge commit, and use that to find out which logical column each + * edge will collapse to. * - * In which case the number of parents will be one greater than the - * number of added columns. + * Commits are rendered once all edges have collapsed to their correct + * logcial column, so commit_index gives us the right visual offset for + * the merge commit. */ - int added_cols = (graph->num_new_columns - graph->num_columns); - int parent_in_old_cols = graph->num_parents - added_cols; - /* - * In both cases, commit_index corresponds to the edge labeled "0". - */ - int first_col = graph->commit_index + dashless_parents - - parent_in_old_cols; + int i, j; + struct column *col; - int i; - for (i = 0; i < dashful_parents; i++) { - graph_line_write_column(line, &graph->new_columns[i+first_col], '-'); - graph_line_write_column(line, &graph->new_columns[i+first_col], - i == dashful_parents-1 ? '.' : '-'); + int dashed_parents = graph_num_dashed_parents(graph); + + for (i = 0; i < dashed_parents; i++) { + j = graph->mapping[(graph->commit_index + i + 2) * 2]; + col = &graph->new_columns[j]; + + graph_line_write_column(line, col, '-'); + graph_line_write_column(line, col, (i == dashed_parents - 1) ? '.' : '-'); } + + return; } static void graph_output_commit_line(struct git_graph *graph, struct graph_line *line) diff --git a/t/t4214-log-graph-octopus.sh b/t/t4214-log-graph-octopus.sh index 21bc600a82d442..40d27db674cf10 100755 --- a/t/t4214-log-graph-octopus.sh +++ b/t/t4214-log-graph-octopus.sh @@ -121,7 +121,7 @@ test_expect_success 'log --graph with normal octopus merge and child, no color' test_cmp expect.uncolored actual ' -test_expect_failure 'log --graph with normal octopus and child merge with colors' ' +test_expect_success 'log --graph with normal octopus and child merge with colors' ' cat >expect.colors <<-\EOF && * after-merge *---. octopus-merge @@ -161,7 +161,7 @@ test_expect_success 'log --graph with tricky octopus merge and its child, no col test_cmp expect.uncolored actual ' -test_expect_failure 'log --graph with tricky octopus merge and its child with colors' ' +test_expect_success 'log --graph with tricky octopus merge and its child with colors' ' test_config log.graphColors red,green,yellow,blue,magenta,cyan && cat >expect.colors <<-\EOF && * left @@ -205,7 +205,7 @@ test_expect_success 'log --graph with crossover in octopus merge, no color' ' test_cmp expect.uncolored actual ' -test_expect_failure 'log --graph with crossover in octopus merge with colors' ' +test_expect_success 'log --graph with crossover in octopus merge with colors' ' test_config log.graphColors red,green,yellow,blue,magenta,cyan && cat >expect.colors <<-\EOF && * after-4 @@ -253,7 +253,7 @@ test_expect_success 'log --graph with crossover in octopus merge and its child, test_cmp expect.uncolored actual ' -test_expect_failure 'log --graph with crossover in octopus merge and its child with colors' ' +test_expect_success 'log --graph with crossover in octopus merge and its child with colors' ' test_config log.graphColors red,green,yellow,blue,magenta,cyan && cat >expect.colors <<-\EOF && * after-4 @@ -349,7 +349,7 @@ test_expect_success 'log --graph with unrelated commit and octopus child, no col test_cmp expect.uncolored actual ' -test_expect_failure 'log --graph with unrelated commit and octopus child with colors' ' +test_expect_success 'log --graph with unrelated commit and octopus child with colors' ' test_config log.graphColors red,green,yellow,blue,magenta,cyan && cat >expect.colors <<-\EOF && * after-initial From 8af69cf3e214ee9df3f78bd508465b75881b17a8 Mon Sep 17 00:00:00 2001 From: Doan Tran Cong Danh Date: Wed, 16 Oct 2019 12:18:40 +0700 Subject: [PATCH 027/953] t3301: test diagnose messages for too few/many paramters Commit bbb1b8a35a ("notes: check number of parameters to "git notes copy"", 2010-06-28) added a test for too many or too few of parameters provided to `git notes copy'. However, the test only ensures that the command will fail but it doesn't really check if it fails because of number of parameters. If we accidentally lifted the check inside our code base, the test may still have failed because the provided parameter is not a valid ref. Correct it. Signed-off-by: Doan Tran Cong Danh Signed-off-by: Junio C Hamano --- t/t3301-notes.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh index d3fa298c6a1b38..d7767e44383c99 100755 --- a/t/t3301-notes.sh +++ b/t/t3301-notes.sh @@ -1167,8 +1167,10 @@ test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' ' ' test_expect_success 'git notes copy diagnoses too many or too few parameters' ' - test_must_fail git notes copy && - test_must_fail git notes copy one two three + test_must_fail git notes copy 2>error && + test_i18ngrep "too few parameters" error && + test_must_fail git notes copy one two three 2>error && + test_i18ngrep "too many parameters" error ' test_expect_success 'git notes get-ref expands refs/heads/master to refs/notes/refs/heads/master' ' From d58deb9c4e151d4d8380cd14223391ce0d58f588 Mon Sep 17 00:00:00 2001 From: Doan Tran Cong Danh Date: Wed, 16 Oct 2019 12:18:41 +0700 Subject: [PATCH 028/953] notes: fix minimum number of parameters to "copy" subcommand The builtin/notes.c::copy() function is prepared to handle either one or two arguments given from the command line; when one argument is given, to-obj defaults to HEAD. bbb1b8a3 ("notes: check number of parameters to "git notes copy"", 2010-06-28) tried to make sure "git notes copy" (with *no* other argument) does not dereference NULL by checking the number of parameters, but it incorrectly insisted that we need two arguments, instead of either one or two. This disabled the defaulting to-obj to HEAD. Correct it. Signed-off-by: Doan Tran Cong Danh Signed-off-by: Junio C Hamano --- Documentation/git-notes.txt | 6 +++--- builtin/notes.c | 2 +- t/t3301-notes.sh | 40 +++++++++++++++++++++++++++++++++++-- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt index f56a5a91975d59..ced2e8280ef5e4 100644 --- a/Documentation/git-notes.txt +++ b/Documentation/git-notes.txt @@ -10,7 +10,7 @@ SYNOPSIS [verse] 'git notes' [list []] 'git notes' add [-f] [--allow-empty] [-F | -m | (-c | -C) ] [] -'git notes' copy [-f] ( --stdin | ) +'git notes' copy [-f] ( --stdin | [] ) 'git notes' append [--allow-empty] [-F | -m | (-c | -C) ] [] 'git notes' edit [--allow-empty] [] 'git notes' show [] @@ -68,8 +68,8 @@ add:: subcommand). copy:: - Copy the notes for the first object onto the second object. - Abort if the second object already has notes, or if the first + Copy the notes for the first object onto the second object (defaults to + HEAD). Abort if the second object already has notes, or if the first object has none (use -f to overwrite existing notes to the second object). This subcommand is equivalent to: `git notes add [-f] -C $(git notes list ) ` diff --git a/builtin/notes.c b/builtin/notes.c index 02e97f55c5a01b..95456f316549c9 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -513,7 +513,7 @@ static int copy(int argc, const char **argv, const char *prefix) } } - if (argc < 2) { + if (argc < 1) { error(_("too few parameters")); usage_with_options(git_notes_copy_usage, options); } diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh index d7767e44383c99..d66a5f6faa0ae8 100755 --- a/t/t3301-notes.sh +++ b/t/t3301-notes.sh @@ -864,6 +864,24 @@ test_expect_success 'append to note from other note with "git notes append -c"' ' test_expect_success 'copy note with "git notes copy"' ' + commit=$(git rev-parse 4th) && + cat >expect <<-EOF && + commit $commit + Author: A U Thor + Date: Thu Apr 7 15:16:13 2005 -0700 + + ${indent}4th + + Notes: + ${indent}This is a blob object + EOF + git notes copy 8th 4th && + git log 3rd..4th >actual && + test_cmp expect actual && + test "$(git note list 4th)" = "$(git note list 8th)" +' + +test_expect_success 'copy note with "git notes copy" with default' ' test_commit 11th && commit=$(git rev-parse HEAD) && cat >expect <<-EOF && @@ -878,7 +896,7 @@ test_expect_success 'copy note with "git notes copy"' ' ${indent} ${indent}yet another note EOF - git notes copy HEAD^ HEAD && + git notes copy HEAD^ && git log -1 >actual && test_cmp expect actual && test "$(git notes list HEAD)" = "$(git notes list HEAD^)" @@ -892,6 +910,24 @@ test_expect_success 'prevent overwrite with "git notes copy"' ' ' test_expect_success 'allow overwrite with "git notes copy -f"' ' + commit=$(git rev-parse HEAD) && + cat >expect <<-EOF && + commit $commit + Author: A U Thor + Date: Thu Apr 7 15:23:13 2005 -0700 + + ${indent}11th + + Notes: + ${indent}This is a blob object + EOF + git notes copy -f HEAD~3 HEAD && + git log -1 >actual && + test_cmp expect actual && + test "$(git notes list HEAD)" = "$(git notes list HEAD~3)" +' + +test_expect_success 'allow overwrite with "git notes copy -f" with default' ' commit=$(git rev-parse HEAD) && cat >expect <<-EOF && commit $commit @@ -905,7 +941,7 @@ test_expect_success 'allow overwrite with "git notes copy -f"' ' ${indent} ${indent}yet another note EOF - git notes copy -f HEAD~2 HEAD && + git notes copy -f HEAD~2 && git log -1 >actual && test_cmp expect actual && test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" From c78fe00459d49cd57cbfabc5c564af0cb9a934f1 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 18 Oct 2019 00:42:13 -0400 Subject: [PATCH 029/953] parse_commit_buffer(): treat lookup_commit() failure as parse error While parsing the parents of a commit, if we are able to parse an actual oid but lookup_commit() fails on it (because we previously saw it in this process as a different object type), we silently omit the parent and do not report any error to the caller. The caller has no way of knowing this happened, because even an empty parent list is a valid parse result. As a result, it's possible to fool our "rev-list" connectivity check into accepting a corrupted set of objects. There's a test for this case already in t6102, but unfortunately it has a slight error. It creates a broken commit with a parent line pointing to a blob, and then checks that rev-list notices the problem in two cases: 1. the "lone" case: we traverse the broken commit by itself (here we try to actually load the blob from disk and find out that it's not a commit) 2. the "seen" case: we parse the blob earlier in the process, and then when calling lookup_commit() we realize immediately that it's not a commit The "seen" variant for this test mistakenly parsed another commit instead of the blob, meaning that we were actually just testing the "lone" case again. Changing that reveals the breakage (and shows that this fixes it). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- commit.c | 11 ++++++++--- t/t6102-rev-list-unexpected-objects.sh | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/commit.c b/commit.c index 40890ae7ce8a48..6467c9e175fad0 100644 --- a/commit.c +++ b/commit.c @@ -432,8 +432,11 @@ int parse_commit_buffer(struct repository *r, struct commit *item, const void *b if (graft && (graft->nr_parent < 0 || grafts_replace_parents)) continue; new_parent = lookup_commit(r, &parent); - if (new_parent) - pptr = &commit_list_insert(new_parent, pptr)->next; + if (!new_parent) + return error("bad parent %s in commit %s", + oid_to_hex(&parent), + oid_to_hex(&item->object.oid)); + pptr = &commit_list_insert(new_parent, pptr)->next; } if (graft) { int i; @@ -442,7 +445,9 @@ int parse_commit_buffer(struct repository *r, struct commit *item, const void *b new_parent = lookup_commit(r, &graft->parent[i]); if (!new_parent) - continue; + return error("bad graft parent %s in commit %s", + oid_to_hex(&graft->parent[i]), + oid_to_hex(&item->object.oid)); pptr = &commit_list_insert(new_parent, pptr)->next; } } diff --git a/t/t6102-rev-list-unexpected-objects.sh b/t/t6102-rev-list-unexpected-objects.sh index 28611c978e6c00..52cde097dd5c1c 100755 --- a/t/t6102-rev-list-unexpected-objects.sh +++ b/t/t6102-rev-list-unexpected-objects.sh @@ -52,7 +52,7 @@ test_expect_success 'traverse unexpected non-commit parent (lone)' ' ' test_expect_success 'traverse unexpected non-commit parent (seen)' ' - test_must_fail git rev-list --objects $commit $broken_commit \ + test_must_fail git rev-list --objects $blob $broken_commit \ >output 2>&1 && test_i18ngrep "not a commit" output ' From 12736d2f027c72d4c900f10ae064d2a673344c9e Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 18 Oct 2019 00:43:29 -0400 Subject: [PATCH 030/953] parse_commit_buffer(): treat lookup_tree() failure as parse error If parsing a commit yields a valid tree oid, but we've seen that same oid as a non-tree in the same process, the resulting commit struct will end up with a NULL tree pointer, but not otherwise report a parsing failure. That's perhaps convenient for callers which want to operate on even partially corrupt commits (e.g., by still looking at the parents). But it leaves a potential trap for most callers, who now have to manually check for a NULL tree. Most do not, and it's likely that there are possible segfaults lurking. I say "possible" because there are many candidates, and I don't think it's worth following through on reproducing them when we can just fix them all in one spot. And certainly we _have_ seen real-world cases, such as the one fixed by 806278dead (commit-graph.c: handle corrupt/missing trees, 2019-09-05). Note that we can't quite drop the check in the caller added by that commit yet, as there's some subtlety with repeated parsings (which will be addressed in a future commit). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- commit.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/commit.c b/commit.c index 6467c9e175fad0..810419a16871cf 100644 --- a/commit.c +++ b/commit.c @@ -401,6 +401,7 @@ int parse_commit_buffer(struct repository *r, struct commit *item, const void *b struct commit_graft *graft; const int tree_entry_len = the_hash_algo->hexsz + 5; const int parent_entry_len = the_hash_algo->hexsz + 7; + struct tree *tree; if (item->object.parsed) return 0; @@ -412,7 +413,12 @@ int parse_commit_buffer(struct repository *r, struct commit *item, const void *b if (get_oid_hex(bufptr + 5, &parent) < 0) return error("bad tree pointer in commit %s", oid_to_hex(&item->object.oid)); - set_commit_tree(item, lookup_tree(r, &parent)); + tree = lookup_tree(r, &parent); + if (!tree) + return error("bad tree pointer %s in commit %s", + oid_to_hex(&parent), + oid_to_hex(&item->object.oid)); + set_commit_tree(item, tree); bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */ pptr = &item->parents; From 78d50148b955283e027ff46f310a4d3930ad42c0 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 18 Oct 2019 00:45:35 -0400 Subject: [PATCH 031/953] parse_tag_buffer(): treat NULL tag pointer as parse error When parsing a tag, we may end up with a NULL "tagged" field when there's a type mismatch (e.g., the tag claims to point to object X as a commit, but we previously saw X as a blob in the same process), but we do not otherwise indicate a parse failure to the caller. This is similar to the case discussed in the previous commit, where a commit could end up with a NULL tree field: while slightly convenient for callers who want to overlook a corrupt object, it means that normal callers have to explicitly deal with this case (rather than just relying on the return code from parsing). And most don't, leading to segfault fixes like the one in c77722b3ea (use get_tagged_oid(), 2019-09-05). Let's address this more centrally, by returning an error code from the parse itself, which most callers would already notice (adventurous callers are free to ignore the error and continue looking at the struct). This also covers the case where the tag contains a nonsensical "type" field (there we produced a user-visible error but still returned success to the caller; now we'll produce a slightly better message and return an error). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- tag.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tag.c b/tag.c index bfa0e3143580f4..6a51efda8d7d59 100644 --- a/tag.c +++ b/tag.c @@ -167,10 +167,15 @@ int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, u } else if (!strcmp(type, tag_type)) { item->tagged = (struct object *)lookup_tag(r, &oid); } else { - error("Unknown type %s", type); - item->tagged = NULL; + return error("unknown tag type '%s' in %s", + type, oid_to_hex(&item->object.oid)); } + if (!item->tagged) + return error("bad tag pointer to %s in %s", + oid_to_hex(&oid), + oid_to_hex(&item->object.oid)); + if (bufptr + 4 < tail && starts_with(bufptr, "tag ")) ; /* good */ else From 0e40a73a4c768c220dabf14f173f33c87a4f4829 Mon Sep 17 00:00:00 2001 From: Philip Oakley Date: Sun, 20 Oct 2019 12:03:06 +0100 Subject: [PATCH 032/953] Doc: Bundle file usage Improve the command description, including paragraph spacing. Git URLs can accept bundle files for fetch, pull and clone, include in that section. Include git clone in the bundle usage description. Correct the quoting of . Detail the options for cloning a complete repo. Signed-off-by: Philip Oakley Signed-off-by: Junio C Hamano --- Documentation/git-bundle.txt | 23 +++++++++++++++++------ Documentation/urls.txt | 3 +++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Documentation/git-bundle.txt b/Documentation/git-bundle.txt index 7d6c9dcd177b6a..545940022b8365 100644 --- a/Documentation/git-bundle.txt +++ b/Documentation/git-bundle.txt @@ -20,11 +20,14 @@ DESCRIPTION Some workflows require that one or more branches of development on one machine be replicated on another machine, but the two machines cannot be directly connected, and therefore the interactive Git protocols (git, -ssh, http) cannot be used. This command provides support for -'git fetch' and 'git pull' to operate by packaging objects and references -in an archive at the originating machine, then importing those into -another repository using 'git fetch' and 'git pull' -after moving the archive by some means (e.g., by sneakernet). As no +ssh, http) cannot be used. + +The 'git bundle' command packages objects and references in an archive +at the originating machine, which can then be imported into another +repository using 'git fetch', 'git pull', or 'git clone', +after moving the archive by some means (e.g., by sneakernet). + +As no direct connection between the repositories exists, the user must specify a basis for the bundle that is held by the destination repository: the bundle assumes that all objects in the basis are already in the @@ -35,7 +38,7 @@ OPTIONS create :: Used to create a bundle named 'file'. This requires the - 'git-rev-list-args' arguments to define the bundle contents. + '' arguments to define the bundle contents. verify :: Used to check that a bundle file is valid and will apply @@ -92,6 +95,14 @@ It is okay to err on the side of caution, causing the bundle file to contain objects already in the destination, as these are ignored when unpacking at the destination. +`git clone` can use any bundle created without negative refspecs +(e.g., `new`, but not `old..new`). +If you want to match `git clone --mirror`, which would include your +refs such as `refs/remotes/*`, use `--all`. +If you want to provide the same set of refs that a clone directly +from the source repository would get, use `--branches --tags` for +the ``. + EXAMPLES -------- diff --git a/Documentation/urls.txt b/Documentation/urls.txt index bc354fe2dce57b..1c229d758152b6 100644 --- a/Documentation/urls.txt +++ b/Documentation/urls.txt @@ -53,6 +53,9 @@ These two syntaxes are mostly equivalent, except the former implies --local option. endif::git-clone[] +'git clone', 'git fetch' and 'git pull', but not 'git push', will also +accept a suitable bundle file. See linkgit:git-bundle[1]. + When Git doesn't know how to handle a certain transport protocol, it attempts to use the 'remote-' remote helper, if one exists. To explicitly request a remote helper, the following syntax From feebd2d256adffa6a1e31832266ee9466a63c0c2 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Fri, 18 Oct 2019 16:55:56 -0700 Subject: [PATCH 033/953] rebase: hide --preserve-merges option Since --preserve-merges has been deprecated in favour of --rebase-merges, mark this option as hidden so it no longer shows up in the usage and completions. Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano --- builtin/rebase.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 21ac10f739997e..0d63651d9582e2 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1099,9 +1099,10 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) N_("let the user edit the list of commits to rebase"), PARSE_OPT_NOARG | PARSE_OPT_NONEG, parse_opt_interactive }, - OPT_SET_INT('p', "preserve-merges", &options.type, - N_("(DEPRECATED) try to recreate merges instead of " - "ignoring them"), REBASE_PRESERVE_MERGES), + OPT_SET_INT_F('p', "preserve-merges", &options.type, + N_("(DEPRECATED) try to recreate merges instead of " + "ignoring them"), + REBASE_PRESERVE_MERGES, PARSE_OPT_HIDDEN), OPT_BOOL(0, "rerere-autoupdate", &options.allow_rerere_autoupdate, N_("allow rerere to update index with resolved " From 86795774bb9ca3c63b94d3d0930405c1ba9148ec Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Thu, 17 Oct 2019 17:46:51 +0000 Subject: [PATCH 034/953] builtin/blame.c: constants into bit shift format We are looking at bitfield constants, and elsewhere in the Git source code, such cases are handled via bit shift operators rather than octal numbers, which also makes it easier to spot holes in the range (if, say, 1<<5 was missing, it is easier to spot it between 1<<4 and 1<<6 than it is to spot a missing 040 between a 020 and a 0100). Signed-off-by: Hariom Verma Signed-off-by: Junio C Hamano --- builtin/blame.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/builtin/blame.c b/builtin/blame.c index b6534d4dea9ad8..44733f1256b752 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -320,18 +320,18 @@ static const char *format_time(timestamp_t time, const char *tz_str, return time_buf.buf; } -#define OUTPUT_ANNOTATE_COMPAT 001 -#define OUTPUT_LONG_OBJECT_NAME 002 -#define OUTPUT_RAW_TIMESTAMP 004 -#define OUTPUT_PORCELAIN 010 -#define OUTPUT_SHOW_NAME 020 -#define OUTPUT_SHOW_NUMBER 040 -#define OUTPUT_SHOW_SCORE 0100 -#define OUTPUT_NO_AUTHOR 0200 -#define OUTPUT_SHOW_EMAIL 0400 -#define OUTPUT_LINE_PORCELAIN 01000 -#define OUTPUT_COLOR_LINE 02000 -#define OUTPUT_SHOW_AGE_WITH_COLOR 04000 +#define OUTPUT_ANNOTATE_COMPAT (1U<<0) +#define OUTPUT_LONG_OBJECT_NAME (1U<<1) +#define OUTPUT_RAW_TIMESTAMP (1U<<2) +#define OUTPUT_PORCELAIN (1U<<3) +#define OUTPUT_SHOW_NAME (1U<<4) +#define OUTPUT_SHOW_NUMBER (1U<<5) +#define OUTPUT_SHOW_SCORE (1U<<6) +#define OUTPUT_NO_AUTHOR (1U<<7) +#define OUTPUT_SHOW_EMAIL (1U<<8) +#define OUTPUT_LINE_PORCELAIN (1U<<9) +#define OUTPUT_COLOR_LINE (1U<<10) +#define OUTPUT_SHOW_AGE_WITH_COLOR (1U<<11) static void emit_porcelain_details(struct blame_origin *suspect, int repeat) { From 80736d7c5eabe49062aeaea47b83eba2bb40314d Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 23 Oct 2019 11:26:37 +0900 Subject: [PATCH 035/953] doc: am --show-current-patch gives an entire e-mail message The existing wording gives an impression that it only gives the contents of the $GIT_DIR/rebase-apply/patch file, i.e. the patch proper, but the option actually emits the entire e-mail message being processed (iow, one of the output files from "git mailsplit"). Signed-off-by: Junio C Hamano --- Documentation/git-am.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/git-am.txt b/Documentation/git-am.txt index fc3b993c3338b5..fc5750b3b81ef5 100644 --- a/Documentation/git-am.txt +++ b/Documentation/git-am.txt @@ -177,7 +177,7 @@ default. You can use `--no-utf8` to override this. untouched. --show-current-patch:: - Show the patch being applied when "git am" is stopped because + Show the entire e-mail message "git am" has stopped at, because of conflicts. DISCUSSION From d3eebaad5ef02284c86d6c4b80199eac58c6729b Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Tue, 22 Oct 2019 21:22:49 +0000 Subject: [PATCH 036/953] merge-recursive: clean up get_renamed_dir_portion() Dscho noted a few things making this function hard to follow. Restructure it a bit and add comments to make it easier to follow. The restructurings include: * There was a special case if-check at the end of the function checking whether someone just renamed a file within its original directory, meaning that there could be no directory rename involved. That check was slightly convoluted; it could be done in a more straightforward fashion earlier in the function, and can be done more cheaply too (no call to strncmp). * The conditions for advancing end_of_old and end_of_new before calling strchr were both confusing and unnecessary. If either points at a '/', then they need to be advanced in order to find the next '/'. If either doesn't point at a '/', then advancing them one char before calling strchr() doesn't hurt. So, just rip out the if conditions and advance both before calling strchr(). Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- merge-recursive.c | 60 ++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/merge-recursive.c b/merge-recursive.c index 22a12cfeba381d..f80e48f623b98a 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -1943,8 +1943,8 @@ static void get_renamed_dir_portion(const char *old_path, const char *new_path, char **old_dir, char **new_dir) { char *end_of_old, *end_of_new; - int old_len, new_len; + /* Default return values: NULL, meaning no rename */ *old_dir = NULL; *new_dir = NULL; @@ -1955,43 +1955,55 @@ static void get_renamed_dir_portion(const char *old_path, const char *new_path, * "a/b/c/d" was renamed to "a/b/some/thing/else" * so, for this example, this function returns "a/b/c/d" in * *old_dir and "a/b/some/thing/else" in *new_dir. - * - * Also, if the basename of the file changed, we don't care. We - * want to know which portion of the directory, if any, changed. + */ + + /* + * If the basename of the file changed, we don't care. We want + * to know which portion of the directory, if any, changed. */ end_of_old = strrchr(old_path, '/'); end_of_new = strrchr(new_path, '/'); - if (end_of_old == NULL || end_of_new == NULL) - return; + return; /* We haven't modified *old_dir or *new_dir yet. */ + + /* Find the first non-matching character traversing backwards */ while (*--end_of_new == *--end_of_old && end_of_old != old_path && end_of_new != new_path) ; /* Do nothing; all in the while loop */ + /* - * We've found the first non-matching character in the directory - * paths. That means the current directory we were comparing - * represents the rename. Move end_of_old and end_of_new back - * to the full directory name. + * If both got back to the beginning of their strings, then the + * directory didn't change at all, only the basename did. */ - if (*end_of_old == '/') - end_of_old++; - if (*end_of_old != '/') - end_of_new++; - end_of_old = strchr(end_of_old, '/'); - end_of_new = strchr(end_of_new, '/'); + if (end_of_old == old_path && end_of_new == new_path && + *end_of_old == *end_of_new) + return; /* We haven't modified *old_dir or *new_dir yet. */ /* - * It may have been the case that old_path and new_path were the same - * directory all along. Don't claim a rename if they're the same. + * We've found the first non-matching character in the directory + * paths. That means the current characters we were looking at + * were part of the first non-matching subdir name going back from + * the end of the strings. Get the whole name by advancing both + * end_of_old and end_of_new to the NEXT '/' character. That will + * represent the entire directory rename. + * + * The reason for the increment is cases like + * a/b/star/foo/whatever.c -> a/b/tar/foo/random.c + * After dropping the basename and going back to the first + * non-matching character, we're now comparing: + * a/b/s and a/b/ + * and we want to be comparing: + * a/b/star/ and a/b/tar/ + * but without the pre-increment, the one on the right would stay + * a/b/. */ - old_len = end_of_old - old_path; - new_len = end_of_new - new_path; + end_of_old = strchr(++end_of_old, '/'); + end_of_new = strchr(++end_of_new, '/'); - if (old_len != new_len || strncmp(old_path, new_path, old_len)) { - *old_dir = xstrndup(old_path, old_len); - *new_dir = xstrndup(new_path, new_len); - } + /* Copy the old and new directories into *old_dir and *new_dir. */ + *old_dir = xstrndup(old_path, end_of_old - old_path); + *new_dir = xstrndup(new_path, end_of_new - new_path); } static void remove_hashmap_entries(struct hashmap *dir_renames, From 49b8133a9ece199a17db8bb2545202c6eac67485 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Tue, 22 Oct 2019 21:22:50 +0000 Subject: [PATCH 037/953] merge-recursive: fix merging a subdirectory into the root directory We allow renaming all entries in e.g. a directory named z/ into a directory named y/ to be detected as a z/ -> y/ rename, so that if the other side of history adds any files to the directory z/ in the mean time, we can provide the hint that they should be moved to y/. There is no reason to not allow 'y/' to be the root directory, but the code did not handle that case correctly. Add a testcase and the necessary special checks to support this case. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- merge-recursive.c | 52 ++++++++++++- t/t6043-merge-rename-directories.sh | 114 ++++++++++++++++++++++++++++ 2 files changed, 163 insertions(+), 3 deletions(-) diff --git a/merge-recursive.c b/merge-recursive.c index f80e48f623b98a..ec6071536852bf 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -1931,6 +1931,16 @@ static char *apply_dir_rename(struct dir_rename_entry *entry, return NULL; oldlen = strlen(entry->dir); + if (entry->new_dir.len == 0) + /* + * If someone renamed/merged a subdirectory into the root + * directory (e.g. 'some/subdir' -> ''), then we want to + * avoid returning + * '' + '/filename' + * as the rename; we need to make old_path + oldlen advance + * past the '/' character. + */ + oldlen++; newlen = entry->new_dir.len + (strlen(old_path) - oldlen) + 1; strbuf_grow(&new_path, newlen); strbuf_addbuf(&new_path, &entry->new_dir); @@ -1963,8 +1973,26 @@ static void get_renamed_dir_portion(const char *old_path, const char *new_path, */ end_of_old = strrchr(old_path, '/'); end_of_new = strrchr(new_path, '/'); - if (end_of_old == NULL || end_of_new == NULL) - return; /* We haven't modified *old_dir or *new_dir yet. */ + + /* + * If end_of_old is NULL, old_path wasn't in a directory, so there + * could not be a directory rename (our rule elsewhere that a + * directory which still exists is not considered to have been + * renamed means the root directory can never be renamed -- because + * the root directory always exists). + */ + if (end_of_old == NULL) + return; /* Note: *old_dir and *new_dir are still NULL */ + + /* + * If new_path contains no directory (end_of_new is NULL), then we + * have a rename of old_path's directory to the root directory. + */ + if (end_of_new == NULL) { + *old_dir = xstrndup(old_path, end_of_old - old_path); + *new_dir = xstrdup(""); + return; + } /* Find the first non-matching character traversing backwards */ while (*--end_of_new == *--end_of_old && @@ -1978,7 +2006,25 @@ static void get_renamed_dir_portion(const char *old_path, const char *new_path, */ if (end_of_old == old_path && end_of_new == new_path && *end_of_old == *end_of_new) - return; /* We haven't modified *old_dir or *new_dir yet. */ + return; /* Note: *old_dir and *new_dir are still NULL */ + + /* + * If end_of_new got back to the beginning of its string, and + * end_of_old got back to the beginning of some subdirectory, then + * we have a rename/merge of a subdirectory into the root, which + * needs slightly special handling. + * + * Note: There is no need to consider the opposite case, with a + * rename/merge of the root directory into some subdirectory + * because as noted above the root directory always exists so it + * cannot be considered to be renamed. + */ + if (end_of_new == new_path && + end_of_old != old_path && end_of_old[-1] == '/') { + *old_dir = xstrndup(old_path, --end_of_old - old_path); + *new_dir = xstrdup(""); + return; + } /* * We've found the first non-matching character in the directory diff --git a/t/t6043-merge-rename-directories.sh b/t/t6043-merge-rename-directories.sh index c966147d5d73ee..32cdd1f493a4af 100755 --- a/t/t6043-merge-rename-directories.sh +++ b/t/t6043-merge-rename-directories.sh @@ -4051,6 +4051,120 @@ test_expect_success '12c-check: Moving one directory hierarchy into another w/ c ) ' +# Testcase 12d, Rename/merge of subdirectory into the root +# Commit O: a/b/subdir/foo +# Commit A: subdir/foo +# Commit B: a/b/subdir/foo, a/b/bar +# Expected: subdir/foo, bar + +test_expect_success '12d-setup: Rename/merge subdir into the root, variant 1' ' + test_create_repo 12d && + ( + cd 12d && + + mkdir -p a/b/subdir && + test_commit a/b/subdir/foo && + + git branch O && + git branch A && + git branch B && + + git checkout A && + mkdir subdir && + git mv a/b/subdir/foo.t subdir/foo.t && + test_tick && + git commit -m "A" && + + git checkout B && + test_commit a/b/bar + ) +' + +test_expect_success '12d-check: Rename/merge subdir into the root, variant 1' ' + ( + cd 12d && + + git checkout A^0 && + + git -c merge.directoryRenames=true merge -s recursive B^0 && + + git ls-files -s >out && + test_line_count = 2 out && + + git rev-parse >actual \ + HEAD:subdir/foo.t HEAD:bar.t && + git rev-parse >expect \ + O:a/b/subdir/foo.t B:a/b/bar.t && + test_cmp expect actual && + + git hash-object bar.t >actual && + git rev-parse B:a/b/bar.t >expect && + test_cmp expect actual && + + test_must_fail git rev-parse HEAD:a/b/subdir/foo.t && + test_must_fail git rev-parse HEAD:a/b/bar.t && + test_path_is_missing a/ && + test_path_is_file bar.t + ) +' + +# Testcase 12e, Rename/merge of subdirectory into the root +# Commit O: a/b/foo +# Commit A: foo +# Commit B: a/b/foo, a/b/bar +# Expected: foo, bar + +test_expect_success '12e-setup: Rename/merge subdir into the root, variant 2' ' + test_create_repo 12e && + ( + cd 12e && + + mkdir -p a/b && + test_commit a/b/foo && + + git branch O && + git branch A && + git branch B && + + git checkout A && + mkdir subdir && + git mv a/b/foo.t foo.t && + test_tick && + git commit -m "A" && + + git checkout B && + test_commit a/b/bar + ) +' + +test_expect_success '12e-check: Rename/merge subdir into the root, variant 2' ' + ( + cd 12e && + + git checkout A^0 && + + git -c merge.directoryRenames=true merge -s recursive B^0 && + + git ls-files -s >out && + test_line_count = 2 out && + + git rev-parse >actual \ + HEAD:foo.t HEAD:bar.t && + git rev-parse >expect \ + O:a/b/foo.t B:a/b/bar.t && + test_cmp expect actual && + + git hash-object bar.t >actual && + git rev-parse B:a/b/bar.t >expect && + test_cmp expect actual && + + test_must_fail git rev-parse HEAD:a/b/foo.t && + test_must_fail git rev-parse HEAD:a/b/bar.t && + test_path_is_missing a/ && + test_path_is_file bar.t + ) +' + ########################################################################### # SECTION 13: Checking informational and conflict messages # From da1e295e008ba016eef008385afb2c20c7fc3ff8 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Tue, 22 Oct 2019 21:22:51 +0000 Subject: [PATCH 038/953] t604[236]: do not run setup in separate tests Transform the setup "tests" to setup functions, and have the actual tests call the setup functions. Advantages: * Should make life easier for people working with webby CI/PR builds who have to abuse mice (and their own index finger as well) in order to switch from viewing one testcase to another. Sounds awful; hopefully this will improve things for them. * Improves re-runnability: any failed test in any of these three files can now be re-run in isolation, e.g. ./t6042* --ver --imm -x --run=21 whereas before it would require two tests to be specified to the --run argument, the other needing to be picked out as the relevant setup test from one or two tests before. * Importantly, this still keeps the "setup" and "test" sections somewhat separate to make it easier for readers to discern what is just ancillary setup and what the intent of the test is. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- t/t6042-merge-rename-corner-cases.sh | 111 +++--- t/t6043-merge-rename-directories.sh | 466 ++++++++++++++----------- t/t6046-merge-skip-unneeded-updates.sh | 135 ++++--- 3 files changed, 393 insertions(+), 319 deletions(-) diff --git a/t/t6042-merge-rename-corner-cases.sh b/t/t6042-merge-rename-corner-cases.sh index c5b57f40c3d127..b047cf1c1c3735 100755 --- a/t/t6042-merge-rename-corner-cases.sh +++ b/t/t6042-merge-rename-corner-cases.sh @@ -5,7 +5,7 @@ test_description="recursive merge corner cases w/ renames but not criss-crosses" . ./test-lib.sh -test_expect_success 'setup rename/delete + untracked file' ' +test_setup_rename_delete_untracked () { test_create_repo rename-delete-untracked && ( cd rename-delete-untracked && @@ -29,9 +29,10 @@ test_expect_success 'setup rename/delete + untracked file' ' git commit -m track-people-instead-of-objects && echo "Myyy PRECIOUSSS" >ring ) -' +} test_expect_success "Does git preserve Gollum's precious artifact?" ' + test_setup_rename_delete_untracked && ( cd rename-delete-untracked && @@ -49,7 +50,7 @@ test_expect_success "Does git preserve Gollum's precious artifact?" ' # # We should be able to merge B & C cleanly -test_expect_success 'setup rename/modify/add-source conflict' ' +test_setup_rename_modify_add_source () { test_create_repo rename-modify-add-source && ( cd rename-modify-add-source && @@ -70,9 +71,10 @@ test_expect_success 'setup rename/modify/add-source conflict' ' git add a && git commit -m C ) -' +} test_expect_failure 'rename/modify/add-source conflict resolvable' ' + test_setup_rename_modify_add_source && ( cd rename-modify-add-source && @@ -88,7 +90,7 @@ test_expect_failure 'rename/modify/add-source conflict resolvable' ' ) ' -test_expect_success 'setup resolvable conflict missed if rename missed' ' +test_setup_break_detection_1 () { test_create_repo break-detection-1 && ( cd break-detection-1 && @@ -110,9 +112,10 @@ test_expect_success 'setup resolvable conflict missed if rename missed' ' git add a && git commit -m C ) -' +} test_expect_failure 'conflict caused if rename not detected' ' + test_setup_break_detection_1 && ( cd break-detection-1 && @@ -135,7 +138,7 @@ test_expect_failure 'conflict caused if rename not detected' ' ) ' -test_expect_success 'setup conflict resolved wrong if rename missed' ' +test_setup_break_detection_2 () { test_create_repo break-detection-2 && ( cd break-detection-2 && @@ -160,9 +163,10 @@ test_expect_success 'setup conflict resolved wrong if rename missed' ' git add a && git commit -m E ) -' +} test_expect_failure 'missed conflict if rename not detected' ' + test_setup_break_detection_2 && ( cd break-detection-2 && @@ -182,7 +186,7 @@ test_expect_failure 'missed conflict if rename not detected' ' # Commit B: rename a->b # Commit C: rename a->b, add unrelated a -test_expect_success 'setup undetected rename/add-source causes data loss' ' +test_setup_break_detection_3 () { test_create_repo break-detection-3 && ( cd break-detection-3 && @@ -202,9 +206,10 @@ test_expect_success 'setup undetected rename/add-source causes data loss' ' git add a && git commit -m C ) -' +} test_expect_failure 'detect rename/add-source and preserve all data' ' + test_setup_break_detection_3 && ( cd break-detection-3 && @@ -231,6 +236,7 @@ test_expect_failure 'detect rename/add-source and preserve all data' ' ' test_expect_failure 'detect rename/add-source and preserve all data, merge other way' ' + test_setup_break_detection_3 && ( cd break-detection-3 && @@ -256,10 +262,10 @@ test_expect_failure 'detect rename/add-source and preserve all data, merge other ) ' -test_expect_success 'setup content merge + rename/directory conflict' ' - test_create_repo rename-directory-1 && +test_setup_rename_directory () { + test_create_repo rename-directory-$1 && ( - cd rename-directory-1 && + cd rename-directory-$1 && printf "1\n2\n3\n4\n5\n6\n" >file && git add file && @@ -290,11 +296,12 @@ test_expect_success 'setup content merge + rename/directory conflict' ' test_tick && git commit -m left ) -' +} test_expect_success 'rename/directory conflict + clean content merge' ' + test_setup_rename_directory 1a && ( - cd rename-directory-1 && + cd rename-directory-1a && git checkout left-clean^0 && @@ -320,8 +327,9 @@ test_expect_success 'rename/directory conflict + clean content merge' ' ' test_expect_success 'rename/directory conflict + content merge conflict' ' + test_setup_rename_directory 1b && ( - cd rename-directory-1 && + cd rename-directory-1b && git reset --hard && git clean -fdqx && @@ -358,7 +366,7 @@ test_expect_success 'rename/directory conflict + content merge conflict' ' ) ' -test_expect_success 'setup content merge + rename/directory conflict w/ disappearing dir' ' +test_setup_rename_directory_2 () { test_create_repo rename-directory-2 && ( cd rename-directory-2 && @@ -385,9 +393,10 @@ test_expect_success 'setup content merge + rename/directory conflict w/ disappea test_tick && git commit -m left ) -' +} test_expect_success 'disappearing dir in rename/directory conflict handled' ' + test_setup_rename_directory_2 && ( cd rename-directory-2 && @@ -416,10 +425,10 @@ test_expect_success 'disappearing dir in rename/directory conflict handled' ' # Commit A: rename a->b, modifying b too # Commit B: modify a, add different b -test_expect_success 'setup rename-with-content-merge vs. add' ' - test_create_repo rename-with-content-merge-and-add && +test_setup_rename_with_content_merge_and_add () { + test_create_repo rename-with-content-merge-and-add-$1 && ( - cd rename-with-content-merge-and-add && + cd rename-with-content-merge-and-add-$1 && test_seq 1 5 >a && git add a && @@ -438,11 +447,12 @@ test_expect_success 'setup rename-with-content-merge vs. add' ' git add a b && git commit -m B ) -' +} test_expect_success 'handle rename-with-content-merge vs. add' ' + test_setup_rename_with_content_merge_and_add AB && ( - cd rename-with-content-merge-and-add && + cd rename-with-content-merge-and-add-AB && git checkout A^0 && @@ -483,8 +493,9 @@ test_expect_success 'handle rename-with-content-merge vs. add' ' ' test_expect_success 'handle rename-with-content-merge vs. add, merge other way' ' + test_setup_rename_with_content_merge_and_add BA && ( - cd rename-with-content-merge-and-add && + cd rename-with-content-merge-and-add-BA && git reset --hard && git clean -fdx && @@ -539,7 +550,7 @@ test_expect_success 'handle rename-with-content-merge vs. add, merge other way' # * The working copy should have two files, both of form c~; does it? # * Nothing else should be present. Is anything? -test_expect_success 'setup rename/rename (2to1) + modify/modify' ' +test_setup_rename_rename_2to1 () { test_create_repo rename-rename-2to1 && ( cd rename-rename-2to1 && @@ -562,9 +573,10 @@ test_expect_success 'setup rename/rename (2to1) + modify/modify' ' git add a && git commit -m C ) -' +} test_expect_success 'handle rename/rename (2to1) conflict correctly' ' + test_setup_rename_rename_2to1 && ( cd rename-rename-2to1 && @@ -610,7 +622,7 @@ test_expect_success 'handle rename/rename (2to1) conflict correctly' ' # Commit A: new file: a # Commit B: rename a->b # Commit C: rename a->c -test_expect_success 'setup simple rename/rename (1to2) conflict' ' +test_setup_rename_rename_1to2 () { test_create_repo rename-rename-1to2 && ( cd rename-rename-1to2 && @@ -631,9 +643,10 @@ test_expect_success 'setup simple rename/rename (1to2) conflict' ' test_tick && git commit -m C ) -' +} test_expect_success 'merge has correct working tree contents' ' + test_setup_rename_rename_1to2 && ( cd rename-rename-1to2 && @@ -667,7 +680,7 @@ test_expect_success 'merge has correct working tree contents' ' # # Merging of B & C should NOT be clean; there's a rename/rename conflict -test_expect_success 'setup rename/rename(1to2)/add-source conflict' ' +test_setup_rename_rename_1to2_add_source_1 () { test_create_repo rename-rename-1to2-add-source-1 && ( cd rename-rename-1to2-add-source-1 && @@ -687,9 +700,10 @@ test_expect_success 'setup rename/rename(1to2)/add-source conflict' ' git add a && git commit -m C ) -' +} test_expect_failure 'detect conflict with rename/rename(1to2)/add-source merge' ' + test_setup_rename_rename_1to2_add_source_1 && ( cd rename-rename-1to2-add-source-1 && @@ -714,7 +728,7 @@ test_expect_failure 'detect conflict with rename/rename(1to2)/add-source merge' ) ' -test_expect_success 'setup rename/rename(1to2)/add-source resolvable conflict' ' +test_setup_rename_rename_1to2_add_source_2 () { test_create_repo rename-rename-1to2-add-source-2 && ( cd rename-rename-1to2-add-source-2 && @@ -737,9 +751,10 @@ test_expect_success 'setup rename/rename(1to2)/add-source resolvable conflict' ' test_tick && git commit -m two ) -' +} test_expect_failure 'rename/rename/add-source still tracks new a file' ' + test_setup_rename_rename_1to2_add_source_2 && ( cd rename-rename-1to2-add-source-2 && @@ -759,7 +774,7 @@ test_expect_failure 'rename/rename/add-source still tracks new a file' ' ) ' -test_expect_success 'setup rename/rename(1to2)/add-dest conflict' ' +test_setup_rename_rename_1to2_add_dest () { test_create_repo rename-rename-1to2-add-dest && ( cd rename-rename-1to2-add-dest && @@ -784,9 +799,10 @@ test_expect_success 'setup rename/rename(1to2)/add-dest conflict' ' test_tick && git commit -m two ) -' +} test_expect_success 'rename/rename/add-dest merge still knows about conflicting file versions' ' + test_setup_rename_rename_1to2_add_dest && ( cd rename-rename-1to2-add-dest && @@ -838,7 +854,7 @@ test_expect_success 'rename/rename/add-dest merge still knows about conflicting # Commit B: rename foo->bar # Expected: CONFLICT (rename/add/delete), two-way merged bar -test_expect_success 'rad-setup: rename/add/delete conflict' ' +test_setup_rad () { test_create_repo rad && ( cd rad && @@ -860,9 +876,10 @@ test_expect_success 'rad-setup: rename/add/delete conflict' ' git mv foo bar && git commit -m "rename foo to bar" ) -' +} test_expect_failure 'rad-check: rename/add/delete conflict' ' + test_setup_rad && ( cd rad && @@ -904,7 +921,7 @@ test_expect_failure 'rad-check: rename/add/delete conflict' ' # Commit B: rename bar->baz, rm foo # Expected: CONFLICT (rename/rename/delete/delete), two-way merged baz -test_expect_success 'rrdd-setup: rename/rename(2to1)/delete/delete conflict' ' +test_setup_rrdd () { test_create_repo rrdd && ( cd rrdd && @@ -927,9 +944,10 @@ test_expect_success 'rrdd-setup: rename/rename(2to1)/delete/delete conflict' ' git rm foo && git commit -m "Rename bar, remove foo" ) -' +} test_expect_failure 'rrdd-check: rename/rename(2to1)/delete/delete conflict' ' + test_setup_rrdd && ( cd rrdd && @@ -973,7 +991,7 @@ test_expect_failure 'rrdd-check: rename/rename(2to1)/delete/delete conflict' ' # Expected: six CONFLICT(rename/rename) messages, each path in two of the # multi-way merged contents found in two, four, six -test_expect_success 'mod6-setup: chains of rename/rename(1to2) and rename/rename(2to1)' ' +test_setup_mod6 () { test_create_repo mod6 && ( cd mod6 && @@ -1009,9 +1027,10 @@ test_expect_success 'mod6-setup: chains of rename/rename(1to2) and rename/rename test_tick && git commit -m "B" ) -' +} test_expect_failure 'mod6-check: chains of rename/rename(1to2) and rename/rename(2to1)' ' + test_setup_mod6 && ( cd mod6 && @@ -1108,7 +1127,8 @@ test_conflicts_with_adds_and_renames() { # files. Is it present? # 4) There should not be any three~* files in the working # tree - test_expect_success "setup simple $sideL/$sideR conflict" ' + test_setup_collision_conflict () { + #test_expect_success "setup simple $sideL/$sideR conflict" ' test_create_repo simple_${sideL}_${sideR} && ( cd simple_${sideL}_${sideR} && @@ -1185,9 +1205,11 @@ test_conflicts_with_adds_and_renames() { fi && test_tick && git commit -m R ) - ' + #' + } test_expect_success "check simple $sideL/$sideR conflict" ' + test_setup_collision_conflict && ( cd simple_${sideL}_${sideR} && @@ -1254,7 +1276,7 @@ test_conflicts_with_adds_and_renames add add # # So, we have four different conflicting files that all end up at path # 'three'. -test_expect_success 'setup nested conflicts from rename/rename(2to1)' ' +test_setup_nested_conflicts_from_rename_rename () { test_create_repo nested_conflicts_from_rename_rename && ( cd nested_conflicts_from_rename_rename && @@ -1305,9 +1327,10 @@ test_expect_success 'setup nested conflicts from rename/rename(2to1)' ' git add one three && test_tick && git commit -m german ) -' +} test_expect_success 'check nested conflicts from rename/rename(2to1)' ' + test_setup_nested_conflicts_from_rename_rename && ( cd nested_conflicts_from_rename_rename && diff --git a/t/t6043-merge-rename-directories.sh b/t/t6043-merge-rename-directories.sh index 32cdd1f493a4af..bd2f97ba95525c 100755 --- a/t/t6043-merge-rename-directories.sh +++ b/t/t6043-merge-rename-directories.sh @@ -38,7 +38,7 @@ test_description="recursive merge with directory renames" # Commit B: z/{b,c,d,e/f} # Expected: y/{b,c,d,e/f} -test_expect_success '1a-setup: Simple directory rename detection' ' +test_setup_1a () { test_create_repo 1a && ( cd 1a && @@ -67,9 +67,10 @@ test_expect_success '1a-setup: Simple directory rename detection' ' test_tick && git commit -m "B" ) -' +} -test_expect_success '1a-check: Simple directory rename detection' ' +test_expect_success '1a: Simple directory rename detection' ' + test_setup_1a && ( cd 1a && @@ -103,7 +104,7 @@ test_expect_success '1a-check: Simple directory rename detection' ' # Commit B: y/{b,c,d} # Expected: y/{b,c,d,e} -test_expect_success '1b-setup: Merge a directory with another' ' +test_setup_1b () { test_create_repo 1b && ( cd 1b && @@ -134,9 +135,10 @@ test_expect_success '1b-setup: Merge a directory with another' ' test_tick && git commit -m "B" ) -' +} -test_expect_success '1b-check: Merge a directory with another' ' +test_expect_success '1b: Merge a directory with another' ' + test_setup_1b && ( cd 1b && @@ -165,7 +167,7 @@ test_expect_success '1b-check: Merge a directory with another' ' # Commit B: z/{b,c,d} # Expected: y/{b,c,d} (because x/d -> z/d -> y/d) -test_expect_success '1c-setup: Transitive renaming' ' +test_setup_1c () { test_create_repo 1c && ( cd 1c && @@ -193,9 +195,10 @@ test_expect_success '1c-setup: Transitive renaming' ' test_tick && git commit -m "B" ) -' +} -test_expect_success '1c-check: Transitive renaming' ' +test_expect_success '1c: Transitive renaming' ' + test_setup_1c && ( cd 1c && @@ -227,7 +230,7 @@ test_expect_success '1c-check: Transitive renaming' ' # Note: y/m & z/n should definitely move into x. By the same token, both # y/wham_1 & z/wham_2 should too...giving us a conflict. -test_expect_success '1d-setup: Directory renames cause a rename/rename(2to1) conflict' ' +test_setup_1d () { test_create_repo 1d && ( cd 1d && @@ -262,9 +265,10 @@ test_expect_success '1d-setup: Directory renames cause a rename/rename(2to1) con test_tick && git commit -m "B" ) -' +} -test_expect_success '1d-check: Directory renames cause a rename/rename(2to1) conflict' ' +test_expect_success '1d: Directory renames cause a rename/rename(2to1) conflict' ' + test_setup_1d && ( cd 1d && @@ -313,7 +317,7 @@ test_expect_success '1d-check: Directory renames cause a rename/rename(2to1) con # Commit B: z/{oldb,oldc,d} # Expected: y/{newb,newc,d} -test_expect_success '1e-setup: Renamed directory, with all files being renamed too' ' +test_setup_1e () { test_create_repo 1e && ( cd 1e && @@ -342,9 +346,10 @@ test_expect_success '1e-setup: Renamed directory, with all files being renamed t test_tick && git commit -m "B" ) -' +} -test_expect_success '1e-check: Renamed directory, with all files being renamed too' ' +test_expect_success '1e: Renamed directory, with all files being renamed too' ' + test_setup_1e && ( cd 1e && @@ -371,7 +376,7 @@ test_expect_success '1e-check: Renamed directory, with all files being renamed t # Commit B: y/{b,c}, x/{d,e,f} # Expected: y/{b,c}, x/{d,e,f,g} -test_expect_success '1f-setup: Split a directory into two other directories' ' +test_setup_1f () { test_create_repo 1f && ( cd 1f && @@ -408,9 +413,10 @@ test_expect_success '1f-setup: Split a directory into two other directories' ' test_tick && git commit -m "B" ) -' +} -test_expect_success '1f-check: Split a directory into two other directories' ' +test_expect_success '1f: Split a directory into two other directories' ' + test_setup_1f && ( cd 1f && @@ -459,7 +465,7 @@ test_expect_success '1f-check: Split a directory into two other directories' ' # Commit A: y/b, w/c # Commit B: z/{b,c,d} # Expected: y/b, w/c, z/d, with warning about z/ -> (y/ vs. w/) conflict -test_expect_success '2a-setup: Directory split into two on one side, with equal numbers of paths' ' +test_setup_2a () { test_create_repo 2a && ( cd 2a && @@ -489,9 +495,10 @@ test_expect_success '2a-setup: Directory split into two on one side, with equal test_tick && git commit -m "B" ) -' +} -test_expect_success '2a-check: Directory split into two on one side, with equal numbers of paths' ' +test_expect_success '2a: Directory split into two on one side, with equal numbers of paths' ' + test_setup_2a && ( cd 2a && @@ -520,7 +527,7 @@ test_expect_success '2a-check: Directory split into two on one side, with equal # Commit A: y/b, w/c # Commit B: z/{b,c}, x/d # Expected: y/b, w/c, x/d; No warning about z/ -> (y/ vs. w/) conflict -test_expect_success '2b-setup: Directory split into two on one side, with equal numbers of paths' ' +test_setup_2b () { test_create_repo 2b && ( cd 2b && @@ -551,9 +558,10 @@ test_expect_success '2b-setup: Directory split into two on one side, with equal test_tick && git commit -m "B" ) -' +} -test_expect_success '2b-check: Directory split into two on one side, with equal numbers of paths' ' +test_expect_success '2b: Directory split into two on one side, with equal numbers of paths' ' + test_setup_2b && ( cd 2b && @@ -601,7 +609,7 @@ test_expect_success '2b-check: Directory split into two on one side, with equal # Commit A: z/{b,c,d} (no change) # Commit B: y/{b,c}, x/d # Expected: y/{b,c}, x/d -test_expect_success '3a-setup: Avoid implicit rename if involved as source on other side' ' +test_setup_3a () { test_create_repo 3a && ( cd 3a && @@ -632,9 +640,10 @@ test_expect_success '3a-setup: Avoid implicit rename if involved as source on ot test_tick && git commit -m "B" ) -' +} -test_expect_success '3a-check: Avoid implicit rename if involved as source on other side' ' +test_expect_success '3a: Avoid implicit rename if involved as source on other side' ' + test_setup_3a && ( cd 3a && @@ -664,7 +673,7 @@ test_expect_success '3a-check: Avoid implicit rename if involved as source on ot # get it involved in directory rename detection. If it were, we might # end up with CONFLICT:(z/d -> y/d vs. x/d vs. w/d), i.e. a # rename/rename/rename(1to3) conflict, which is just weird. -test_expect_success '3b-setup: Avoid implicit rename if involved as source on current side' ' +test_setup_3b () { test_create_repo 3b && ( cd 3b && @@ -697,9 +706,10 @@ test_expect_success '3b-setup: Avoid implicit rename if involved as source on cu test_tick && git commit -m "B" ) -' +} -test_expect_success '3b-check: Avoid implicit rename if involved as source on current side' ' +test_expect_success '3b: Avoid implicit rename if involved as source on current side' ' + test_setup_3b && ( cd 3b && @@ -786,7 +796,7 @@ test_expect_success '3b-check: Avoid implicit rename if involved as source on cu # Expected: y/{b,c,d}, z/{e,f} # NOTE: Even though most files from z moved to y, we don't want f to follow. -test_expect_success '4a-setup: Directory split, with original directory still present' ' +test_setup_4a () { test_create_repo 4a && ( cd 4a && @@ -818,9 +828,10 @@ test_expect_success '4a-setup: Directory split, with original directory still pr test_tick && git commit -m "B" ) -' +} -test_expect_success '4a-check: Directory split, with original directory still present' ' +test_expect_success '4a: Directory split, with original directory still present' ' + test_setup_4a && ( cd 4a && @@ -874,7 +885,7 @@ test_expect_success '4a-check: Directory split, with original directory still pr # of history, giving us no way to represent this conflict in the # index. -test_expect_success '5a-setup: Merge directories, other side adds files to original and target' ' +test_setup_5a () { test_create_repo 5a && ( cd 5a && @@ -907,9 +918,10 @@ test_expect_success '5a-setup: Merge directories, other side adds files to origi test_tick && git commit -m "B" ) -' +} -test_expect_success '5a-check: Merge directories, other side adds files to original and target' ' +test_expect_success '5a: Merge directories, other side adds files to original and target' ' + test_setup_5a && ( cd 5a && @@ -948,7 +960,7 @@ test_expect_success '5a-check: Merge directories, other side adds files to origi # cause us to bail on directory rename detection for that path, falling # back to git behavior without the directory rename detection. -test_expect_success '5b-setup: Rename/delete in order to get add/add/add conflict' ' +test_setup_5b () { test_create_repo 5b && ( cd 5b && @@ -981,9 +993,10 @@ test_expect_success '5b-setup: Rename/delete in order to get add/add/add conflic test_tick && git commit -m "B" ) -' +} -test_expect_success '5b-check: Rename/delete in order to get add/add/add conflict' ' +test_expect_success '5b: Rename/delete in order to get add/add/add conflict' ' + test_setup_5b && ( cd 5b && @@ -1024,7 +1037,7 @@ test_expect_success '5b-check: Rename/delete in order to get add/add/add conflic # y/d are y/d_2 and y/d_4. We still do the move from z/e to y/e, # though, because it doesn't have anything in the way. -test_expect_success '5c-setup: Transitive rename would cause rename/rename/rename/add/add/add' ' +test_setup_5c () { test_create_repo 5c && ( cd 5c && @@ -1061,9 +1074,10 @@ test_expect_success '5c-setup: Transitive rename would cause rename/rename/renam test_tick && git commit -m "B" ) -' +} -test_expect_success '5c-check: Transitive rename would cause rename/rename/rename/add/add/add' ' +test_expect_success '5c: Transitive rename would cause rename/rename/rename/add/add/add' ' + test_setup_5c && ( cd 5c && @@ -1113,7 +1127,7 @@ test_expect_success '5c-check: Transitive rename would cause rename/rename/renam # detection for z/d_2, but that doesn't prevent us from applying the # directory rename detection for z/f -> y/f. -test_expect_success '5d-setup: Directory/file/file conflict due to directory rename' ' +test_setup_5d () { test_create_repo 5d && ( cd 5d && @@ -1145,9 +1159,10 @@ test_expect_success '5d-setup: Directory/file/file conflict due to directory ren test_tick && git commit -m "B" ) -' +} -test_expect_success '5d-check: Directory/file/file conflict due to directory rename' ' +test_expect_success '5d: Directory/file/file conflict due to directory rename' ' + test_setup_5d && ( cd 5d && @@ -1205,7 +1220,7 @@ test_expect_success '5d-check: Directory/file/file conflict due to directory ren # them under y/ doesn't accidentally catch z/d and make it look like # it is also involved in a rename/delete conflict. -test_expect_success '6a-setup: Tricky rename/delete' ' +test_setup_6a () { test_create_repo 6a && ( cd 6a && @@ -1235,9 +1250,10 @@ test_expect_success '6a-setup: Tricky rename/delete' ' test_tick && git commit -m "B" ) -' +} -test_expect_success '6a-check: Tricky rename/delete' ' +test_expect_success '6a: Tricky rename/delete' ' + test_setup_6a && ( cd 6a && @@ -1271,7 +1287,7 @@ test_expect_success '6a-check: Tricky rename/delete' ' # but B did that rename and still decided to put the file into z/, # so we probably shouldn't apply directory rename detection for it. -test_expect_success '6b-setup: Same rename done on both sides' ' +test_setup_6b () { test_create_repo 6b && ( cd 6b && @@ -1300,9 +1316,10 @@ test_expect_success '6b-setup: Same rename done on both sides' ' test_tick && git commit -m "B" ) -' +} -test_expect_success '6b-check: Same rename done on both sides' ' +test_expect_success '6b: Same rename done on both sides' ' + test_setup_6b && ( cd 6b && @@ -1334,7 +1351,7 @@ test_expect_success '6b-check: Same rename done on both sides' ' # NOTE: Seems obvious, but just checking that the implementation doesn't # "accidentally detect a rename" and give us y/{b,c,d}. -test_expect_success '6c-setup: Rename only done on same side' ' +test_setup_6c () { test_create_repo 6c && ( cd 6c && @@ -1362,9 +1379,10 @@ test_expect_success '6c-setup: Rename only done on same side' ' test_tick && git commit -m "B" ) -' +} -test_expect_success '6c-check: Rename only done on same side' ' +test_expect_success '6c: Rename only done on same side' ' + test_setup_6c && ( cd 6c && @@ -1396,7 +1414,7 @@ test_expect_success '6c-check: Rename only done on same side' ' # NOTE: Again, this seems obvious but just checking that the implementation # doesn't "accidentally detect a rename" and give us y/{b,c,d}. -test_expect_success '6d-setup: We do not always want transitive renaming' ' +test_setup_6d () { test_create_repo 6d && ( cd 6d && @@ -1424,9 +1442,10 @@ test_expect_success '6d-setup: We do not always want transitive renaming' ' test_tick && git commit -m "B" ) -' +} -test_expect_success '6d-check: We do not always want transitive renaming' ' +test_expect_success '6d: We do not always want transitive renaming' ' + test_setup_6d && ( cd 6d && @@ -1458,7 +1477,7 @@ test_expect_success '6d-check: We do not always want transitive renaming' ' # doesn't "accidentally detect a rename" and give us y/{b,c} + # add/add conflict on y/d_1 vs y/d_2. -test_expect_success '6e-setup: Add/add from one side' ' +test_setup_6e () { test_create_repo 6e && ( cd 6e && @@ -1487,9 +1506,10 @@ test_expect_success '6e-setup: Add/add from one side' ' test_tick && git commit -m "B" ) -' +} -test_expect_success '6e-check: Add/add from one side' ' +test_expect_success '6e: Add/add from one side' ' + test_setup_6e && ( cd 6e && @@ -1552,7 +1572,7 @@ test_expect_success '6e-check: Add/add from one side' ' # Expected: y/d, CONFLICT(rename/rename for both z/b and z/c) # NOTE: There's a rename of z/ here, y/ has more renames, so z/d -> y/d. -test_expect_success '7a-setup: rename-dir vs. rename-dir (NOT split evenly) PLUS add-other-file' ' +test_setup_7a () { test_create_repo 7a && ( cd 7a && @@ -1583,9 +1603,10 @@ test_expect_success '7a-setup: rename-dir vs. rename-dir (NOT split evenly) PLUS test_tick && git commit -m "B" ) -' +} -test_expect_success '7a-check: rename-dir vs. rename-dir (NOT split evenly) PLUS add-other-file' ' +test_expect_success '7a: rename-dir vs. rename-dir (NOT split evenly) PLUS add-other-file' ' + test_setup_7a && ( cd 7a && @@ -1623,7 +1644,7 @@ test_expect_success '7a-check: rename-dir vs. rename-dir (NOT split evenly) PLUS # Commit B: z/{b,c,d_1}, w/d_2 # Expected: y/{b,c}, CONFLICT(rename/rename(2to1): x/d_1, w/d_2 -> y_d) -test_expect_success '7b-setup: rename/rename(2to1), but only due to transitive rename' ' +test_setup_7b () { test_create_repo 7b && ( cd 7b && @@ -1655,9 +1676,10 @@ test_expect_success '7b-setup: rename/rename(2to1), but only due to transitive r test_tick && git commit -m "B" ) -' +} -test_expect_success '7b-check: rename/rename(2to1), but only due to transitive rename' ' +test_expect_success '7b: rename/rename(2to1), but only due to transitive rename' ' + test_setup_7b && ( cd 7b && @@ -1702,7 +1724,7 @@ test_expect_success '7b-check: rename/rename(2to1), but only due to transitive r # neither CONFLICT(x/d -> w/d vs. z/d) # nor CONFLiCT x/d -> w/d vs. y/d vs. z/d) -test_expect_success '7c-setup: rename/rename(1to...2or3); transitive rename may add complexity' ' +test_setup_7c () { test_create_repo 7c && ( cd 7c && @@ -1732,9 +1754,10 @@ test_expect_success '7c-setup: rename/rename(1to...2or3); transitive rename may test_tick && git commit -m "B" ) -' +} -test_expect_success '7c-check: rename/rename(1to...2or3); transitive rename may add complexity' ' +test_expect_success '7c: rename/rename(1to...2or3); transitive rename may add complexity' ' + test_setup_7c && ( cd 7c && @@ -1766,7 +1789,7 @@ test_expect_success '7c-check: rename/rename(1to...2or3); transitive rename may # Expected: y/{b,c}, CONFLICT(delete x/d vs rename to y/d) # NOTE: z->y so NOT CONFLICT(delete x/d vs rename to z/d) -test_expect_success '7d-setup: transitive rename involved in rename/delete; how is it reported?' ' +test_setup_7d () { test_create_repo 7d && ( cd 7d && @@ -1796,9 +1819,10 @@ test_expect_success '7d-setup: transitive rename involved in rename/delete; how test_tick && git commit -m "B" ) -' +} -test_expect_success '7d-check: transitive rename involved in rename/delete; how is it reported?' ' +test_expect_success '7d: transitive rename involved in rename/delete; how is it reported?' ' + test_setup_7d && ( cd 7d && @@ -1851,7 +1875,7 @@ test_expect_success '7d-check: transitive rename involved in rename/delete; how # see testcases 9c and 9d for further discussion of this issue and # how it's resolved. -test_expect_success '7e-setup: transitive rename in rename/delete AND dirs in the way' ' +test_setup_7e () { test_create_repo 7e && ( cd 7e && @@ -1886,9 +1910,10 @@ test_expect_success '7e-setup: transitive rename in rename/delete AND dirs in th test_tick && git commit -m "B" ) -' +} -test_expect_success '7e-check: transitive rename in rename/delete AND dirs in the way' ' +test_expect_success '7e: transitive rename in rename/delete AND dirs in the way' ' + test_setup_7e && ( cd 7e && @@ -1945,7 +1970,7 @@ test_expect_success '7e-check: transitive rename in rename/delete AND dirs in th # simple rule from section 5 prevents me from handling this as optimally as # we potentially could. -test_expect_success '8a-setup: Dual-directory rename, one into the others way' ' +test_setup_8a () { test_create_repo 8a && ( cd 8a && @@ -1977,9 +2002,10 @@ test_expect_success '8a-setup: Dual-directory rename, one into the others way' ' test_tick && git commit -m "B" ) -' +} -test_expect_success '8a-check: Dual-directory rename, one into the others way' ' +test_expect_success '8a: Dual-directory rename, one into the others way' ' + test_setup_8a && ( cd 8a && @@ -2023,7 +2049,7 @@ test_expect_success '8a-check: Dual-directory rename, one into the others way' ' # making us fall back to pre-directory-rename-detection behavior for both # e_1 and e_2. -test_expect_success '8b-setup: Dual-directory rename, one into the others way, with conflicting filenames' ' +test_setup_8b () { test_create_repo 8b && ( cd 8b && @@ -2055,9 +2081,10 @@ test_expect_success '8b-setup: Dual-directory rename, one into the others way, w test_tick && git commit -m "B" ) -' +} -test_expect_success '8b-check: Dual-directory rename, one into the others way, with conflicting filenames' ' +test_expect_success '8b: Dual-directory rename, one into the others way, with conflicting filenames' ' + test_setup_8b && ( cd 8b && @@ -2096,7 +2123,7 @@ test_expect_success '8b-check: Dual-directory rename, one into the others way, w # rename/rename(1to2) conflicts -- see testcase 9h. See also # notes in 8d. -test_expect_success '8c-setup: modify/delete or rename+modify/delete?' ' +test_setup_8c () { test_create_repo 8c && ( cd 8c && @@ -2127,9 +2154,10 @@ test_expect_success '8c-setup: modify/delete or rename+modify/delete?' ' test_tick && git commit -m "B" ) -' +} -test_expect_success '8c-check: modify/delete or rename+modify/delete' ' +test_expect_success '8c: modify/delete or rename+modify/delete' ' + test_setup_8c && ( cd 8c && @@ -2175,7 +2203,7 @@ test_expect_success '8c-check: modify/delete or rename+modify/delete' ' # during merging are supposed to be about opposite sides doing things # differently. -test_expect_success '8d-setup: rename/delete...or not?' ' +test_setup_8d () { test_create_repo 8d && ( cd 8d && @@ -2204,9 +2232,10 @@ test_expect_success '8d-setup: rename/delete...or not?' ' test_tick && git commit -m "B" ) -' +} -test_expect_success '8d-check: rename/delete...or not?' ' +test_expect_success '8d: rename/delete...or not?' ' + test_setup_8d && ( cd 8d && @@ -2250,7 +2279,7 @@ test_expect_success '8d-check: rename/delete...or not?' ' # about the ramifications of doing that, I didn't know how to rule out # that opening other weird edge and corner cases so I just punted. -test_expect_success '8e-setup: Both sides rename, one side adds to original directory' ' +test_setup_8e () { test_create_repo 8e && ( cd 8e && @@ -2279,9 +2308,10 @@ test_expect_success '8e-setup: Both sides rename, one side adds to original dire test_tick && git commit -m "B" ) -' +} -test_expect_success '8e-check: Both sides rename, one side adds to original directory' ' +test_expect_success '8e: Both sides rename, one side adds to original directory' ' + test_setup_8e && ( cd 8e && @@ -2333,7 +2363,7 @@ test_expect_success '8e-check: Both sides rename, one side adds to original dire # of which one had the most paths going to it. A naive implementation # of that could take the new file in commit B at z/i to x/w/i or x/i. -test_expect_success '9a-setup: Inner renamed directory within outer renamed directory' ' +test_setup_9a () { test_create_repo 9a && ( cd 9a && @@ -2366,9 +2396,10 @@ test_expect_success '9a-setup: Inner renamed directory within outer renamed dire test_tick && git commit -m "B" ) -' +} -test_expect_success '9a-check: Inner renamed directory within outer renamed directory' ' +test_expect_success '9a: Inner renamed directory within outer renamed directory' ' + test_setup_9a && ( cd 9a && @@ -2404,7 +2435,7 @@ test_expect_success '9a-check: Inner renamed directory within outer renamed dire # Commit B: z/{b,c,d_3} # Expected: y/{b,c,d_merged} -test_expect_success '9b-setup: Transitive rename with content merge' ' +test_setup_9b () { test_create_repo 9b && ( cd 9b && @@ -2436,9 +2467,10 @@ test_expect_success '9b-setup: Transitive rename with content merge' ' test_tick && git commit -m "B" ) -' +} -test_expect_success '9b-check: Transitive rename with content merge' ' +test_expect_success '9b: Transitive rename with content merge' ' + test_setup_9b && ( cd 9b && @@ -2491,7 +2523,7 @@ test_expect_success '9b-check: Transitive rename with content merge' ' # away, then ignore that particular rename from the other side of # history for any implicit directory renames. -test_expect_success '9c-setup: Doubly transitive rename?' ' +test_setup_9c () { test_create_repo 9c && ( cd 9c && @@ -2526,9 +2558,10 @@ test_expect_success '9c-setup: Doubly transitive rename?' ' test_tick && git commit -m "B" ) -' +} -test_expect_success '9c-check: Doubly transitive rename?' ' +test_expect_success '9c: Doubly transitive rename?' ' + test_setup_9c && ( cd 9c && @@ -2579,7 +2612,7 @@ test_expect_success '9c-check: Doubly transitive rename?' ' # simple rules that are consistent with what we need for all the other # testcases and simplifies things for the user. -test_expect_success '9d-setup: N-way transitive rename?' ' +test_setup_9d () { test_create_repo 9d && ( cd 9d && @@ -2614,9 +2647,10 @@ test_expect_success '9d-setup: N-way transitive rename?' ' test_tick && git commit -m "B" ) -' +} -test_expect_success '9d-check: N-way transitive rename?' ' +test_expect_success '9d: N-way transitive rename?' ' + test_setup_9d && ( cd 9d && @@ -2653,7 +2687,7 @@ test_expect_success '9d-check: N-way transitive rename?' ' # Expected: combined/{a,b,c,d,e,f,g,h,i,j,k,l}, CONFLICT(Nto1) warnings, # dir1/yo, dir2/yo, dir3/yo, dirN/yo -test_expect_success '9e-setup: N-to-1 whammo' ' +test_setup_9e () { test_create_repo 9e && ( cd 9e && @@ -2696,9 +2730,10 @@ test_expect_success '9e-setup: N-to-1 whammo' ' test_tick && git commit -m "B" ) -' +} -test_expect_success C_LOCALE_OUTPUT '9e-check: N-to-1 whammo' ' +test_expect_success C_LOCALE_OUTPUT '9e: N-to-1 whammo' ' + test_setup_9e && ( cd 9e && @@ -2745,7 +2780,7 @@ test_expect_success C_LOCALE_OUTPUT '9e-check: N-to-1 whammo' ' # Commit B: goal/{a,b}/$more_files, goal/c # Expected: priority/{a,b}/$more_files, priority/c -test_expect_success '9f-setup: Renamed directory that only contained immediate subdirs' ' +test_setup_9f () { test_create_repo 9f && ( cd 9f && @@ -2774,9 +2809,10 @@ test_expect_success '9f-setup: Renamed directory that only contained immediate s test_tick && git commit -m "B" ) -' +} -test_expect_success '9f-check: Renamed directory that only contained immediate subdirs' ' +test_expect_success '9f: Renamed directory that only contained immediate subdirs' ' + test_setup_9f && ( cd 9f && @@ -2809,7 +2845,7 @@ test_expect_success '9f-check: Renamed directory that only contained immediate s # Commit B: goal/{a,b}/$more_files, goal/c # Expected: priority/{alpha,bravo}/$more_files, priority/c -test_expect_success '9g-setup: Renamed directory that only contained immediate subdirs, immediate subdirs renamed' ' +test_setup_9g () { test_create_repo 9g && ( cd 9g && @@ -2841,9 +2877,9 @@ test_expect_success '9g-setup: Renamed directory that only contained immediate s test_tick && git commit -m "B" ) -' +} -test_expect_failure '9g-check: Renamed directory that only contained immediate subdirs, immediate subdirs renamed' ' +test_expect_failure '9g: Renamed directory that only contained immediate subdirs, immediate subdirs renamed' ' ( cd 9g && @@ -2877,7 +2913,7 @@ test_expect_failure '9g-check: Renamed directory that only contained immediate s # Expected: y/{b,c}, x/d_2 # NOTE: If we applied the z/ -> y/ rename to z/d, then we'd end up with # a rename/rename(1to2) conflict (z/d -> y/d vs. x/d) -test_expect_success '9h-setup: Avoid dir rename on merely modified path' ' +test_setup_9h () { test_create_repo 9h && ( cd 9h && @@ -2910,9 +2946,10 @@ test_expect_success '9h-setup: Avoid dir rename on merely modified path' ' test_tick && git commit -m "B" ) -' +} -test_expect_success '9h-check: Avoid dir rename on merely modified path' ' +test_expect_success '9h: Avoid dir rename on merely modified path' ' + test_setup_9h && ( cd 9h && @@ -2957,7 +2994,7 @@ test_expect_success '9h-check: Avoid dir rename on merely modified path' ' # Expected: Aborted Merge + # ERROR_MSG(untracked working tree files would be overwritten by merge) -test_expect_success '10a-setup: Overwrite untracked with normal rename/delete' ' +test_setup_10a () { test_create_repo 10a && ( cd 10a && @@ -2983,9 +3020,10 @@ test_expect_success '10a-setup: Overwrite untracked with normal rename/delete' ' test_tick && git commit -m "B" ) -' +} -test_expect_success '10a-check: Overwrite untracked with normal rename/delete' ' +test_expect_success '10a: Overwrite untracked with normal rename/delete' ' + test_setup_10a && ( cd 10a && @@ -3021,7 +3059,7 @@ test_expect_success '10a-check: Overwrite untracked with normal rename/delete' ' # z/c_1 -> z/d_1 rename recorded at stage 3 for y/d + # ERROR_MSG(refusing to lose untracked file at 'y/d') -test_expect_success '10b-setup: Overwrite untracked with dir rename + delete' ' +test_setup_10b () { test_create_repo 10b && ( cd 10b && @@ -3050,9 +3088,10 @@ test_expect_success '10b-setup: Overwrite untracked with dir rename + delete' ' test_tick && git commit -m "B" ) -' +} -test_expect_success '10b-check: Overwrite untracked with dir rename + delete' ' +test_expect_success '10b: Overwrite untracked with dir rename + delete' ' + test_setup_10b && ( cd 10b && @@ -3098,10 +3137,10 @@ test_expect_success '10b-check: Overwrite untracked with dir rename + delete' ' # y/c~B^0 + # ERROR_MSG(Refusing to lose untracked file at y/c) -test_expect_success '10c-setup: Overwrite untracked with dir rename/rename(1to2)' ' - test_create_repo 10c && +test_setup_10c () { + test_create_repo 10c_$1 && ( - cd 10c && + cd 10c_$1 && mkdir z x && echo a >z/a && @@ -3128,11 +3167,12 @@ test_expect_success '10c-setup: Overwrite untracked with dir rename/rename(1to2) test_tick && git commit -m "B" ) -' +} -test_expect_success '10c-check: Overwrite untracked with dir rename/rename(1to2)' ' +test_expect_success '10c1: Overwrite untracked with dir rename/rename(1to2)' ' + test_setup_10c 1 && ( - cd 10c && + cd 10c_1 && git checkout A^0 && echo important >y/c && @@ -3163,9 +3203,10 @@ test_expect_success '10c-check: Overwrite untracked with dir rename/rename(1to2) ) ' -test_expect_success '10c-check: Overwrite untracked with dir rename/rename(1to2), other direction' ' +test_expect_success '10c2: Overwrite untracked with dir rename/rename(1to2), other direction' ' + test_setup_10c 2 && ( - cd 10c && + cd 10c_2 && git reset --hard && git clean -fdqx && @@ -3208,7 +3249,7 @@ test_expect_success '10c-check: Overwrite untracked with dir rename/rename(1to2) # CONFLICT(rename/rename) z/c_1 vs x/f_2 -> y/wham # ERROR_MSG(Refusing to lose untracked file at y/wham) -test_expect_success '10d-setup: Delete untracked with dir rename/rename(2to1)' ' +test_setup_10d () { test_create_repo 10d && ( cd 10d && @@ -3240,9 +3281,10 @@ test_expect_success '10d-setup: Delete untracked with dir rename/rename(2to1)' ' test_tick && git commit -m "B" ) -' +} -test_expect_success '10d-check: Delete untracked with dir rename/rename(2to1)' ' +test_expect_success '10d: Delete untracked with dir rename/rename(2to1)' ' + test_setup_10d && ( cd 10d && @@ -3290,7 +3332,7 @@ test_expect_success '10d-check: Delete untracked with dir rename/rename(2to1)' ' # Commit B: z/{a,b,c} # Expected: y/{a,b,c} + untracked z/c -test_expect_success '10e-setup: Does git complain about untracked file that is not really in the way?' ' +test_setup_10e () { test_create_repo 10e && ( cd 10e && @@ -3317,9 +3359,9 @@ test_expect_success '10e-setup: Does git complain about untracked file that is n test_tick && git commit -m "B" ) -' +} -test_expect_failure '10e-check: Does git complain about untracked file that is not really in the way?' ' +test_expect_failure '10e: Does git complain about untracked file that is not really in the way?' ' ( cd 10e && @@ -3371,7 +3413,7 @@ test_expect_failure '10e-check: Does git complain about untracked file that is n # z/c~HEAD with contents of B:z/b_v2, # z/c with uncommitted mods on top of A:z/c_v1 -test_expect_success '11a-setup: Avoid losing dirty contents with simple rename' ' +test_setup_11a () { test_create_repo 11a && ( cd 11a && @@ -3398,9 +3440,10 @@ test_expect_success '11a-setup: Avoid losing dirty contents with simple rename' test_tick && git commit -m "B" ) -' +} -test_expect_success '11a-check: Avoid losing dirty contents with simple rename' ' +test_expect_success '11a: Avoid losing dirty contents with simple rename' ' + test_setup_11a && ( cd 11a && @@ -3441,7 +3484,7 @@ test_expect_success '11a-check: Avoid losing dirty contents with simple rename' # ERROR_MSG(Refusing to lose dirty file at z/c) -test_expect_success '11b-setup: Avoid losing dirty file involved in directory rename' ' +test_setup_11b () { test_create_repo 11b && ( cd 11b && @@ -3470,9 +3513,10 @@ test_expect_success '11b-setup: Avoid losing dirty file involved in directory re test_tick && git commit -m "B" ) -' +} -test_expect_success '11b-check: Avoid losing dirty file involved in directory rename' ' +test_expect_success '11b: Avoid losing dirty file involved in directory rename' ' + test_setup_11b && ( cd 11b && @@ -3515,7 +3559,7 @@ test_expect_success '11b-check: Avoid losing dirty file involved in directory re # Expected: Abort_msg("following files would be overwritten by merge") + # y/c left untouched (still has uncommitted mods) -test_expect_success '11c-setup: Avoid losing not-uptodate with rename + D/F conflict' ' +test_setup_11c () { test_create_repo 11c && ( cd 11c && @@ -3545,9 +3589,10 @@ test_expect_success '11c-setup: Avoid losing not-uptodate with rename + D/F conf test_tick && git commit -m "B" ) -' +} -test_expect_success '11c-check: Avoid losing not-uptodate with rename + D/F conflict' ' +test_expect_success '11c: Avoid losing not-uptodate with rename + D/F conflict' ' + test_setup_11c && ( cd 11c && @@ -3581,7 +3626,7 @@ test_expect_success '11c-check: Avoid losing not-uptodate with rename + D/F conf # Warning_Msg("Refusing to lose dirty file at z/c) + # y/{a,c~HEAD,c/d}, x/b, now-untracked z/c_v1 with uncommitted mods -test_expect_success '11d-setup: Avoid losing not-uptodate with rename + D/F conflict' ' +test_setup_11d () { test_create_repo 11d && ( cd 11d && @@ -3612,9 +3657,10 @@ test_expect_success '11d-setup: Avoid losing not-uptodate with rename + D/F conf test_tick && git commit -m "B" ) -' +} -test_expect_success '11d-check: Avoid losing not-uptodate with rename + D/F conflict' ' +test_expect_success '11d: Avoid losing not-uptodate with rename + D/F conflict' ' + test_setup_11d && ( cd 11d && @@ -3659,7 +3705,7 @@ test_expect_success '11d-check: Avoid losing not-uptodate with rename + D/F conf # y/c~HEAD has A:y/c_2 contents # y/c has dirty file from before merge -test_expect_success '11e-setup: Avoid deleting not-uptodate with dir rename/rename(1to2)/add' ' +test_setup_11e () { test_create_repo 11e && ( cd 11e && @@ -3691,9 +3737,10 @@ test_expect_success '11e-setup: Avoid deleting not-uptodate with dir rename/rena test_tick && git commit -m "B" ) -' +} -test_expect_success '11e-check: Avoid deleting not-uptodate with dir rename/rename(1to2)/add' ' +test_expect_success '11e: Avoid deleting not-uptodate with dir rename/rename(1to2)/add' ' + test_setup_11e && ( cd 11e && @@ -3744,7 +3791,7 @@ test_expect_success '11e-check: Avoid deleting not-uptodate with dir rename/rena # CONFLICT(rename/rename) x/c vs x/d -> y/wham # ERROR_MSG(Refusing to lose dirty file at y/wham) -test_expect_success '11f-setup: Avoid deleting not-uptodate with dir rename/rename(2to1)' ' +test_setup_11f () { test_create_repo 11f && ( cd 11f && @@ -3773,9 +3820,10 @@ test_expect_success '11f-setup: Avoid deleting not-uptodate with dir rename/rena test_tick && git commit -m "B" ) -' +} -test_expect_success '11f-check: Avoid deleting not-uptodate with dir rename/rename(2to1)' ' +test_expect_success '11f: Avoid deleting not-uptodate with dir rename/rename(2to1)' ' + test_setup_11f && ( cd 11f && @@ -3832,7 +3880,7 @@ test_expect_success '11f-check: Avoid deleting not-uptodate with dir rename/rena # Commit B: node1/{leaf1,leaf2,leaf5}, node2/{leaf3,leaf4,leaf6} # Expected: node1/{leaf1,leaf2,leaf5,node2/{leaf3,leaf4,leaf6}} -test_expect_success '12a-setup: Moving one directory hierarchy into another' ' +test_setup_12a () { test_create_repo 12a && ( cd 12a && @@ -3862,9 +3910,10 @@ test_expect_success '12a-setup: Moving one directory hierarchy into another' ' test_tick && git commit -m "B" ) -' +} -test_expect_success '12a-check: Moving one directory hierarchy into another' ' +test_expect_success '12a: Moving one directory hierarchy into another' ' + test_setup_12a && ( cd 12a && @@ -3910,7 +3959,7 @@ test_expect_success '12a-check: Moving one directory hierarchy into another' ' # To which, I can do no more than shrug my shoulders and say that # even simple rules give weird results when given weird inputs. -test_expect_success '12b-setup: Moving two directory hierarchies into each other' ' +test_setup_12b () { test_create_repo 12b && ( cd 12b && @@ -3938,9 +3987,10 @@ test_expect_success '12b-setup: Moving two directory hierarchies into each other test_tick && git commit -m "B" ) -' +} -test_expect_success '12b-check: Moving two directory hierarchies into each other' ' +test_expect_success '12b: Moving two directory hierarchies into each other' ' + test_setup_12b && ( cd 12b && @@ -3976,7 +4026,7 @@ test_expect_success '12b-check: Moving two directory hierarchies into each other # NOTE: This is *exactly* like 12c, except that every path is modified on # each side of the merge. -test_expect_success '12c-setup: Moving one directory hierarchy into another w/ content merge' ' +test_setup_12c () { test_create_repo 12c && ( cd 12c && @@ -4008,9 +4058,10 @@ test_expect_success '12c-setup: Moving one directory hierarchy into another w/ c test_tick && git commit -m "B" ) -' +} -test_expect_success '12c-check: Moving one directory hierarchy into another w/ content merge' ' +test_expect_success '12c: Moving one directory hierarchy into another w/ content merge' ' + test_setup_12c && ( cd 12c && @@ -4057,7 +4108,7 @@ test_expect_success '12c-check: Moving one directory hierarchy into another w/ c # Commit B: a/b/subdir/foo, a/b/bar # Expected: subdir/foo, bar -test_expect_success '12d-setup: Rename/merge subdir into the root, variant 1' ' +test_setup_12d () { test_create_repo 12d && ( cd 12d && @@ -4078,9 +4129,10 @@ test_expect_success '12d-setup: Rename/merge subdir into the root, variant 1' ' git checkout B && test_commit a/b/bar ) -' +} -test_expect_success '12d-check: Rename/merge subdir into the root, variant 1' ' +test_expect_success '12d: Rename/merge subdir into the root, variant 1' ' + test_setup_12d && ( cd 12d && @@ -4114,7 +4166,7 @@ test_expect_success '12d-check: Rename/merge subdir into the root, variant 1' ' # Commit B: a/b/foo, a/b/bar # Expected: foo, bar -test_expect_success '12e-setup: Rename/merge subdir into the root, variant 2' ' +test_setup_12e () { test_create_repo 12e && ( cd 12e && @@ -4135,9 +4187,10 @@ test_expect_success '12e-setup: Rename/merge subdir into the root, variant 2' ' git checkout B && test_commit a/b/bar ) -' +} -test_expect_success '12e-check: Rename/merge subdir into the root, variant 2' ' +test_expect_success '12e: Rename/merge subdir into the root, variant 2' ' + test_setup_12e && ( cd 12e && @@ -4182,10 +4235,10 @@ test_expect_success '12e-check: Rename/merge subdir into the root, variant 2' ' # Commit B: z/{b,c,d,e/f} # Expected: y/{b,c,d,e/f}, with notices/conflicts for both y/d and y/e/f -test_expect_success '13a-setup: messages for newly added files' ' - test_create_repo 13a && +test_setup_13a () { + test_create_repo 13a_$1 && ( - cd 13a && + cd 13a_$1 && mkdir z && echo b >z/b && @@ -4211,11 +4264,12 @@ test_expect_success '13a-setup: messages for newly added files' ' test_tick && git commit -m "B" ) -' +} -test_expect_success '13a-check(conflict): messages for newly added files' ' +test_expect_success '13a(conflict): messages for newly added files' ' + test_setup_13a conflict && ( - cd 13a && + cd 13a_conflict && git checkout A^0 && @@ -4235,9 +4289,10 @@ test_expect_success '13a-check(conflict): messages for newly added files' ' ) ' -test_expect_success '13a-check(info): messages for newly added files' ' +test_expect_success '13a(info): messages for newly added files' ' + test_setup_13a info && ( - cd 13a && + cd 13a_info && git reset --hard && git checkout A^0 && @@ -4267,10 +4322,10 @@ test_expect_success '13a-check(info): messages for newly added files' ' # Expected: y/{b,c,d_merged}, with two conflict messages for y/d, # one about content, and one about file location -test_expect_success '13b-setup: messages for transitive rename with conflicted content' ' - test_create_repo 13b && +test_setup_13b () { + test_create_repo 13b_$1 && ( - cd 13b && + cd 13b_$1 && mkdir x && mkdir z && @@ -4299,11 +4354,12 @@ test_expect_success '13b-setup: messages for transitive rename with conflicted c test_tick && git commit -m "B" ) -' +} -test_expect_success '13b-check(conflict): messages for transitive rename with conflicted content' ' +test_expect_success '13b(conflict): messages for transitive rename with conflicted content' ' + test_setup_13b conflict && ( - cd 13b && + cd 13b_conflict && git checkout A^0 && @@ -4321,9 +4377,10 @@ test_expect_success '13b-check(conflict): messages for transitive rename with co ) ' -test_expect_success '13b-check(info): messages for transitive rename with conflicted content' ' +test_expect_success '13b(info): messages for transitive rename with conflicted content' ' + test_setup_13b info && ( - cd 13b && + cd 13b_info && git reset --hard && git checkout A^0 && @@ -4352,10 +4409,10 @@ test_expect_success '13b-check(info): messages for transitive rename with confli # d and B had full knowledge, but that's a slippery slope as # shown in testcase 13d. -test_expect_success '13c-setup: messages for rename/rename(1to1) via transitive rename' ' - test_create_repo 13c && +test_setup_13c () { + test_create_repo 13c_$1 && ( - cd 13c && + cd 13c_$1 && mkdir x && mkdir z && @@ -4383,11 +4440,12 @@ test_expect_success '13c-setup: messages for rename/rename(1to1) via transitive test_tick && git commit -m "B" ) -' +} -test_expect_success '13c-check(conflict): messages for rename/rename(1to1) via transitive rename' ' +test_expect_success '13c(conflict): messages for rename/rename(1to1) via transitive rename' ' + test_setup_13c conflict && ( - cd 13c && + cd 13c_conflict && git checkout A^0 && @@ -4404,9 +4462,10 @@ test_expect_success '13c-check(conflict): messages for rename/rename(1to1) via t ) ' -test_expect_success '13c-check(info): messages for rename/rename(1to1) via transitive rename' ' +test_expect_success '13c(info): messages for rename/rename(1to1) via transitive rename' ' + test_setup_13c info && ( - cd 13c && + cd 13c_info && git reset --hard && git checkout A^0 && @@ -4438,10 +4497,10 @@ test_expect_success '13c-check(info): messages for rename/rename(1to1) via trans # * B renames a/y to c/y, and A renames c/->d/ => a/y -> d/y # No conflict in where a/y ends up, so put it in d/y. -test_expect_success '13d-setup: messages for rename/rename(1to1) via dual transitive rename' ' - test_create_repo 13d && +test_setup_13d () { + test_create_repo 13d_$1 && ( - cd 13d && + cd 13d_$1 && mkdir a && mkdir b && @@ -4470,11 +4529,12 @@ test_expect_success '13d-setup: messages for rename/rename(1to1) via dual transi test_tick && git commit -m "B" ) -' +} -test_expect_success '13d-check(conflict): messages for rename/rename(1to1) via dual transitive rename' ' +test_expect_success '13d(conflict): messages for rename/rename(1to1) via dual transitive rename' ' + test_setup_13d conflict && ( - cd 13d && + cd 13d_conflict && git checkout A^0 && @@ -4494,9 +4554,10 @@ test_expect_success '13d-check(conflict): messages for rename/rename(1to1) via d ) ' -test_expect_success '13d-check(info): messages for rename/rename(1to1) via dual transitive rename' ' +test_expect_success '13d(info): messages for rename/rename(1to1) via dual transitive rename' ' + test_setup_13d info && ( - cd 13d && + cd 13d_info && git reset --hard && git checkout A^0 && @@ -4562,7 +4623,7 @@ test_expect_success '13d-check(info): messages for rename/rename(1to1) via dual # in the outer merge for this special kind of setup, but it at # least avoids hitting a BUG(). # -test_expect_success '13e-setup: directory rename detection in recursive case' ' +test_setup_13e () { test_create_repo 13e && ( cd 13e && @@ -4607,9 +4668,10 @@ test_expect_success '13e-setup: directory rename detection in recursive case' ' test_tick && git commit -m "D" ) -' +} -test_expect_success '13e-check: directory rename detection in recursive case' ' +test_expect_success '13e: directory rename detection in recursive case' ' + test_setup_13e && ( cd 13e && diff --git a/t/t6046-merge-skip-unneeded-updates.sh b/t/t6046-merge-skip-unneeded-updates.sh index 3a47623ed3160b..b7e46698321588 100755 --- a/t/t6046-merge-skip-unneeded-updates.sh +++ b/t/t6046-merge-skip-unneeded-updates.sh @@ -36,10 +36,10 @@ test_description="merge cases" # Commit B: b_3 # Expected: b_2 -test_expect_success '1a-setup: Modify(A)/Modify(B), change on B subset of A' ' - test_create_repo 1a && +test_setup_1a () { + test_create_repo 1a_$1 && ( - cd 1a && + cd 1a_$1 && test_write_lines 1 2 3 4 5 6 7 8 9 10 >b && git add b && @@ -62,13 +62,12 @@ test_expect_success '1a-setup: Modify(A)/Modify(B), change on B subset of A' ' test_tick && git commit -m "B" ) -' +} -test_expect_success '1a-check-L: Modify(A)/Modify(B), change on B subset of A' ' - test_when_finished "git -C 1a reset --hard" && - test_when_finished "git -C 1a clean -fd" && +test_expect_success '1a-L: Modify(A)/Modify(B), change on B subset of A' ' + test_setup_1a L && ( - cd 1a && + cd 1a_L && git checkout A^0 && @@ -96,11 +95,10 @@ test_expect_success '1a-check-L: Modify(A)/Modify(B), change on B subset of A' ' ) ' -test_expect_success '1a-check-R: Modify(A)/Modify(B), change on B subset of A' ' - test_when_finished "git -C 1a reset --hard" && - test_when_finished "git -C 1a clean -fd" && +test_expect_success '1a-R: Modify(A)/Modify(B), change on B subset of A' ' + test_setup_1a R && ( - cd 1a && + cd 1a_R && git checkout B^0 && @@ -133,10 +131,10 @@ test_expect_success '1a-check-R: Modify(A)/Modify(B), change on B subset of A' ' # Commit B: c_1 # Expected: c_2 -test_expect_success '2a-setup: Modify(A)/rename(B)' ' - test_create_repo 2a && +test_setup_2a () { + test_create_repo 2a_$1 && ( - cd 2a && + cd 2a_$1 && test_seq 1 10 >b && git add b && @@ -158,13 +156,12 @@ test_expect_success '2a-setup: Modify(A)/rename(B)' ' test_tick && git commit -m "B" ) -' +} -test_expect_success '2a-check-L: Modify/rename, merge into modify side' ' - test_when_finished "git -C 2a reset --hard" && - test_when_finished "git -C 2a clean -fd" && +test_expect_success '2a-L: Modify/rename, merge into modify side' ' + test_setup_2a L && ( - cd 2a && + cd 2a_L && git checkout A^0 && @@ -189,11 +186,10 @@ test_expect_success '2a-check-L: Modify/rename, merge into modify side' ' ) ' -test_expect_success '2a-check-R: Modify/rename, merge into rename side' ' - test_when_finished "git -C 2a reset --hard" && - test_when_finished "git -C 2a clean -fd" && +test_expect_success '2a-R: Modify/rename, merge into rename side' ' + test_setup_2a R && ( - cd 2a && + cd 2a_R && git checkout B^0 && @@ -224,10 +220,10 @@ test_expect_success '2a-check-R: Modify/rename, merge into rename side' ' # Commit B: b_3 # Expected: c_2 -test_expect_success '2b-setup: Rename+Mod(A)/Mod(B), B mods subset of A' ' - test_create_repo 2b && +test_setup_2b () { + test_create_repo 2b_$1 && ( - cd 2b && + cd 2b_$1 && test_write_lines 1 2 3 4 5 6 7 8 9 10 >b && git add b && @@ -251,13 +247,12 @@ test_expect_success '2b-setup: Rename+Mod(A)/Mod(B), B mods subset of A' ' test_tick && git commit -m "B" ) -' +} -test_expect_success '2b-check-L: Rename+Mod(A)/Mod(B), B mods subset of A' ' - test_when_finished "git -C 2b reset --hard" && - test_when_finished "git -C 2b clean -fd" && +test_expect_success '2b-L: Rename+Mod(A)/Mod(B), B mods subset of A' ' + test_setup_2b L && ( - cd 2b && + cd 2b_L && git checkout A^0 && @@ -288,11 +283,10 @@ test_expect_success '2b-check-L: Rename+Mod(A)/Mod(B), B mods subset of A' ' ) ' -test_expect_success '2b-check-R: Rename+Mod(A)/Mod(B), B mods subset of A' ' - test_when_finished "git -C 2b reset --hard" && - test_when_finished "git -C 2b clean -fd" && +test_expect_success '2b-R: Rename+Mod(A)/Mod(B), B mods subset of A' ' + test_setup_2b R && ( - cd 2b && + cd 2b_R && git checkout B^0 && @@ -332,7 +326,7 @@ test_expect_success '2b-check-R: Rename+Mod(A)/Mod(B), B mods subset of A' ' # skip the update, then we're in trouble. This test verifies we do # not make that particular mistake. -test_expect_success '2c-setup: Modify b & add c VS rename b->c' ' +test_setup_2c () { test_create_repo 2c && ( cd 2c && @@ -358,9 +352,10 @@ test_expect_success '2c-setup: Modify b & add c VS rename b->c' ' test_tick && git commit -m "B" ) -' +} -test_expect_success '2c-check: Modify b & add c VS rename b->c' ' +test_expect_success '2c: Modify b & add c VS rename b->c' ' + test_setup_2c && ( cd 2c && @@ -428,10 +423,10 @@ test_expect_success '2c-check: Modify b & add c VS rename b->c' ' # Commit B: bq_1, bar/whatever # Expected: bar/{bq_2, whatever} -test_expect_success '3a-setup: bq_1->foo/bq_2 on A, foo/->bar/ on B' ' - test_create_repo 3a && +test_setup_3a () { + test_create_repo 3a_$1 && ( - cd 3a && + cd 3a_$1 && mkdir foo && test_seq 1 10 >bq && @@ -456,13 +451,12 @@ test_expect_success '3a-setup: bq_1->foo/bq_2 on A, foo/->bar/ on B' ' test_tick && git commit -m "B" ) -' +} -test_expect_success '3a-check-L: bq_1->foo/bq_2 on A, foo/->bar/ on B' ' - test_when_finished "git -C 3a reset --hard" && - test_when_finished "git -C 3a clean -fd" && +test_expect_success '3a-L: bq_1->foo/bq_2 on A, foo/->bar/ on B' ' + test_setup_3a L && ( - cd 3a && + cd 3a_L && git checkout A^0 && @@ -487,11 +481,10 @@ test_expect_success '3a-check-L: bq_1->foo/bq_2 on A, foo/->bar/ on B' ' ) ' -test_expect_success '3a-check-R: bq_1->foo/bq_2 on A, foo/->bar/ on B' ' - test_when_finished "git -C 3a reset --hard" && - test_when_finished "git -C 3a clean -fd" && +test_expect_success '3a-R: bq_1->foo/bq_2 on A, foo/->bar/ on B' ' + test_setup_3a R && ( - cd 3a && + cd 3a_R && git checkout B^0 && @@ -522,10 +515,10 @@ test_expect_success '3a-check-R: bq_1->foo/bq_2 on A, foo/->bar/ on B' ' # Commit B: bq_2, bar/whatever # Expected: bar/{bq_2, whatever} -test_expect_success '3b-setup: bq_1->foo/bq_2 on A, foo/->bar/ on B' ' - test_create_repo 3b && +test_setup_3b () { + test_create_repo 3b_$1 && ( - cd 3b && + cd 3b_$1 && mkdir foo && test_seq 1 10 >bq && @@ -550,13 +543,12 @@ test_expect_success '3b-setup: bq_1->foo/bq_2 on A, foo/->bar/ on B' ' test_tick && git commit -m "B" ) -' +} -test_expect_success '3b-check-L: bq_1->foo/bq_2 on A, foo/->bar/ on B' ' - test_when_finished "git -C 3b reset --hard" && - test_when_finished "git -C 3b clean -fd" && +test_expect_success '3b-L: bq_1->foo/bq_2 on A, foo/->bar/ on B' ' + test_setup_3b L && ( - cd 3b && + cd 3b_L && git checkout A^0 && @@ -581,11 +573,10 @@ test_expect_success '3b-check-L: bq_1->foo/bq_2 on A, foo/->bar/ on B' ' ) ' -test_expect_success '3b-check-R: bq_1->foo/bq_2 on A, foo/->bar/ on B' ' - test_when_finished "git -C 3b reset --hard" && - test_when_finished "git -C 3b clean -fd" && +test_expect_success '3b-R: bq_1->foo/bq_2 on A, foo/->bar/ on B' ' + test_setup_3b R && ( - cd 3b && + cd 3b_R && git checkout B^0 && @@ -621,7 +612,7 @@ test_expect_success '3b-check-R: bq_1->foo/bq_2 on A, foo/->bar/ on B' ' # Working copy: b_4 # Expected: b_2 for merge, b_4 in working copy -test_expect_success '4a-setup: Change on A, change on B subset of A, dirty mods present' ' +test_setup_4a () { test_create_repo 4a && ( cd 4a && @@ -647,7 +638,7 @@ test_expect_success '4a-setup: Change on A, change on B subset of A, dirty mods test_tick && git commit -m "B" ) -' +} # NOTE: For as long as we continue using unpack_trees() without index_only # set to true, it will error out on a case like this claiming the the locally @@ -655,9 +646,8 @@ test_expect_success '4a-setup: Change on A, change on B subset of A, dirty mods # correct requires doing the merge in-memory first, then realizing that no # updates to the file are necessary, and thus that we can just leave the path # alone. -test_expect_failure '4a-check: Change on A, change on B subset of A, dirty mods present' ' - test_when_finished "git -C 4a reset --hard" && - test_when_finished "git -C 4a clean -fd" && +test_expect_failure '4a: Change on A, change on B subset of A, dirty mods present' ' + test_setup_4a && ( cd 4a && @@ -695,7 +685,7 @@ test_expect_failure '4a-check: Change on A, change on B subset of A, dirty mods # Working copy: c_4 # Expected: c_2 -test_expect_success '4b-setup: Rename+Mod(A)/Mod(B), change on B subset of A, dirty mods present' ' +test_setup_4b () { test_create_repo 4b && ( cd 4b && @@ -722,11 +712,10 @@ test_expect_success '4b-setup: Rename+Mod(A)/Mod(B), change on B subset of A, di test_tick && git commit -m "B" ) -' +} -test_expect_success '4b-check: Rename+Mod(A)/Mod(B), change on B subset of A, dirty mods present' ' - test_when_finished "git -C 4b reset --hard" && - test_when_finished "git -C 4b clean -fd" && +test_expect_success '4b: Rename+Mod(A)/Mod(B), change on B subset of A, dirty mods present' ' + test_setup_4b && ( cd 4b && From efbc3aee08dfac70d426cca93cc5cfc0f14f8ee7 Mon Sep 17 00:00:00 2001 From: William Baker Date: Mon, 21 Oct 2019 18:39:58 +0000 Subject: [PATCH 039/953] midx: add MIDX_PROGRESS flag Add the MIDX_PROGRESS flag and update the write|verify|expire|repack functions in midx.h to accept a flags parameter. The MIDX_PROGRESS flag indicates whether the caller of the function would like progress information to be displayed. This patch only changes the method prototypes and does not change the functionality. The functionality change will be handled by a later patch. Signed-off-by: William Baker Signed-off-by: Junio C Hamano --- builtin/multi-pack-index.c | 8 ++++---- builtin/repack.c | 2 +- midx.c | 8 ++++---- midx.h | 10 ++++++---- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c index b1ea1a6aa17724..e86b8cd17debd8 100644 --- a/builtin/multi-pack-index.c +++ b/builtin/multi-pack-index.c @@ -47,16 +47,16 @@ int cmd_multi_pack_index(int argc, const char **argv, trace2_cmd_mode(argv[0]); if (!strcmp(argv[0], "repack")) - return midx_repack(the_repository, opts.object_dir, (size_t)opts.batch_size); + return midx_repack(the_repository, opts.object_dir, (size_t)opts.batch_size, 0); if (opts.batch_size) die(_("--batch-size option is only for 'repack' subcommand")); if (!strcmp(argv[0], "write")) - return write_midx_file(opts.object_dir); + return write_midx_file(opts.object_dir, 0); if (!strcmp(argv[0], "verify")) - return verify_midx_file(the_repository, opts.object_dir); + return verify_midx_file(the_repository, opts.object_dir, 0); if (!strcmp(argv[0], "expire")) - return expire_midx_packs(the_repository, opts.object_dir); + return expire_midx_packs(the_repository, opts.object_dir, 0); die(_("unrecognized subcommand: %s"), argv[0]); } diff --git a/builtin/repack.c b/builtin/repack.c index 094c2f8ea48cae..397081d568c62a 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -562,7 +562,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix) remove_temporary_files(); if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0)) - write_midx_file(get_object_directory()); + write_midx_file(get_object_directory(), 0); string_list_clear(&names, 0); string_list_clear(&rollback, 0); diff --git a/midx.c b/midx.c index f29afc0d2daba3..f169a681dd34e9 100644 --- a/midx.c +++ b/midx.c @@ -1016,7 +1016,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index * return result; } -int write_midx_file(const char *object_dir) +int write_midx_file(const char *object_dir, unsigned flags) { return write_midx_internal(object_dir, NULL, NULL); } @@ -1076,7 +1076,7 @@ static int compare_pair_pos_vs_id(const void *_a, const void *_b) display_progress(progress, _n); \ } while (0) -int verify_midx_file(struct repository *r, const char *object_dir) +int verify_midx_file(struct repository *r, const char *object_dir, unsigned flags) { struct pair_pos_vs_id *pairs = NULL; uint32_t i; @@ -1183,7 +1183,7 @@ int verify_midx_file(struct repository *r, const char *object_dir) return verify_midx_error; } -int expire_midx_packs(struct repository *r, const char *object_dir) +int expire_midx_packs(struct repository *r, const char *object_dir, unsigned flags) { uint32_t i, *count, result = 0; struct string_list packs_to_drop = STRING_LIST_INIT_DUP; @@ -1315,7 +1315,7 @@ static int fill_included_packs_batch(struct repository *r, return 0; } -int midx_repack(struct repository *r, const char *object_dir, size_t batch_size) +int midx_repack(struct repository *r, const char *object_dir, size_t batch_size, unsigned flags) { int result = 0; uint32_t i; diff --git a/midx.h b/midx.h index f0ae656b5d7676..e6fa356b5caaf6 100644 --- a/midx.h +++ b/midx.h @@ -37,6 +37,8 @@ struct multi_pack_index { char object_dir[FLEX_ARRAY]; }; +#define MIDX_PROGRESS (1 << 0) + struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local); int prepare_midx_pack(struct repository *r, struct multi_pack_index *m, uint32_t pack_int_id); int bsearch_midx(const struct object_id *oid, struct multi_pack_index *m, uint32_t *result); @@ -47,11 +49,11 @@ int fill_midx_entry(struct repository *r, const struct object_id *oid, struct pa int midx_contains_pack(struct multi_pack_index *m, const char *idx_or_pack_name); int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, int local); -int write_midx_file(const char *object_dir); +int write_midx_file(const char *object_dir, unsigned flags); void clear_midx_file(struct repository *r); -int verify_midx_file(struct repository *r, const char *object_dir); -int expire_midx_packs(struct repository *r, const char *object_dir); -int midx_repack(struct repository *r, const char *object_dir, size_t batch_size); +int verify_midx_file(struct repository *r, const char *object_dir, unsigned flags); +int expire_midx_packs(struct repository *r, const char *object_dir, unsigned flags); +int midx_repack(struct repository *r, const char *object_dir, size_t batch_size, unsigned flags); void close_midx(struct multi_pack_index *m); From 840cef0c70e4c664d814d09f304d4be9a63d11e4 Mon Sep 17 00:00:00 2001 From: William Baker Date: Mon, 21 Oct 2019 18:39:59 +0000 Subject: [PATCH 040/953] midx: add progress to write_midx_file Add progress to write_midx_file. Progress is displayed when the MIDX_PROGRESS flag is set. Signed-off-by: William Baker Signed-off-by: Junio C Hamano --- midx.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/midx.c b/midx.c index f169a681dd34e9..716aeecefb1f68 100644 --- a/midx.c +++ b/midx.c @@ -448,6 +448,8 @@ struct pack_list { uint32_t nr; uint32_t alloc; struct multi_pack_index *m; + struct progress *progress; + unsigned pack_paths_checked; }; static void add_pack_to_midx(const char *full_path, size_t full_path_len, @@ -456,6 +458,7 @@ static void add_pack_to_midx(const char *full_path, size_t full_path_len, struct pack_list *packs = (struct pack_list *)data; if (ends_with(file_name, ".idx")) { + display_progress(packs->progress, ++packs->pack_paths_checked); if (packs->m && midx_contains_pack(packs->m, file_name)) return; @@ -785,7 +788,7 @@ static size_t write_midx_large_offsets(struct hashfile *f, uint32_t nr_large_off } static int write_midx_internal(const char *object_dir, struct multi_pack_index *m, - struct string_list *packs_to_drop) + struct string_list *packs_to_drop, unsigned flags) { unsigned char cur_chunk, num_chunks = 0; char *midx_name; @@ -799,6 +802,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index * uint64_t chunk_offsets[MIDX_MAX_CHUNKS + 1]; uint32_t nr_entries, num_large_offsets = 0; struct pack_midx_entry *entries = NULL; + struct progress *progress = NULL; int large_offsets_needed = 0; int pack_name_concat_len = 0; int dropped_packs = 0; @@ -833,7 +837,14 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index * } } + packs.pack_paths_checked = 0; + if (flags & MIDX_PROGRESS) + packs.progress = start_progress(_("Adding packfiles to multi-pack-index"), 0); + else + packs.progress = NULL; + for_each_file_in_pack_dir(object_dir, add_pack_to_midx, &packs); + stop_progress(&packs.progress); if (packs.m && packs.nr == packs.m->num_packs && !packs_to_drop) goto cleanup; @@ -958,6 +969,9 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index * written += MIDX_CHUNKLOOKUP_WIDTH; } + if (flags & MIDX_PROGRESS) + progress = start_progress(_("Writing chunks to multi-pack-index"), + num_chunks); for (i = 0; i < num_chunks; i++) { if (written != chunk_offsets[i]) BUG("incorrect chunk offset (%"PRIu64" != %"PRIu64") for chunk id %"PRIx32, @@ -990,7 +1004,10 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index * BUG("trying to write unknown chunk id %"PRIx32, chunk_ids[i]); } + + display_progress(progress, i + 1); } + stop_progress(&progress); if (written != chunk_offsets[num_chunks]) BUG("incorrect final offset %"PRIu64" != %"PRIu64, @@ -1018,7 +1035,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index * int write_midx_file(const char *object_dir, unsigned flags) { - return write_midx_internal(object_dir, NULL, NULL); + return write_midx_internal(object_dir, NULL, NULL, flags); } void clear_midx_file(struct repository *r) @@ -1221,7 +1238,7 @@ int expire_midx_packs(struct repository *r, const char *object_dir, unsigned fla free(count); if (packs_to_drop.nr) - result = write_midx_internal(object_dir, m, &packs_to_drop); + result = write_midx_internal(object_dir, m, &packs_to_drop, flags); string_list_clear(&packs_to_drop, 0); return result; @@ -1370,7 +1387,7 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size, goto cleanup; } - result = write_midx_internal(object_dir, m, NULL); + result = write_midx_internal(object_dir, m, NULL, flags); m = NULL; cleanup: From 8dc18f8937faf542da785b28062731ddfbfee974 Mon Sep 17 00:00:00 2001 From: William Baker Date: Mon, 21 Oct 2019 18:40:00 +0000 Subject: [PATCH 041/953] midx: add progress to expire_midx_packs Add progress to expire_midx_packs. Progress is displayed when the MIDX_PROGRESS flag is set. Signed-off-by: William Baker Signed-off-by: Junio C Hamano --- midx.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/midx.c b/midx.c index 716aeecefb1f68..cb2c6026036490 100644 --- a/midx.c +++ b/midx.c @@ -1205,18 +1205,29 @@ int expire_midx_packs(struct repository *r, const char *object_dir, unsigned fla uint32_t i, *count, result = 0; struct string_list packs_to_drop = STRING_LIST_INIT_DUP; struct multi_pack_index *m = load_multi_pack_index(object_dir, 1); + struct progress *progress = NULL; if (!m) return 0; count = xcalloc(m->num_packs, sizeof(uint32_t)); + + if (flags & MIDX_PROGRESS) + progress = start_progress(_("Counting referenced objects"), + m->num_objects); for (i = 0; i < m->num_objects; i++) { int pack_int_id = nth_midxed_pack_int_id(m, i); count[pack_int_id]++; + display_progress(progress, i + 1); } + stop_progress(&progress); + if (flags & MIDX_PROGRESS) + progress = start_progress(_("Finding and deleting unreferenced packfiles"), + m->num_packs); for (i = 0; i < m->num_packs; i++) { char *pack_name; + display_progress(progress, i + 1); if (count[i]) continue; @@ -1234,6 +1245,7 @@ int expire_midx_packs(struct repository *r, const char *object_dir, unsigned fla unlink_pack_path(pack_name, 0); free(pack_name); } + stop_progress(&progress); free(count); From ad60096d1c82a6e05a01bb33c12cd1070bf01b4f Mon Sep 17 00:00:00 2001 From: William Baker Date: Mon, 21 Oct 2019 18:40:01 +0000 Subject: [PATCH 042/953] midx: honor the MIDX_PROGRESS flag in verify_midx_file Update verify_midx_file to only display progress when the MIDX_PROGRESS flag is set. Signed-off-by: William Baker Signed-off-by: Junio C Hamano --- midx.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/midx.c b/midx.c index cb2c6026036490..1b22b2144e2492 100644 --- a/midx.c +++ b/midx.c @@ -1097,15 +1097,16 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag { struct pair_pos_vs_id *pairs = NULL; uint32_t i; - struct progress *progress; + struct progress *progress = NULL; struct multi_pack_index *m = load_multi_pack_index(object_dir, 1); verify_midx_error = 0; if (!m) return 0; - progress = start_progress(_("Looking for referenced packfiles"), - m->num_packs); + if (flags & MIDX_PROGRESS) + progress = start_progress(_("Looking for referenced packfiles"), + m->num_packs); for (i = 0; i < m->num_packs; i++) { if (prepare_midx_pack(r, m, i)) midx_report("failed to load pack in position %d", i); @@ -1123,8 +1124,9 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag i, oid_fanout1, oid_fanout2, i + 1); } - progress = start_sparse_progress(_("Verifying OID order in MIDX"), - m->num_objects - 1); + if (flags & MIDX_PROGRESS) + progress = start_sparse_progress(_("Verifying OID order in multi-pack-index"), + m->num_objects - 1); for (i = 0; i < m->num_objects - 1; i++) { struct object_id oid1, oid2; @@ -1151,13 +1153,15 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag pairs[i].pack_int_id = nth_midxed_pack_int_id(m, i); } - progress = start_sparse_progress(_("Sorting objects by packfile"), - m->num_objects); + if (flags & MIDX_PROGRESS) + progress = start_sparse_progress(_("Sorting objects by packfile"), + m->num_objects); display_progress(progress, 0); /* TODO: Measure QSORT() progress */ QSORT(pairs, m->num_objects, compare_pair_pos_vs_id); stop_progress(&progress); - progress = start_sparse_progress(_("Verifying object offsets"), m->num_objects); + if (flags & MIDX_PROGRESS) + progress = start_sparse_progress(_("Verifying object offsets"), m->num_objects); for (i = 0; i < m->num_objects; i++) { struct object_id oid; struct pack_entry e; From 64d80e7d52cc2663a44157fc3d49af576ea10192 Mon Sep 17 00:00:00 2001 From: William Baker Date: Mon, 21 Oct 2019 18:40:02 +0000 Subject: [PATCH 043/953] midx: honor the MIDX_PROGRESS flag in midx_repack Update midx_repack to only display progress when the MIDX_PROGRESS flag is set. Signed-off-by: William Baker Signed-off-by: Junio C Hamano --- midx.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/midx.c b/midx.c index 1b22b2144e2492..37ec28623af67f 100644 --- a/midx.c +++ b/midx.c @@ -1373,6 +1373,12 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size, strbuf_addstr(&base_name, object_dir); strbuf_addstr(&base_name, "/pack/pack"); argv_array_push(&cmd.args, base_name.buf); + + if (flags & MIDX_PROGRESS) + argv_array_push(&cmd.args, "--progress"); + else + argv_array_push(&cmd.args, "-q"); + strbuf_release(&base_name); cmd.git_cmd = 1; From 680cba2c2b1c8120c960faf80cf80a7636519be2 Mon Sep 17 00:00:00 2001 From: William Baker Date: Mon, 21 Oct 2019 18:40:03 +0000 Subject: [PATCH 044/953] multi-pack-index: add [--[no-]progress] option. Add the --[no-]progress option to git multi-pack-index. Pass the MIDX_PROGRESS flag to the subcommand functions when progress should be displayed by multi-pack-index. The progress feature was added to 'verify' in 144d703 ("multi-pack-index: report progress during 'verify'", 2018-09-13) but some subcommands were not updated to display progress, and the ability to opt-out was overlooked. Signed-off-by: William Baker Signed-off-by: Junio C Hamano --- Documentation/git-multi-pack-index.txt | 6 ++- builtin/multi-pack-index.c | 18 +++++-- t/t5319-multi-pack-index.sh | 69 ++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 6 deletions(-) diff --git a/Documentation/git-multi-pack-index.txt b/Documentation/git-multi-pack-index.txt index 233b2b786271cc..642d9ac5b72365 100644 --- a/Documentation/git-multi-pack-index.txt +++ b/Documentation/git-multi-pack-index.txt @@ -9,7 +9,7 @@ git-multi-pack-index - Write and verify multi-pack-indexes SYNOPSIS -------- [verse] -'git multi-pack-index' [--object-dir=] +'git multi-pack-index' [--object-dir=] [--[no-]progress] DESCRIPTION ----------- @@ -23,6 +23,10 @@ OPTIONS `/packs/multi-pack-index` for the current MIDX file, and `/packs` for the pack-files to index. +--[no-]progress:: + Turn progress on/off explicitly. If neither is specified, progress is + shown if standard error is connected to a terminal. + The following subcommands are available: write:: diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c index e86b8cd17debd8..5bf88cd2a8e2c3 100644 --- a/builtin/multi-pack-index.c +++ b/builtin/multi-pack-index.c @@ -6,21 +6,25 @@ #include "trace2.h" static char const * const builtin_multi_pack_index_usage[] = { - N_("git multi-pack-index [--object-dir=] (write|verify|expire|repack --batch-size=)"), + N_("git multi-pack-index [] (write|verify|expire|repack --batch-size=)"), NULL }; static struct opts_multi_pack_index { const char *object_dir; unsigned long batch_size; + int progress; } opts; int cmd_multi_pack_index(int argc, const char **argv, const char *prefix) { + unsigned flags = 0; + static struct option builtin_multi_pack_index_options[] = { OPT_FILENAME(0, "object-dir", &opts.object_dir, N_("object directory containing set of packfile and pack-index pairs")), + OPT_BOOL(0, "progress", &opts.progress, N_("force progress reporting")), OPT_MAGNITUDE(0, "batch-size", &opts.batch_size, N_("during repack, collect pack-files of smaller size into a batch that is larger than this size")), OPT_END(), @@ -28,12 +32,15 @@ int cmd_multi_pack_index(int argc, const char **argv, git_config(git_default_config, NULL); + opts.progress = isatty(2); argc = parse_options(argc, argv, prefix, builtin_multi_pack_index_options, builtin_multi_pack_index_usage, 0); if (!opts.object_dir) opts.object_dir = get_object_directory(); + if (opts.progress) + flags |= MIDX_PROGRESS; if (argc == 0) usage_with_options(builtin_multi_pack_index_usage, @@ -47,16 +54,17 @@ int cmd_multi_pack_index(int argc, const char **argv, trace2_cmd_mode(argv[0]); if (!strcmp(argv[0], "repack")) - return midx_repack(the_repository, opts.object_dir, (size_t)opts.batch_size, 0); + return midx_repack(the_repository, opts.object_dir, + (size_t)opts.batch_size, flags); if (opts.batch_size) die(_("--batch-size option is only for 'repack' subcommand")); if (!strcmp(argv[0], "write")) - return write_midx_file(opts.object_dir, 0); + return write_midx_file(opts.object_dir, flags); if (!strcmp(argv[0], "verify")) - return verify_midx_file(the_repository, opts.object_dir, 0); + return verify_midx_file(the_repository, opts.object_dir, flags); if (!strcmp(argv[0], "expire")) - return expire_midx_packs(the_repository, opts.object_dir, 0); + return expire_midx_packs(the_repository, opts.object_dir, flags); die(_("unrecognized subcommand: %s"), argv[0]); } diff --git a/t/t5319-multi-pack-index.sh b/t/t5319-multi-pack-index.sh index c72ca0439993bb..cd2f87be6afe24 100755 --- a/t/t5319-multi-pack-index.sh +++ b/t/t5319-multi-pack-index.sh @@ -147,6 +147,21 @@ test_expect_success 'write midx with two packs' ' compare_results_with_midx "two packs" +test_expect_success 'write progress off for redirected stderr' ' + git multi-pack-index --object-dir=$objdir write 2>err && + test_line_count = 0 err +' + +test_expect_success 'write force progress on for stderr' ' + git multi-pack-index --object-dir=$objdir --progress write 2>err && + test_file_not_empty err +' + +test_expect_success 'write with the --no-progress option' ' + git multi-pack-index --object-dir=$objdir --no-progress write 2>err && + test_line_count = 0 err +' + test_expect_success 'add more packs' ' for j in $(test_seq 11 20) do @@ -169,6 +184,21 @@ test_expect_success 'verify multi-pack-index success' ' git multi-pack-index verify --object-dir=$objdir ' +test_expect_success 'verify progress off for redirected stderr' ' + git multi-pack-index verify --object-dir=$objdir 2>err && + test_line_count = 0 err +' + +test_expect_success 'verify force progress on for stderr' ' + git multi-pack-index verify --object-dir=$objdir --progress 2>err && + test_file_not_empty err +' + +test_expect_success 'verify with the --no-progress option' ' + git multi-pack-index verify --object-dir=$objdir --no-progress 2>err && + test_line_count = 0 err +' + # usage: corrupt_midx_and_verify corrupt_midx_and_verify() { POS=$1 && @@ -284,6 +314,21 @@ test_expect_success 'git-fsck incorrect offset' ' "git -c core.multipackindex=true fsck" ' +test_expect_success 'repack progress off for redirected stderr' ' + git multi-pack-index --object-dir=$objdir repack 2>err && + test_line_count = 0 err +' + +test_expect_success 'repack force progress on for stderr' ' + git multi-pack-index --object-dir=$objdir --progress repack 2>err && + test_file_not_empty err +' + +test_expect_success 'repack with the --no-progress option' ' + git multi-pack-index --object-dir=$objdir --no-progress repack 2>err && + test_line_count = 0 err +' + test_expect_success 'repack removes multi-pack-index' ' test_path_is_file $objdir/pack/multi-pack-index && GIT_TEST_MULTI_PACK_INDEX=0 git repack -adf && @@ -413,6 +458,30 @@ test_expect_success 'expire does not remove any packs' ' ) ' +test_expect_success 'expire progress off for redirected stderr' ' + ( + cd dup && + git multi-pack-index expire 2>err && + test_line_count = 0 err + ) +' + +test_expect_success 'expire force progress on for stderr' ' + ( + cd dup && + git multi-pack-index --progress expire 2>err && + test_file_not_empty err + ) +' + +test_expect_success 'expire with the --no-progress option' ' + ( + cd dup && + git multi-pack-index --no-progress expire 2>err && + test_line_count = 0 err + ) +' + test_expect_success 'expire removes unreferenced packs' ' ( cd dup && From e536b1fedf777ad8958a6f299d9d59db6299e697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?SZEDER=20G=C3=A1bor?= Date: Mon, 21 Oct 2019 18:00:39 +0200 Subject: [PATCH 045/953] Documentation: mention more worktree-specific exceptions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a directory in $GIT_DIR is overridden when $GIT_COMMON_DIR is set, then usually all paths within that directory are overridden as well. There are a couple of exceptions, though, and two of them, namely 'refs/rewritten' and 'logs/HEAD' are not mentioned in 'gitrepository-layout'. Document them as well. Signed-off-by: SZEDER Gábor Signed-off-by: Junio C Hamano --- Documentation/gitrepository-layout.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Documentation/gitrepository-layout.txt b/Documentation/gitrepository-layout.txt index 216b11ee88f4e9..f4066fd0261074 100644 --- a/Documentation/gitrepository-layout.txt +++ b/Documentation/gitrepository-layout.txt @@ -96,9 +96,9 @@ refs:: directory. The 'git prune' command knows to preserve objects reachable from refs found in this directory and its subdirectories. - This directory is ignored (except refs/bisect and - refs/worktree) if $GIT_COMMON_DIR is set and - "$GIT_COMMON_DIR/refs" will be used instead. + This directory is ignored (except refs/bisect, + refs/rewritten and refs/worktree) if $GIT_COMMON_DIR is + set and "$GIT_COMMON_DIR/refs" will be used instead. refs/heads/`name`:: records tip-of-the-tree commit objects of branch `name` @@ -240,8 +240,8 @@ remotes:: logs:: Records of changes made to refs are stored in this directory. See linkgit:git-update-ref[1] for more information. This - directory is ignored if $GIT_COMMON_DIR is set and - "$GIT_COMMON_DIR/logs" will be used instead. + directory is ignored (except logs/HEAD) if $GIT_COMMON_DIR is + set and "$GIT_COMMON_DIR/logs" will be used instead. logs/refs/heads/`name`:: Records all changes made to the branch tip named `name`. From 7cb8c929d76c12750fdece2e5da75d207938d3b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?SZEDER=20G=C3=A1bor?= Date: Mon, 21 Oct 2019 18:00:40 +0200 Subject: [PATCH 046/953] path.c: clarify trie_find()'s in-code comment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A fairly long comment describes trie_find()'s behavior and shows examples, but it's slightly incomplete/inaccurate. Update this comment to specify how trie_find() handles a negative return value from the given match function. Furthermore, update the list of examples to include not only two but three levels of path components. This makes the examples slightly more complicated, but it can illustrate the behavior in more corner cases. Finally, basically everything refers to the data stored for a key as "value", with two confusing exceptions: - The type definition of the match function calls its corresponding parameter 'data'. Rename that parameter to 'value'. (check_common(), the only function of this type already calls it 'value'). - The table of examples above trie_find() has a "val from node" column, which has nothing to do with the value stored in the trie: it's a "prefix of the key for which the trie contains a value" that led to that node. Rename that column header to "prefix to node". Note that neither the original nor the updated description and examples correspond 100% to the current implementation, because the implementation is a bit buggy, but the comment describes the desired behavior. The bug will be fixed in the last patch of this series. Signed-off-by: SZEDER Gábor Signed-off-by: Junio C Hamano --- path.c | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/path.c b/path.c index 25e97b8c3f76ce..d10f0e0d8e3dad 100644 --- a/path.c +++ b/path.c @@ -236,30 +236,41 @@ static void *add_to_trie(struct trie *root, const char *key, void *value) return old; } -typedef int (*match_fn)(const char *unmatched, void *data, void *baton); +typedef int (*match_fn)(const char *unmatched, void *value, void *baton); /* * Search a trie for some key. Find the longest /-or-\0-terminated - * prefix of the key for which the trie contains a value. Call fn - * with the unmatched portion of the key and the found value, and - * return its return value. If there is no such prefix, return -1. + * prefix of the key for which the trie contains a value. If there is + * no such prefix, return -1. Otherwise call fn with the unmatched + * portion of the key and the found value. If fn returns 0 or + * positive, then return its return value. If fn returns negative, + * then call fn with the next-longest /-terminated prefix of the key + * (i.e. a parent directory) for which the trie contains a value, and + * handle its return value the same way. If there is no shorter + * /-terminated prefix with a value left, then return the negative + * return value of the most recent fn invocation. * * The key is partially normalized: consecutive slashes are skipped. * - * For example, consider the trie containing only [refs, - * refs/worktree] (both with values). - * - * | key | unmatched | val from node | return value | - * |-----------------|------------|---------------|--------------| - * | a | not called | n/a | -1 | - * | refs | \0 | refs | as per fn | - * | refs/ | / | refs | as per fn | - * | refs/w | /w | refs | as per fn | - * | refs/worktree | \0 | refs/worktree | as per fn | - * | refs/worktree/ | / | refs/worktree | as per fn | - * | refs/worktree/a | /a | refs/worktree | as per fn | - * |-----------------|------------|---------------|--------------| + * For example, consider the trie containing only [logs, + * logs/refs/bisect], both with values, but not logs/refs. * + * | key | unmatched | prefix to node | return value | + * |--------------------|----------------|------------------|--------------| + * | a | not called | n/a | -1 | + * | logstore | not called | n/a | -1 | + * | logs | \0 | logs | as per fn | + * | logs/ | / | logs | as per fn | + * | logs/refs | /refs | logs | as per fn | + * | logs/refs/ | /refs/ | logs | as per fn | + * | logs/refs/b | /refs/b | logs | as per fn | + * | logs/refs/bisected | /refs/bisected | logs | as per fn | + * | logs/refs/bisect | \0 | logs/refs/bisect | as per fn | + * | logs/refs/bisect/ | / | logs/refs/bisect | as per fn | + * | logs/refs/bisect/a | /a | logs/refs/bisect | as per fn | + * | (If fn in the previous line returns -1, then fn is called once more:) | + * | logs/refs/bisect/a | /refs/bisect/a | logs | as per fn | + * |--------------------|----------------|------------------|--------------| */ static int trie_find(struct trie *root, const char *key, match_fn fn, void *baton) From 8a64881b44e03264fb0c3c26fc00a01c12cd67ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?SZEDER=20G=C3=A1bor?= Date: Mon, 21 Oct 2019 18:00:41 +0200 Subject: [PATCH 047/953] path.c: mark 'logs/HEAD' in 'common_list' as file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 'logs/HEAD', i.e. HEAD's reflog, is a file, but its entry in 'common_list' has the 'is_dir' bit set. Unset that bit to make it consistent with what 'logs/HEAD' is supposed to be. This doesn't make a difference in behavior: check_common() is the only function that looks at the 'is_dir' bit, and that function either returns 0, or '!exclude', which for 'logs/HEAD' results in 0 as well. Signed-off-by: SZEDER Gábor Signed-off-by: Junio C Hamano --- path.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/path.c b/path.c index d10f0e0d8e3dad..7f243f3c5636d6 100644 --- a/path.c +++ b/path.c @@ -113,7 +113,7 @@ static struct common_dir common_list[] = { { 0, 1, 0, "info" }, { 0, 0, 1, "info/sparse-checkout" }, { 1, 1, 0, "logs" }, - { 1, 1, 1, "logs/HEAD" }, + { 1, 0, 1, "logs/HEAD" }, { 0, 1, 1, "logs/refs/bisect" }, { 0, 1, 1, "logs/refs/rewritten" }, { 0, 1, 1, "logs/refs/worktree" }, From c72fc40d0904cbf3199258c2f471c2351e024b1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?SZEDER=20G=C3=A1bor?= Date: Mon, 21 Oct 2019 18:00:42 +0200 Subject: [PATCH 048/953] path.c: clarify two field names in 'struct common_dir' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An array of 'struct common_dir' instances is used to specify whether various paths in $GIT_DIR are specific to a worktree, or are common, i.e. belong to main worktree. The names of two fields in this struct are somewhat confusing or ambigious: - The path is recorded in the struct's 'dirname' field, even though several entries are regular files e.g. 'gc.pid', 'packed-refs', etc. Rename this field to 'path' to reduce confusion. - The field 'exclude' tells whether the path is excluded... from where? Excluded from the common dir or from the worktree? It means the former, but it's ambigious. Rename this field to 'is_common' to make it unambigious what it means. This, however, means the exact opposite of what 'exclude' meant, so we have to negate the field's value in all entries as well. The diff is best viewed with '--color-words'. Signed-off-by: SZEDER Gábor Signed-off-by: Junio C Hamano --- path.c | 66 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/path.c b/path.c index 7f243f3c5636d6..81e9bfe7a93eb3 100644 --- a/path.c +++ b/path.c @@ -101,36 +101,36 @@ struct common_dir { /* Not considered garbage for report_linked_checkout_garbage */ unsigned ignore_garbage:1; unsigned is_dir:1; - /* Not common even though its parent is */ - unsigned exclude:1; - const char *dirname; + /* Belongs to the common dir, though it may contain paths that don't */ + unsigned is_common:1; + const char *path; }; static struct common_dir common_list[] = { - { 0, 1, 0, "branches" }, - { 0, 1, 0, "common" }, - { 0, 1, 0, "hooks" }, - { 0, 1, 0, "info" }, - { 0, 0, 1, "info/sparse-checkout" }, - { 1, 1, 0, "logs" }, - { 1, 0, 1, "logs/HEAD" }, - { 0, 1, 1, "logs/refs/bisect" }, - { 0, 1, 1, "logs/refs/rewritten" }, - { 0, 1, 1, "logs/refs/worktree" }, - { 0, 1, 0, "lost-found" }, - { 0, 1, 0, "objects" }, - { 0, 1, 0, "refs" }, - { 0, 1, 1, "refs/bisect" }, - { 0, 1, 1, "refs/rewritten" }, - { 0, 1, 1, "refs/worktree" }, - { 0, 1, 0, "remotes" }, - { 0, 1, 0, "worktrees" }, - { 0, 1, 0, "rr-cache" }, - { 0, 1, 0, "svn" }, - { 0, 0, 0, "config" }, - { 1, 0, 0, "gc.pid" }, - { 0, 0, 0, "packed-refs" }, - { 0, 0, 0, "shallow" }, + { 0, 1, 1, "branches" }, + { 0, 1, 1, "common" }, + { 0, 1, 1, "hooks" }, + { 0, 1, 1, "info" }, + { 0, 0, 0, "info/sparse-checkout" }, + { 1, 1, 1, "logs" }, + { 1, 0, 0, "logs/HEAD" }, + { 0, 1, 0, "logs/refs/bisect" }, + { 0, 1, 0, "logs/refs/rewritten" }, + { 0, 1, 0, "logs/refs/worktree" }, + { 0, 1, 1, "lost-found" }, + { 0, 1, 1, "objects" }, + { 0, 1, 1, "refs" }, + { 0, 1, 0, "refs/bisect" }, + { 0, 1, 0, "refs/rewritten" }, + { 0, 1, 0, "refs/worktree" }, + { 0, 1, 1, "remotes" }, + { 0, 1, 1, "worktrees" }, + { 0, 1, 1, "rr-cache" }, + { 0, 1, 1, "svn" }, + { 0, 0, 1, "config" }, + { 1, 0, 1, "gc.pid" }, + { 0, 0, 1, "packed-refs" }, + { 0, 0, 1, "shallow" }, { 0, 0, 0, NULL } }; @@ -331,8 +331,8 @@ static void init_common_trie(void) if (common_trie_done_setup) return; - for (p = common_list; p->dirname; p++) - add_to_trie(&common_trie, p->dirname, p); + for (p = common_list; p->path; p++) + add_to_trie(&common_trie, p->path, p); common_trie_done_setup = 1; } @@ -349,10 +349,10 @@ static int check_common(const char *unmatched, void *value, void *baton) return 0; if (dir->is_dir && (unmatched[0] == 0 || unmatched[0] == '/')) - return !dir->exclude; + return dir->is_common; if (!dir->is_dir && unmatched[0] == 0) - return !dir->exclude; + return dir->is_common; return 0; } @@ -376,8 +376,8 @@ void report_linked_checkout_garbage(void) return; strbuf_addf(&sb, "%s/", get_git_dir()); len = sb.len; - for (p = common_list; p->dirname; p++) { - const char *path = p->dirname; + for (p = common_list; p->path; p++) { + const char *path = p->path; if (p->ignore_garbage) continue; strbuf_setlen(&sb, len); From f45f88b2e483649cd063a7dc7826c03025683e56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?SZEDER=20G=C3=A1bor?= Date: Mon, 21 Oct 2019 18:00:43 +0200 Subject: [PATCH 049/953] path.c: don't call the match function without value in trie_find() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 'logs/refs' is not a working tree-specific path, but since commit b9317d55a3 (Make sure refs/rewritten/ is per-worktree, 2019-03-07) 'git rev-parse --git-path' has been returning a bogus path if a trailing '/' is present: $ git -C WT/ rev-parse --git-path logs/refs --git-path logs/refs/ /home/szeder/src/git/.git/logs/refs /home/szeder/src/git/.git/worktrees/WT/logs/refs/ We use a trie data structure to efficiently decide whether a path belongs to the common dir or is working tree-specific. As it happens b9317d55a3 triggered a bug that is as old as the trie implementation itself, added in 4e09cf2acf (path: optimize common dir checking, 2015-08-31). - According to the comment describing trie_find(), it should only call the given match function 'fn' for a "/-or-\0-terminated prefix of the key for which the trie contains a value". This is not true: there are three places where trie_find() calls the match function, but one of them is missing the check for value's existence. - b9317d55a3 added two new keys to the trie: 'logs/refs/rewritten' and 'logs/refs/worktree', next to the already existing 'logs/refs/bisect'. This resulted in a trie node with the path 'logs/refs/', which didn't exist before, and which doesn't have a value attached. A query for 'logs/refs/' finds this node and then hits that one callsite of the match function which doesn't check for the value's existence, and thus invokes the match function with NULL as value. - When the match function check_common() is invoked with a NULL value, it returns 0, which indicates that the queried path doesn't belong to the common directory, ultimately resulting the bogus path shown above. Add the missing condition to trie_find() so it will never invoke the match function with a non-existing value. check_common() will then no longer have to check that it got a non-NULL value, so remove that condition. I believe that there are no other paths that could cause similar bogus output. AFAICT the only other key resulting in the match function being called with a NULL value is 'co' (because of the keys 'common' and 'config'). However, as they are not in a directory that belongs to the common directory the resulting working tree-specific path is expected. Signed-off-by: SZEDER Gábor Signed-off-by: Junio C Hamano --- path.c | 11 ++++++----- t/t0060-path-utils.sh | 2 ++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/path.c b/path.c index 81e9bfe7a93eb3..4b69360c71f183 100644 --- a/path.c +++ b/path.c @@ -299,9 +299,13 @@ static int trie_find(struct trie *root, const char *key, match_fn fn, /* Matched the entire compressed section */ key += i; - if (!*key) + if (!*key) { /* End of key */ - return fn(key, root->value, baton); + if (root->value) + return fn(key, root->value, baton); + else + return -1; + } /* Partial path normalization: skip consecutive slashes */ while (key[0] == '/' && key[1] == '/') @@ -345,9 +349,6 @@ static int check_common(const char *unmatched, void *value, void *baton) { struct common_dir *dir = value; - if (!dir) - return 0; - if (dir->is_dir && (unmatched[0] == 0 || unmatched[0] == '/')) return dir->is_common; diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh index c7b53e494ba43f..501e1a288df4c5 100755 --- a/t/t0060-path-utils.sh +++ b/t/t0060-path-utils.sh @@ -288,6 +288,8 @@ test_git_path GIT_COMMON_DIR=bar index .git/index test_git_path GIT_COMMON_DIR=bar HEAD .git/HEAD test_git_path GIT_COMMON_DIR=bar logs/HEAD .git/logs/HEAD test_git_path GIT_COMMON_DIR=bar logs/refs/bisect/foo .git/logs/refs/bisect/foo +test_git_path GIT_COMMON_DIR=bar logs/refs bar/logs/refs +test_git_path GIT_COMMON_DIR=bar logs/refs/ bar/logs/refs/ test_git_path GIT_COMMON_DIR=bar logs/refs/bisec/foo bar/logs/refs/bisec/foo test_git_path GIT_COMMON_DIR=bar logs/refs/bisec bar/logs/refs/bisec test_git_path GIT_COMMON_DIR=bar logs/refs/bisectfoo bar/logs/refs/bisectfoo From 6c96630cb0900446f7069f64d3d58bac539c0a58 Mon Sep 17 00:00:00 2001 From: Heba Waly Date: Wed, 23 Oct 2019 05:30:52 +0000 Subject: [PATCH 050/953] config: move documentation to config.h Move the documentation from Documentation/technical/api-config.txt into config.h as it's easier for the developers to find the usage information beside the code instead of looking for it in another doc file, also documentation/technical/api-config.txt is removed because the information it has is now redundant and it'll be hard to keep it up to date and syncronized with the documentation in config.h Signed-off-by: Heba Waly Reviewed-by: Emily Shaffer Signed-off-by: Junio C Hamano --- Documentation/technical/api-config.txt | 319 ----------------------- config.h | 335 +++++++++++++++++++++++++ 2 files changed, 335 insertions(+), 319 deletions(-) delete mode 100644 Documentation/technical/api-config.txt diff --git a/Documentation/technical/api-config.txt b/Documentation/technical/api-config.txt deleted file mode 100644 index 7d20716c32a453..00000000000000 --- a/Documentation/technical/api-config.txt +++ /dev/null @@ -1,319 +0,0 @@ -config API -========== - -The config API gives callers a way to access Git configuration files -(and files which have the same syntax). See linkgit:git-config[1] for a -discussion of the config file syntax. - -General Usage -------------- - -Config files are parsed linearly, and each variable found is passed to a -caller-provided callback function. The callback function is responsible -for any actions to be taken on the config option, and is free to ignore -some options. It is not uncommon for the configuration to be parsed -several times during the run of a Git program, with different callbacks -picking out different variables useful to themselves. - -A config callback function takes three parameters: - -- the name of the parsed variable. This is in canonical "flat" form: the - section, subsection, and variable segments will be separated by dots, - and the section and variable segments will be all lowercase. E.g., - `core.ignorecase`, `diff.SomeType.textconv`. - -- the value of the found variable, as a string. If the variable had no - value specified, the value will be NULL (typically this means it - should be interpreted as boolean true). - -- a void pointer passed in by the caller of the config API; this can - contain callback-specific data - -A config callback should return 0 for success, or -1 if the variable -could not be parsed properly. - -Basic Config Querying ---------------------- - -Most programs will simply want to look up variables in all config files -that Git knows about, using the normal precedence rules. To do this, -call `git_config` with a callback function and void data pointer. - -`git_config` will read all config sources in order of increasing -priority. Thus a callback should typically overwrite previously-seen -entries with new ones (e.g., if both the user-wide `~/.gitconfig` and -repo-specific `.git/config` contain `color.ui`, the config machinery -will first feed the user-wide one to the callback, and then the -repo-specific one; by overwriting, the higher-priority repo-specific -value is left at the end). - -The `config_with_options` function lets the caller examine config -while adjusting some of the default behavior of `git_config`. It should -almost never be used by "regular" Git code that is looking up -configuration variables. It is intended for advanced callers like -`git-config`, which are intentionally tweaking the normal config-lookup -process. It takes two extra parameters: - -`config_source`:: -If this parameter is non-NULL, it specifies the source to parse for -configuration, rather than looking in the usual files. See `struct -git_config_source` in `config.h` for details. Regular `git_config` defaults -to `NULL`. - -`opts`:: -Specify options to adjust the behavior of parsing config files. See `struct -config_options` in `config.h` for details. As an example: regular `git_config` -sets `opts.respect_includes` to `1` by default. - -Reading Specific Files ----------------------- - -To read a specific file in git-config format, use -`git_config_from_file`. This takes the same callback and data parameters -as `git_config`. - -Querying For Specific Variables -------------------------------- - -For programs wanting to query for specific variables in a non-callback -manner, the config API provides two functions `git_config_get_value` -and `git_config_get_value_multi`. They both read values from an internal -cache generated previously from reading the config files. - -`int git_config_get_value(const char *key, const char **value)`:: - - Finds the highest-priority value for the configuration variable `key`, - stores the pointer to it in `value` and returns 0. When the - configuration variable `key` is not found, returns 1 without touching - `value`. The caller should not free or modify `value`, as it is owned - by the cache. - -`const struct string_list *git_config_get_value_multi(const char *key)`:: - - Finds and returns the value list, sorted in order of increasing priority - for the configuration variable `key`. When the configuration variable - `key` is not found, returns NULL. The caller should not free or modify - the returned pointer, as it is owned by the cache. - -`void git_config_clear(void)`:: - - Resets and invalidates the config cache. - -The config API also provides type specific API functions which do conversion -as well as retrieval for the queried variable, including: - -`int git_config_get_int(const char *key, int *dest)`:: - - Finds and parses the value to an integer for the configuration variable - `key`. Dies on error; otherwise, stores the value of the parsed integer in - `dest` and returns 0. When the configuration variable `key` is not found, - returns 1 without touching `dest`. - -`int git_config_get_ulong(const char *key, unsigned long *dest)`:: - - Similar to `git_config_get_int` but for unsigned longs. - -`int git_config_get_bool(const char *key, int *dest)`:: - - Finds and parses the value into a boolean value, for the configuration - variable `key` respecting keywords like "true" and "false". Integer - values are converted into true/false values (when they are non-zero or - zero, respectively). Other values cause a die(). If parsing is successful, - stores the value of the parsed result in `dest` and returns 0. When the - configuration variable `key` is not found, returns 1 without touching - `dest`. - -`int git_config_get_bool_or_int(const char *key, int *is_bool, int *dest)`:: - - Similar to `git_config_get_bool`, except that integers are copied as-is, - and `is_bool` flag is unset. - -`int git_config_get_maybe_bool(const char *key, int *dest)`:: - - Similar to `git_config_get_bool`, except that it returns -1 on error - rather than dying. - -`int git_config_get_string_const(const char *key, const char **dest)`:: - - Allocates and copies the retrieved string into the `dest` parameter for - the configuration variable `key`; if NULL string is given, prints an - error message and returns -1. When the configuration variable `key` is - not found, returns 1 without touching `dest`. - -`int git_config_get_string(const char *key, char **dest)`:: - - Similar to `git_config_get_string_const`, except that retrieved value - copied into the `dest` parameter is a mutable string. - -`int git_config_get_pathname(const char *key, const char **dest)`:: - - Similar to `git_config_get_string`, but expands `~` or `~user` into - the user's home directory when found at the beginning of the path. - -`git_die_config(const char *key, const char *err, ...)`:: - - First prints the error message specified by the caller in `err` and then - dies printing the line number and the file name of the highest priority - value for the configuration variable `key`. - -`void git_die_config_linenr(const char *key, const char *filename, int linenr)`:: - - Helper function which formats the die error message according to the - parameters entered. Used by `git_die_config()`. It can be used by callers - handling `git_config_get_value_multi()` to print the correct error message - for the desired value. - -See test-config.c for usage examples. - -Value Parsing Helpers ---------------------- - -To aid in parsing string values, the config API provides callbacks with -a number of helper functions, including: - -`git_config_int`:: -Parse the string to an integer, including unit factors. Dies on error; -otherwise, returns the parsed result. - -`git_config_ulong`:: -Identical to `git_config_int`, but for unsigned longs. - -`git_config_bool`:: -Parse a string into a boolean value, respecting keywords like "true" and -"false". Integer values are converted into true/false values (when they -are non-zero or zero, respectively). Other values cause a die(). If -parsing is successful, the return value is the result. - -`git_config_bool_or_int`:: -Same as `git_config_bool`, except that integers are returned as-is, and -an `is_bool` flag is unset. - -`git_parse_maybe_bool`:: -Same as `git_config_bool`, except that it returns -1 on error rather -than dying. - -`git_config_string`:: -Allocates and copies the value string into the `dest` parameter; if no -string is given, prints an error message and returns -1. - -`git_config_pathname`:: -Similar to `git_config_string`, but expands `~` or `~user` into the -user's home directory when found at the beginning of the path. - -Include Directives ------------------- - -By default, the config parser does not respect include directives. -However, a caller can use the special `git_config_include` wrapper -callback to support them. To do so, you simply wrap your "real" callback -function and data pointer in a `struct config_include_data`, and pass -the wrapper to the regular config-reading functions. For example: - -------------------------------------------- -int read_file_with_include(const char *file, config_fn_t fn, void *data) -{ - struct config_include_data inc = CONFIG_INCLUDE_INIT; - inc.fn = fn; - inc.data = data; - return git_config_from_file(git_config_include, file, &inc); -} -------------------------------------------- - -`git_config` respects includes automatically. The lower-level -`git_config_from_file` does not. - -Custom Configsets ------------------ - -A `config_set` can be used to construct an in-memory cache for -config-like files that the caller specifies (i.e., files like `.gitmodules`, -`~/.gitconfig` etc.). For example, - ----------------------------------------- -struct config_set gm_config; -git_configset_init(&gm_config); -int b; -/* we add config files to the config_set */ -git_configset_add_file(&gm_config, ".gitmodules"); -git_configset_add_file(&gm_config, ".gitmodules_alt"); - -if (!git_configset_get_bool(gm_config, "submodule.frotz.ignore", &b)) { - /* hack hack hack */ -} - -/* when we are done with the configset */ -git_configset_clear(&gm_config); ----------------------------------------- - -Configset API provides functions for the above mentioned work flow, including: - -`void git_configset_init(struct config_set *cs)`:: - - Initializes the config_set `cs`. - -`int git_configset_add_file(struct config_set *cs, const char *filename)`:: - - Parses the file and adds the variable-value pairs to the `config_set`, - dies if there is an error in parsing the file. Returns 0 on success, or - -1 if the file does not exist or is inaccessible. The user has to decide - if he wants to free the incomplete configset or continue using it when - the function returns -1. - -`int git_configset_get_value(struct config_set *cs, const char *key, const char **value)`:: - - Finds the highest-priority value for the configuration variable `key` - and config set `cs`, stores the pointer to it in `value` and returns 0. - When the configuration variable `key` is not found, returns 1 without - touching `value`. The caller should not free or modify `value`, as it - is owned by the cache. - -`const struct string_list *git_configset_get_value_multi(struct config_set *cs, const char *key)`:: - - Finds and returns the value list, sorted in order of increasing priority - for the configuration variable `key` and config set `cs`. When the - configuration variable `key` is not found, returns NULL. The caller - should not free or modify the returned pointer, as it is owned by the cache. - -`void git_configset_clear(struct config_set *cs)`:: - - Clears `config_set` structure, removes all saved variable-value pairs. - -In addition to above functions, the `config_set` API provides type specific -functions in the vein of `git_config_get_int` and family but with an extra -parameter, pointer to struct `config_set`. -They all behave similarly to the `git_config_get*()` family described in -"Querying For Specific Variables" above. - -Writing Config Files --------------------- - -Git gives multiple entry points in the Config API to write config values to -files namely `git_config_set_in_file` and `git_config_set`, which write to -a specific config file or to `.git/config` respectively. They both take a -key/value pair as parameter. -In the end they both call `git_config_set_multivar_in_file` which takes four -parameters: - -- the name of the file, as a string, to which key/value pairs will be written. - -- the name of key, as a string. This is in canonical "flat" form: the section, - subsection, and variable segments will be separated by dots, and the section - and variable segments will be all lowercase. - E.g., `core.ignorecase`, `diff.SomeType.textconv`. - -- the value of the variable, as a string. If value is equal to NULL, it will - remove the matching key from the config file. - -- the value regex, as a string. It will disregard key/value pairs where value - does not match. - -- a multi_replace value, as an int. If value is equal to zero, nothing or only - one matching key/value is replaced, else all matching key/values (regardless - how many) are removed, before the new pair is written. - -It returns 0 on success. - -Also, there are functions `git_config_rename_section` and -`git_config_rename_section_in_file` with parameters `old_name` and `new_name` -for renaming or removing sections in the config files. If NULL is passed -through `new_name` parameter, the section will be removed from the config file. diff --git a/config.h b/config.h index f0ed464004da60..91fd4c5e96ae79 100644 --- a/config.h +++ b/config.h @@ -4,6 +4,22 @@ #include "hashmap.h" #include "string-list.h" + +/** + * The config API gives callers a way to access Git configuration files + * (and files which have the same syntax). + * + * General Usage + * ------------- + * + * Config files are parsed linearly, and each variable found is passed to a + * caller-provided callback function. The callback function is responsible + * for any actions to be taken on the config option, and is free to ignore + * some options. It is not uncommon for the configuration to be parsed + * several times during the run of a Git program, with different callbacks + * picking out different variables useful to themselves. + */ + struct object_id; /* git_config_parse_key() returns these negated: */ @@ -71,9 +87,34 @@ struct config_options { } error_action; }; +/** + * A config callback function takes three parameters: + * + * - the name of the parsed variable. This is in canonical "flat" form: the + * section, subsection, and variable segments will be separated by dots, + * and the section and variable segments will be all lowercase. E.g., + * `core.ignorecase`, `diff.SomeType.textconv`. + * + * - the value of the found variable, as a string. If the variable had no + * value specified, the value will be NULL (typically this means it + * should be interpreted as boolean true). + * + * - a void pointer passed in by the caller of the config API; this can + * contain callback-specific data + * + * A config callback should return 0 for success, or -1 if the variable + * could not be parsed properly. + */ typedef int (*config_fn_t)(const char *, const char *, void *); + int git_default_config(const char *, const char *, void *); + +/** + * Read a specific file in git-config format. + * This function takes the same callback and data parameters as `git_config`. + */ int git_config_from_file(config_fn_t fn, const char *, void *); + int git_config_from_file_with_options(config_fn_t fn, const char *, void *, const struct config_options *); @@ -88,34 +129,157 @@ void git_config_push_parameter(const char *text); int git_config_from_parameters(config_fn_t fn, void *data); void read_early_config(config_fn_t cb, void *data); void read_very_early_config(config_fn_t cb, void *data); + +/** + * Most programs will simply want to look up variables in all config files + * that Git knows about, using the normal precedence rules. To do this, + * call `git_config` with a callback function and void data pointer. + * + * `git_config` will read all config sources in order of increasing + * priority. Thus a callback should typically overwrite previously-seen + * entries with new ones (e.g., if both the user-wide `~/.gitconfig` and + * repo-specific `.git/config` contain `color.ui`, the config machinery + * will first feed the user-wide one to the callback, and then the + * repo-specific one; by overwriting, the higher-priority repo-specific + * value is left at the end). + */ void git_config(config_fn_t fn, void *); + +/** + * Lets the caller examine config while adjusting some of the default + * behavior of `git_config`. It should almost never be used by "regular" + * Git code that is looking up configuration variables. + * It is intended for advanced callers like `git-config`, which are + * intentionally tweaking the normal config-lookup process. + * It takes two extra parameters: + * + * - `config_source` + * If this parameter is non-NULL, it specifies the source to parse for + * configuration, rather than looking in the usual files. See `struct + * git_config_source` in `config.h` for details. Regular `git_config` defaults + * to `NULL`. + * + * - `opts` + * Specify options to adjust the behavior of parsing config files. See `struct + * config_options` in `config.h` for details. As an example: regular `git_config` + * sets `opts.respect_includes` to `1` by default. + */ int config_with_options(config_fn_t fn, void *, struct git_config_source *config_source, const struct config_options *opts); + +/** + * Value Parsing Helpers + * --------------------- + * + * The following helper functions aid in parsing string values + */ + int git_parse_ssize_t(const char *, ssize_t *); int git_parse_ulong(const char *, unsigned long *); + +/** + * Same as `git_config_bool`, except that it returns -1 on error rather + * than dying. + */ int git_parse_maybe_bool(const char *); + +/** + * Parse the string to an integer, including unit factors. Dies on error; + * otherwise, returns the parsed result. + */ int git_config_int(const char *, const char *); + int64_t git_config_int64(const char *, const char *); + +/** + * Identical to `git_config_int`, but for unsigned longs. + */ unsigned long git_config_ulong(const char *, const char *); + ssize_t git_config_ssize_t(const char *, const char *); + +/** + * Same as `git_config_bool`, except that integers are returned as-is, and + * an `is_bool` flag is unset. + */ int git_config_bool_or_int(const char *, const char *, int *); + +/** + * Parse a string into a boolean value, respecting keywords like "true" and + * "false". Integer values are converted into true/false values (when they + * are non-zero or zero, respectively). Other values cause a die(). If + * parsing is successful, the return value is the result. + */ int git_config_bool(const char *, const char *); + +/** + * Allocates and copies the value string into the `dest` parameter; if no + * string is given, prints an error message and returns -1. + */ int git_config_string(const char **, const char *, const char *); + +/** + * Similar to `git_config_string`, but expands `~` or `~user` into the + * user's home directory when found at the beginning of the path. + */ int git_config_pathname(const char **, const char *, const char *); + int git_config_expiry_date(timestamp_t *, const char *, const char *); int git_config_color(char *, const char *, const char *); int git_config_set_in_file_gently(const char *, const char *, const char *); + +/** + * write config values to a specific config file, takes a key/value pair as + * parameter. + */ void git_config_set_in_file(const char *, const char *, const char *); + int git_config_set_gently(const char *, const char *); + +/** + * write config values to `.git/config`, takes a key/value pair as parameter. + */ void git_config_set(const char *, const char *); + int git_config_parse_key(const char *, char **, int *); int git_config_key_is_valid(const char *key); int git_config_set_multivar_gently(const char *, const char *, const char *, int); void git_config_set_multivar(const char *, const char *, const char *, int); int git_config_set_multivar_in_file_gently(const char *, const char *, const char *, const char *, int); + +/** + * takes four parameters: + * + * - the name of the file, as a string, to which key/value pairs will be written. + * + * - the name of key, as a string. This is in canonical "flat" form: the section, + * subsection, and variable segments will be separated by dots, and the section + * and variable segments will be all lowercase. + * E.g., `core.ignorecase`, `diff.SomeType.textconv`. + * + * - the value of the variable, as a string. If value is equal to NULL, it will + * remove the matching key from the config file. + * + * - the value regex, as a string. It will disregard key/value pairs where value + * does not match. + * + * - a multi_replace value, as an int. If value is equal to zero, nothing or only + * one matching key/value is replaced, else all matching key/values (regardless + * how many) are removed, before the new pair is written. + * + * It returns 0 on success. + */ void git_config_set_multivar_in_file(const char *, const char *, const char *, const char *, int); + +/** + * rename or remove sections in the config file + * parameters `old_name` and `new_name` + * If NULL is passed through `new_name` parameter, + * the section will be removed from the config file. + */ int git_config_rename_section(const char *, const char *); + int git_config_rename_section_in_file(const char *, const char *, const char *); int git_config_copy_section(const char *, const char *); int git_config_copy_section_in_file(const char *, const char *, const char *); @@ -142,6 +306,30 @@ enum config_scope current_config_scope(void); const char *current_config_origin_type(void); const char *current_config_name(void); +/** + * Include Directives + * ------------------ + * + * By default, the config parser does not respect include directives. + * However, a caller can use the special `git_config_include` wrapper + * callback to support them. To do so, you simply wrap your "real" callback + * function and data pointer in a `struct config_include_data`, and pass + * the wrapper to the regular config-reading functions. For example: + * + * ------------------------------------------- + * int read_file_with_include(const char *file, config_fn_t fn, void *data) + * { + * struct config_include_data inc = CONFIG_INCLUDE_INIT; + * inc.fn = fn; + * inc.data = data; + * return git_config_from_file(git_config_include, file, &inc); + * } + * ------------------------------------------- + * + * `git_config` respects includes automatically. The lower-level + * `git_config_from_file` does not. + * + */ struct config_include_data { int depth; config_fn_t fn; @@ -169,6 +357,33 @@ int parse_config_key(const char *var, const char **subsection, int *subsection_len, const char **key); +/** + * Custom Configsets + * ----------------- + * + * A `config_set` can be used to construct an in-memory cache for + * config-like files that the caller specifies (i.e., files like `.gitmodules`, + * `~/.gitconfig` etc.). For example, + * + * ---------------------------------------- + * struct config_set gm_config; + * git_configset_init(&gm_config); + * int b; + * //we add config files to the config_set + * git_configset_add_file(&gm_config, ".gitmodules"); + * git_configset_add_file(&gm_config, ".gitmodules_alt"); + * + * if (!git_configset_get_bool(gm_config, "submodule.frotz.ignore", &b)) { + * //hack hack hack + * } + * + * when we are done with the configset: + * git_configset_clear(&gm_config); + * ---------------------------------------- + * + * Configset API provides functions for the above mentioned work flow + */ + struct config_set_element { struct hashmap_entry ent; char *key; @@ -197,16 +412,47 @@ struct config_set { struct configset_list list; }; +/** + * Initializes the config_set `cs`. + */ void git_configset_init(struct config_set *cs); + +/** + * Parses the file and adds the variable-value pairs to the `config_set`, + * dies if there is an error in parsing the file. Returns 0 on success, or + * -1 if the file does not exist or is inaccessible. The user has to decide + * if he wants to free the incomplete configset or continue using it when + * the function returns -1. + */ int git_configset_add_file(struct config_set *cs, const char *filename); + +/** + * Finds and returns the value list, sorted in order of increasing priority + * for the configuration variable `key` and config set `cs`. When the + * configuration variable `key` is not found, returns NULL. The caller + * should not free or modify the returned pointer, as it is owned by the cache. + */ const struct string_list *git_configset_get_value_multi(struct config_set *cs, const char *key); + +/** + * Clears `config_set` structure, removes all saved variable-value pairs. + */ void git_configset_clear(struct config_set *cs); /* * These functions return 1 if not found, and 0 if found, leaving the found * value in the 'dest' pointer. */ + +/* + * Finds the highest-priority value for the configuration variable `key` + * and config set `cs`, stores the pointer to it in `value` and returns 0. + * When the configuration variable `key` is not found, returns 1 without + * touching `value`. The caller should not free or modify `value`, as it + * is owned by the cache. + */ int git_configset_get_value(struct config_set *cs, const char *key, const char **dest); + int git_configset_get_string_const(struct config_set *cs, const char *key, const char **dest); int git_configset_get_string(struct config_set *cs, const char *key, char **dest); int git_configset_get_int(struct config_set *cs, const char *key, int *dest); @@ -240,17 +486,94 @@ int repo_config_get_maybe_bool(struct repository *repo, int repo_config_get_pathname(struct repository *repo, const char *key, const char **dest); +/** + * Querying For Specific Variables + * ------------------------------- + * + * For programs wanting to query for specific variables in a non-callback + * manner, the config API provides two functions `git_config_get_value` + * and `git_config_get_value_multi`. They both read values from an internal + * cache generated previously from reading the config files. + */ + +/** + * Finds the highest-priority value for the configuration variable `key`, + * stores the pointer to it in `value` and returns 0. When the + * configuration variable `key` is not found, returns 1 without touching + * `value`. The caller should not free or modify `value`, as it is owned + * by the cache. + */ int git_config_get_value(const char *key, const char **value); + +/** + * Finds and returns the value list, sorted in order of increasing priority + * for the configuration variable `key`. When the configuration variable + * `key` is not found, returns NULL. The caller should not free or modify + * the returned pointer, as it is owned by the cache. + */ const struct string_list *git_config_get_value_multi(const char *key); + +/** + * Resets and invalidates the config cache. + */ void git_config_clear(void); + +/** + * Allocates and copies the retrieved string into the `dest` parameter for + * the configuration variable `key`; if NULL string is given, prints an + * error message and returns -1. When the configuration variable `key` is + * not found, returns 1 without touching `dest`. + */ int git_config_get_string_const(const char *key, const char **dest); + +/** + * Similar to `git_config_get_string_const`, except that retrieved value + * copied into the `dest` parameter is a mutable string. + */ int git_config_get_string(const char *key, char **dest); + +/** + * Finds and parses the value to an integer for the configuration variable + * `key`. Dies on error; otherwise, stores the value of the parsed integer in + * `dest` and returns 0. When the configuration variable `key` is not found, + * returns 1 without touching `dest`. + */ int git_config_get_int(const char *key, int *dest); + +/** + * Similar to `git_config_get_int` but for unsigned longs. + */ int git_config_get_ulong(const char *key, unsigned long *dest); + +/** + * Finds and parses the value into a boolean value, for the configuration + * variable `key` respecting keywords like "true" and "false". Integer + * values are converted into true/false values (when they are non-zero or + * zero, respectively). Other values cause a die(). If parsing is successful, + * stores the value of the parsed result in `dest` and returns 0. When the + * configuration variable `key` is not found, returns 1 without touching + * `dest`. + */ int git_config_get_bool(const char *key, int *dest); + +/** + * Similar to `git_config_get_bool`, except that integers are copied as-is, + * and `is_bool` flag is unset. + */ int git_config_get_bool_or_int(const char *key, int *is_bool, int *dest); + +/** + * Similar to `git_config_get_bool`, except that it returns -1 on error + * rather than dying. + */ int git_config_get_maybe_bool(const char *key, int *dest); + +/** + * Similar to `git_config_get_string`, but expands `~` or `~user` into + * the user's home directory when found at the beginning of the path. + */ int git_config_get_pathname(const char *key, const char **dest); + int git_config_get_index_threads(int *dest); int git_config_get_untracked_cache(void); int git_config_get_split_index(void); @@ -270,7 +593,19 @@ struct key_value_info { enum config_scope scope; }; +/** + * First prints the error message specified by the caller in `err` and then + * dies printing the line number and the file name of the highest priority + * value for the configuration variable `key`. + */ NORETURN void git_die_config(const char *key, const char *err, ...) __attribute__((format(printf, 2, 3))); + +/** + * Helper function which formats the die error message according to the + * parameters entered. Used by `git_die_config()`. It can be used by callers + * handling `git_config_get_value_multi()` to print the correct error message + * for the desired value. + */ NORETURN void git_die_config_linenr(const char *key, const char *filename, int linenr); #define LOOKUP_CONFIG(mapping, var) \ From fa87b813853b12fee2a931c6084134fe1eea3b55 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 23 Oct 2019 16:32:28 -0700 Subject: [PATCH 051/953] t4108: replace create_file with test_write_lines Since the locally defined create_file() duplicates the functionality of the test_write_lines() helper function, remove create_file() and replace all instances with test_write_lines(). While we're at it, move redirection operators to the end of the command which is the more conventional place to put it. Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano --- t/t4108-apply-threeway.sh | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/t/t4108-apply-threeway.sh b/t/t4108-apply-threeway.sh index fa5d4efb89dc4e..b109ecbd9fc76e 100755 --- a/t/t4108-apply-threeway.sh +++ b/t/t4108-apply-threeway.sh @@ -4,13 +4,6 @@ test_description='git apply --3way' . ./test-lib.sh -create_file () { - for i - do - echo "$i" - done -} - sanitize_conflicted_diff () { sed -e ' /^index /d @@ -20,7 +13,7 @@ sanitize_conflicted_diff () { test_expect_success setup ' test_tick && - create_file >one 1 2 3 4 5 6 7 && + test_write_lines 1 2 3 4 5 6 7 >one && cat one >two && git add one two && git commit -m initial && @@ -28,13 +21,13 @@ test_expect_success setup ' git branch side && test_tick && - create_file >one 1 two 3 4 5 six 7 && - create_file >two 1 two 3 4 5 6 7 && + test_write_lines 1 two 3 4 5 six 7 >one && + test_write_lines 1 two 3 4 5 6 7 >two && git commit -a -m master && git checkout side && - create_file >one 1 2 3 4 five 6 7 && - create_file >two 1 2 3 4 five 6 7 && + test_write_lines 1 2 3 4 five 6 7 >one && + test_write_lines 1 2 3 4 five 6 7 >two && git commit -a -m side && git checkout master @@ -87,7 +80,7 @@ test_expect_success 'apply with --3way with rerere enabled' ' test_must_fail git merge --no-commit side && # Manually resolve and record the resolution - create_file 1 two 3 4 five six 7 >one && + test_write_lines 1 two 3 4 five six 7 >one && git rerere && cat one >expect && @@ -104,14 +97,14 @@ test_expect_success 'apply -3 with add/add conflict setup' ' git reset --hard && git checkout -b adder && - create_file 1 2 3 4 5 6 7 >three && - create_file 1 2 3 4 5 6 7 >four && + test_write_lines 1 2 3 4 5 6 7 >three && + test_write_lines 1 2 3 4 5 6 7 >four && git add three four && git commit -m "add three and four" && git checkout -b another adder^ && - create_file 1 2 3 4 5 6 7 >three && - create_file 1 2 3 four 5 6 7 >four && + test_write_lines 1 2 3 4 5 6 7 >three && + test_write_lines 1 2 3 four 5 6 7 >four && git add three four && git commit -m "add three and four" && From b0069684d430ea67fd3fbe019c71a18d4ef87fa3 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 23 Oct 2019 16:32:31 -0700 Subject: [PATCH 052/953] t4108: remove git command upstream of pipe Before, the output of `git diff HEAD` would always be piped to sanitize_conflicted_diff(). However, since the Git command was upstream of the pipe, in case the Git command fails, the return code would be lost. Rewrite into separate statements so that the return code is no longer lost. Since only the command `git diff HEAD` was being piped to sanitize_conflicted_diff(), move the command into the function and rename it to print_sanitized_conflicted_diff(). Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano --- t/t4108-apply-threeway.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/t/t4108-apply-threeway.sh b/t/t4108-apply-threeway.sh index b109ecbd9fc76e..3c0ddacddf8834 100755 --- a/t/t4108-apply-threeway.sh +++ b/t/t4108-apply-threeway.sh @@ -4,11 +4,12 @@ test_description='git apply --3way' . ./test-lib.sh -sanitize_conflicted_diff () { +print_sanitized_conflicted_diff () { + git diff HEAD >diff.raw && sed -e ' /^index /d s/^\(+[<>][<>][<>][<>]*\) .*/\1/ - ' + ' diff.raw } test_expect_success setup ' @@ -54,14 +55,14 @@ test_expect_success 'apply with --3way' ' git checkout master^0 && test_must_fail git merge --no-commit side && git ls-files -s >expect.ls && - git diff HEAD | sanitize_conflicted_diff >expect.diff && + print_sanitized_conflicted_diff >expect.diff && # should fail to apply git reset --hard && git checkout master^0 && test_must_fail git apply --index --3way P.diff && git ls-files -s >actual.ls && - git diff HEAD | sanitize_conflicted_diff >actual.diff && + print_sanitized_conflicted_diff >actual.diff && # The result should resemble the corresponding merge test_cmp expect.ls actual.ls && @@ -114,7 +115,7 @@ test_expect_success 'apply -3 with add/add conflict setup' ' git checkout adder^0 && test_must_fail git merge --no-commit another && git ls-files -s >expect.ls && - git diff HEAD | sanitize_conflicted_diff >expect.diff + print_sanitized_conflicted_diff >expect.diff ' test_expect_success 'apply -3 with add/add conflict' ' @@ -124,7 +125,7 @@ test_expect_success 'apply -3 with add/add conflict' ' test_must_fail git apply --index --3way P.diff && # ... and leave conflicts in the index and in the working tree git ls-files -s >actual.ls && - git diff HEAD | sanitize_conflicted_diff >actual.diff && + print_sanitized_conflicted_diff >actual.diff && # The result should resemble the corresponding merge test_cmp expect.ls actual.ls && From 95806205cd7013f524b6a7f10afc8542ab0c1929 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 23 Oct 2019 16:32:33 -0700 Subject: [PATCH 053/953] t4108: use `test_config` instead of `git config` Since `git config` leaves the configurations set even after the test case completes, use `test_config` instead so that the configurations are reset once the test case finishes. Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano --- t/t4108-apply-threeway.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/t4108-apply-threeway.sh b/t/t4108-apply-threeway.sh index 3c0ddacddf8834..7f96ae9101ad67 100755 --- a/t/t4108-apply-threeway.sh +++ b/t/t4108-apply-threeway.sh @@ -70,7 +70,7 @@ test_expect_success 'apply with --3way' ' ' test_expect_success 'apply with --3way with rerere enabled' ' - git config rerere.enabled true && + test_config rerere.enabled true && # Merging side should be similar to applying this patch git diff ...side >P.diff && From aa76ae4905c28e264f0affc58e36c1db692fa881 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 23 Oct 2019 16:32:36 -0700 Subject: [PATCH 054/953] t4108: demonstrate bug in apply Currently, apply does not respect the merge.conflictStyle setting. Demonstrate this by making the 'apply with --3way' test case generic and extending it to show that the configuration of merge.conflictStyle = diff3 causes a breakage. Change print_sanitized_conflicted_diff() to also sanitize `|||||||` conflict markers. Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano --- t/t4108-apply-threeway.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/t/t4108-apply-threeway.sh b/t/t4108-apply-threeway.sh index 7f96ae9101ad67..bffe37f1baa1f0 100755 --- a/t/t4108-apply-threeway.sh +++ b/t/t4108-apply-threeway.sh @@ -8,7 +8,7 @@ print_sanitized_conflicted_diff () { git diff HEAD >diff.raw && sed -e ' /^index /d - s/^\(+[<>][<>][<>][<>]*\) .*/\1/ + s/^\(+[<>|][<>|][<>|][<>|]*\) .*/\1/ ' diff.raw } @@ -46,7 +46,7 @@ test_expect_success 'apply without --3way' ' git diff-index --exit-code --cached HEAD ' -test_expect_success 'apply with --3way' ' +test_apply_with_3way () { # Merging side should be similar to applying this patch git diff ...side >P.diff && @@ -67,6 +67,15 @@ test_expect_success 'apply with --3way' ' # The result should resemble the corresponding merge test_cmp expect.ls actual.ls && test_cmp expect.diff actual.diff +} + +test_expect_success 'apply with --3way' ' + test_apply_with_3way +' + +test_expect_failure 'apply with --3way with merge.conflictStyle = diff3' ' + test_config merge.conflictStyle diff3 && + test_apply_with_3way ' test_expect_success 'apply with --3way with rerere enabled' ' From 091489d068e0e812123f5114149bdb0e7d74c257 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 23 Oct 2019 16:32:38 -0700 Subject: [PATCH 055/953] apply: respect merge.conflictStyle in --3way Before, when doing a 3-way merge, the merge.conflictStyle option was not respected and the "merge" style was always used, even if "diff3" was specified. Call git_xmerge_config() at the end of git_apply_config() so that the merge.conflictStyle config is read. Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano --- apply.c | 2 +- t/t4108-apply-threeway.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apply.c b/apply.c index cde95369bb3f3a..84704572ca9508 100644 --- a/apply.c +++ b/apply.c @@ -32,7 +32,7 @@ static void git_apply_config(void) { git_config_get_string_const("apply.whitespace", &apply_default_whitespace); git_config_get_string_const("apply.ignorewhitespace", &apply_default_ignorewhitespace); - git_config(git_default_config, NULL); + git_config(git_xmerge_config, NULL); } static int parse_whitespace_option(struct apply_state *state, const char *option) diff --git a/t/t4108-apply-threeway.sh b/t/t4108-apply-threeway.sh index bffe37f1baa1f0..d7349ced6be0aa 100755 --- a/t/t4108-apply-threeway.sh +++ b/t/t4108-apply-threeway.sh @@ -73,7 +73,7 @@ test_expect_success 'apply with --3way' ' test_apply_with_3way ' -test_expect_failure 'apply with --3way with merge.conflictStyle = diff3' ' +test_expect_success 'apply with --3way with merge.conflictStyle = diff3' ' test_config merge.conflictStyle diff3 && test_apply_with_3way ' From 7b4fb434b410358b7a70ef772463292e18bf6c30 Mon Sep 17 00:00:00 2001 From: Heba Waly Date: Thu, 24 Oct 2019 11:29:11 +0000 Subject: [PATCH 056/953] documentation: remove empty doc files Remove empty and redundant documentation files from the Documentation/technical/ directory. The empty doc files included only TODO messages with no documentation for years. Instead an approach is being taken to keep all doc beside the code in the relevant header files. Having empty doc files is confusing and disappointing to anybody looking for information, besides having the documentation in header files makes it easier for developers to find the information they are looking for. Some of the content which could have gone here already exists elsewhere: - api-object-access.txt -> sha1-file.c and object.h have some details. - api-quote.txt -> quote.h has some details. - api-xdiff-interface.txt -> xdiff-interface.h has some details. - api-grep.txt -> grep.h does not have enough documentation at the moment. Signed-off-by: Heba Waly Reviewed-by: Emily Shaffer Signed-off-by: Junio C Hamano --- Documentation/technical/api-grep.txt | 8 -------- Documentation/technical/api-object-access.txt | 15 --------------- Documentation/technical/api-quote.txt | 10 ---------- Documentation/technical/api-xdiff-interface.txt | 7 ------- 4 files changed, 40 deletions(-) delete mode 100644 Documentation/technical/api-grep.txt delete mode 100644 Documentation/technical/api-object-access.txt delete mode 100644 Documentation/technical/api-quote.txt delete mode 100644 Documentation/technical/api-xdiff-interface.txt diff --git a/Documentation/technical/api-grep.txt b/Documentation/technical/api-grep.txt deleted file mode 100644 index a69cc8964d585d..00000000000000 --- a/Documentation/technical/api-grep.txt +++ /dev/null @@ -1,8 +0,0 @@ -grep API -======== - -Talk about , things like: - -* grep_buffer() - -(JC) diff --git a/Documentation/technical/api-object-access.txt b/Documentation/technical/api-object-access.txt deleted file mode 100644 index 5b29622d00ea61..00000000000000 --- a/Documentation/technical/api-object-access.txt +++ /dev/null @@ -1,15 +0,0 @@ -object access API -================= - -Talk about and family, things like - -* read_sha1_file() -* read_object_with_reference() -* has_sha1_file() -* write_sha1_file() -* pretend_object_file() -* lookup_{object,commit,tag,blob,tree} -* parse_{object,commit,tag,blob,tree} -* Use of object flags - -(JC, Shawn, Daniel, Dscho, Linus) diff --git a/Documentation/technical/api-quote.txt b/Documentation/technical/api-quote.txt deleted file mode 100644 index e8a1bce94e05f0..00000000000000 --- a/Documentation/technical/api-quote.txt +++ /dev/null @@ -1,10 +0,0 @@ -quote API -========= - -Talk about , things like - -* sq_quote and unquote -* c_style quote and unquote -* quoting for foreign languages - -(JC) diff --git a/Documentation/technical/api-xdiff-interface.txt b/Documentation/technical/api-xdiff-interface.txt deleted file mode 100644 index 6296ecad1d6551..00000000000000 --- a/Documentation/technical/api-xdiff-interface.txt +++ /dev/null @@ -1,7 +0,0 @@ -xdiff interface API -=================== - -Talk about our calling convention to xdiff library, including -xdiff_emit_consume_fn. - -(Dscho, JC) From 2ae4944aac4afd3b114729ef4b5b833c7d8fd832 Mon Sep 17 00:00:00 2001 From: Prarit Bhargava Date: Thu, 24 Oct 2019 19:36:15 -0400 Subject: [PATCH 057/953] t6006: use test-lib.sh definitions Use name and email definitions from test-lib.sh. Signed-off-by: Prarit Bhargava Signed-off-by: Junio C Hamano --- t/t6006-rev-list-format.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh index cfb74d0e03541e..1f7d3f7acc9c35 100755 --- a/t/t6006-rev-list-format.sh +++ b/t/t6006-rev-list-format.sh @@ -111,14 +111,14 @@ EOF # we don't test relative here test_format author %an%n%ae%n%ad%n%aD%n%at <expect && + echo "$GIT_COMMITTER_NAME:$GIT_COMMITTER_EMAIL" >expect && git log -g -1 --format="%gn:%ge" >actual && test_cmp expect actual ' From 45e206f0d845cfc85c39c98d0090104e72176d71 Mon Sep 17 00:00:00 2001 From: Prarit Bhargava Date: Thu, 24 Oct 2019 19:36:16 -0400 Subject: [PATCH 058/953] t4203: use test-lib.sh definitions Use name and email definitions from test-lib.sh. Signed-off-by: Prarit Bhargava Signed-off-by: Junio C Hamano --- t/t4203-mailmap.sh | 94 +++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh index 918ada69eb9666..e8f9c0f5bc8c37 100755 --- a/t/t4203-mailmap.sh +++ b/t/t4203-mailmap.sh @@ -13,8 +13,8 @@ fuzz_blame () { } test_expect_success setup ' - cat >contacts <<-\EOF && - A U Thor + cat >contacts <<- EOF && + $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> nick1 EOF @@ -33,19 +33,19 @@ test_expect_success 'check-mailmap no arguments' ' ' test_expect_success 'check-mailmap arguments' ' - cat >expect <<-\EOF && - A U Thor + cat >expect <<- EOF && + $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> nick1 EOF git check-mailmap \ - "A U Thor " \ + "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" \ "nick1 " >actual && test_cmp expect actual ' test_expect_success 'check-mailmap --stdin' ' - cat >expect <<-\EOF && - A U Thor + cat >expect <<- EOF && + $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> nick1 EOF git check-mailmap --stdin actual && @@ -66,8 +66,8 @@ test_expect_success 'check-mailmap bogus contact' ' test_must_fail git check-mailmap bogus ' -cat >expect <<\EOF -A U Thor (1): +cat >expect << EOF +$GIT_AUTHOR_NAME (1): initial nick1 (1): @@ -90,7 +90,7 @@ nick1 (1): EOF test_expect_success 'default .mailmap' ' - echo "Repo Guy " > .mailmap && + echo "Repo Guy <$GIT_AUTHOR_EMAIL>" > .mailmap && git shortlog HEAD >actual && test_cmp expect actual ' @@ -122,7 +122,7 @@ Internal Guy (1): EOF test_expect_success 'mailmap.file override' ' - echo "External Guy " >> internal_mailmap/.mailmap && + echo "External Guy <$GIT_AUTHOR_EMAIL>" >> internal_mailmap/.mailmap && git config mailmap.file internal_mailmap/.mailmap && git shortlog HEAD >actual && test_cmp expect actual @@ -178,8 +178,8 @@ test_expect_success 'name entry after email entry, case-insensitive' ' test_cmp expect actual ' -cat >expect <<\EOF -A U Thor (1): +cat >expect << EOF +$GIT_AUTHOR_NAME (1): initial nick1 (1): @@ -195,18 +195,18 @@ test_expect_success 'No mailmap files, but configured' ' test_expect_success 'setup mailmap blob tests' ' git checkout -b map && test_when_finished "git checkout master" && - cat >just-bugs <<-\EOF && + cat >just-bugs <<- EOF && Blob Guy EOF - cat >both <<-\EOF && - Blob Guy + cat >both <<- EOF && + Blob Guy <$GIT_AUTHOR_EMAIL> Blob Guy EOF - printf "Tricky Guy " >no-newline && + printf "Tricky Guy <$GIT_AUTHOR_EMAIL>" >no-newline && git add just-bugs both no-newline && git commit -m "my mailmaps" && - echo "Repo Guy " >.mailmap && - echo "Internal Guy " >internal.map + echo "Repo Guy <$GIT_AUTHOR_EMAIL>" >.mailmap && + echo "Internal Guy <$GIT_AUTHOR_EMAIL>" >internal.map ' test_expect_success 'mailmap.blob set' ' @@ -266,12 +266,12 @@ test_expect_success 'mailmap.blob defaults to off in non-bare repo' ' git init non-bare && ( cd non-bare && - test_commit one .mailmap "Fake Name " && + test_commit one .mailmap "Fake Name <$GIT_AUTHOR_EMAIL>" && echo " 1 Fake Name" >expect && git shortlog -ns HEAD >actual && test_cmp expect actual && rm .mailmap && - echo " 1 A U Thor" >expect && + echo " 1 $GIT_AUTHOR_NAME" >expect && git shortlog -ns HEAD >actual && test_cmp expect actual ) @@ -305,26 +305,26 @@ test_expect_success 'cleanup after mailmap.blob tests' ' ' test_expect_success 'single-character name' ' - echo " 1 A " >expect && + echo " 1 A <$GIT_AUTHOR_EMAIL>" >expect && echo " 1 nick1 " >>expect && - echo "A " >.mailmap && + echo "A <$GIT_AUTHOR_EMAIL>" >.mailmap && test_when_finished "rm .mailmap" && git shortlog -es HEAD >actual && test_cmp expect actual ' test_expect_success 'preserve canonical email case' ' - echo " 1 A U Thor " >expect && + echo " 1 $GIT_AUTHOR_NAME " >expect && echo " 1 nick1 " >>expect && - echo " " >.mailmap && + echo " <$GIT_AUTHOR_EMAIL>" >.mailmap && test_when_finished "rm .mailmap" && git shortlog -es HEAD >actual && test_cmp expect actual ' # Extended mailmap configurations should give us the following output for shortlog -cat >expect <<\EOF -A U Thor (1): +cat >expect << EOF +$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> (1): initial CTO (1): @@ -370,7 +370,7 @@ test_expect_success 'Shortlog output (complex mapping)' ' git commit --author "CTO " -m seventh && mkdir -p internal_mailmap && - echo "Committed " > internal_mailmap/.mailmap && + echo "Committed <$GIT_COMMITTER_EMAIL>" > internal_mailmap/.mailmap && echo " " >> internal_mailmap/.mailmap && echo "Some Dude nick1 " >> internal_mailmap/.mailmap && echo "Other Author nick2 " >> internal_mailmap/.mailmap && @@ -384,27 +384,27 @@ test_expect_success 'Shortlog output (complex mapping)' ' ' # git log with --pretty format which uses the name and email mailmap placemarkers -cat >expect <<\EOF +cat >expect << EOF Author CTO maps to CTO -Committer C O Mitter maps to Committed +Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL> Author claus maps to Santa Claus -Committer C O Mitter maps to Committed +Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL> Author santa maps to Santa Claus -Committer C O Mitter maps to Committed +Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL> Author nick2 maps to Other Author -Committer C O Mitter maps to Committed +Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL> Author nick2 maps to Other Author -Committer C O Mitter maps to Committed +Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL> Author nick1 maps to Some Dude -Committer C O Mitter maps to Committed +Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL> -Author A U Thor maps to A U Thor -Committer C O Mitter maps to Committed +Author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> maps to $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> +Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL> EOF test_expect_success 'Log output (complex mapping)' ' @@ -412,14 +412,14 @@ test_expect_success 'Log output (complex mapping)' ' test_cmp expect actual ' -cat >expect <<\EOF +cat >expect << EOF Author: CTO Author: Santa Claus Author: Santa Claus Author: Other Author Author: Other Author Author: Some Dude -Author: A U Thor +Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> EOF test_expect_success 'Log output with --use-mailmap' ' @@ -427,14 +427,14 @@ test_expect_success 'Log output with --use-mailmap' ' test_cmp expect actual ' -cat >expect <<\EOF +cat >expect << EOF Author: CTO Author: Santa Claus Author: Santa Claus Author: Other Author Author: Other Author Author: Some Dude -Author: A U Thor +Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> EOF test_expect_success 'Log output with log.mailmap' ' @@ -443,28 +443,28 @@ test_expect_success 'Log output with log.mailmap' ' ' test_expect_success 'log.mailmap=false disables mailmap' ' - cat >expect <<-\EOF && + cat >expect <<- EOF && Author: CTO Author: claus Author: santa Author: nick2 Author: nick2 Author: nick1 - Author: A U Thor + Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> EOF git -c log.mailmap=False log | grep Author > actual && test_cmp expect actual ' test_expect_success '--no-use-mailmap disables mailmap' ' - cat >expect <<-\EOF && + cat >expect <<- EOF && Author: CTO Author: claus Author: santa Author: nick2 Author: nick2 Author: nick1 - Author: A U Thor + Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> EOF git log --no-use-mailmap | grep Author > actual && test_cmp expect actual @@ -500,8 +500,8 @@ test_expect_success 'Only grep replaced author with --use-mailmap' ' ' # git blame -cat >expect <<\EOF -^OBJI (A U Thor DATE 1) one +cat >expect < Date: Mon, 28 Oct 2019 00:58:55 +0000 Subject: [PATCH 059/953] rev-parse: add a --show-object-format option Add an option to print the object format used for input, output, or storage. This allows shell scripts to discover the hash algorithm in use. Since the transition plan allows for multiple input algorithms, document that we may provide multiple results for input, and the format that the results may take. While we don't support this now, documenting it early means that script authors can future-proof their scripts for when we do. Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- Documentation/git-rev-parse.txt | 7 +++++++ builtin/rev-parse.c | 11 +++++++++++ t/t1500-rev-parse.sh | 15 +++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt index e72d332b831676..9985477efe9c3e 100644 --- a/Documentation/git-rev-parse.txt +++ b/Documentation/git-rev-parse.txt @@ -274,6 +274,13 @@ print a message to stderr and exit with nonzero status. Show the path to the shared index file in split index mode, or empty if not in split-index mode. +--show-object-format[=(storage|input|output)]:: + Show the object format (hash algorithm) used for the repository + for storage inside the `.git` directory, input, or output. For + input, multiple algorithms may be printed, space-separated. + If not specified, the default is "storage". + + Other Options ~~~~~~~~~~~~~ diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index f8bbe6d47ec397..6c5d5d6a70f9c8 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -918,6 +918,17 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) show_datestring("--min-age=", arg); continue; } + if (opt_with_value(arg, "--show-object-format", &arg)) { + const char *val = arg ? arg : "storage"; + + if (strcmp(val, "storage") && + strcmp(val, "input") && + strcmp(val, "output")) + die("unknown mode for --show-object-format: %s", + arg); + puts(the_hash_algo->name); + continue; + } if (show_flag(arg) && verify) die_no_single_rev(quiet); continue; diff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh index 01abee533dedfd..0177fd815c03d9 100755 --- a/t/t1500-rev-parse.sh +++ b/t/t1500-rev-parse.sh @@ -59,6 +59,7 @@ test_rev_parse () { ROOT=$(pwd) test_expect_success 'setup' ' + test_oid_init && mkdir -p sub/dir work && cp -R .git repo.git ' @@ -131,6 +132,20 @@ test_expect_success 'rev-parse --is-shallow-repository in non-shallow repo' ' test_cmp expect actual ' +test_expect_success 'rev-parse --show-object-format in repo' ' + echo "$(test_oid algo)" >expect && + git rev-parse --show-object-format >actual && + test_cmp expect actual && + git rev-parse --show-object-format=storage >actual && + test_cmp expect actual && + git rev-parse --show-object-format=input >actual && + test_cmp expect actual && + git rev-parse --show-object-format=output >actual && + test_cmp expect actual && + test_must_fail git rev-parse --show-object-format=squeamish-ossifrage 2>err && + grep "unknown mode for --show-object-format: squeamish-ossifrage" err +' + test_expect_success 'showing the superproject correctly' ' git rev-parse --show-superproject-working-tree >out && test_must_be_empty out && From 0b408ca2bd75807296509122c90cb0111844376a Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 28 Oct 2019 00:58:56 +0000 Subject: [PATCH 060/953] t1305: avoid comparing extensions A repository using a hash other than SHA-1 will need to have an extension in the config file. Ignore any extensions when comparing config files, since they don't usefully contribute to the goal of the test. Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- t/t1305-config-include.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/t1305-config-include.sh b/t/t1305-config-include.sh index d20b4d150d42c9..f1e1b289f989ea 100755 --- a/t/t1305-config-include.sh +++ b/t/t1305-config-include.sh @@ -63,7 +63,7 @@ test_expect_success 'listing includes option and expansion' ' test.one=1 EOF git config --list >actual.full && - grep -v ^core actual.full >actual && + grep -v -e ^core -e ^extensions actual.full >actual && test_cmp expect actual ' From 440bf91dfad62bb02dff3aa13837391fc8a8c4bf Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 28 Oct 2019 00:58:57 +0000 Subject: [PATCH 061/953] t3429: remove SHA1 annotation This test passes successfully with SHA-256, so remove the annotation which limits it to SHA-1. Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- t/t3429-rebase-edit-todo.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/t3429-rebase-edit-todo.sh b/t/t3429-rebase-edit-todo.sh index 76f6d306eaf39e..63edf171143b70 100755 --- a/t/t3429-rebase-edit-todo.sh +++ b/t/t3429-rebase-edit-todo.sh @@ -11,7 +11,7 @@ test_expect_success 'rebase exec modifies rebase-todo' ' test -e F ' -test_expect_success SHA1 'loose object cache vs re-reading todo list' ' +test_expect_success 'loose object cache vs re-reading todo list' ' GIT_REBASE_TODO=.git/rebase-merge/git-rebase-todo && export GIT_REBASE_TODO && write_script append-todo.sh <<-\EOS && From 32a67072673ac444da6c618d62be80559a7728ce Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 28 Oct 2019 00:58:58 +0000 Subject: [PATCH 062/953] t4010: abstract away SHA-1-specific constants Adjust the test so that it computes variables for object IDs instead of using hard-coded hashes. Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- t/t4010-diff-pathspec.sh | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/t/t4010-diff-pathspec.sh b/t/t4010-diff-pathspec.sh index 281f8fad0c7168..e5ca359edfa608 100755 --- a/t/t4010-diff-pathspec.sh +++ b/t/t4010-diff-pathspec.sh @@ -17,11 +17,15 @@ test_expect_success \ 'echo frotz >file0 && mkdir path1 && echo rezrov >path1/file1 && + before0=$(git hash-object file0) && + before1=$(git hash-object path1/file1) && git update-index --add file0 path1/file1 && tree=$(git write-tree) && echo "$tree" && echo nitfol >file0 && echo yomin >path1/file1 && + after0=$(git hash-object file0) && + after1=$(git hash-object path1/file1) && git update-index file0 path1/file1' cat >expected <<\EOF @@ -31,32 +35,32 @@ test_expect_success \ 'git diff-index --cached $tree -- path >current && compare_diff_raw current expected' -cat >expected <<\EOF -:100644 100644 766498d93a4b06057a8e49d23f4068f1170ff38f 0a41e115ab61be0328a19b29f18cdcb49338d516 M path1/file1 +cat >expected <current && compare_diff_raw current expected' -cat >expected <<\EOF -:100644 100644 766498d93a4b06057a8e49d23f4068f1170ff38f 0a41e115ab61be0328a19b29f18cdcb49338d516 M path1/file1 +cat >expected <current && compare_diff_raw current expected' -cat >expected <<\EOF -:100644 100644 766498d93a4b06057a8e49d23f4068f1170ff38f 0a41e115ab61be0328a19b29f18cdcb49338d516 M path1/file1 +cat >expected <current && compare_diff_raw current expected' -cat >expected <<\EOF -:100644 100644 8e4020bb5a8d8c873b25de15933e75cc0fc275df dca6b92303befc93086aa025d90a5facd7eb2812 M file0 +cat >expected < Date: Mon, 28 Oct 2019 00:58:59 +0000 Subject: [PATCH 063/953] t4011: abstract away SHA-1-specific constants Adjust the test so that it computes variables for object IDs instead of using hard-coded hashes. Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- t/t4011-diff-symlink.sh | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/t/t4011-diff-symlink.sh b/t/t4011-diff-symlink.sh index 5ae19b987d65d0..717034bb50b57f 100755 --- a/t/t4011-diff-symlink.sh +++ b/t/t4011-diff-symlink.sh @@ -9,11 +9,24 @@ test_description='Test diff of symlinks. . ./test-lib.sh . "$TEST_DIRECTORY"/diff-lib.sh +# Print the short OID of a symlink with the given name. +symlink_oid () { + local oid=$(printf "%s" "$1" | git hash-object --stdin) && + git rev-parse --short "$oid" +} + +# Print the short OID of the given file. +short_oid () { + local oid=$(git hash-object "$1") && + git rev-parse --short "$oid" +} + test_expect_success 'diff new symlink and file' ' - cat >expected <<-\EOF && + symlink=$(symlink_oid xyzzy) && + cat >expected <<-EOF && diff --git a/frotz b/frotz new file mode 120000 - index 0000000..7c465af + index 0000000..$symlink --- /dev/null +++ b/frotz @@ -0,0 +1 @@ @@ -21,7 +34,7 @@ test_expect_success 'diff new symlink and file' ' \ No newline at end of file diff --git a/nitfol b/nitfol new file mode 100644 - index 0000000..7c465af + index 0000000..$symlink --- /dev/null +++ b/nitfol @@ -0,0 +1 @@ @@ -46,10 +59,10 @@ test_expect_success 'diff unchanged symlink and file' ' ' test_expect_success 'diff removed symlink and file' ' - cat >expected <<-\EOF && + cat >expected <<-EOF && diff --git a/frotz b/frotz deleted file mode 120000 - index 7c465af..0000000 + index $symlink..0000000 --- a/frotz +++ /dev/null @@ -1 +0,0 @@ @@ -57,7 +70,7 @@ test_expect_success 'diff removed symlink and file' ' \ No newline at end of file diff --git a/nitfol b/nitfol deleted file mode 100644 - index 7c465af..0000000 + index $symlink..0000000 --- a/nitfol +++ /dev/null @@ -1 +0,0 @@ @@ -90,9 +103,10 @@ test_expect_success 'diff identical, but newly created symlink and file' ' ' test_expect_success 'diff different symlink and file' ' - cat >expected <<-\EOF && + new=$(symlink_oid yxyyz) && + cat >expected <<-EOF && diff --git a/frotz b/frotz - index 7c465af..df1db54 120000 + index $symlink..$new 120000 --- a/frotz +++ b/frotz @@ -1 +1 @@ @@ -101,7 +115,7 @@ test_expect_success 'diff different symlink and file' ' +yxyyz \ No newline at end of file diff --git a/nitfol b/nitfol - index 7c465af..df1db54 100644 + index $symlink..$new 100644 --- a/nitfol +++ b/nitfol @@ -1 +1 @@ @@ -137,14 +151,16 @@ test_expect_success SYMLINKS 'setup symlinks with attributes' ' ' test_expect_success SYMLINKS 'symlinks do not respect userdiff config by path' ' - cat >expect <<-\EOF && + file=$(short_oid file.bin) && + link=$(symlink_oid file.bin) && + cat >expect <<-EOF && diff --git a/file.bin b/file.bin new file mode 100644 - index 0000000..d95f3ad + index 0000000..$file Binary files /dev/null and b/file.bin differ diff --git a/link.bin b/link.bin new file mode 120000 - index 0000000..dce41ec + index 0000000..$link --- /dev/null +++ b/link.bin @@ -0,0 +1 @@ From 79b0edc1a0ae856511d5923195c4d144461a955e Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 28 Oct 2019 00:59:00 +0000 Subject: [PATCH 064/953] t4015: abstract away SHA-1-specific constants Adjust the test so that it computes variables for object IDs instead of using hard-coded hashes. Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- t/t4015-diff-whitespace.sh | 89 +++++++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 36 deletions(-) diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh index 6b087df3dcbd01..eadaf572626372 100755 --- a/t/t4015-diff-whitespace.sh +++ b/t/t4015-diff-whitespace.sh @@ -16,6 +16,7 @@ test_expect_success "Ray Lehtiniemi's example" ' } while (0); EOF git update-index --add x && + before=$(git rev-parse --short $(git hash-object x)) && cat <<-\EOF >x && do @@ -24,10 +25,11 @@ test_expect_success "Ray Lehtiniemi's example" ' } while (0); EOF + after=$(git rev-parse --short $(git hash-object x)) && - cat <<-\EOF >expect && + cat <<-EOF >expect && diff --git a/x b/x - index adf3937..6edc172 100644 + index $before..$after 100644 --- a/x +++ b/x @@ -1,3 +1,5 @@ @@ -61,6 +63,7 @@ test_expect_success 'another test, without options' ' EOF git update-index x && + before=$(git rev-parse --short $(git hash-object x)) && tr "_" " " <<-\EOF >x && _ whitespace at beginning @@ -70,10 +73,11 @@ test_expect_success 'another test, without options' ' unchanged line CR at end EOF + after=$(git rev-parse --short $(git hash-object x)) && - tr "Q_" "\015 " <<-\EOF >expect && + tr "Q_" "\015 " <<-EOF >expect && diff --git a/x b/x - index d99af23..22d9f73 100644 + index $before..$after 100644 --- a/x +++ b/x @@ -1,6 +1,6 @@ @@ -108,9 +112,9 @@ test_expect_success 'another test, without options' ' git diff -w --ignore-cr-at-eol >out && test_must_be_empty out && - tr "Q_" "\015 " <<-\EOF >expect && + tr "Q_" "\015 " <<-EOF >expect && diff --git a/x b/x - index d99af23..22d9f73 100644 + index $before..$after 100644 --- a/x +++ b/x @@ -1,6 +1,6 @@ @@ -132,9 +136,9 @@ test_expect_success 'another test, without options' ' git diff -b --ignore-cr-at-eol >out && test_cmp expect out && - tr "Q_" "\015 " <<-\EOF >expect && + tr "Q_" "\015 " <<-EOF >expect && diff --git a/x b/x - index d99af23..22d9f73 100644 + index $before..$after 100644 --- a/x +++ b/x @@ -1,6 +1,6 @@ @@ -154,9 +158,9 @@ test_expect_success 'another test, without options' ' git diff --ignore-space-at-eol --ignore-cr-at-eol >out && test_cmp expect out && - tr "Q_" "\015 " <<-\EOF >expect && + tr "Q_" "\015 " <<-EOF >expect && diff --git a/x b/x - index_d99af23..22d9f73 100644 + index_$before..$after 100644 --- a/x +++ b/x @@ -1,6 +1,6 @@ @@ -786,23 +790,25 @@ test_expect_success 'whitespace-only changes not reported' ' test_must_be_empty actual ' -cat <expect -diff --git a/x b/z -similarity index NUM% -rename from x -rename to z -index 380c32a..a97b785 100644 -EOF test_expect_success 'whitespace-only changes reported across renames' ' git reset --hard && for i in 1 2 3 4 5 6 7 8 9; do echo "$i$i$i$i$i$i"; done >x && git add x && + before=$(git rev-parse --short $(git hash-object x)) && git commit -m "base" && sed -e "5s/^/ /" x >z && git rm x && git add z && + after=$(git rev-parse --short $(git hash-object z)) && git diff -w -M --cached | sed -e "/^similarity index /s/[0-9][0-9]*/NUM/" >actual && + cat <<-EOF >expect && + diff --git a/x b/z + similarity index NUM% + rename from x + rename to z + index $before..$after 100644 + EOF test_cmp expect actual ' @@ -858,13 +864,15 @@ test_expect_success 'diff that introduces a line with only tabs' ' git config core.whitespace blank-at-eol && git reset --hard && echo "test" >x && + before=$(git rev-parse --short $(git hash-object x)) && git commit -m "initial" x && echo "{NTN}" | tr "NT" "\n\t" >>x && + after=$(git rev-parse --short $(git hash-object x)) && git diff --color | test_decode_color >current && - cat >expected <<-\EOF && + cat >expected <<-EOF && diff --git a/x b/x - index 9daeafb..2874b91 100644 + index $before..$after 100644 --- a/x +++ b/x @@ -1 +1,4 @@ @@ -883,19 +891,21 @@ test_expect_success 'diff that introduces and removes ws breakages' ' echo "0. blank-at-eol " && echo "1. blank-at-eol " } >x && + before=$(git rev-parse --short $(git hash-object x)) && git commit -a --allow-empty -m preimage && { echo "0. blank-at-eol " && echo "1. still-blank-at-eol " && echo "2. and a new line " } >x && + after=$(git rev-parse --short $(git hash-object x)) && git diff --color | test_decode_color >current && - cat >expected <<-\EOF && + cat >expected <<-EOF && diff --git a/x b/x - index d0233a2..700886e 100644 + index $before..$after 100644 --- a/x +++ b/x @@ -1,2 +1,3 @@ @@ -915,16 +925,18 @@ test_expect_success 'ws-error-highlight test setup' ' echo "0. blank-at-eol " && echo "1. blank-at-eol " } >x && + before=$(git rev-parse --short $(git hash-object x)) && git commit -a --allow-empty -m preimage && { echo "0. blank-at-eol " && echo "1. still-blank-at-eol " && echo "2. and a new line " } >x && + after=$(git rev-parse --short $(git hash-object x)) && - cat >expect.default-old <<-\EOF && + cat >expect.default-old <<-EOF && diff --git a/x b/x - index d0233a2..700886e 100644 + index $before..$after 100644 --- a/x +++ b/x @@ -1,2 +1,3 @@ @@ -934,9 +946,9 @@ test_expect_success 'ws-error-highlight test setup' ' +2. and a new line EOF - cat >expect.all <<-\EOF && + cat >expect.all <<-EOF && diff --git a/x b/x - index d0233a2..700886e 100644 + index $before..$after 100644 --- a/x +++ b/x @@ -1,2 +1,3 @@ @@ -946,9 +958,9 @@ test_expect_success 'ws-error-highlight test setup' ' +2. and a new line EOF - cat >expect.none <<-\EOF + cat >expect.none <<-EOF diff --git a/x b/x - index d0233a2..700886e 100644 + index $before..$after 100644 --- a/x +++ b/x @@ -1,2 +1,3 @@ @@ -1022,14 +1034,15 @@ test_expect_success 'detect moved code, complete file' ' EOF git add test.c && git commit -m "add main function" && + file=$(git rev-parse --short HEAD:test.c) && git mv test.c main.c && test_config color.diff.oldMoved "normal red" && test_config color.diff.newMoved "normal green" && git diff HEAD --color-moved=zebra --color --no-renames | test_decode_color >actual && - cat >expected <<-\EOF && + cat >expected <<-EOF && diff --git a/main.c b/main.c new file mode 100644 - index 0000000..a986c57 + index 0000000..$file --- /dev/null +++ b/main.c @@ -0,0 +1,5 @@ @@ -1040,7 +1053,7 @@ test_expect_success 'detect moved code, complete file' ' +} diff --git a/test.c b/test.c deleted file mode 100644 - index a986c57..0000000 + index $file..0000000 --- a/test.c +++ /dev/null @@ -1,5 +0,0 @@ @@ -1094,6 +1107,8 @@ test_expect_success 'detect malicious moved code, inside file' ' EOF git add main.c test.c && git commit -m "add main and test file" && + before_main=$(git rev-parse --short HEAD:main.c) && + before_test=$(git rev-parse --short HEAD:test.c) && cat <<-\EOF >main.c && #include int stuff() @@ -1126,10 +1141,12 @@ test_expect_success 'detect malicious moved code, inside file' ' bar(); } EOF + after_main=$(git rev-parse --short $(git hash-object main.c)) && + after_test=$(git rev-parse --short $(git hash-object test.c)) && git diff HEAD --no-renames --color-moved=zebra --color | test_decode_color >actual && - cat <<-\EOF >expected && + cat <<-EOF >expected && diff --git a/main.c b/main.c - index 27a619c..7cf9336 100644 + index $before_main..$after_main 100644 --- a/main.c +++ b/main.c @@ -5,13 +5,6 @@ printf("Hello "); @@ -1147,7 +1164,7 @@ test_expect_success 'detect malicious moved code, inside file' ' { foo(); diff --git a/test.c b/test.c - index 1dc1d85..2bedec9 100644 + index $before_test..$after_test 100644 --- a/test.c +++ b/test.c @@ -4,6 +4,13 @@ int bar() @@ -1176,9 +1193,9 @@ test_expect_success 'plain moved code, inside file' ' test_config color.diff.newMovedAlternative "yellow" && # needs previous test as setup git diff HEAD --no-renames --color-moved=plain --color | test_decode_color >actual && - cat <<-\EOF >expected && + cat <<-EOF >expected && diff --git a/main.c b/main.c - index 27a619c..7cf9336 100644 + index $before_main..$after_main 100644 --- a/main.c +++ b/main.c @@ -5,13 +5,6 @@ printf("Hello "); @@ -1196,7 +1213,7 @@ test_expect_success 'plain moved code, inside file' ' { foo(); diff --git a/test.c b/test.c - index 1dc1d85..2bedec9 100644 + index $before_test..$after_test 100644 --- a/test.c +++ b/test.c @@ -4,6 +4,13 @@ int bar() From 45e2ef2b1d7093e535a0c3963e64a0c212aace54 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 28 Oct 2019 00:59:01 +0000 Subject: [PATCH 065/953] t4027: make hash-size independent Instead of hard-coding the length of an object ID, look this value up using the translation tables. Similarly, compute input data for invalid submodule entries using the tables as well. Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- t/t4027-diff-submodule.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/t/t4027-diff-submodule.sh b/t/t4027-diff-submodule.sh index 9aa8e2b39b45a6..e29deaf4a50952 100755 --- a/t/t4027-diff-submodule.sh +++ b/t/t4027-diff-submodule.sh @@ -6,6 +6,7 @@ test_description='difference in submodules' . "$TEST_DIRECTORY"/diff-lib.sh test_expect_success setup ' + test_oid_init && test_tick && test_create_repo sub && ( @@ -36,7 +37,8 @@ test_expect_success setup ' ' test_expect_success 'git diff --raw HEAD' ' - git diff --raw --abbrev=40 HEAD >actual && + hexsz=$(test_oid hexsz) && + git diff --raw --abbrev=$hexsz HEAD >actual && test_cmp expect actual ' @@ -245,23 +247,21 @@ test_expect_success 'git diff (empty submodule dir)' ' ' test_expect_success 'conflicted submodule setup' ' - - # 39 efs - c=fffffffffffffffffffffffffffffffffffffff && + c=$(test_oid ff_1) && ( echo "000000 $ZERO_OID 0 sub" && echo "160000 1$c 1 sub" && echo "160000 2$c 2 sub" && echo "160000 3$c 3 sub" ) | git update-index --index-info && - echo >expect.nosub '\''diff --cc sub + echo >expect.nosub "diff --cc sub index 2ffffff,3ffffff..0000000 --- a/sub +++ b/sub @@@ -1,1 -1,1 +1,1 @@@ -- Subproject commit 2fffffffffffffffffffffffffffffffffffffff - -Subproject commit 3fffffffffffffffffffffffffffffffffffffff -++Subproject commit 0000000000000000000000000000000000000000'\'' && +- Subproject commit 2$c + -Subproject commit 3$c +++Subproject commit $ZERO_OID" && hh=$(git rev-parse HEAD) && sed -e "s/$ZERO_OID/$hh/" expect.nosub >expect.withsub From 0253e126a271f10dc1f1fc630193a4026ec8a7ee Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 28 Oct 2019 00:59:02 +0000 Subject: [PATCH 066/953] t4034: abstract away SHA-1-specific constants Adjust the test so that it computes variables for object IDs instead of using hard-coded hashes. Move some expected result heredocs around so that they can use computed variables. Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- t/t4034-diff-words.sh | 93 +++++++++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 39 deletions(-) diff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh index 9a93c2a3e0dd8a..fb145aa173ee4e 100755 --- a/t/t4034-diff-words.sh +++ b/t/t4034-diff-words.sh @@ -19,9 +19,11 @@ cat >post.simple <<-\EOF aeff = aeff * ( aaa ) EOF -cat >expect.letter-runs-are-words <<-\EOF +pre=$(git rev-parse --short $(git hash-object pre.simple)) +post=$(git rev-parse --short $(git hash-object post.simple)) +cat >expect.letter-runs-are-words <<-EOF diff --git a/pre b/post - index 330b04f..5ed8eff 100644 + index $pre..$post 100644 --- a/pre +++ b/post @@ -1,3 +1,7 @@ @@ -33,9 +35,9 @@ cat >expect.letter-runs-are-words <<-\EOF aeff = aeff * ( aaa ) EOF -cat >expect.non-whitespace-is-word <<-\EOF +cat >expect.non-whitespace-is-word <<-EOF diff --git a/pre b/post - index 330b04f..5ed8eff 100644 + index $pre..$post 100644 --- a/pre +++ b/post @@ -1,3 +1,7 @@ @@ -49,9 +51,12 @@ cat >expect.non-whitespace-is-word <<-\EOF EOF word_diff () { + pre=$(git rev-parse --short $(git hash-object pre)) && + post=$(git rev-parse --short $(git hash-object post)) && test_must_fail git diff --no-index "$@" pre post >output && test_decode_color output.decrypted && - test_cmp expect output.decrypted + sed -e "2s/index [^ ]*/index $pre..$post/" expect >expected + test_cmp expected output.decrypted } test_language_driver () { @@ -77,9 +82,9 @@ test_expect_success 'set up pre and post with runs of whitespace' ' ' test_expect_success 'word diff with runs of whitespace' ' - cat >expect <<-\EOF && + cat >expect <<-EOF && diff --git a/pre b/post - index 330b04f..5ed8eff 100644 + index $pre..$post 100644 --- a/pre +++ b/post @@ -1,3 +1,7 @@ @@ -97,9 +102,9 @@ test_expect_success 'word diff with runs of whitespace' ' ' test_expect_success '--word-diff=porcelain' ' - sed 's/#.*$//' >expect <<-\EOF && + sed 's/#.*$//' >expect <<-EOF && diff --git a/pre b/post - index 330b04f..5ed8eff 100644 + index $pre..$post 100644 --- a/pre +++ b/post @@ -1,3 +1,7 @@ @@ -121,9 +126,9 @@ test_expect_success '--word-diff=porcelain' ' ' test_expect_success '--word-diff=plain' ' - cat >expect <<-\EOF && + cat >expect <<-EOF && diff --git a/pre b/post - index 330b04f..5ed8eff 100644 + index $pre..$post 100644 --- a/pre +++ b/post @@ -1,3 +1,7 @@ @@ -140,9 +145,9 @@ test_expect_success '--word-diff=plain' ' ' test_expect_success '--word-diff=plain --color' ' - cat >expect <<-\EOF && + cat >expect <<-EOF && diff --git a/pre b/post - index 330b04f..5ed8eff 100644 + index $pre..$post 100644 --- a/pre +++ b/post @@ -1,3 +1,7 @@ @@ -158,9 +163,9 @@ test_expect_success '--word-diff=plain --color' ' ' test_expect_success 'word diff without context' ' - cat >expect <<-\EOF && + cat >expect <<-EOF && diff --git a/pre b/post - index 330b04f..5ed8eff 100644 + index $pre..$post 100644 --- a/pre +++ b/post @@ -1 +1 @@ @@ -207,9 +212,9 @@ test_expect_success 'command-line overrides config' ' ' test_expect_success 'command-line overrides config: --word-diff-regex' ' - cat >expect <<-\EOF && + cat >expect <<-EOF && diff --git a/pre b/post - index 330b04f..5ed8eff 100644 + index $pre..$post 100644 --- a/pre +++ b/post @@ -1,3 +1,7 @@ @@ -234,9 +239,9 @@ test_expect_success 'setup: remove diff driver regex' ' ' test_expect_success 'use configured regex' ' - cat >expect <<-\EOF && + cat >expect <<-EOF && diff --git a/pre b/post - index 330b04f..5ed8eff 100644 + index $pre..$post 100644 --- a/pre +++ b/post @@ -1,3 +1,7 @@ @@ -254,9 +259,11 @@ test_expect_success 'use configured regex' ' test_expect_success 'test parsing words for newline' ' echo "aaa (aaa)" >pre && echo "aaa (aaa) aaa" >post && - cat >expect <<-\EOF && + pre=$(git rev-parse --short $(git hash-object pre)) && + post=$(git rev-parse --short $(git hash-object post)) && + cat >expect <<-EOF && diff --git a/pre b/post - index c29453b..be22f37 100644 + index $pre..$post 100644 --- a/pre +++ b/post @@ -1 +1 @@ @@ -268,9 +275,11 @@ test_expect_success 'test parsing words for newline' ' test_expect_success 'test when words are only removed at the end' ' echo "(:" >pre && echo "(" >post && - cat >expect <<-\EOF && + pre=$(git rev-parse --short $(git hash-object pre)) && + post=$(git rev-parse --short $(git hash-object post)) && + cat >expect <<-EOF && diff --git a/pre b/post - index 289cb9d..2d06f37 100644 + index $pre..$post 100644 --- a/pre +++ b/post @@ -1 +1 @@ @@ -282,9 +291,11 @@ test_expect_success 'test when words are only removed at the end' ' test_expect_success '--word-diff=none' ' echo "(:" >pre && echo "(" >post && - cat >expect <<-\EOF && + pre=$(git rev-parse --short $(git hash-object pre)) && + post=$(git rev-parse --short $(git hash-object post)) && + cat >expect <<-EOF && diff --git a/pre b/post - index 289cb9d..2d06f37 100644 + index $pre..$post 100644 --- a/pre +++ b/post @@ -1 +1 @@ @@ -317,16 +328,6 @@ test_language_driver ruby test_language_driver tex test_expect_success 'word-diff with diff.sbe' ' - cat >expect <<-\EOF && - diff --git a/pre b/post - index a1a53b5..bc8fe6d 100644 - --- a/pre - +++ b/post - @@ -1,3 +1,3 @@ - a - - [-b-]{+c+} - EOF cat >pre <<-\EOF && a @@ -337,21 +338,35 @@ test_expect_success 'word-diff with diff.sbe' ' c EOF + pre=$(git rev-parse --short $(git hash-object pre)) && + post=$(git rev-parse --short $(git hash-object post)) && + cat >expect <<-EOF && + diff --git a/pre b/post + index $pre..$post 100644 + --- a/pre + +++ b/post + @@ -1,3 +1,3 @@ + a + + [-b-]{+c+} + EOF test_config diff.suppress-blank-empty true && word_diff --word-diff=plain ' test_expect_success 'word-diff with no newline at EOF' ' - cat >expect <<-\EOF && + printf "%s" "a a a a a" >pre && + printf "%s" "a a ab a a" >post && + pre=$(git rev-parse --short $(git hash-object pre)) && + post=$(git rev-parse --short $(git hash-object post)) && + cat >expect <<-EOF && diff --git a/pre b/post - index 7bf316e..3dd0303 100644 + index $pre..$post 100644 --- a/pre +++ b/post @@ -1 +1 @@ a a [-a-]{+ab+} a a EOF - printf "%s" "a a a a a" >pre && - printf "%s" "a a ab a a" >post && word_diff --word-diff=plain ' From 0370b354147de8cb25cf9722bf70a441c0d1fbf4 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 28 Oct 2019 00:59:03 +0000 Subject: [PATCH 067/953] t4038: abstract away SHA-1 specific constants Compute several object IDs that exist in expected output, since we don't care about the specific object IDs, only that the format of the output is syntactically correct. Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- t/t4038-diff-combined.sh | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/t/t4038-diff-combined.sh b/t/t4038-diff-combined.sh index d4afe125548bed..15fc054fdb7e68 100755 --- a/t/t4038-diff-combined.sh +++ b/t/t4038-diff-combined.sh @@ -440,11 +440,13 @@ test_expect_success 'setup for --combined-all-paths' ' git branch side2c && git checkout side1c && test_seq 1 10 >filename-side1c && + side1cf=$(git hash-object filename-side1c) && git add filename-side1c && git commit -m with && git checkout side2c && test_seq 1 9 >filename-side2c && echo ten >>filename-side2c && + side2cf=$(git hash-object filename-side2c) && git add filename-side2c && git commit -m iam && git checkout -b mergery side1c && @@ -452,13 +454,14 @@ test_expect_success 'setup for --combined-all-paths' ' git rm filename-side1c && echo eleven >>filename-side2c && git mv filename-side2c filename-merged && + mergedf=$(git hash-object filename-merged) && git add filename-merged && git commit ' test_expect_success '--combined-all-paths and --raw' ' - cat <<-\EOF >expect && - ::100644 100644 100644 f00c965d8307308469e537302baa73048488f162 088bd5d92c2a8e0203ca8e7e4c2a5c692f6ae3f7 333b9c62519f285e1854830ade0fe1ef1d40ee1b RR filename-side1c filename-side2c filename-merged + cat <<-EOF >expect && + ::100644 100644 100644 $side1cf $side2cf $mergedf RR filename-side1c filename-side2c filename-merged EOF git diff-tree -c -M --raw --combined-all-paths HEAD >actual.tmp && sed 1d actual && @@ -482,11 +485,13 @@ test_expect_success FUNNYNAMES 'setup for --combined-all-paths with funny names' git checkout side1d && test_seq 1 10 >"$(printf "file\twith\ttabs")" && git add file* && + side1df=$(git hash-object *tabs) && git commit -m with && git checkout side2d && test_seq 1 9 >"$(printf "i\tam\ttabbed")" && echo ten >>"$(printf "i\tam\ttabbed")" && git add *tabbed && + side2df=$(git hash-object *tabbed) && git commit -m iam && git checkout -b funny-names-mergery side1d && git merge --no-commit side2d && @@ -494,12 +499,14 @@ test_expect_success FUNNYNAMES 'setup for --combined-all-paths with funny names' echo eleven >>"$(printf "i\tam\ttabbed")" && git mv "$(printf "i\tam\ttabbed")" "$(printf "fickle\tnaming")" && git add fickle* && - git commit + headf=$(git hash-object fickle*) && + git commit && + head=$(git rev-parse HEAD) ' test_expect_success FUNNYNAMES '--combined-all-paths and --raw and funny names' ' - cat <<-\EOF >expect && - ::100644 100644 100644 f00c965d8307308469e537302baa73048488f162 088bd5d92c2a8e0203ca8e7e4c2a5c692f6ae3f7 333b9c62519f285e1854830ade0fe1ef1d40ee1b RR "file\twith\ttabs" "i\tam\ttabbed" "fickle\tnaming" + cat <<-EOF >expect && + ::100644 100644 100644 $side1df $side2df $headf RR "file\twith\ttabs" "i\tam\ttabbed" "fickle\tnaming" EOF git diff-tree -c -M --raw --combined-all-paths HEAD >actual.tmp && sed 1d actual && @@ -507,7 +514,7 @@ test_expect_success FUNNYNAMES '--combined-all-paths and --raw and funny names' ' test_expect_success FUNNYNAMES '--combined-all-paths and --raw -and -z and funny names' ' - printf "aaf8087c3cbd4db8e185a2d074cf27c53cfb75d7\0::100644 100644 100644 f00c965d8307308469e537302baa73048488f162 088bd5d92c2a8e0203ca8e7e4c2a5c692f6ae3f7 333b9c62519f285e1854830ade0fe1ef1d40ee1b RR\0file\twith\ttabs\0i\tam\ttabbed\0fickle\tnaming\0" >expect && + printf "$head\0::100644 100644 100644 $side1df $side2df $headf RR\0file\twith\ttabs\0i\tam\ttabbed\0fickle\tnaming\0" >expect && git diff-tree -c -M --raw --combined-all-paths -z HEAD >actual && test_cmp -a expect actual ' From 37ab8ebef164cc2813658c824561a09dc7cde22f Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 28 Oct 2019 00:59:04 +0000 Subject: [PATCH 068/953] t4039: abstract away SHA-1-specific constants Adjust the test so that it computes variables for object IDs instead of using hard-coded hashes. Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- t/t4039-diff-assume-unchanged.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/t/t4039-diff-assume-unchanged.sh b/t/t4039-diff-assume-unchanged.sh index 53ac44b0f00368..0eb0314a8b35da 100755 --- a/t/t4039-diff-assume-unchanged.sh +++ b/t/t4039-diff-assume-unchanged.sh @@ -12,6 +12,7 @@ test_expect_success 'setup' ' git commit -m zero && echo one > one && echo two > two && + blob=$(git hash-object one) && git add one two && git commit -m onetwo && git update-index --assume-unchanged one && @@ -20,7 +21,7 @@ test_expect_success 'setup' ' ' test_expect_success 'diff-index does not examine assume-unchanged entries' ' - git diff-index HEAD^ -- one | grep -q 5626abf0f72e58d7a153368ba57db4c673c0e171 + git diff-index HEAD^ -- one | grep -q $blob ' test_expect_success 'diff-files does not examine assume-unchanged entries' ' From 38ee26b2a3764da5120c3e0340501babef6d51c3 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 28 Oct 2019 00:59:05 +0000 Subject: [PATCH 069/953] t4044: update test to work with SHA-256 This test produces pseudo-collisions and tests git diff's behavior with them, and is therefore sensitive to the hash in use. Update the test to compute the collisions for both SHA-1 and SHA-256 using appropriate constants. Move the heredocs inside the setup block so that all of the setup code can be tested for failure. Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- t/t4044-diff-index-unique-abbrev.sh | 46 +++++++++++++++++++---------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/t/t4044-diff-index-unique-abbrev.sh b/t/t4044-diff-index-unique-abbrev.sh index 647905e01fb963..4701796d10e102 100755 --- a/t/t4044-diff-index-unique-abbrev.sh +++ b/t/t4044-diff-index-unique-abbrev.sh @@ -3,34 +3,48 @@ test_description='test unique sha1 abbreviation on "index from..to" line' . ./test-lib.sh -if ! test_have_prereq SHA1 -then - skip_all='not using SHA-1 for objects' - test_done -fi - -cat >expect_initial <expect_update < foo && + hash1 sha1:51d2738463ea4ca66f8691c91e33ce64b7d41bb1 + hash1 sha256:ae31dfff0af93b2c62b0098a039b38569c43b0a7e97b873000ca42d128f27350 + + hasht1 sha1:51d27384 + hasht1 sha256:ae31dfff + + hash2 sha1:51d2738efb4ad8a1e40bed839ab8e116f0a15e47 + hash2 sha256:ae31dffada88a46fd5f53c7ed5aa25a7a8951f1d5e88456c317c8d5484d263e5 + + hasht2 sha1:51d2738e + hasht2 sha256:ae31dffa + EOF + + cat >expect_initial <<-EOF && + 100644 blob $(test_oid hash1) foo + EOF + + cat >expect_update <<-EOF && + 100644 blob $(test_oid hash2) foo + EOF + + echo "$(test_oid val1)" > foo && git add foo && git commit -m "initial" && git cat-file -p HEAD: > actual && test_cmp expect_initial actual && - echo 11742 > foo && + echo "$(test_oid val2)" > foo && git commit -a -m "update" && git cat-file -p HEAD: > actual && test_cmp expect_update actual ' cat >expect < Date: Mon, 28 Oct 2019 00:59:06 +0000 Subject: [PATCH 070/953] t4045: make hash-size independent Replace a hard-coded all-zeros object ID with a use of $ZERO_OID. Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- t/t4045-diff-relative.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/t4045-diff-relative.sh b/t/t4045-diff-relative.sh index 36f8ed8a818714..258808708e1093 100755 --- a/t/t4045-diff-relative.sh +++ b/t/t4045-diff-relative.sh @@ -70,7 +70,7 @@ check_raw () { expect=$1 shift cat >expected <<-EOF - :000000 100644 0000000000000000000000000000000000000000 $blob A $expect + :000000 100644 $ZERO_OID $blob A $expect EOF test_expect_success "--raw $*" " git -C '$dir' diff --no-abbrev --raw $* HEAD^ >actual && From fa26d5ede6e6c2a07590d3564efc1f92f82fcc0f Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 28 Oct 2019 00:59:07 +0000 Subject: [PATCH 071/953] t4048: abstract away SHA-1-specific constants Adjust the test so that it computes variables for object IDs instead of using hard-coded hashes. Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- t/t4048-diff-combined-binary.sh | 58 ++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/t/t4048-diff-combined-binary.sh b/t/t4048-diff-combined-binary.sh index 87a8949500bbfb..7f9ad9fa3d1f97 100755 --- a/t/t4048-diff-combined-binary.sh +++ b/t/t4048-diff-combined-binary.sh @@ -9,24 +9,27 @@ test_expect_success 'setup binary merge conflict' ' git commit -m one && echo twoQ2 | q_to_nul >binary && git commit -a -m two && + two=$(git rev-parse --short HEAD:binary) && git checkout -b branch-binary HEAD^ && echo threeQ3 | q_to_nul >binary && git commit -a -m three && + three=$(git rev-parse --short HEAD:binary) && test_must_fail git merge master && echo resolvedQhooray | q_to_nul >binary && - git commit -a -m resolved + git commit -a -m resolved && + res=$(git rev-parse --short HEAD:binary) ' -cat >expect <<'EOF' +cat >expect <expect <<'EOF' +cat >expect <expect <<'EOF' +cat >expect <.gitattributes ' -cat >expect <<'EOF' +cat >expect <expect <<'EOF' +cat >expect <expect <<'EOF' +cat >expect <expect <<'EOF' +cat >expect <expect <<'EOF' +cat >expect <expect <<'EOF' +cat >expect <expect <<'EOF' +cat >expect <expect <<'EOF' +cat >expect < Date: Fri, 25 Oct 2019 18:49:09 +0200 Subject: [PATCH 072/953] builtin/commit-graph.c: remove subcommand-less usage string MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The first line in 'git commit-graph's usage string indicates that this command can be invoked without specifying a subcommand. However, this is not the case: $ git commit-graph usage: git commit-graph [--object-dir ] or: git commit-graph read [--object-dir ] [...] $ echo $? 129 Remove this line from the usage string. The synopsis in the manpage doesn't contain this line. Signed-off-by: SZEDER Gábor Signed-off-by: Junio C Hamano --- builtin/commit-graph.c | 1 - 1 file changed, 1 deletion(-) diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c index 38027b83d9d832..04ff71fea6cc4b 100644 --- a/builtin/commit-graph.c +++ b/builtin/commit-graph.c @@ -8,7 +8,6 @@ #include "object-store.h" static char const * const builtin_commit_graph_usage[] = { - N_("git commit-graph [--object-dir ]"), N_("git commit-graph read [--object-dir ]"), N_("git commit-graph verify [--object-dir ] [--shallow]"), N_("git commit-graph write [--object-dir ] [--append|--split] [--reachable|--stdin-packs|--stdin-commits] "), From 228c78fbd42b58ebf43477290432c149358b04b1 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 25 Oct 2019 17:20:20 -0400 Subject: [PATCH 073/953] commit, tag: don't set parsed bit for parse failures If we can't parse a commit, then parse_commit() will return an error code. But it _also_ sets the "parsed" flag, which tells us not to bother trying to re-parse the object. That means that subsequent parses have no idea that the information in the struct may be bogus. I.e., doing this: parse_commit(commit); ... if (parse_commit(commit) < 0) die("commit is broken"); will never trigger the die(). The second parse_commit() will see the "parsed" flag and quietly return success. There are two obvious ways to fix this: 1. Stop setting "parsed" until we've successfully parsed. 2. Keep a second "corrupt" flag to indicate that we saw an error (and when the parsed flag is set, return 0/-1 depending on the corrupt flag). This patch does option 1. The obvious downside versus option 2 is that we might continually re-parse a broken object. But in practice, corruption like this is rare, and we typically die() or return an error in the caller. So it's OK not to worry about optimizing for corruption. And it's much simpler: we don't need to use an extra bit in the object struct, and callers which check the "parsed" flag don't need to learn about the corrupt bit, too. There's no new test here, because this case is already covered in t5318. Note that we do need to update the expected message there, because we now detect the problem in the return from "parse_commit()", and not with a separate check for a NULL tree. In fact, we can now ditch that explicit tree check entirely, as we're covered robustly by this change (and the previous recent change to treat a NULL tree as a parse error). We'll also give tags the same treatment. I don't know offhand of any cases where the problem can be triggered (it implies somebody ignoring a parse error earlier in the process), but consistently returning an error should cause the least surprise. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- commit-graph.c | 3 --- commit.c | 14 +++++++++++++- t/t5318-commit-graph.sh | 2 +- tag.c | 12 +++++++++++- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/commit-graph.c b/commit-graph.c index fc4a43b8d6eb11..852b9c39e68e63 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -855,9 +855,6 @@ static void write_graph_chunk_data(struct hashfile *f, int hash_len, die(_("unable to parse commit %s"), oid_to_hex(&(*list)->object.oid)); tree = get_commit_tree_oid(*list); - if (!tree) - die(_("unable to get tree for %s"), - oid_to_hex(&(*list)->object.oid)); hashwrite(f, tree->hash, hash_len); parent = (*list)->parents; diff --git a/commit.c b/commit.c index 810419a16871cf..e12e7998ad02e6 100644 --- a/commit.c +++ b/commit.c @@ -405,7 +405,18 @@ int parse_commit_buffer(struct repository *r, struct commit *item, const void *b if (item->object.parsed) return 0; - item->object.parsed = 1; + + if (item->parents) { + /* + * Presumably this is leftover from an earlier failed parse; + * clear it out in preparation for us re-parsing (we'll hit the + * same error, but that's good, since it lets our caller know + * the result cannot be trusted. + */ + free_commit_list(item->parents); + item->parents = NULL; + } + tail += size; if (tail <= bufptr + tree_entry_len + 1 || memcmp(bufptr, "tree ", 5) || bufptr[tree_entry_len] != '\n') @@ -462,6 +473,7 @@ int parse_commit_buffer(struct repository *r, struct commit *item, const void *b if (check_graph) load_commit_graph_info(r, item); + item->object.parsed = 1; return 0; } diff --git a/t/t5318-commit-graph.sh b/t/t5318-commit-graph.sh index d42b3efe391836..127b4048568072 100755 --- a/t/t5318-commit-graph.sh +++ b/t/t5318-commit-graph.sh @@ -660,7 +660,7 @@ test_expect_success 'corrupt commit-graph write (missing tree)' ' git commit-tree -p "$broken" -m "good" "$tree" >good && test_must_fail git commit-graph write --stdin-commits \ test_err && - test_i18ngrep "unable to get tree for" test_err + test_i18ngrep "unable to parse commit" test_err ) ' diff --git a/tag.c b/tag.c index 6a51efda8d7d59..71b544467efacd 100644 --- a/tag.c +++ b/tag.c @@ -141,7 +141,16 @@ int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, u if (item->object.parsed) return 0; - item->object.parsed = 1; + + if (item->tag) { + /* + * Presumably left over from a previous failed parse; + * clear it out in preparation for re-parsing (we'll probably + * hit the same error, which lets us tell our current caller + * about the problem). + */ + FREE_AND_NULL(item->tag); + } if (size < the_hash_algo->hexsz + 24) return -1; @@ -192,6 +201,7 @@ int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, u else item->date = 0; + item->object.parsed = 1; return 0; } From 1de6007d851816723e283720ba2683c908d38f10 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 18 Oct 2019 00:48:20 -0400 Subject: [PATCH 074/953] fsck: stop checking commit->tree value We check in fsck_commit_buffer() that commit->tree isn't NULL, which in turn generally comes from a previous parse by parse_commit(). But this isn't really accomplishing anything. The two things we might care about are: - was there a syntactically valid "tree " line in the object? But we've just done our own parse in fsck_commit_buffer() to check this. - does it point to a valid tree object? But checking the "tree" pointer here doesn't actually accomplish that; it just shows that lookup_tree() didn't return NULL, which only means that we haven't yet seen that oid as a non-tree in this process. A real connectivity check would exhaustively walk all graph links, and we do that already in a separate function. So this code isn't helping anything. And it makes the fsck code slightly more confusing and rigid (e.g., it requires that any commit structs have already been parsed). Let's drop it. As a bit of history, the presence of this code looks like a leftover from early fsck code (which did rely on parse_commit() to do most of the parsing). The check comes from ff5ebe39b0 (Port fsck-cache to use parsing functions, 2005-04-18), but we later added an explicit walk in 355885d531 (add generic, type aware object chain walker, 2008-02-25). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- fsck.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/fsck.c b/fsck.c index cdb7d8db03017e..6dfc533fb03d80 100644 --- a/fsck.c +++ b/fsck.c @@ -800,11 +800,6 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer, err = fsck_ident(&buffer, &commit->object, options); if (err) return err; - if (!get_commit_tree(commit)) { - err = report(options, &commit->object, FSCK_MSG_BAD_TREE, "could not load commit's tree %s", oid_to_hex(&tree_oid)); - if (err) - return err; - } if (memchr(buffer_begin, '\0', size)) { err = report(options, &commit->object, FSCK_MSG_NUL_IN_COMMIT, "NUL byte in the commit object body"); From ec65231571d9316144acac9dde49acef279c713c Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 18 Oct 2019 00:49:10 -0400 Subject: [PATCH 075/953] fsck: stop checking commit->parent counts In 4516338243 (builtin-fsck: reports missing parent commits, 2008-02-25), we added code to check that fsck found the same number of parents from parsing the commit itself as we see in the commit struct we got from parse_commit_buffer(). Back then the rationale was that the normal commit parser might skip some bad parents. But earlier in this series, we started treating that reliably as a parsing error, meaning that we'd complain about it before we even hit the code in fsck.c. Let's drop this code, which now makes fsck_commit_buffer() completely independent of any parsed values in the commit struct (that's conceptually cleaner, and also opens up more refactoring options). Note that we can also drop the MISSING_PARENT and MISSING_GRAFT fsck identifiers. This is no loss, as these would not trigger reliably anyway. We'd hit them only when lookup_commit() failed, which occurs only if we happen to have seen the object with another type already in the same process. In most cases, we'd actually run into the problem during the connectivity walk, not here. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- fsck.c | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/fsck.c b/fsck.c index 6dfc533fb03d80..a0f8ae7650a42f 100644 --- a/fsck.c +++ b/fsck.c @@ -43,10 +43,8 @@ static struct oidset gitmodules_done = OIDSET_INIT; FUNC(MISSING_AUTHOR, ERROR) \ FUNC(MISSING_COMMITTER, ERROR) \ FUNC(MISSING_EMAIL, ERROR) \ - FUNC(MISSING_GRAFT, ERROR) \ FUNC(MISSING_NAME_BEFORE_EMAIL, ERROR) \ FUNC(MISSING_OBJECT, ERROR) \ - FUNC(MISSING_PARENT, ERROR) \ FUNC(MISSING_SPACE_BEFORE_DATE, ERROR) \ FUNC(MISSING_SPACE_BEFORE_EMAIL, ERROR) \ FUNC(MISSING_TAG, ERROR) \ @@ -739,8 +737,7 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer, unsigned long size, struct fsck_options *options) { struct object_id tree_oid, oid; - struct commit_graft *graft; - unsigned parent_count, parent_line_count = 0, author_count; + unsigned author_count; int err; const char *buffer_begin = buffer; const char *p; @@ -763,24 +760,6 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer, return err; } buffer = p + 1; - parent_line_count++; - } - graft = lookup_commit_graft(the_repository, &commit->object.oid); - 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) { - err = report(options, &commit->object, FSCK_MSG_MISSING_GRAFT, "graft objects missing"); - if (err) - return err; - } - } else { - if (parent_count != parent_line_count) { - err = report(options, &commit->object, FSCK_MSG_MISSING_PARENT, "parent objects missing"); - if (err) - return err; - } } author_count = 0; while (skip_prefix(buffer, "author ", &buffer)) { From 2175a0c601af269c7aa335bc7faf27e36173ca08 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 18 Oct 2019 00:51:19 -0400 Subject: [PATCH 076/953] fsck: stop checking tag->tagged Way back in 92d4c85d24 (fsck-cache: fix SIGSEGV on bad tag object, 2005-05-03), we added an fsck check that the "tagged" field of a tag struct isn't NULL. But that was mainly protecting the printing code for "--tags", and that code wasn't moved along with the check as part of ba002f3b28 (builtin-fsck: move common object checking code to fsck.c, 2008-02-25). It could also serve to detect type mismatch problems (where a tag points to object X as a commit, but really X is a blob), but it couldn't do so reliably (we'd call lookup_commit(X), but it will only notice the problem if we happen to have previously called lookup_blob(X) in the same process). And as of a commit earlier in this series, we'd consider that a parse error and complain about the object even before getting to this point anyway. So let's drop this "tag->tagged" check. It's not helping anything, and getting rid of it makes the function conceptually cleaner, as it really is just checking the buffer we feed it. In fact, we can get rid of our one-line wrapper and just unify fsck_tag() and fsck_tag_buffer(). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- fsck.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/fsck.c b/fsck.c index a0f8ae7650a42f..79ce3a97c8f93a 100644 --- a/fsck.c +++ b/fsck.c @@ -798,8 +798,8 @@ static int fsck_commit(struct commit *commit, const char *data, return ret; } -static int fsck_tag_buffer(struct tag *tag, const char *data, - unsigned long size, struct fsck_options *options) +static int fsck_tag(struct tag *tag, const char *data, + unsigned long size, struct fsck_options *options) { struct object_id oid; int ret = 0; @@ -893,17 +893,6 @@ static int fsck_tag_buffer(struct tag *tag, const char *data, return ret; } -static int fsck_tag(struct tag *tag, const char *data, - unsigned long size, struct fsck_options *options) -{ - struct object *tagged = tag->tagged; - - if (!tagged) - return report(options, &tag->object, FSCK_MSG_BAD_TAG_OBJECT, "could not load tagged object"); - - return fsck_tag_buffer(tag, data, size, options); -} - struct fsck_gitmodules_data { struct object *obj; struct fsck_options *options; From 23a173a761c9ed9a1e90167386e8b908728f27c0 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 18 Oct 2019 00:54:12 -0400 Subject: [PATCH 077/953] fsck: require an actual buffer for non-blobs The fsck_object() function takes in a buffer, but also a "struct object". The rules for using these vary between types: - for a commit, we'll use the provided buffer; if it's NULL, we'll fall back to get_commit_buffer(), which loads from either an in-memory cache or from disk. If the latter fails, we'd die(), which is non-ideal for fsck. - for a tag, a NULL buffer will fall back to loading the object from disk (and failure would lead to an fsck error) - for a tree, we _never_ look at the provided buffer, and always use tree->buffer - for a blob, we usually don't look at the buffer at all, unless it has been marked as a .gitmodule file. In that case we check the buffer given to us, or assume a NULL buffer is a very large blob (and complain about it) This is much more complex than it needs to be. It turns out that nobody ever feeds a NULL buffer that isn't a blob: - git-fsck calls fsck_object() only from fsck_obj(). That in turn is called by one of: - fsck_obj_buffer(), which is a callback to verify_pack(), which unpacks everything except large blobs into a buffer (see pack-check.c, lines 131-141). - fsck_loose(), which hits a BUG() on non-blobs with a NULL buffer (builtin/fsck.c, lines 639-640) And in either case, we'll have just called parse_object_buffer() anyway, which would segfault on a NULL buffer for commits or tags (not for trees, but it would install a NULL tree->buffer which would later cause a segfault) - git-index-pack asserts that the buffer is non-NULL unless the object is a blob (see builtin/index-pack.c, line 832) - git-unpack-objects always writes a non-NULL buffer into its obj_buffer hash, which is then fed to fsck_object(). (There is actually a funny thing here where it does not store blob buffers at all, nor does it call fsck on them; it does check any needed blobs via fsck_finish() though). Let's make the rules simpler, which reduces the amount of code and gives us more flexibility in refactoring the fsck code. The new rules are: - only blobs are allowed to pass a NULL buffer - we always use the provided buffer, never pulling information from the object struct We don't have to adjust any callers, because they were already adhering to these. Note that we do drop a few fsck identifiers for missing tags, but that was all dead code (because nobody passed a NULL tag buffer). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- fsck.c | 51 +++++++++------------------------------------------ fsck.h | 6 +++++- 2 files changed, 14 insertions(+), 43 deletions(-) diff --git a/fsck.c b/fsck.c index 79ce3a97c8f93a..347a0ef5c94253 100644 --- a/fsck.c +++ b/fsck.c @@ -49,13 +49,11 @@ static struct oidset gitmodules_done = OIDSET_INIT; FUNC(MISSING_SPACE_BEFORE_EMAIL, ERROR) \ FUNC(MISSING_TAG, ERROR) \ FUNC(MISSING_TAG_ENTRY, ERROR) \ - FUNC(MISSING_TAG_OBJECT, ERROR) \ FUNC(MISSING_TREE, ERROR) \ FUNC(MISSING_TREE_OBJECT, ERROR) \ FUNC(MISSING_TYPE, ERROR) \ FUNC(MISSING_TYPE_ENTRY, ERROR) \ FUNC(MULTIPLE_AUTHORS, ERROR) \ - FUNC(TAG_OBJECT_NOT_TAG, ERROR) \ FUNC(TREE_NOT_SORTED, ERROR) \ FUNC(UNKNOWN_TYPE, ERROR) \ FUNC(ZERO_PADDED_DATE, ERROR) \ @@ -541,7 +539,9 @@ static int verify_ordered(unsigned mode1, const char *name1, unsigned mode2, con return c1 < c2 ? 0 : TREE_UNORDERED; } -static int fsck_tree(struct tree *item, struct fsck_options *options) +static int fsck_tree(struct tree *item, + const char *buffer, unsigned long size, + struct fsck_options *options) { int retval = 0; int has_null_sha1 = 0; @@ -558,7 +558,7 @@ static int fsck_tree(struct tree *item, struct fsck_options *options) unsigned o_mode; const char *o_name; - if (init_tree_desc_gently(&desc, item->buffer, item->size)) { + if (init_tree_desc_gently(&desc, buffer, size)) { retval += report(options, &item->object, FSCK_MSG_BAD_TREE, "cannot be parsed as a tree"); return retval; } @@ -733,8 +733,8 @@ static int fsck_ident(const char **ident, struct object *obj, struct fsck_option return 0; } -static int fsck_commit_buffer(struct commit *commit, const char *buffer, - unsigned long size, struct fsck_options *options) +static int fsck_commit(struct commit *commit, const char *buffer, + unsigned long size, struct fsck_options *options) { struct object_id tree_oid, oid; unsigned author_count; @@ -788,47 +788,15 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer, return 0; } -static int fsck_commit(struct commit *commit, const char *data, - unsigned long size, struct fsck_options *options) -{ - const char *buffer = data ? data : get_commit_buffer(commit, &size); - int ret = fsck_commit_buffer(commit, buffer, size, options); - if (!data) - unuse_commit_buffer(commit, buffer); - return ret; -} - -static int fsck_tag(struct tag *tag, const char *data, +static int fsck_tag(struct tag *tag, const char *buffer, unsigned long size, struct fsck_options *options) { struct object_id oid; int ret = 0; - const char *buffer; - char *to_free = NULL, *eol; + char *eol; struct strbuf sb = STRBUF_INIT; const char *p; - if (data) - buffer = data; - else { - enum object_type type; - - buffer = to_free = - read_object_file(&tag->object.oid, &type, &size); - if (!buffer) - return report(options, &tag->object, - FSCK_MSG_MISSING_TAG_OBJECT, - "cannot read tag object"); - - if (type != OBJ_TAG) { - ret = report(options, &tag->object, - FSCK_MSG_TAG_OBJECT_NOT_TAG, - "expected tag got %s", - type_name(type)); - goto done; - } - } - ret = verify_headers(buffer, size, &tag->object, options); if (ret) goto done; @@ -889,7 +857,6 @@ static int fsck_tag(struct tag *tag, const char *data, done: strbuf_release(&sb); - free(to_free); return ret; } @@ -979,7 +946,7 @@ int fsck_object(struct object *obj, void *data, unsigned long size, if (obj->type == OBJ_BLOB) return fsck_blob((struct blob *)obj, data, size, options); if (obj->type == OBJ_TREE) - return fsck_tree((struct tree *) obj, options); + return fsck_tree((struct tree *) obj, data, size, options); if (obj->type == OBJ_COMMIT) return fsck_commit((struct commit *) obj, (const char *) data, size, options); diff --git a/fsck.h b/fsck.h index b95595ae5fee6c..e479461075da22 100644 --- a/fsck.h +++ b/fsck.h @@ -52,7 +52,11 @@ struct fsck_options { * 0 everything OK */ int fsck_walk(struct object *obj, void *data, struct fsck_options *options); -/* If NULL is passed for data, we assume the object is local and read it. */ + +/* + * Blob objects my pass a NULL data pointer, which indicates they are too large + * to fit in memory. All other types must pass a real buffer. + */ int fsck_object(struct object *obj, void *data, unsigned long size, struct fsck_options *options); From a59cfb32300baab00ee9cec68326309f4b2faca9 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 18 Oct 2019 00:56:13 -0400 Subject: [PATCH 078/953] fsck: unify object-name code Commit 90cf590f53 (fsck: optionally show more helpful info for broken links, 2016-07-17) added a system for decorating objects with names. The code is split across builtin/fsck.c (which gives the initial names) and fsck.c (which adds to the names as it traverses the object graph). This leads to some duplication, where both sites have near-identical describe_object() functions (the difference being that the one in builtin/fsck.c uses a circular array of buffers to allow multiple calls in a single printf). Let's provide a unified object_name API for fsck. That lets us drop the duplication, as well as making the interface boundaries more clear (which will let us refactor the implementation more in a future patch). We'll leave describe_object() in builtin/fsck.c as a thin wrapper around the new API, as it relies on a static global to make its many callers a bit shorter. We'll also convert the bare add_decoration() calls in builtin/fsck.c to put_object_name(). This fixes two minor bugs: 1. We leak many small strings. add_decoration() has a last-one-wins approach: it updates the decoration to the new string and returns the old one. But we ignore the return value, leaking the old string. This is quite common to trigger, since we look at reflogs: the tip of any ref will be described both by looking at the actual ref, as well as the latest reflog entry. So we'd always end up leaking one of those strings. 2. The last-one-wins approach gives us lousy names. For instance, we first look at all of the refs, and then all of the reflogs. So rather than seeing "refs/heads/master", we're likely to overwrite it with "HEAD@{12345678}". We're generally better off using the first name we find. And indeed, the test in t1450 expects this ugly HEAD@{} name. After this patch, we've switched to using fsck_put_object_name()'s first-one-wins semantics, and we output the more human-friendly "refs/tags/julius" (and the test is updated accordingly). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/fsck.c | 50 ++++++++---------------------- fsck.c | 82 ++++++++++++++++++++++++++++++------------------- fsck.h | 24 +++++++++++++++ t/t1450-fsck.sh | 2 +- 4 files changed, 89 insertions(+), 69 deletions(-) diff --git a/builtin/fsck.c b/builtin/fsck.c index 18403a94fa4224..237643cc1d9aad 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -52,24 +52,7 @@ static int name_objects; static const char *describe_object(struct object *obj) { - static struct strbuf bufs[] = { - STRBUF_INIT, STRBUF_INIT, STRBUF_INIT, STRBUF_INIT - }; - static int b = 0; - struct strbuf *buf; - char *name = NULL; - - if (name_objects) - name = lookup_decoration(fsck_walk_options.object_names, obj); - - buf = bufs + b; - b = (b + 1) % ARRAY_SIZE(bufs); - strbuf_reset(buf); - strbuf_addstr(buf, oid_to_hex(&obj->oid)); - if (name) - strbuf_addf(buf, " (%s)", name); - - return buf->buf; + return fsck_describe_object(&fsck_walk_options, obj); } static const char *printable_type(struct object *obj) @@ -499,10 +482,10 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid, if (!is_null_oid(oid)) { obj = lookup_object(the_repository, oid); if (obj && (obj->flags & HAS_OBJ)) { - if (timestamp && name_objects) - add_decoration(fsck_walk_options.object_names, - obj, - xstrfmt("%s@{%"PRItime"}", refname, timestamp)); + if (timestamp) + fsck_put_object_name(&fsck_walk_options, obj, + "%s@{%"PRItime"}", + refname, timestamp); obj->flags |= USED; mark_object_reachable(obj); } else if (!is_promisor_object(oid)) { @@ -566,9 +549,8 @@ static int fsck_handle_ref(const char *refname, const struct object_id *oid, } default_refs++; obj->flags |= USED; - if (name_objects) - add_decoration(fsck_walk_options.object_names, - obj, xstrdup(refname)); + fsck_put_object_name(&fsck_walk_options, + obj, "%s", refname); mark_object_reachable(obj); return 0; @@ -742,9 +724,7 @@ static int fsck_cache_tree(struct cache_tree *it) return 1; } obj->flags |= USED; - if (name_objects) - add_decoration(fsck_walk_options.object_names, - obj, xstrdup(":")); + fsck_put_object_name(&fsck_walk_options, obj, ":"); mark_object_reachable(obj); if (obj->type != OBJ_TREE) err |= objerror(obj, _("non-tree in cache-tree")); @@ -830,8 +810,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) } if (name_objects) - fsck_walk_options.object_names = - xcalloc(1, sizeof(struct decoration)); + fsck_enable_object_names(&fsck_walk_options); git_config(fsck_config, NULL); @@ -890,9 +869,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) } obj->flags |= USED; - if (name_objects) - add_decoration(fsck_walk_options.object_names, - obj, xstrdup(arg)); + fsck_put_object_name(&fsck_walk_options, obj, + "%s", arg); mark_object_reachable(obj); continue; } @@ -928,10 +906,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) continue; obj = &blob->object; obj->flags |= USED; - if (name_objects) - add_decoration(fsck_walk_options.object_names, - obj, - xstrfmt(":%s", active_cache[i]->name)); + fsck_put_object_name(&fsck_walk_options, obj, + ":%s", active_cache[i]->name); mark_object_reachable(obj); } if (active_cache_tree) diff --git a/fsck.c b/fsck.c index 347a0ef5c94253..ecd5957362cb23 100644 --- a/fsck.c +++ b/fsck.c @@ -312,15 +312,21 @@ static int report(struct fsck_options *options, struct object *object, return result; } -static char *get_object_name(struct fsck_options *options, struct object *obj) +void fsck_enable_object_names(struct fsck_options *options) +{ + if (!options->object_names) + options->object_names = xcalloc(1, sizeof(struct decoration)); +} + +const char *fsck_get_object_name(struct fsck_options *options, struct object *obj) { if (!options->object_names) return NULL; return lookup_decoration(options->object_names, obj); } -static void put_object_name(struct fsck_options *options, struct object *obj, - const char *fmt, ...) +void fsck_put_object_name(struct fsck_options *options, struct object *obj, + const char *fmt, ...) { va_list ap; struct strbuf buf = STRBUF_INIT; @@ -337,17 +343,27 @@ static void put_object_name(struct fsck_options *options, struct object *obj, va_end(ap); } -static const char *describe_object(struct fsck_options *o, struct object *obj) +const char *fsck_describe_object(struct fsck_options *options, + struct object *obj) { - static struct strbuf buf = STRBUF_INIT; - char *name; - - strbuf_reset(&buf); - strbuf_addstr(&buf, oid_to_hex(&obj->oid)); - if (o->object_names && (name = lookup_decoration(o->object_names, obj))) - strbuf_addf(&buf, " (%s)", name); + static struct strbuf bufs[] = { + STRBUF_INIT, STRBUF_INIT, STRBUF_INIT, STRBUF_INIT + }; + static int b = 0; + struct strbuf *buf; + char *name = NULL; + + if (options->object_names) + name = lookup_decoration(options->object_names, obj); + + buf = bufs + b; + b = (b + 1) % ARRAY_SIZE(bufs); + strbuf_reset(buf); + strbuf_addstr(buf, oid_to_hex(&obj->oid)); + if (name) + strbuf_addf(buf, " (%s)", name); - return buf.buf; + return buf->buf; } static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *options) @@ -360,7 +376,7 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op if (parse_tree(tree)) return -1; - name = get_object_name(options, &tree->object); + name = fsck_get_object_name(options, &tree->object); if (init_tree_desc_gently(&desc, tree->buffer, tree->size)) return -1; while (tree_entry_gently(&desc, &entry)) { @@ -373,20 +389,21 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op if (S_ISDIR(entry.mode)) { obj = (struct object *)lookup_tree(the_repository, &entry.oid); if (name && obj) - put_object_name(options, obj, "%s%s/", name, - entry.path); + fsck_put_object_name(options, obj, "%s%s/", + name, entry.path); result = options->walk(obj, OBJ_TREE, data, options); } else if (S_ISREG(entry.mode) || S_ISLNK(entry.mode)) { obj = (struct object *)lookup_blob(the_repository, &entry.oid); if (name && obj) - put_object_name(options, obj, "%s%s", name, - entry.path); + fsck_put_object_name(options, obj, "%s%s", + name, entry.path); result = options->walk(obj, OBJ_BLOB, data, options); } else { result = error("in tree %s: entry %s has bad mode %.6o", - describe_object(options, &tree->object), entry.path, entry.mode); + fsck_describe_object(options, &tree->object), + entry.path, entry.mode); } if (result < 0) return result; @@ -407,10 +424,10 @@ static int fsck_walk_commit(struct commit *commit, void *data, struct fsck_optio if (parse_commit(commit)) return -1; - name = get_object_name(options, &commit->object); + name = fsck_get_object_name(options, &commit->object); if (name) - put_object_name(options, &get_commit_tree(commit)->object, - "%s:", name); + fsck_put_object_name(options, &get_commit_tree(commit)->object, + "%s:", name); result = options->walk((struct object *)get_commit_tree(commit), OBJ_TREE, data, options); @@ -441,13 +458,15 @@ static int fsck_walk_commit(struct commit *commit, void *data, struct fsck_optio struct object *obj = &parents->item->object; if (counter++) - put_object_name(options, obj, "%s^%d", - name, counter); + fsck_put_object_name(options, obj, "%s^%d", + name, counter); else if (generation > 0) - put_object_name(options, obj, "%.*s~%d", - name_prefix_len, name, generation + 1); + fsck_put_object_name(options, obj, "%.*s~%d", + name_prefix_len, name, + generation + 1); else - put_object_name(options, obj, "%s^", name); + fsck_put_object_name(options, obj, "%s^", + name); } result = options->walk((struct object *)parents->item, OBJ_COMMIT, data, options); if (result < 0) @@ -461,12 +480,12 @@ static int fsck_walk_commit(struct commit *commit, void *data, struct fsck_optio static int fsck_walk_tag(struct tag *tag, void *data, struct fsck_options *options) { - char *name = get_object_name(options, &tag->object); + const char *name = fsck_get_object_name(options, &tag->object); if (parse_tag(tag)) return -1; if (name) - put_object_name(options, tag->tagged, "%s", name); + fsck_put_object_name(options, tag->tagged, "%s", name); return options->walk(tag->tagged, OBJ_ANY, data, options); } @@ -488,7 +507,8 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options) case OBJ_TAG: return fsck_walk_tag((struct tag *)obj, data, options); default: - error("Unknown object type for %s", describe_object(options, obj)); + error("Unknown object type for %s", + fsck_describe_object(options, obj)); return -1; } } @@ -962,10 +982,10 @@ int fsck_error_function(struct fsck_options *o, struct object *obj, int msg_type, const char *message) { if (msg_type == FSCK_WARN) { - warning("object %s: %s", describe_object(o, obj), message); + warning("object %s: %s", fsck_describe_object(o, obj), message); return 0; } - error("object %s: %s", describe_object(o, obj), message); + error("object %s: %s", fsck_describe_object(o, obj), message); return 1; } diff --git a/fsck.h b/fsck.h index e479461075da22..6228f0b2d49fe6 100644 --- a/fsck.h +++ b/fsck.h @@ -67,4 +67,28 @@ int fsck_object(struct object *obj, void *data, unsigned long size, */ int fsck_finish(struct fsck_options *options); +/* + * Subsystem for storing human-readable names for each object. + * + * If fsck_enable_object_names() has not been called, all other functions are + * noops. + * + * Use fsck_put_object_name() to seed initial names (e.g. from refnames); the + * fsck code will extend that while walking trees, etc. + * + * Use fsck_get_object_name() to get a single name (or NULL if none). Or the + * more convenient describe_object(), which always produces an output string + * with the oid combined with the name (if any). Note that the return value + * points to a rotating array of static buffers, and may be invalidated by a + * subsequent call. + */ +void fsck_enable_object_names(struct fsck_options *options); +const char *fsck_get_object_name(struct fsck_options *options, + struct object *obj); +__attribute__((format (printf,3,4))) +void fsck_put_object_name(struct fsck_options *options, struct object *obj, + const char *fmt, ...); +const char *fsck_describe_object(struct fsck_options *options, + struct object *obj); + #endif diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index 50d28e6fdb6079..7c7ff7e961d406 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -616,7 +616,7 @@ test_expect_success 'fsck --name-objects' ' remove_object $(git rev-parse julius:caesar.t) && test_must_fail git fsck --name-objects >out && tree=$(git rev-parse --verify julius:) && - test_i18ngrep -E "$tree \((refs/heads/master|HEAD)@\{[0-9]*\}:" out + test_i18ngrep "$tree (refs/tags/julius:" out ) ' From d40bbc109b6f5d9e5e5088095cc33fef2e25971e Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 18 Oct 2019 00:56:38 -0400 Subject: [PATCH 079/953] fsck_describe_object(): build on our get_object_name() primitive This isolates the implementation detail of using the decoration code to our put/get functions. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- fsck.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/fsck.c b/fsck.c index ecd5957362cb23..b0c4de67c9f472 100644 --- a/fsck.c +++ b/fsck.c @@ -351,10 +351,7 @@ const char *fsck_describe_object(struct fsck_options *options, }; static int b = 0; struct strbuf *buf; - char *name = NULL; - - if (options->object_names) - name = lookup_decoration(options->object_names, obj); + const char *name = fsck_get_object_name(options, obj); buf = bufs + b; b = (b + 1) % ARRAY_SIZE(bufs); From 733902905d4db54612fef9755bb31fd35a89e76c Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 18 Oct 2019 00:57:37 -0400 Subject: [PATCH 080/953] fsck: use oids rather than objects for object_name API We don't actually care about having object structs; we only need to look up decorations by oid. Let's accept this more limited form, which will give our callers more flexibility. Note that the decoration API we rely on uses object structs itself (even though it only looks at their oids). We can solve this by switching to a kh_oid_map (we could also use the hashmap oidmap, but it's more awkward for the simple case of just storing a void pointer). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/fsck.c | 12 +++++----- fsck.c | 61 ++++++++++++++++++++++++++++---------------------- fsck.h | 9 ++++---- 3 files changed, 45 insertions(+), 37 deletions(-) diff --git a/builtin/fsck.c b/builtin/fsck.c index 237643cc1d9aad..66fa727c14d97c 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -52,7 +52,7 @@ static int name_objects; static const char *describe_object(struct object *obj) { - return fsck_describe_object(&fsck_walk_options, obj); + return fsck_describe_object(&fsck_walk_options, &obj->oid); } static const char *printable_type(struct object *obj) @@ -483,7 +483,7 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid, obj = lookup_object(the_repository, oid); if (obj && (obj->flags & HAS_OBJ)) { if (timestamp) - fsck_put_object_name(&fsck_walk_options, obj, + fsck_put_object_name(&fsck_walk_options, oid, "%s@{%"PRItime"}", refname, timestamp); obj->flags |= USED; @@ -550,7 +550,7 @@ static int fsck_handle_ref(const char *refname, const struct object_id *oid, default_refs++; obj->flags |= USED; fsck_put_object_name(&fsck_walk_options, - obj, "%s", refname); + oid, "%s", refname); mark_object_reachable(obj); return 0; @@ -724,7 +724,7 @@ static int fsck_cache_tree(struct cache_tree *it) return 1; } obj->flags |= USED; - fsck_put_object_name(&fsck_walk_options, obj, ":"); + fsck_put_object_name(&fsck_walk_options, &it->oid, ":"); mark_object_reachable(obj); if (obj->type != OBJ_TREE) err |= objerror(obj, _("non-tree in cache-tree")); @@ -869,7 +869,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) } obj->flags |= USED; - fsck_put_object_name(&fsck_walk_options, obj, + fsck_put_object_name(&fsck_walk_options, &oid, "%s", arg); mark_object_reachable(obj); continue; @@ -906,7 +906,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) continue; obj = &blob->object; obj->flags |= USED; - fsck_put_object_name(&fsck_walk_options, obj, + fsck_put_object_name(&fsck_walk_options, &obj->oid, ":%s", active_cache[i]->name); mark_object_reachable(obj); } diff --git a/fsck.c b/fsck.c index b0c4de67c9f472..124c0184d4ea22 100644 --- a/fsck.c +++ b/fsck.c @@ -315,48 +315,56 @@ static int report(struct fsck_options *options, struct object *object, void fsck_enable_object_names(struct fsck_options *options) { if (!options->object_names) - options->object_names = xcalloc(1, sizeof(struct decoration)); + options->object_names = kh_init_oid_map(); } -const char *fsck_get_object_name(struct fsck_options *options, struct object *obj) +const char *fsck_get_object_name(struct fsck_options *options, + const struct object_id *oid) { + khiter_t pos; if (!options->object_names) return NULL; - return lookup_decoration(options->object_names, obj); + pos = kh_get_oid_map(options->object_names, *oid); + if (pos >= kh_end(options->object_names)) + return NULL; + return kh_value(options->object_names, pos); } -void fsck_put_object_name(struct fsck_options *options, struct object *obj, +void fsck_put_object_name(struct fsck_options *options, + const struct object_id *oid, const char *fmt, ...) { va_list ap; struct strbuf buf = STRBUF_INIT; - char *existing; + khiter_t pos; + int hashret; if (!options->object_names) return; - existing = lookup_decoration(options->object_names, obj); - if (existing) + + pos = kh_put_oid_map(options->object_names, *oid, &hashret); + if (!hashret) return; va_start(ap, fmt); strbuf_vaddf(&buf, fmt, ap); - add_decoration(options->object_names, obj, strbuf_detach(&buf, NULL)); + kh_value(options->object_names, pos) = strbuf_detach(&buf, NULL); va_end(ap); } const char *fsck_describe_object(struct fsck_options *options, - struct object *obj) + const struct object_id *oid) { static struct strbuf bufs[] = { STRBUF_INIT, STRBUF_INIT, STRBUF_INIT, STRBUF_INIT }; static int b = 0; struct strbuf *buf; - const char *name = fsck_get_object_name(options, obj); + const char *name = fsck_get_object_name(options, oid); buf = bufs + b; b = (b + 1) % ARRAY_SIZE(bufs); strbuf_reset(buf); - strbuf_addstr(buf, oid_to_hex(&obj->oid)); + strbuf_addstr(buf, oid_to_hex(oid)); if (name) strbuf_addf(buf, " (%s)", name); @@ -373,7 +381,7 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op if (parse_tree(tree)) return -1; - name = fsck_get_object_name(options, &tree->object); + name = fsck_get_object_name(options, &tree->object.oid); if (init_tree_desc_gently(&desc, tree->buffer, tree->size)) return -1; while (tree_entry_gently(&desc, &entry)) { @@ -386,20 +394,20 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op if (S_ISDIR(entry.mode)) { obj = (struct object *)lookup_tree(the_repository, &entry.oid); if (name && obj) - fsck_put_object_name(options, obj, "%s%s/", + fsck_put_object_name(options, &entry.oid, "%s%s/", name, entry.path); result = options->walk(obj, OBJ_TREE, data, options); } else if (S_ISREG(entry.mode) || S_ISLNK(entry.mode)) { obj = (struct object *)lookup_blob(the_repository, &entry.oid); if (name && obj) - fsck_put_object_name(options, obj, "%s%s", + fsck_put_object_name(options, &entry.oid, "%s%s", name, entry.path); result = options->walk(obj, OBJ_BLOB, data, options); } else { result = error("in tree %s: entry %s has bad mode %.6o", - fsck_describe_object(options, &tree->object), + fsck_describe_object(options, &tree->object.oid), entry.path, entry.mode); } if (result < 0) @@ -421,9 +429,9 @@ static int fsck_walk_commit(struct commit *commit, void *data, struct fsck_optio if (parse_commit(commit)) return -1; - name = fsck_get_object_name(options, &commit->object); + name = fsck_get_object_name(options, &commit->object.oid); if (name) - fsck_put_object_name(options, &get_commit_tree(commit)->object, + fsck_put_object_name(options, get_commit_tree_oid(commit), "%s:", name); result = options->walk((struct object *)get_commit_tree(commit), @@ -452,18 +460,17 @@ static int fsck_walk_commit(struct commit *commit, void *data, struct fsck_optio while (parents) { if (name) { - struct object *obj = &parents->item->object; + struct object_id *oid = &parents->item->object.oid; if (counter++) - fsck_put_object_name(options, obj, "%s^%d", + fsck_put_object_name(options, oid, "%s^%d", name, counter); else if (generation > 0) - fsck_put_object_name(options, obj, "%.*s~%d", + fsck_put_object_name(options, oid, "%.*s~%d", name_prefix_len, name, generation + 1); else - fsck_put_object_name(options, obj, "%s^", - name); + fsck_put_object_name(options, oid, "%s^", name); } result = options->walk((struct object *)parents->item, OBJ_COMMIT, data, options); if (result < 0) @@ -477,12 +484,12 @@ static int fsck_walk_commit(struct commit *commit, void *data, struct fsck_optio static int fsck_walk_tag(struct tag *tag, void *data, struct fsck_options *options) { - const char *name = fsck_get_object_name(options, &tag->object); + const char *name = fsck_get_object_name(options, &tag->object.oid); if (parse_tag(tag)) return -1; if (name) - fsck_put_object_name(options, tag->tagged, "%s", name); + fsck_put_object_name(options, &tag->tagged->oid, "%s", name); return options->walk(tag->tagged, OBJ_ANY, data, options); } @@ -505,7 +512,7 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options) return fsck_walk_tag((struct tag *)obj, data, options); default: error("Unknown object type for %s", - fsck_describe_object(options, obj)); + fsck_describe_object(options, &obj->oid)); return -1; } } @@ -979,10 +986,10 @@ int fsck_error_function(struct fsck_options *o, struct object *obj, int msg_type, const char *message) { if (msg_type == FSCK_WARN) { - warning("object %s: %s", fsck_describe_object(o, obj), message); + warning("object %s: %s", fsck_describe_object(o, &obj->oid), message); return 0; } - error("object %s: %s", fsck_describe_object(o, obj), message); + error("object %s: %s", fsck_describe_object(o, &obj->oid), message); return 1; } diff --git a/fsck.h b/fsck.h index 6228f0b2d49fe6..36cfa463af2cd2 100644 --- a/fsck.h +++ b/fsck.h @@ -38,7 +38,7 @@ struct fsck_options { unsigned strict:1; int *msg_type; struct oidset skiplist; - struct decoration *object_names; + kh_oid_map_t *object_names; }; #define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT } @@ -84,11 +84,12 @@ int fsck_finish(struct fsck_options *options); */ void fsck_enable_object_names(struct fsck_options *options); const char *fsck_get_object_name(struct fsck_options *options, - struct object *obj); + const struct object_id *oid); __attribute__((format (printf,3,4))) -void fsck_put_object_name(struct fsck_options *options, struct object *obj, +void fsck_put_object_name(struct fsck_options *options, + const struct object_id *oid, const char *fmt, ...); const char *fsck_describe_object(struct fsck_options *options, - struct object *obj); + const struct object_id *oid); #endif From 82ef89b318a3c88a3e6af21a05b75abf56d715da Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 18 Oct 2019 00:58:07 -0400 Subject: [PATCH 081/953] fsck: don't require object structs for display functions Our printable_type() and describe_object() functions take whole object structs, but they really only care about the oid and type. Let's take those individually in order to give our callers more flexibility. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/fsck.c | 69 +++++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/builtin/fsck.c b/builtin/fsck.c index 66fa727c14d97c..59c77c1baa3811 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -50,23 +50,20 @@ static int name_objects; #define ERROR_REFS 010 #define ERROR_COMMIT_GRAPH 020 -static const char *describe_object(struct object *obj) +static const char *describe_object(const struct object_id *oid) { - return fsck_describe_object(&fsck_walk_options, &obj->oid); + return fsck_describe_object(&fsck_walk_options, oid); } -static const char *printable_type(struct object *obj) +static const char *printable_type(const struct object_id *oid, + enum object_type type) { const char *ret; - if (obj->type == OBJ_NONE) { - enum object_type type = oid_object_info(the_repository, - &obj->oid, NULL); - if (type > 0) - object_as_type(the_repository, obj, type, 0); - } + if (type == OBJ_NONE) + type = oid_object_info(the_repository, oid, NULL); - ret = type_name(obj->type); + ret = type_name(type); if (!ret) ret = _("unknown"); @@ -101,7 +98,8 @@ static int objerror(struct object *obj, const char *err) errors_found |= ERROR_OBJECT; /* TRANSLATORS: e.g. error in tree 01bfda: */ fprintf_ln(stderr, _("error in %s %s: %s"), - printable_type(obj), describe_object(obj), err); + printable_type(&obj->oid, obj->type), + describe_object(&obj->oid), err); return -1; } @@ -112,12 +110,14 @@ static int fsck_error_func(struct fsck_options *o, case FSCK_WARN: /* TRANSLATORS: e.g. warning in tree 01bfda: */ fprintf_ln(stderr, _("warning in %s %s: %s"), - printable_type(obj), describe_object(obj), message); + printable_type(&obj->oid, obj->type), + describe_object(&obj->oid), message); return 0; case FSCK_ERROR: /* TRANSLATORS: e.g. error in tree 01bfda: */ fprintf_ln(stderr, _("error in %s %s: %s"), - printable_type(obj), describe_object(obj), message); + printable_type(&obj->oid, obj->type), + describe_object(&obj->oid), message); return 1; default: BUG("%d (FSCK_IGNORE?) should never trigger this callback", type); @@ -138,7 +138,8 @@ static int mark_object(struct object *obj, int type, void *data, struct fsck_opt if (!obj) { /* ... these references to parent->fld are safe here */ printf_ln(_("broken link from %7s %s"), - printable_type(parent), describe_object(parent)); + printable_type(&parent->oid, parent->type), + describe_object(&parent->oid)); printf_ln(_("broken link from %7s %s"), (type == OBJ_ANY ? _("unknown") : type_name(type)), _("unknown")); @@ -166,10 +167,10 @@ static int mark_object(struct object *obj, int type, void *data, struct fsck_opt if (parent && !has_object_file(&obj->oid)) { printf_ln(_("broken link from %7s %s\n" " to %7s %s"), - printable_type(parent), - describe_object(parent), - printable_type(obj), - describe_object(obj)); + printable_type(&parent->oid, parent->type), + describe_object(&parent->oid), + printable_type(&obj->oid, obj->type), + describe_object(&obj->oid)); errors_found |= ERROR_REACHABLE; } return 1; @@ -275,8 +276,9 @@ static void check_reachable_object(struct object *obj) return; if (has_object_pack(&obj->oid)) return; /* it is in pack - forget about it */ - printf_ln(_("missing %s %s"), printable_type(obj), - describe_object(obj)); + printf_ln(_("missing %s %s"), + printable_type(&obj->oid, obj->type), + describe_object(&obj->oid)); errors_found |= ERROR_REACHABLE; return; } @@ -301,8 +303,9 @@ static void check_unreachable_object(struct object *obj) * since this is something that is prunable. */ if (show_unreachable) { - printf_ln(_("unreachable %s %s"), printable_type(obj), - describe_object(obj)); + printf_ln(_("unreachable %s %s"), + printable_type(&obj->oid, obj->type), + describe_object(&obj->oid)); return; } @@ -320,12 +323,13 @@ static void check_unreachable_object(struct object *obj) */ if (!(obj->flags & USED)) { if (show_dangling) - printf_ln(_("dangling %s %s"), printable_type(obj), - describe_object(obj)); + printf_ln(_("dangling %s %s"), + printable_type(&obj->oid, obj->type), + describe_object(&obj->oid)); if (write_lost_and_found) { char *filename = git_pathdup("lost-found/%s/%s", obj->type == OBJ_COMMIT ? "commit" : "other", - describe_object(obj)); + describe_object(&obj->oid)); FILE *f; if (safe_create_leading_directories_const(filename)) { @@ -338,7 +342,7 @@ static void check_unreachable_object(struct object *obj) if (stream_blob_to_fd(fileno(f), &obj->oid, NULL, 1)) die_errno(_("could not write '%s'"), filename); } else - fprintf(f, "%s\n", describe_object(obj)); + fprintf(f, "%s\n", describe_object(&obj->oid)); if (fclose(f)) die_errno(_("could not finish '%s'"), filename); @@ -357,7 +361,7 @@ static void check_unreachable_object(struct object *obj) static void check_object(struct object *obj) { if (verbose) - fprintf_ln(stderr, _("Checking %s"), describe_object(obj)); + fprintf_ln(stderr, _("Checking %s"), describe_object(&obj->oid)); if (obj->flags & REACHABLE) check_reachable_object(obj); @@ -415,7 +419,8 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size) if (verbose) fprintf_ln(stderr, _("Checking %s %s"), - printable_type(obj), describe_object(obj)); + printable_type(&obj->oid, obj->type), + describe_object(&obj->oid)); if (fsck_walk(obj, NULL, &fsck_obj_options)) objerror(obj, _("broken links")); @@ -428,7 +433,7 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size) if (!commit->parents && show_root) printf_ln(_("root %s"), - describe_object(&commit->object)); + describe_object(&commit->object.oid)); } if (obj->type == OBJ_TAG) { @@ -436,10 +441,10 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size) if (show_tags && tag->tagged) { printf_ln(_("tagged %s %s (%s) in %s"), - printable_type(tag->tagged), - describe_object(tag->tagged), + printable_type(&tag->tagged->oid, tag->tagged->type), + describe_object(&tag->tagged->oid), tag->tag, - describe_object(&tag->object)); + describe_object(&tag->object.oid)); } } From 5afc4b1dc622d574bcd67b5845789a0b5875431a Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 18 Oct 2019 00:58:40 -0400 Subject: [PATCH 082/953] fsck: only provide oid/type in fsck_error callback None of the callbacks actually care about having a "struct object"; they're happy with just the oid and type information. So let's give ourselves more flexibility to avoid having a "struct object" by just passing the broken-down fields. Note that the callback already takes a "type" field for the fsck message type. We'll rename that to "msg_type" (and use "object_type" for the object type) to make the distinction explicit. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/fsck.c | 17 ++++++++++------- fsck.c | 11 +++++++---- fsck.h | 6 ++++-- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/builtin/fsck.c b/builtin/fsck.c index 59c77c1baa3811..8d13794b1412c8 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -104,23 +104,26 @@ static int objerror(struct object *obj, const char *err) } static int fsck_error_func(struct fsck_options *o, - struct object *obj, int type, const char *message) + const struct object_id *oid, + enum object_type object_type, + int msg_type, const char *message) { - switch (type) { + switch (msg_type) { case FSCK_WARN: /* TRANSLATORS: e.g. warning in tree 01bfda: */ fprintf_ln(stderr, _("warning in %s %s: %s"), - printable_type(&obj->oid, obj->type), - describe_object(&obj->oid), message); + printable_type(oid, object_type), + describe_object(oid), message); return 0; case FSCK_ERROR: /* TRANSLATORS: e.g. error in tree 01bfda: */ fprintf_ln(stderr, _("error in %s %s: %s"), - printable_type(&obj->oid, obj->type), - describe_object(&obj->oid), message); + printable_type(oid, object_type), + describe_object(oid), message); return 1; default: - BUG("%d (FSCK_IGNORE?) should never trigger this callback", type); + BUG("%d (FSCK_IGNORE?) should never trigger this callback", + msg_type); } } diff --git a/fsck.c b/fsck.c index 124c0184d4ea22..c036ba09ab9cb0 100644 --- a/fsck.c +++ b/fsck.c @@ -305,7 +305,8 @@ static int report(struct fsck_options *options, struct object *object, va_start(ap, fmt); strbuf_vaddf(&sb, fmt, ap); - result = options->error_func(options, object, msg_type, sb.buf); + result = options->error_func(options, &object->oid, object->type, + msg_type, sb.buf); strbuf_release(&sb); va_end(ap); @@ -983,13 +984,15 @@ int fsck_object(struct object *obj, void *data, unsigned long size, } int fsck_error_function(struct fsck_options *o, - struct object *obj, int msg_type, const char *message) + const struct object_id *oid, + enum object_type object_type, + int msg_type, const char *message) { if (msg_type == FSCK_WARN) { - warning("object %s: %s", fsck_describe_object(o, &obj->oid), message); + warning("object %s: %s", fsck_describe_object(o, oid), message); return 0; } - error("object %s: %s", fsck_describe_object(o, &obj->oid), message); + error("object %s: %s", fsck_describe_object(o, oid), message); return 1; } diff --git a/fsck.h b/fsck.h index 36cfa463af2cd2..69cf715e798ce2 100644 --- a/fsck.h +++ b/fsck.h @@ -27,10 +27,12 @@ typedef int (*fsck_walk_func)(struct object *obj, int type, void *data, struct f /* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ typedef int (*fsck_error)(struct fsck_options *o, - struct object *obj, int type, const char *message); + const struct object_id *oid, enum object_type object_type, + int msg_type, const char *message); int fsck_error_function(struct fsck_options *o, - struct object *obj, int type, const char *message); + const struct object_id *oid, enum object_type object_type, + int msg_type, const char *message); struct fsck_options { fsck_walk_func walk; From f59793763deb970dd5acffe2dffd34e791d44df8 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 18 Oct 2019 00:58:51 -0400 Subject: [PATCH 083/953] fsck: only require an oid for skiplist functions The skiplist is inherently an oidset, so we don't need a full object struct. Let's take just the oid to give our callers more flexibility. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- fsck.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fsck.c b/fsck.c index c036ba09ab9cb0..2309c40a11430e 100644 --- a/fsck.c +++ b/fsck.c @@ -277,9 +277,10 @@ static void append_msg_id(struct strbuf *sb, const char *msg_id) strbuf_addstr(sb, ": "); } -static int object_on_skiplist(struct fsck_options *opts, struct object *obj) +static int object_on_skiplist(struct fsck_options *opts, + const struct object_id *oid) { - return opts && obj && oidset_contains(&opts->skiplist, &obj->oid); + return opts && oid && oidset_contains(&opts->skiplist, oid); } __attribute__((format (printf, 4, 5))) @@ -293,7 +294,7 @@ static int report(struct fsck_options *options, struct object *object, if (msg_type == FSCK_IGNORE) return 0; - if (object_on_skiplist(options, object)) + if (object_on_skiplist(options, &object->oid)) return 0; if (msg_type == FSCK_FATAL) @@ -935,7 +936,7 @@ static int fsck_blob(struct blob *blob, const char *buf, return 0; oidset_insert(&gitmodules_done, &blob->object.oid); - if (object_on_skiplist(options, &blob->object)) + if (object_on_skiplist(options, &blob->object.oid)) return 0; if (!buf) { From 38370253fd43f494ca628e47b4d9c6e629990fc7 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 18 Oct 2019 00:59:15 -0400 Subject: [PATCH 084/953] fsck: don't require an object struct for report() The report() function really only cares about the oid and type of the object, not the full object struct. Let's convert it to take those two items separately, which gives our callers more flexibility. This makes some already-long lines even longer. I've mostly left them, as our eventual goal is to shrink these down as we continue refactoring (e.g., "&item->object" becomes "&item->object.oid, item->object.type", but will eventually shrink down to "oid, type"). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- fsck.c | 128 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 69 insertions(+), 59 deletions(-) diff --git a/fsck.c b/fsck.c index 2309c40a11430e..465247be71fc4d 100644 --- a/fsck.c +++ b/fsck.c @@ -283,9 +283,10 @@ static int object_on_skiplist(struct fsck_options *opts, return opts && oid && oidset_contains(&opts->skiplist, oid); } -__attribute__((format (printf, 4, 5))) -static int report(struct fsck_options *options, struct object *object, - enum fsck_msg_id id, const char *fmt, ...) +__attribute__((format (printf, 5, 6))) +static int report(struct fsck_options *options, + const struct object_id *oid, enum object_type object_type, + enum fsck_msg_id id, const char *fmt, ...) { va_list ap; struct strbuf sb = STRBUF_INIT; @@ -294,7 +295,7 @@ static int report(struct fsck_options *options, struct object *object, if (msg_type == FSCK_IGNORE) return 0; - if (object_on_skiplist(options, &object->oid)) + if (object_on_skiplist(options, oid)) return 0; if (msg_type == FSCK_FATAL) @@ -306,7 +307,7 @@ static int report(struct fsck_options *options, struct object *object, va_start(ap, fmt); strbuf_vaddf(&sb, fmt, ap); - result = options->error_func(options, &object->oid, object->type, + result = options->error_func(options, oid, object_type, msg_type, sb.buf); strbuf_release(&sb); va_end(ap); @@ -585,7 +586,7 @@ static int fsck_tree(struct tree *item, const char *o_name; if (init_tree_desc_gently(&desc, buffer, size)) { - retval += report(options, &item->object, FSCK_MSG_BAD_TREE, "cannot be parsed as a tree"); + retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_BAD_TREE, "cannot be parsed as a tree"); return retval; } @@ -611,13 +612,14 @@ static int fsck_tree(struct tree *item, if (!S_ISLNK(mode)) oidset_insert(&gitmodules_found, oid); else - retval += report(options, &item->object, + retval += report(options, + &item->object.oid, item->object.type, FSCK_MSG_GITMODULES_SYMLINK, ".gitmodules is a symbolic link"); } if (update_tree_entry_gently(&desc)) { - retval += report(options, &item->object, FSCK_MSG_BAD_TREE, "cannot be parsed as a tree"); + retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_BAD_TREE, "cannot be parsed as a tree"); break; } @@ -662,25 +664,25 @@ static int fsck_tree(struct tree *item, } if (has_null_sha1) - retval += report(options, &item->object, FSCK_MSG_NULL_SHA1, "contains entries pointing to null sha1"); + retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_NULL_SHA1, "contains entries pointing to null sha1"); if (has_full_path) - retval += report(options, &item->object, FSCK_MSG_FULL_PATHNAME, "contains full pathnames"); + retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_FULL_PATHNAME, "contains full pathnames"); if (has_empty_name) - retval += report(options, &item->object, FSCK_MSG_EMPTY_NAME, "contains empty pathname"); + retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_EMPTY_NAME, "contains empty pathname"); if (has_dot) - retval += report(options, &item->object, FSCK_MSG_HAS_DOT, "contains '.'"); + retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_HAS_DOT, "contains '.'"); if (has_dotdot) - retval += report(options, &item->object, FSCK_MSG_HAS_DOTDOT, "contains '..'"); + retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_HAS_DOTDOT, "contains '..'"); if (has_dotgit) - retval += report(options, &item->object, FSCK_MSG_HAS_DOTGIT, "contains '.git'"); + retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_HAS_DOTGIT, "contains '.git'"); if (has_zero_pad) - retval += report(options, &item->object, FSCK_MSG_ZERO_PADDED_FILEMODE, "contains zero-padded file modes"); + retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_ZERO_PADDED_FILEMODE, "contains zero-padded file modes"); if (has_bad_modes) - retval += report(options, &item->object, FSCK_MSG_BAD_FILEMODE, "contains bad file modes"); + retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_BAD_FILEMODE, "contains bad file modes"); if (has_dup_entries) - retval += report(options, &item->object, FSCK_MSG_DUPLICATE_ENTRIES, "contains duplicate file entries"); + retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_DUPLICATE_ENTRIES, "contains duplicate file entries"); if (not_properly_sorted) - retval += report(options, &item->object, FSCK_MSG_TREE_NOT_SORTED, "not properly sorted"); + retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_TREE_NOT_SORTED, "not properly sorted"); return retval; } @@ -693,7 +695,7 @@ static int verify_headers(const void *data, unsigned long size, for (i = 0; i < size; i++) { switch (buffer[i]) { case '\0': - return report(options, obj, + return report(options, &obj->oid, obj->type, FSCK_MSG_NUL_IN_HEADER, "unterminated header: NUL at offset %ld", i); case '\n': @@ -711,7 +713,7 @@ static int verify_headers(const void *data, unsigned long size, if (size && buffer[size - 1] == '\n') return 0; - return report(options, obj, + return report(options, &obj->oid, obj->type, FSCK_MSG_UNTERMINATED_HEADER, "unterminated header"); } @@ -725,28 +727,28 @@ static int fsck_ident(const char **ident, struct object *obj, struct fsck_option (*ident)++; if (*p == '<') - return report(options, obj, FSCK_MSG_MISSING_NAME_BEFORE_EMAIL, "invalid author/committer line - missing space before email"); + return report(options, &obj->oid, obj->type, FSCK_MSG_MISSING_NAME_BEFORE_EMAIL, "invalid author/committer line - missing space before email"); p += strcspn(p, "<>\n"); if (*p == '>') - return report(options, obj, FSCK_MSG_BAD_NAME, "invalid author/committer line - bad name"); + return report(options, &obj->oid, obj->type, FSCK_MSG_BAD_NAME, "invalid author/committer line - bad name"); if (*p != '<') - return report(options, obj, FSCK_MSG_MISSING_EMAIL, "invalid author/committer line - missing email"); + return report(options, &obj->oid, obj->type, FSCK_MSG_MISSING_EMAIL, "invalid author/committer line - missing email"); if (p[-1] != ' ') - return report(options, obj, FSCK_MSG_MISSING_SPACE_BEFORE_EMAIL, "invalid author/committer line - missing space before email"); + return report(options, &obj->oid, obj->type, FSCK_MSG_MISSING_SPACE_BEFORE_EMAIL, "invalid author/committer line - missing space before email"); p++; p += strcspn(p, "<>\n"); if (*p != '>') - return report(options, obj, FSCK_MSG_BAD_EMAIL, "invalid author/committer line - bad email"); + return report(options, &obj->oid, obj->type, FSCK_MSG_BAD_EMAIL, "invalid author/committer line - bad email"); p++; if (*p != ' ') - return report(options, obj, FSCK_MSG_MISSING_SPACE_BEFORE_DATE, "invalid author/committer line - missing space before date"); + return report(options, &obj->oid, obj->type, FSCK_MSG_MISSING_SPACE_BEFORE_DATE, "invalid author/committer line - missing space before date"); p++; if (*p == '0' && p[1] != ' ') - return report(options, obj, FSCK_MSG_ZERO_PADDED_DATE, "invalid author/committer line - zero-padded date"); + return report(options, &obj->oid, obj->type, FSCK_MSG_ZERO_PADDED_DATE, "invalid author/committer line - zero-padded date"); if (date_overflows(parse_timestamp(p, &end, 10))) - return report(options, obj, FSCK_MSG_BAD_DATE_OVERFLOW, "invalid author/committer line - date causes integer overflow"); + return report(options, &obj->oid, obj->type, FSCK_MSG_BAD_DATE_OVERFLOW, "invalid author/committer line - date causes integer overflow"); if ((end == p || *end != ' ')) - return report(options, obj, FSCK_MSG_BAD_DATE, "invalid author/committer line - bad date"); + return report(options, &obj->oid, obj->type, FSCK_MSG_BAD_DATE, "invalid author/committer line - bad date"); p = end + 1; if ((*p != '+' && *p != '-') || !isdigit(p[1]) || @@ -754,7 +756,7 @@ static int fsck_ident(const char **ident, struct object *obj, struct fsck_option !isdigit(p[3]) || !isdigit(p[4]) || (p[5] != '\n')) - return report(options, obj, FSCK_MSG_BAD_TIMEZONE, "invalid author/committer line - bad time zone"); + return report(options, &obj->oid, obj->type, FSCK_MSG_BAD_TIMEZONE, "invalid author/committer line - bad time zone"); p += 6; return 0; } @@ -772,16 +774,16 @@ static int fsck_commit(struct commit *commit, const char *buffer, return -1; if (!skip_prefix(buffer, "tree ", &buffer)) - return report(options, &commit->object, FSCK_MSG_MISSING_TREE, "invalid format - expected 'tree' line"); + return report(options, &commit->object.oid, commit->object.type, FSCK_MSG_MISSING_TREE, "invalid format - expected 'tree' line"); if (parse_oid_hex(buffer, &tree_oid, &p) || *p != '\n') { - err = report(options, &commit->object, FSCK_MSG_BAD_TREE_SHA1, "invalid 'tree' line format - bad sha1"); + err = report(options, &commit->object.oid, commit->object.type, FSCK_MSG_BAD_TREE_SHA1, "invalid 'tree' line format - bad sha1"); if (err) return err; } buffer = p + 1; while (skip_prefix(buffer, "parent ", &buffer)) { if (parse_oid_hex(buffer, &oid, &p) || *p != '\n') { - err = report(options, &commit->object, FSCK_MSG_BAD_PARENT_SHA1, "invalid 'parent' line format - bad sha1"); + err = report(options, &commit->object.oid, commit->object.type, FSCK_MSG_BAD_PARENT_SHA1, "invalid 'parent' line format - bad sha1"); if (err) return err; } @@ -795,18 +797,18 @@ static int fsck_commit(struct commit *commit, const char *buffer, return err; } if (author_count < 1) - err = report(options, &commit->object, FSCK_MSG_MISSING_AUTHOR, "invalid format - expected 'author' line"); + err = report(options, &commit->object.oid, commit->object.type, FSCK_MSG_MISSING_AUTHOR, "invalid format - expected 'author' line"); else if (author_count > 1) - err = report(options, &commit->object, FSCK_MSG_MULTIPLE_AUTHORS, "invalid format - multiple 'author' lines"); + err = report(options, &commit->object.oid, commit->object.type, FSCK_MSG_MULTIPLE_AUTHORS, "invalid format - multiple 'author' lines"); if (err) return err; if (!skip_prefix(buffer, "committer ", &buffer)) - return report(options, &commit->object, FSCK_MSG_MISSING_COMMITTER, "invalid format - expected 'committer' line"); + return report(options, &commit->object.oid, commit->object.type, FSCK_MSG_MISSING_COMMITTER, "invalid format - expected 'committer' line"); err = fsck_ident(&buffer, &commit->object, options); if (err) return err; if (memchr(buffer_begin, '\0', size)) { - err = report(options, &commit->object, FSCK_MSG_NUL_IN_COMMIT, + err = report(options, &commit->object.oid, commit->object.type, FSCK_MSG_NUL_IN_COMMIT, "NUL byte in the commit object body"); if (err) return err; @@ -828,45 +830,46 @@ static int fsck_tag(struct tag *tag, const char *buffer, goto done; if (!skip_prefix(buffer, "object ", &buffer)) { - ret = report(options, &tag->object, FSCK_MSG_MISSING_OBJECT, "invalid format - expected 'object' line"); + ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_MISSING_OBJECT, "invalid format - expected 'object' line"); goto done; } if (parse_oid_hex(buffer, &oid, &p) || *p != '\n') { - ret = report(options, &tag->object, FSCK_MSG_BAD_OBJECT_SHA1, "invalid 'object' line format - bad sha1"); + ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_BAD_OBJECT_SHA1, "invalid 'object' line format - bad sha1"); if (ret) goto done; } buffer = p + 1; if (!skip_prefix(buffer, "type ", &buffer)) { - ret = report(options, &tag->object, FSCK_MSG_MISSING_TYPE_ENTRY, "invalid format - expected 'type' line"); + ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_MISSING_TYPE_ENTRY, "invalid format - expected 'type' line"); goto done; } eol = strchr(buffer, '\n'); if (!eol) { - ret = report(options, &tag->object, FSCK_MSG_MISSING_TYPE, "invalid format - unexpected end after 'type' line"); + ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_MISSING_TYPE, "invalid format - unexpected end after 'type' line"); goto done; } if (type_from_string_gently(buffer, eol - buffer, 1) < 0) - ret = report(options, &tag->object, FSCK_MSG_BAD_TYPE, "invalid 'type' value"); + ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_BAD_TYPE, "invalid 'type' value"); if (ret) goto done; buffer = eol + 1; if (!skip_prefix(buffer, "tag ", &buffer)) { - ret = report(options, &tag->object, FSCK_MSG_MISSING_TAG_ENTRY, "invalid format - expected 'tag' line"); + ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_MISSING_TAG_ENTRY, "invalid format - expected 'tag' line"); goto done; } eol = strchr(buffer, '\n'); if (!eol) { - ret = report(options, &tag->object, FSCK_MSG_MISSING_TAG, "invalid format - unexpected end after 'type' line"); + ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_MISSING_TAG, "invalid format - unexpected end after 'type' line"); goto done; } strbuf_addf(&sb, "refs/tags/%.*s", (int)(eol - buffer), buffer); if (check_refname_format(sb.buf, 0)) { - ret = report(options, &tag->object, FSCK_MSG_BAD_TAG_NAME, - "invalid 'tag' name: %.*s", - (int)(eol - buffer), buffer); + ret = report(options, &tag->object.oid, tag->object.type, + FSCK_MSG_BAD_TAG_NAME, + "invalid 'tag' name: %.*s", + (int)(eol - buffer), buffer); if (ret) goto done; } @@ -874,7 +877,7 @@ static int fsck_tag(struct tag *tag, const char *buffer, if (!skip_prefix(buffer, "tagger ", &buffer)) { /* early tags do not contain 'tagger' lines; warn only */ - ret = report(options, &tag->object, FSCK_MSG_MISSING_TAGGER_ENTRY, "invalid format - expected 'tagger' line"); + ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_MISSING_TAGGER_ENTRY, "invalid format - expected 'tagger' line"); if (ret) goto done; } @@ -905,19 +908,22 @@ static int fsck_gitmodules_fn(const char *var, const char *value, void *vdata) name = xmemdupz(subsection, subsection_len); if (check_submodule_name(name) < 0) - data->ret |= report(data->options, data->obj, + data->ret |= report(data->options, + &data->obj->oid, data->obj->type, FSCK_MSG_GITMODULES_NAME, "disallowed submodule name: %s", name); if (!strcmp(key, "url") && value && looks_like_command_line_option(value)) - data->ret |= report(data->options, data->obj, + data->ret |= report(data->options, + &data->obj->oid, data->obj->type, FSCK_MSG_GITMODULES_URL, "disallowed submodule url: %s", value); if (!strcmp(key, "path") && value && looks_like_command_line_option(value)) - data->ret |= report(data->options, data->obj, + data->ret |= report(data->options, + &data->obj->oid, data->obj->type, FSCK_MSG_GITMODULES_PATH, "disallowed submodule path: %s", value); @@ -945,7 +951,7 @@ static int fsck_blob(struct blob *blob, const char *buf, * blob too gigantic to load into memory. Let's just consider * that an error. */ - return report(options, &blob->object, + return report(options, &blob->object.oid, blob->object.type, FSCK_MSG_GITMODULES_LARGE, ".gitmodules too large to parse"); } @@ -956,7 +962,7 @@ static int fsck_blob(struct blob *blob, const char *buf, config_opts.error_action = CONFIG_ERROR_SILENT; if (git_config_from_mem(fsck_gitmodules_fn, CONFIG_ORIGIN_BLOB, ".gitmodules", buf, size, &data, &config_opts)) - data.ret |= report(options, &blob->object, + data.ret |= report(options, &blob->object.oid, blob->object.type, FSCK_MSG_GITMODULES_PARSE, "could not parse gitmodules blob"); @@ -967,7 +973,7 @@ int fsck_object(struct object *obj, void *data, unsigned long size, struct fsck_options *options) { if (!obj) - return report(options, obj, FSCK_MSG_BAD_OBJECT_SHA1, "no valid object to fsck"); + return report(options, NULL, OBJ_NONE, FSCK_MSG_BAD_OBJECT_SHA1, "no valid object to fsck"); if (obj->type == OBJ_BLOB) return fsck_blob((struct blob *)obj, data, size, options); @@ -980,8 +986,10 @@ int fsck_object(struct object *obj, void *data, unsigned long size, return fsck_tag((struct tag *) obj, (const char *) data, size, options); - return report(options, obj, FSCK_MSG_UNKNOWN_TYPE, "unknown type '%d' (internal fsck error)", - obj->type); + return report(options, &obj->oid, obj->type, + FSCK_MSG_UNKNOWN_TYPE, + "unknown type '%d' (internal fsck error)", + obj->type); } int fsck_error_function(struct fsck_options *o, @@ -1016,7 +1024,7 @@ int fsck_finish(struct fsck_options *options) blob = lookup_blob(the_repository, oid); if (!blob) { struct object *obj = lookup_unknown_object(oid); - ret |= report(options, obj, + ret |= report(options, &obj->oid, obj->type, FSCK_MSG_GITMODULES_BLOB, "non-blob found at .gitmodules"); continue; @@ -1026,7 +1034,8 @@ int fsck_finish(struct fsck_options *options) if (!buf) { if (is_promisor_object(&blob->object.oid)) continue; - ret |= report(options, &blob->object, + ret |= report(options, + &blob->object.oid, blob->object.type, FSCK_MSG_GITMODULES_MISSING, "unable to read .gitmodules blob"); continue; @@ -1035,7 +1044,8 @@ int fsck_finish(struct fsck_options *options) if (type == OBJ_BLOB) ret |= fsck_blob(blob, buf, size, options); else - ret |= report(options, &blob->object, + ret |= report(options, + &blob->object.oid, blob->object.type, FSCK_MSG_GITMODULES_BLOB, "non-blob found at .gitmodules"); free(buf); From 6da40b22cae536211abcb943ff4f316e9129fcc9 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 18 Oct 2019 00:59:29 -0400 Subject: [PATCH 085/953] fsck: accept an oid instead of a "struct blob" for fsck_blob() We don't actually need any information from the object struct except its oid (and the type, of course, but that's implicitly OBJ_BLOB). This gives our callers more flexibility to drop the object structs, too. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- fsck.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/fsck.c b/fsck.c index 465247be71fc4d..6e9640a1a6fcd9 100644 --- a/fsck.c +++ b/fsck.c @@ -890,7 +890,7 @@ static int fsck_tag(struct tag *tag, const char *buffer, } struct fsck_gitmodules_data { - struct object *obj; + const struct object_id *oid; struct fsck_options *options; int ret; }; @@ -909,21 +909,21 @@ static int fsck_gitmodules_fn(const char *var, const char *value, void *vdata) name = xmemdupz(subsection, subsection_len); if (check_submodule_name(name) < 0) data->ret |= report(data->options, - &data->obj->oid, data->obj->type, + data->oid, OBJ_BLOB, FSCK_MSG_GITMODULES_NAME, "disallowed submodule name: %s", name); if (!strcmp(key, "url") && value && looks_like_command_line_option(value)) data->ret |= report(data->options, - &data->obj->oid, data->obj->type, + data->oid, OBJ_BLOB, FSCK_MSG_GITMODULES_URL, "disallowed submodule url: %s", value); if (!strcmp(key, "path") && value && looks_like_command_line_option(value)) data->ret |= report(data->options, - &data->obj->oid, data->obj->type, + data->oid, OBJ_BLOB, FSCK_MSG_GITMODULES_PATH, "disallowed submodule path: %s", value); @@ -932,17 +932,17 @@ static int fsck_gitmodules_fn(const char *var, const char *value, void *vdata) return 0; } -static int fsck_blob(struct blob *blob, const char *buf, +static int fsck_blob(const struct object_id *oid, const char *buf, unsigned long size, struct fsck_options *options) { struct fsck_gitmodules_data data; struct config_options config_opts = { 0 }; - if (!oidset_contains(&gitmodules_found, &blob->object.oid)) + if (!oidset_contains(&gitmodules_found, oid)) return 0; - oidset_insert(&gitmodules_done, &blob->object.oid); + oidset_insert(&gitmodules_done, oid); - if (object_on_skiplist(options, &blob->object.oid)) + if (object_on_skiplist(options, oid)) return 0; if (!buf) { @@ -951,18 +951,18 @@ static int fsck_blob(struct blob *blob, const char *buf, * blob too gigantic to load into memory. Let's just consider * that an error. */ - return report(options, &blob->object.oid, blob->object.type, + return report(options, oid, OBJ_BLOB, FSCK_MSG_GITMODULES_LARGE, ".gitmodules too large to parse"); } - data.obj = &blob->object; + data.oid = oid; data.options = options; data.ret = 0; config_opts.error_action = CONFIG_ERROR_SILENT; if (git_config_from_mem(fsck_gitmodules_fn, CONFIG_ORIGIN_BLOB, ".gitmodules", buf, size, &data, &config_opts)) - data.ret |= report(options, &blob->object.oid, blob->object.type, + data.ret |= report(options, oid, OBJ_BLOB, FSCK_MSG_GITMODULES_PARSE, "could not parse gitmodules blob"); @@ -976,7 +976,7 @@ int fsck_object(struct object *obj, void *data, unsigned long size, return report(options, NULL, OBJ_NONE, FSCK_MSG_BAD_OBJECT_SHA1, "no valid object to fsck"); if (obj->type == OBJ_BLOB) - return fsck_blob((struct blob *)obj, data, size, options); + return fsck_blob(&obj->oid, data, size, options); if (obj->type == OBJ_TREE) return fsck_tree((struct tree *) obj, data, size, options); if (obj->type == OBJ_COMMIT) @@ -1042,7 +1042,7 @@ int fsck_finish(struct fsck_options *options) } if (type == OBJ_BLOB) - ret |= fsck_blob(blob, buf, size, options); + ret |= fsck_blob(&blob->object.oid, buf, size, options); else ret |= report(options, &blob->object.oid, blob->object.type, From b8b00f1693c149ba03e34d56d8804256e74f6eab Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 18 Oct 2019 00:59:54 -0400 Subject: [PATCH 086/953] fsck: drop blob struct from fsck_finish() Since fsck_blob() no longer requires us to have a "struct blob", we don't need to create one. Which also means we don't need to worry about handling the case that lookup_blob() returns NULL (we'll still catch wrongly-identified blobs when we read the actual object contents and type from disk). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- fsck.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/fsck.c b/fsck.c index 6e9640a1a6fcd9..4ff0ceb4aca6a9 100644 --- a/fsck.c +++ b/fsck.c @@ -1013,7 +1013,6 @@ int fsck_finish(struct fsck_options *options) oidset_iter_init(&gitmodules_found, &iter); while ((oid = oidset_iter_next(&iter))) { - struct blob *blob; enum object_type type; unsigned long size; char *buf; @@ -1021,31 +1020,22 @@ int fsck_finish(struct fsck_options *options) if (oidset_contains(&gitmodules_done, oid)) continue; - blob = lookup_blob(the_repository, oid); - if (!blob) { - struct object *obj = lookup_unknown_object(oid); - ret |= report(options, &obj->oid, obj->type, - FSCK_MSG_GITMODULES_BLOB, - "non-blob found at .gitmodules"); - continue; - } - buf = read_object_file(oid, &type, &size); if (!buf) { - if (is_promisor_object(&blob->object.oid)) + if (is_promisor_object(oid)) continue; ret |= report(options, - &blob->object.oid, blob->object.type, + oid, OBJ_BLOB, FSCK_MSG_GITMODULES_MISSING, "unable to read .gitmodules blob"); continue; } if (type == OBJ_BLOB) - ret |= fsck_blob(&blob->object.oid, buf, size, options); + ret |= fsck_blob(oid, buf, size, options); else ret |= report(options, - &blob->object.oid, blob->object.type, + oid, type, FSCK_MSG_GITMODULES_BLOB, "non-blob found at .gitmodules"); free(buf); From 7854399366fa36854de8e6962a441b02009c10e4 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 18 Oct 2019 01:00:04 -0400 Subject: [PATCH 087/953] fsck: don't require an object struct for fsck_ident() The only thing we do with the struct is pass its oid and type to report(). We can just take those explicitly, which gives our callers more flexibility. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- fsck.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/fsck.c b/fsck.c index 4ff0ceb4aca6a9..e1d06fb210b08b 100644 --- a/fsck.c +++ b/fsck.c @@ -717,7 +717,9 @@ static int verify_headers(const void *data, unsigned long size, FSCK_MSG_UNTERMINATED_HEADER, "unterminated header"); } -static int fsck_ident(const char **ident, struct object *obj, struct fsck_options *options) +static int fsck_ident(const char **ident, + const struct object_id *oid, enum object_type type, + struct fsck_options *options) { const char *p = *ident; char *end; @@ -727,28 +729,28 @@ static int fsck_ident(const char **ident, struct object *obj, struct fsck_option (*ident)++; if (*p == '<') - return report(options, &obj->oid, obj->type, FSCK_MSG_MISSING_NAME_BEFORE_EMAIL, "invalid author/committer line - missing space before email"); + return report(options, oid, type, FSCK_MSG_MISSING_NAME_BEFORE_EMAIL, "invalid author/committer line - missing space before email"); p += strcspn(p, "<>\n"); if (*p == '>') - return report(options, &obj->oid, obj->type, FSCK_MSG_BAD_NAME, "invalid author/committer line - bad name"); + return report(options, oid, type, FSCK_MSG_BAD_NAME, "invalid author/committer line - bad name"); if (*p != '<') - return report(options, &obj->oid, obj->type, FSCK_MSG_MISSING_EMAIL, "invalid author/committer line - missing email"); + return report(options, oid, type, FSCK_MSG_MISSING_EMAIL, "invalid author/committer line - missing email"); if (p[-1] != ' ') - return report(options, &obj->oid, obj->type, FSCK_MSG_MISSING_SPACE_BEFORE_EMAIL, "invalid author/committer line - missing space before email"); + return report(options, oid, type, FSCK_MSG_MISSING_SPACE_BEFORE_EMAIL, "invalid author/committer line - missing space before email"); p++; p += strcspn(p, "<>\n"); if (*p != '>') - return report(options, &obj->oid, obj->type, FSCK_MSG_BAD_EMAIL, "invalid author/committer line - bad email"); + return report(options, oid, type, FSCK_MSG_BAD_EMAIL, "invalid author/committer line - bad email"); p++; if (*p != ' ') - return report(options, &obj->oid, obj->type, FSCK_MSG_MISSING_SPACE_BEFORE_DATE, "invalid author/committer line - missing space before date"); + return report(options, oid, type, FSCK_MSG_MISSING_SPACE_BEFORE_DATE, "invalid author/committer line - missing space before date"); p++; if (*p == '0' && p[1] != ' ') - return report(options, &obj->oid, obj->type, FSCK_MSG_ZERO_PADDED_DATE, "invalid author/committer line - zero-padded date"); + return report(options, oid, type, FSCK_MSG_ZERO_PADDED_DATE, "invalid author/committer line - zero-padded date"); if (date_overflows(parse_timestamp(p, &end, 10))) - return report(options, &obj->oid, obj->type, FSCK_MSG_BAD_DATE_OVERFLOW, "invalid author/committer line - date causes integer overflow"); + return report(options, oid, type, FSCK_MSG_BAD_DATE_OVERFLOW, "invalid author/committer line - date causes integer overflow"); if ((end == p || *end != ' ')) - return report(options, &obj->oid, obj->type, FSCK_MSG_BAD_DATE, "invalid author/committer line - bad date"); + return report(options, oid, type, FSCK_MSG_BAD_DATE, "invalid author/committer line - bad date"); p = end + 1; if ((*p != '+' && *p != '-') || !isdigit(p[1]) || @@ -756,7 +758,7 @@ static int fsck_ident(const char **ident, struct object *obj, struct fsck_option !isdigit(p[3]) || !isdigit(p[4]) || (p[5] != '\n')) - return report(options, &obj->oid, obj->type, FSCK_MSG_BAD_TIMEZONE, "invalid author/committer line - bad time zone"); + return report(options, oid, type, FSCK_MSG_BAD_TIMEZONE, "invalid author/committer line - bad time zone"); p += 6; return 0; } @@ -792,7 +794,7 @@ static int fsck_commit(struct commit *commit, const char *buffer, author_count = 0; while (skip_prefix(buffer, "author ", &buffer)) { author_count++; - err = fsck_ident(&buffer, &commit->object, options); + err = fsck_ident(&buffer, &commit->object.oid, commit->object.type, options); if (err) return err; } @@ -804,7 +806,7 @@ static int fsck_commit(struct commit *commit, const char *buffer, return err; if (!skip_prefix(buffer, "committer ", &buffer)) return report(options, &commit->object.oid, commit->object.type, FSCK_MSG_MISSING_COMMITTER, "invalid format - expected 'committer' line"); - err = fsck_ident(&buffer, &commit->object, options); + err = fsck_ident(&buffer, &commit->object.oid, commit->object.type, options); if (err) return err; if (memchr(buffer_begin, '\0', size)) { @@ -882,7 +884,7 @@ static int fsck_tag(struct tag *tag, const char *buffer, goto done; } else - ret = fsck_ident(&buffer, &tag->object, options); + ret = fsck_ident(&buffer, &tag->object.oid, tag->object.type, options); done: strbuf_release(&sb); From cc579000bf289cea7f9c2e34fcb9cf67e8104616 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 18 Oct 2019 01:00:50 -0400 Subject: [PATCH 088/953] fsck: don't require an object struct in verify_headers() We only need the oid and type to pass on to report(). Let's accept the broken-out parameters to give our callers more flexibility. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- fsck.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/fsck.c b/fsck.c index e1d06fb210b08b..50c93200edab06 100644 --- a/fsck.c +++ b/fsck.c @@ -687,7 +687,8 @@ static int fsck_tree(struct tree *item, } static int verify_headers(const void *data, unsigned long size, - struct object *obj, struct fsck_options *options) + const struct object_id *oid, enum object_type type, + struct fsck_options *options) { const char *buffer = (const char *)data; unsigned long i; @@ -695,7 +696,7 @@ static int verify_headers(const void *data, unsigned long size, for (i = 0; i < size; i++) { switch (buffer[i]) { case '\0': - return report(options, &obj->oid, obj->type, + return report(options, oid, type, FSCK_MSG_NUL_IN_HEADER, "unterminated header: NUL at offset %ld", i); case '\n': @@ -713,7 +714,7 @@ static int verify_headers(const void *data, unsigned long size, if (size && buffer[size - 1] == '\n') return 0; - return report(options, &obj->oid, obj->type, + return report(options, oid, type, FSCK_MSG_UNTERMINATED_HEADER, "unterminated header"); } @@ -772,7 +773,8 @@ static int fsck_commit(struct commit *commit, const char *buffer, const char *buffer_begin = buffer; const char *p; - if (verify_headers(buffer, size, &commit->object, options)) + if (verify_headers(buffer, size, &commit->object.oid, + commit->object.type, options)) return -1; if (!skip_prefix(buffer, "tree ", &buffer)) @@ -827,7 +829,7 @@ static int fsck_tag(struct tag *tag, const char *buffer, struct strbuf sb = STRBUF_INIT; const char *p; - ret = verify_headers(buffer, size, &tag->object, options); + ret = verify_headers(buffer, size, &tag->object.oid, tag->object.type, options); if (ret) goto done; From f648ee70885ce09558101640f540ebec2013cd80 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 18 Oct 2019 01:00:59 -0400 Subject: [PATCH 089/953] fsck: rename vague "oid" local variables In fsck_commit() and fsck_tag(), we have local "oid" variables used for parsing parent and tagged-object oids. Let's give these more specific names in preparation for the functions taking an "oid" parameter for the object we're checking. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- fsck.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fsck.c b/fsck.c index 50c93200edab06..42e7d1f71f32b1 100644 --- a/fsck.c +++ b/fsck.c @@ -767,7 +767,7 @@ static int fsck_ident(const char **ident, static int fsck_commit(struct commit *commit, const char *buffer, unsigned long size, struct fsck_options *options) { - struct object_id tree_oid, oid; + struct object_id tree_oid, parent_oid; unsigned author_count; int err; const char *buffer_begin = buffer; @@ -786,7 +786,7 @@ static int fsck_commit(struct commit *commit, const char *buffer, } buffer = p + 1; while (skip_prefix(buffer, "parent ", &buffer)) { - if (parse_oid_hex(buffer, &oid, &p) || *p != '\n') { + if (parse_oid_hex(buffer, &parent_oid, &p) || *p != '\n') { err = report(options, &commit->object.oid, commit->object.type, FSCK_MSG_BAD_PARENT_SHA1, "invalid 'parent' line format - bad sha1"); if (err) return err; @@ -823,7 +823,7 @@ static int fsck_commit(struct commit *commit, const char *buffer, static int fsck_tag(struct tag *tag, const char *buffer, unsigned long size, struct fsck_options *options) { - struct object_id oid; + struct object_id tagged_oid; int ret = 0; char *eol; struct strbuf sb = STRBUF_INIT; @@ -837,7 +837,7 @@ static int fsck_tag(struct tag *tag, const char *buffer, ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_MISSING_OBJECT, "invalid format - expected 'object' line"); goto done; } - if (parse_oid_hex(buffer, &oid, &p) || *p != '\n') { + if (parse_oid_hex(buffer, &tagged_oid, &p) || *p != '\n') { ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_BAD_OBJECT_SHA1, "invalid 'object' line format - bad sha1"); if (ret) goto done; From 103fb6d43bd6ec7049564cc39e4c0e495f9bfcb8 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 18 Oct 2019 01:01:26 -0400 Subject: [PATCH 090/953] fsck: accept an oid instead of a "struct tag" for fsck_tag() We don't actually look at the tag struct in fsck_tag() beyond its oid and type (which is obviously OBJ_TAG). Just taking an oid gives our callers more flexibility to avoid creating or parsing a struct, and makes it clear that we are fscking just what is in the buffer, not any pre-parsed bits from the struct. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- fsck.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/fsck.c b/fsck.c index 42e7d1f71f32b1..38be501278c5e5 100644 --- a/fsck.c +++ b/fsck.c @@ -820,7 +820,7 @@ static int fsck_commit(struct commit *commit, const char *buffer, return 0; } -static int fsck_tag(struct tag *tag, const char *buffer, +static int fsck_tag(const struct object_id *oid, const char *buffer, unsigned long size, struct fsck_options *options) { struct object_id tagged_oid; @@ -829,48 +829,48 @@ static int fsck_tag(struct tag *tag, const char *buffer, struct strbuf sb = STRBUF_INIT; const char *p; - ret = verify_headers(buffer, size, &tag->object.oid, tag->object.type, options); + ret = verify_headers(buffer, size, oid, OBJ_TAG, options); if (ret) goto done; if (!skip_prefix(buffer, "object ", &buffer)) { - ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_MISSING_OBJECT, "invalid format - expected 'object' line"); + ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_OBJECT, "invalid format - expected 'object' line"); goto done; } if (parse_oid_hex(buffer, &tagged_oid, &p) || *p != '\n') { - ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_BAD_OBJECT_SHA1, "invalid 'object' line format - bad sha1"); + ret = report(options, oid, OBJ_TAG, FSCK_MSG_BAD_OBJECT_SHA1, "invalid 'object' line format - bad sha1"); if (ret) goto done; } buffer = p + 1; if (!skip_prefix(buffer, "type ", &buffer)) { - ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_MISSING_TYPE_ENTRY, "invalid format - expected 'type' line"); + ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_TYPE_ENTRY, "invalid format - expected 'type' line"); goto done; } eol = strchr(buffer, '\n'); if (!eol) { - ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_MISSING_TYPE, "invalid format - unexpected end after 'type' line"); + ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_TYPE, "invalid format - unexpected end after 'type' line"); goto done; } if (type_from_string_gently(buffer, eol - buffer, 1) < 0) - ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_BAD_TYPE, "invalid 'type' value"); + ret = report(options, oid, OBJ_TAG, FSCK_MSG_BAD_TYPE, "invalid 'type' value"); if (ret) goto done; buffer = eol + 1; if (!skip_prefix(buffer, "tag ", &buffer)) { - ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_MISSING_TAG_ENTRY, "invalid format - expected 'tag' line"); + ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_TAG_ENTRY, "invalid format - expected 'tag' line"); goto done; } eol = strchr(buffer, '\n'); if (!eol) { - ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_MISSING_TAG, "invalid format - unexpected end after 'type' line"); + ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_TAG, "invalid format - unexpected end after 'type' line"); goto done; } strbuf_addf(&sb, "refs/tags/%.*s", (int)(eol - buffer), buffer); if (check_refname_format(sb.buf, 0)) { - ret = report(options, &tag->object.oid, tag->object.type, + ret = report(options, oid, OBJ_TAG, FSCK_MSG_BAD_TAG_NAME, "invalid 'tag' name: %.*s", (int)(eol - buffer), buffer); @@ -881,12 +881,12 @@ static int fsck_tag(struct tag *tag, const char *buffer, if (!skip_prefix(buffer, "tagger ", &buffer)) { /* early tags do not contain 'tagger' lines; warn only */ - ret = report(options, &tag->object.oid, tag->object.type, FSCK_MSG_MISSING_TAGGER_ENTRY, "invalid format - expected 'tagger' line"); + ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_TAGGER_ENTRY, "invalid format - expected 'tagger' line"); if (ret) goto done; } else - ret = fsck_ident(&buffer, &tag->object.oid, tag->object.type, options); + ret = fsck_ident(&buffer, oid, OBJ_TAG, options); done: strbuf_release(&sb); @@ -987,8 +987,7 @@ int fsck_object(struct object *obj, void *data, unsigned long size, return fsck_commit((struct commit *) obj, (const char *) data, size, options); if (obj->type == OBJ_TAG) - return fsck_tag((struct tag *) obj, (const char *) data, - size, options); + return fsck_tag(&obj->oid, data, size, options); return report(options, &obj->oid, obj->type, FSCK_MSG_UNKNOWN_TYPE, From c5b4269b57df38b26a3b851833e94abce08583e7 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 18 Oct 2019 01:01:48 -0400 Subject: [PATCH 091/953] fsck: accept an oid instead of a "struct commit" for fsck_commit() We don't actually look at the commit struct in fsck_commit() beyond its oid and type (which is obviously OBJ_COMMIT). Just taking an oid gives our callers more flexibility to avoid creating or parsing a struct, and makes it clear that we are fscking just what is in the buffer, not any pre-parsed bits from the struct. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- fsck.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/fsck.c b/fsck.c index 38be501278c5e5..f8c5bbe891d706 100644 --- a/fsck.c +++ b/fsck.c @@ -764,8 +764,9 @@ static int fsck_ident(const char **ident, return 0; } -static int fsck_commit(struct commit *commit, const char *buffer, - unsigned long size, struct fsck_options *options) +static int fsck_commit(const struct object_id *oid, + const char *buffer, unsigned long size, + struct fsck_options *options) { struct object_id tree_oid, parent_oid; unsigned author_count; @@ -773,21 +774,20 @@ static int fsck_commit(struct commit *commit, const char *buffer, const char *buffer_begin = buffer; const char *p; - if (verify_headers(buffer, size, &commit->object.oid, - commit->object.type, options)) + if (verify_headers(buffer, size, oid, OBJ_COMMIT, options)) return -1; if (!skip_prefix(buffer, "tree ", &buffer)) - return report(options, &commit->object.oid, commit->object.type, FSCK_MSG_MISSING_TREE, "invalid format - expected 'tree' line"); + return report(options, oid, OBJ_COMMIT, FSCK_MSG_MISSING_TREE, "invalid format - expected 'tree' line"); if (parse_oid_hex(buffer, &tree_oid, &p) || *p != '\n') { - err = report(options, &commit->object.oid, commit->object.type, FSCK_MSG_BAD_TREE_SHA1, "invalid 'tree' line format - bad sha1"); + err = report(options, oid, OBJ_COMMIT, FSCK_MSG_BAD_TREE_SHA1, "invalid 'tree' line format - bad sha1"); if (err) return err; } buffer = p + 1; while (skip_prefix(buffer, "parent ", &buffer)) { if (parse_oid_hex(buffer, &parent_oid, &p) || *p != '\n') { - err = report(options, &commit->object.oid, commit->object.type, FSCK_MSG_BAD_PARENT_SHA1, "invalid 'parent' line format - bad sha1"); + err = report(options, oid, OBJ_COMMIT, FSCK_MSG_BAD_PARENT_SHA1, "invalid 'parent' line format - bad sha1"); if (err) return err; } @@ -796,23 +796,23 @@ static int fsck_commit(struct commit *commit, const char *buffer, author_count = 0; while (skip_prefix(buffer, "author ", &buffer)) { author_count++; - err = fsck_ident(&buffer, &commit->object.oid, commit->object.type, options); + err = fsck_ident(&buffer, oid, OBJ_COMMIT, options); if (err) return err; } if (author_count < 1) - err = report(options, &commit->object.oid, commit->object.type, FSCK_MSG_MISSING_AUTHOR, "invalid format - expected 'author' line"); + err = report(options, oid, OBJ_COMMIT, FSCK_MSG_MISSING_AUTHOR, "invalid format - expected 'author' line"); else if (author_count > 1) - err = report(options, &commit->object.oid, commit->object.type, FSCK_MSG_MULTIPLE_AUTHORS, "invalid format - multiple 'author' lines"); + err = report(options, oid, OBJ_COMMIT, FSCK_MSG_MULTIPLE_AUTHORS, "invalid format - multiple 'author' lines"); if (err) return err; if (!skip_prefix(buffer, "committer ", &buffer)) - return report(options, &commit->object.oid, commit->object.type, FSCK_MSG_MISSING_COMMITTER, "invalid format - expected 'committer' line"); - err = fsck_ident(&buffer, &commit->object.oid, commit->object.type, options); + return report(options, oid, OBJ_COMMIT, FSCK_MSG_MISSING_COMMITTER, "invalid format - expected 'committer' line"); + err = fsck_ident(&buffer, oid, OBJ_COMMIT, options); if (err) return err; if (memchr(buffer_begin, '\0', size)) { - err = report(options, &commit->object.oid, commit->object.type, FSCK_MSG_NUL_IN_COMMIT, + err = report(options, oid, OBJ_COMMIT, FSCK_MSG_NUL_IN_COMMIT, "NUL byte in the commit object body"); if (err) return err; @@ -984,8 +984,7 @@ int fsck_object(struct object *obj, void *data, unsigned long size, if (obj->type == OBJ_TREE) return fsck_tree((struct tree *) obj, data, size, options); if (obj->type == OBJ_COMMIT) - return fsck_commit((struct commit *) obj, (const char *) data, - size, options); + return fsck_commit(&obj->oid, data, size, options); if (obj->type == OBJ_TAG) return fsck_tag(&obj->oid, data, size, options); From b2f2039c2b23ff2a417d404f205b9741870d4acd Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 18 Oct 2019 01:02:08 -0400 Subject: [PATCH 092/953] fsck: accept an oid instead of a "struct tree" for fsck_tree() We don't actually look at the tree struct in fsck_tree() beyond its oid and type (which is obviously OBJ_TREE). Just taking an oid gives our callers more flexibility to avoid creating a struct, and makes it clear that we are fscking just what is in the buffer, not any pre-parsed bits from the struct. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- fsck.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/fsck.c b/fsck.c index f8c5bbe891d706..ac4ba4c8e8899d 100644 --- a/fsck.c +++ b/fsck.c @@ -566,7 +566,7 @@ static int verify_ordered(unsigned mode1, const char *name1, unsigned mode2, con return c1 < c2 ? 0 : TREE_UNORDERED; } -static int fsck_tree(struct tree *item, +static int fsck_tree(const struct object_id *oid, const char *buffer, unsigned long size, struct fsck_options *options) { @@ -586,7 +586,7 @@ static int fsck_tree(struct tree *item, const char *o_name; if (init_tree_desc_gently(&desc, buffer, size)) { - retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_BAD_TREE, "cannot be parsed as a tree"); + retval += report(options, oid, OBJ_TREE, FSCK_MSG_BAD_TREE, "cannot be parsed as a tree"); return retval; } @@ -613,13 +613,13 @@ static int fsck_tree(struct tree *item, oidset_insert(&gitmodules_found, oid); else retval += report(options, - &item->object.oid, item->object.type, + oid, OBJ_TREE, FSCK_MSG_GITMODULES_SYMLINK, ".gitmodules is a symbolic link"); } if (update_tree_entry_gently(&desc)) { - retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_BAD_TREE, "cannot be parsed as a tree"); + retval += report(options, oid, OBJ_TREE, FSCK_MSG_BAD_TREE, "cannot be parsed as a tree"); break; } @@ -664,25 +664,25 @@ static int fsck_tree(struct tree *item, } if (has_null_sha1) - retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_NULL_SHA1, "contains entries pointing to null sha1"); + retval += report(options, oid, OBJ_TREE, FSCK_MSG_NULL_SHA1, "contains entries pointing to null sha1"); if (has_full_path) - retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_FULL_PATHNAME, "contains full pathnames"); + retval += report(options, oid, OBJ_TREE, FSCK_MSG_FULL_PATHNAME, "contains full pathnames"); if (has_empty_name) - retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_EMPTY_NAME, "contains empty pathname"); + retval += report(options, oid, OBJ_TREE, FSCK_MSG_EMPTY_NAME, "contains empty pathname"); if (has_dot) - retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_HAS_DOT, "contains '.'"); + retval += report(options, oid, OBJ_TREE, FSCK_MSG_HAS_DOT, "contains '.'"); if (has_dotdot) - retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_HAS_DOTDOT, "contains '..'"); + retval += report(options, oid, OBJ_TREE, FSCK_MSG_HAS_DOTDOT, "contains '..'"); if (has_dotgit) - retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_HAS_DOTGIT, "contains '.git'"); + retval += report(options, oid, OBJ_TREE, FSCK_MSG_HAS_DOTGIT, "contains '.git'"); if (has_zero_pad) - retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_ZERO_PADDED_FILEMODE, "contains zero-padded file modes"); + retval += report(options, oid, OBJ_TREE, FSCK_MSG_ZERO_PADDED_FILEMODE, "contains zero-padded file modes"); if (has_bad_modes) - retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_BAD_FILEMODE, "contains bad file modes"); + retval += report(options, oid, OBJ_TREE, FSCK_MSG_BAD_FILEMODE, "contains bad file modes"); if (has_dup_entries) - retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_DUPLICATE_ENTRIES, "contains duplicate file entries"); + retval += report(options, oid, OBJ_TREE, FSCK_MSG_DUPLICATE_ENTRIES, "contains duplicate file entries"); if (not_properly_sorted) - retval += report(options, &item->object.oid, item->object.type, FSCK_MSG_TREE_NOT_SORTED, "not properly sorted"); + retval += report(options, oid, OBJ_TREE, FSCK_MSG_TREE_NOT_SORTED, "not properly sorted"); return retval; } @@ -982,7 +982,7 @@ int fsck_object(struct object *obj, void *data, unsigned long size, if (obj->type == OBJ_BLOB) return fsck_blob(&obj->oid, data, size, options); if (obj->type == OBJ_TREE) - return fsck_tree((struct tree *) obj, data, size, options); + return fsck_tree(&obj->oid, data, size, options); if (obj->type == OBJ_COMMIT) return fsck_commit(&obj->oid, data, size, options); if (obj->type == OBJ_TAG) From 8dd327b2465c5d2af62b85cb7974ceec41ab25f2 Mon Sep 17 00:00:00 2001 From: Mihail Atanassov Date: Mon, 28 Oct 2019 22:01:22 +0000 Subject: [PATCH 093/953] Documentation/git-bisect.txt: add --no-ff to merge command The hotfix application example uses `git merge --no-commit` to apply temporary changes to the working tree during a bisect operation. In some situations this can be a fast-forward and `merge` will apply the hotfix branch's commits regardless of `--no-commit` (as documented in the `git merge` manual). In the pathological case this will make a `git bisect run` invocation loop indefinitely between the first bisect step and the fast-forwarded post-merge HEAD. Add `--no-ff` to the merge command to avoid this issue. Signed-off-by: Mihail Atanassov Reviewed-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- Documentation/git-bisect.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/git-bisect.txt b/Documentation/git-bisect.txt index 4b45d837a7e7c5..7586c5a8437edf 100644 --- a/Documentation/git-bisect.txt +++ b/Documentation/git-bisect.txt @@ -413,7 +413,7 @@ $ cat ~/test.sh # tweak the working tree by merging the hot-fix branch # and then attempt a build -if git merge --no-commit hot-fix && +if git merge --no-commit --no-ff hot-fix && make then # run project specific test and report its status From 6c020421390e9470b6e1a2e16e6978c239973bb5 Mon Sep 17 00:00:00 2001 From: Miriam Rubio Date: Mon, 28 Oct 2019 17:55:23 +0100 Subject: [PATCH 094/953] clone: rename static function `dir_exists()`. builtin/clone.c has a static function dir_exists() that checks if a given path exists on the filesystem. It returns true (and it is correct for it to return true) when the given path exists as a non-directory (e.g. a regular file). This is confusing. What the caller wants to check, and what this function wants to return, is if the path exists, so rename it to path_exists(). Signed-off-by: Miriam Rubio Signed-off-by: Junio C Hamano --- builtin/clone.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/builtin/clone.c b/builtin/clone.c index f665b28ccccfac..b2644209736c03 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -900,7 +900,7 @@ static void dissociate_from_references(void) free(alternates); } -static int dir_exists(const char *path) +static int path_exists(const char *path) { struct stat sb; return !stat(path, &sb); @@ -982,7 +982,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) dir = guess_dir_name(repo_name, is_bundle, option_bare); strip_trailing_slashes(dir); - dest_exists = dir_exists(dir); + dest_exists = path_exists(dir); if (dest_exists && !is_empty_dir(dir)) die(_("destination path '%s' already exists and is not " "an empty directory."), dir); @@ -993,7 +993,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) work_tree = NULL; else { work_tree = getenv("GIT_WORK_TREE"); - if (work_tree && dir_exists(work_tree)) + if (work_tree && path_exists(work_tree)) die(_("working tree '%s' already exists."), work_tree); } @@ -1021,7 +1021,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) } if (real_git_dir) { - if (dir_exists(real_git_dir)) + if (path_exists(real_git_dir)) junk_git_dir_flags |= REMOVE_DIR_KEEP_TOPLEVEL; junk_git_dir = real_git_dir; } else { From 44ae131e3848a290b165ff0efffa1c504034f776 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?SZEDER=20G=C3=A1bor?= Date: Mon, 28 Oct 2019 11:52:41 +0100 Subject: [PATCH 095/953] builtin/blame.c: remove '--indent-heuristic' from usage string MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The indent heuristic is our default diff heuristic since 33de716387 (diff: enable indent heuristic by default, 2017-05-08), but the usage string of 'git blame' still mentions it as "experimental heuristic". We could simply update the short help associated with the option, but according to the comment above the option's declaration it was "only included here to get included in the "-h" output". That made sense while the feature was still experimental and we wanted to give it more exposure, but nowadays it's unnecessary. So let's rather remove the '--indent-heuristic' option from 'git blame's usage string. Note that 'git blame' will still accept this option, as it is parsed in parse_revision_opt(). Astute readers may notice that this patch removes a comment mentioning "the following two options", but it only removes one option. The reason is that the comment is outdated: that other options was '--compaction-heuristic', and it has already been removed in 3cde4e02ee (diff: retire "compaction" heuristics, 2016-12-23), but that commit forgot to update this comment. Signed-off-by: SZEDER Gábor Signed-off-by: Junio C Hamano --- builtin/blame.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/builtin/blame.c b/builtin/blame.c index b6534d4dea9ad8..a19f2802d7f84b 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -862,14 +862,6 @@ int cmd_blame(int argc, const char **argv, const char *prefix) OPT_STRING_LIST(0, "ignore-revs-file", &ignore_revs_file_list, N_("file"), N_("Ignore revisions from ")), OPT_BIT(0, "color-lines", &output_option, N_("color redundant metadata from previous line differently"), OUTPUT_COLOR_LINE), OPT_BIT(0, "color-by-age", &output_option, N_("color lines by age"), OUTPUT_SHOW_AGE_WITH_COLOR), - - /* - * The following two options are parsed by parse_revision_opt() - * and are only included here to get included in the "-h" - * output: - */ - { OPTION_LOWLEVEL_CALLBACK, 0, "indent-heuristic", NULL, NULL, N_("Use an experimental heuristic to improve diffs"), PARSE_OPT_NOARG, NULL, 0, parse_opt_unknown_cb }, - OPT_BIT(0, "minimal", &xdl_opts, N_("Spend extra cycles to find better match"), XDF_NEED_MINIMAL), OPT_STRING('S', NULL, &revs_file, N_("file"), N_("Use revisions from instead of calling git-rev-list")), OPT_STRING(0, "contents", &contents_from, N_("file"), N_("Use 's contents as the final image")), From 3ce47211a6ecae0ebe241779ef7112ee21f04a74 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 28 Oct 2019 12:57:17 +0000 Subject: [PATCH 096/953] t1400: wrap setup code in test case Without this, you cannot use `--run=<...>` to skip that part, and a run with `--run=0` (which is a common way to determine the test case number corresponding to a given test case title). Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- t/t1400-update-ref.sh | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 1fbd94040818ce..69a7f27311c323 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -344,14 +344,16 @@ test_expect_success "verifying $m's log (logged by config)" ' test_cmp expect .git/logs/$m ' -git update-ref $m $D -cat >.git/logs/$m < 1117150320 -0500 -$C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150350 -0500 -$A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500 -$F $Z $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500 -$Z $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500 -EOF +test_expect_success 'set up for querying the reflog' ' + git update-ref $m $D && + cat >.git/logs/$m <<-EOF + $Z $C $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500 + $C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150350 -0500 + $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500 + $F $Z $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500 + $Z $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500 + EOF +' ed="Thu, 26 May 2005 18:32:00 -0500" gd="Thu, 26 May 2005 18:33:00 -0500" From 76a53d640f72fc77e7e9358dfeb5df5ece56515f Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 28 Oct 2019 12:57:18 +0000 Subject: [PATCH 097/953] git_path(): handle `.lock` files correctly Ever since worktrees were introduced, the `git_path()` function _really_ needed to be called e.g. to get at the path to `logs/HEAD` (`HEAD` is specific to the worktree, and therefore so is its reflog). However, the wrong path is returned for `logs/HEAD.lock`. This does not matter as long as the Git executable is doing the asking, as the path for that `logs/HEAD.lock` file is constructed from `git_path("logs/HEAD")` by appending the `.lock` suffix. However, Git GUI just learned to use `--git-path` instead of appending relative paths to what `git rev-parse --git-dir` returns (and as a consequence not only using the correct hooks directory, but also using the correct paths in worktrees other than the main one). While it does not seem as if Git GUI in particular is asking for `logs/HEAD.lock`, let's be safe rather than sorry. Side note: Git GUI _does_ ask for `index.lock`, but that is already resolved correctly, due to `update_common_dir()` preferring to leave unknown paths in the (worktree-specific) git directory. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- path.c | 6 ++++++ t/t0060-path-utils.sh | 2 ++ 2 files changed, 8 insertions(+) diff --git a/path.c b/path.c index 25e97b8c3f76ce..d086595d1f27eb 100644 --- a/path.c +++ b/path.c @@ -11,6 +11,7 @@ #include "path.h" #include "packfile.h" #include "object-store.h" +#include "lockfile.h" static int get_st_mode_bits(const char *path, int *mode) { @@ -350,9 +351,14 @@ static void update_common_dir(struct strbuf *buf, int git_dir_len, const char *common_dir) { char *base = buf->buf + git_dir_len; + int has_lock_suffix = strbuf_strip_suffix(buf, LOCK_SUFFIX); + init_common_trie(); if (trie_find(&common_trie, base, check_common, NULL) > 0) replace_dir(buf, git_dir_len, common_dir); + + if (has_lock_suffix) + strbuf_addstr(buf, LOCK_SUFFIX); } void report_linked_checkout_garbage(void) diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh index c7b53e494ba43f..2aca8ccff9a075 100755 --- a/t/t0060-path-utils.sh +++ b/t/t0060-path-utils.sh @@ -285,8 +285,10 @@ test_git_path GIT_OBJECT_DIRECTORY=foo objects/foo foo/foo test_git_path GIT_OBJECT_DIRECTORY=foo objects2 .git/objects2 test_expect_success 'setup common repository' 'git --git-dir=bar init' test_git_path GIT_COMMON_DIR=bar index .git/index +test_git_path GIT_COMMON_DIR=bar index.lock .git/index.lock test_git_path GIT_COMMON_DIR=bar HEAD .git/HEAD test_git_path GIT_COMMON_DIR=bar logs/HEAD .git/logs/HEAD +test_git_path GIT_COMMON_DIR=bar logs/HEAD.lock .git/logs/HEAD.lock test_git_path GIT_COMMON_DIR=bar logs/refs/bisect/foo .git/logs/refs/bisect/foo test_git_path GIT_COMMON_DIR=bar logs/refs/bisec/foo bar/logs/refs/bisec/foo test_git_path GIT_COMMON_DIR=bar logs/refs/bisec bar/logs/refs/bisec From 762d5b4f46c98406e94e863133d64d2a1090ca4a Mon Sep 17 00:00:00 2001 From: Philippe Blain Date: Mon, 28 Oct 2019 13:05:46 +0000 Subject: [PATCH 098/953] help: add gitsubmodules to the list of guides The guide "gitsubmodules" was added in d480345 (submodules: overhaul documentation, 2017-06-22), but it was not added to command-list.txt when commit 1b81d8c (help: use command-list.txt for the source of guides, 2018-05-20) taught "git help" to obtain the guide list from this file. Add it now, and capitalize the first word of the description of gitsubmodules, as was done in 1b81d8c (help: use command-list.txt for the source of guides, 2018-05-20) for the other guides. Signed-off-by: Philippe Blain Reviewed-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- Documentation/gitsubmodules.txt | 2 +- command-list.txt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Documentation/gitsubmodules.txt b/Documentation/gitsubmodules.txt index 0a890205b8b508..c476f891b5cefd 100644 --- a/Documentation/gitsubmodules.txt +++ b/Documentation/gitsubmodules.txt @@ -3,7 +3,7 @@ gitsubmodules(7) NAME ---- -gitsubmodules - mounting one repository inside another +gitsubmodules - Mounting one repository inside another SYNOPSIS -------- diff --git a/command-list.txt b/command-list.txt index a9ac72bef487ef..72e435c5a38718 100644 --- a/command-list.txt +++ b/command-list.txt @@ -203,6 +203,7 @@ gitmodules guide gitnamespaces guide gitrepository-layout guide gitrevisions guide +gitsubmodules guide gittutorial-2 guide gittutorial guide gitworkflows guide From 4782cf2ab686bacca8d2908319981ac27d54ca25 Mon Sep 17 00:00:00 2001 From: Philippe Blain Date: Sun, 27 Oct 2019 17:16:25 +0000 Subject: [PATCH 099/953] worktree: teach "add" to ignore submodule.recurse config "worktree add" internally calls "reset --hard", but if submodule.recurse is set, reset tries to recurse into initialized submodules, which makes start_command try to cd into non-existing submodule paths and die. Fix that by making sure that the call to reset in "worktree add" does not recurse. Signed-off-by: Philippe Blain Signed-off-by: Junio C Hamano --- builtin/worktree.c | 2 +- t/t2400-worktree-add.sh | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/builtin/worktree.c b/builtin/worktree.c index a5bb02b2076a27..958bea97fe17e3 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -377,7 +377,7 @@ static int add_worktree(const char *path, const char *refname, if (opts->checkout) { cp.argv = NULL; argv_array_clear(&cp.args); - argv_array_pushl(&cp.args, "reset", "--hard", NULL); + argv_array_pushl(&cp.args, "reset", "--hard", "--no-recurse-submodules", NULL); if (opts->quiet) argv_array_push(&cp.args, "--quiet"); cp.env = child_env.argv; diff --git a/t/t2400-worktree-add.sh b/t/t2400-worktree-add.sh index e819ba741ec960..8a9831413c38e6 100755 --- a/t/t2400-worktree-add.sh +++ b/t/t2400-worktree-add.sh @@ -587,4 +587,28 @@ test_expect_success '"add" should not fail because of another bad worktree' ' ) ' +test_expect_success '"add" with uninitialized submodule, with submodule.recurse unset' ' + test_create_repo submodule && + test_commit -C submodule first && + test_create_repo project && + git -C project submodule add ../submodule && + git -C project add submodule && + test_tick && + git -C project commit -m add_sub && + git clone project project-clone && + git -C project-clone worktree add ../project-2 +' +test_expect_success '"add" with uninitialized submodule, with submodule.recurse set' ' + git -C project-clone -c submodule.recurse worktree add ../project-3 +' + +test_expect_success '"add" with initialized submodule, with submodule.recurse unset' ' + git -C project-clone submodule update --init && + git -C project-clone worktree add ../project-4 +' + +test_expect_success '"add" with initialized submodule, with submodule.recurse set' ' + git -C project-clone -c submodule.recurse worktree add ../project-5 +' + test_done From d8b8217c8a16944dc61a1553464efabc450a6680 Mon Sep 17 00:00:00 2001 From: Prarit Bhargava Date: Tue, 29 Oct 2019 08:09:14 -0400 Subject: [PATCH 100/953] pretty: add "%aL" etc. to show local-part of email addresses In many projects the number of contributors is low enough that users know each other and the full email address doesn't need to be displayed. Displaying only the author's username saves a lot of columns on the screen. Existing 'e/E' (as in "%ae" and "%aE") placeholders would show the author's address as "prarit@redhat.com", which would waste columns to show the same domain-part for all contributors when used in a project internal to redhat. Introduce 'l/L' placeholders that strip '@' and domain part from the e-mail address. Signed-off-by: Prarit Bhargava Signed-off-by: Junio C Hamano --- Documentation/pretty-formats.txt | 6 ++++++ pretty.c | 9 ++++++++- t/t4203-mailmap.sh | 28 ++++++++++++++++++++++++++++ t/t6006-rev-list-format.sh | 8 ++++++-- t/test-lib.sh | 8 ++++++-- 5 files changed, 54 insertions(+), 5 deletions(-) diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt index b87e2e83e6d01d..31c6e8d2b86ad6 100644 --- a/Documentation/pretty-formats.txt +++ b/Documentation/pretty-formats.txt @@ -163,6 +163,9 @@ The placeholders are: '%ae':: author email '%aE':: author email (respecting .mailmap, see linkgit:git-shortlog[1] or linkgit:git-blame[1]) +'%al':: author email local-part (the part before the '@' sign) +'%aL':: author local-part (see '%al') respecting .mailmap, see + linkgit:git-shortlog[1] or linkgit:git-blame[1]) '%ad':: author date (format respects --date= option) '%aD':: author date, RFC2822 style '%ar':: author date, relative @@ -175,6 +178,9 @@ The placeholders are: '%ce':: committer email '%cE':: committer email (respecting .mailmap, see linkgit:git-shortlog[1] or linkgit:git-blame[1]) +'%cl':: author email local-part (the part before the '@' sign) +'%cL':: author local-part (see '%cl') respecting .mailmap, see + linkgit:git-shortlog[1] or linkgit:git-blame[1]) '%cd':: committer date (format respects --date= option) '%cD':: committer date, RFC2822 style '%cr':: committer date, relative diff --git a/pretty.c b/pretty.c index b32f0369531c6f..93eb6e837071a3 100644 --- a/pretty.c +++ b/pretty.c @@ -696,7 +696,7 @@ static size_t format_person_part(struct strbuf *sb, char part, mail = s.mail_begin; maillen = s.mail_end - s.mail_begin; - if (part == 'N' || part == 'E') /* mailmap lookup */ + if (part == 'N' || part == 'E' || part == 'L') /* mailmap lookup */ mailmap_name(&mail, &maillen, &name, &namelen); if (part == 'n' || part == 'N') { /* name */ strbuf_add(sb, name, namelen); @@ -706,6 +706,13 @@ static size_t format_person_part(struct strbuf *sb, char part, strbuf_add(sb, mail, maillen); return placeholder_len; } + if (part == 'l' || part == 'L') { /* local-part */ + const char *at = memchr(mail, '@', maillen); + if (at) + maillen = at - mail; + strbuf_add(sb, mail, maillen); + return placeholder_len; + } if (!s.date_begin) goto skip; diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh index e8f9c0f5bc8c37..586c3a86b1d2cc 100755 --- a/t/t4203-mailmap.sh +++ b/t/t4203-mailmap.sh @@ -412,6 +412,34 @@ test_expect_success 'Log output (complex mapping)' ' test_cmp expect actual ' +cat >expect << EOF +Author email cto@coompany.xx has local-part cto +Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME + +Author email me@company.xx has local-part me +Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME + +Author email me@company.xx has local-part me +Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME + +Author email nick2@company.xx has local-part nick2 +Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME + +Author email bugs@company.xx has local-part bugs +Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME + +Author email bugs@company.xx has local-part bugs +Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME + +Author email author@example.com has local-part author +Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME +EOF + +test_expect_success 'Log output (local-part email address)' ' + git log --pretty=format:"Author email %ae has local-part %al%nCommitter email %ce has local-part %cl%n" >actual && + test_cmp expect actual +' + cat >expect << EOF Author: CTO Author: Santa Claus diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh index 1f7d3f7acc9c35..ebdc49c4965ede 100755 --- a/t/t6006-rev-list-format.sh +++ b/t/t6006-rev-list-format.sh @@ -109,31 +109,35 @@ commit $head1 EOF # we don't test relative here -test_format author %an%n%ae%n%ad%n%aD%n%at < Date: Tue, 29 Oct 2019 10:01:52 -0700 Subject: [PATCH 101/953] submodule: teach set-url subcommand Currently, in the event that a submodule's upstream URL changes, users have to manually alter the URL in the .gitmodules file then run `git submodule sync`. Let's make that process easier. Teach submodule the set-url subcommand which will automatically change the `submodule.$name.url` property in the .gitmodules file and then run `git submodule sync` to complete the process. Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano --- Documentation/git-submodule.txt | 6 +++ contrib/completion/git-completion.bash | 2 +- git-submodule.sh | 52 +++++++++++++++++++++++- t/t7420-submodule-set-url.sh | 55 ++++++++++++++++++++++++++ 4 files changed, 113 insertions(+), 2 deletions(-) create mode 100755 t/t7420-submodule-set-url.sh diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt index 1f46380af2d493..285486d0a81326 100644 --- a/Documentation/git-submodule.txt +++ b/Documentation/git-submodule.txt @@ -16,6 +16,7 @@ SYNOPSIS 'git submodule' [--quiet] deinit [-f|--force] (--all|[--] ...) 'git submodule' [--quiet] update [] [--] [...] 'git submodule' [--quiet] set-branch [] [--] +'git submodule' [--quiet] set-url [--] 'git submodule' [--quiet] summary [] [--] [...] 'git submodule' [--quiet] foreach [--recursive] 'git submodule' [--quiet] sync [--recursive] [--] [...] @@ -180,6 +181,11 @@ set-branch (-d|--default) [--] :: `--default` option removes the submodule..branch configuration key, which causes the tracking branch to default to 'master'. +set-url [--] :: + Sets the URL of the specified submodule to . Then, it will + automatically synchronize the submodule's new remote URL + configuration. + summary [--cached|--files] [(-n|--summary-limit) ] [commit] [--] [...]:: Show commit summary between the given commit (defaults to HEAD) and working tree/index. For a submodule in question, a series of commits diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 00fbe6c03d8539..88c7446414e8e5 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -2779,7 +2779,7 @@ _git_submodule () { __git_has_doubledash && return - local subcommands="add status init deinit update set-branch summary foreach sync absorbgitdirs" + local subcommands="add status init deinit update set-branch set-url summary foreach sync absorbgitdirs" local subcommand="$(__git_find_on_cmdline "$subcommands")" if [ -z "$subcommand" ]; then case "$cur" in diff --git a/git-submodule.sh b/git-submodule.sh index c7f58c5756f7b6..f7374ddbd6e26d 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -12,6 +12,7 @@ USAGE="[--quiet] [--cached] or: $dashless [--quiet] deinit [-f|--force] (--all| [--] ...) or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference ] [--recursive] [--] [...] or: $dashless [--quiet] set-branch (--default|--branch ) [--] + or: $dashless [--quiet] set-url [--] or: $dashless [--quiet] summary [--cached|--files] [--summary-limit ] [commit] [--] [...] or: $dashless [--quiet] foreach [--recursive] or: $dashless [--quiet] sync [--recursive] [--] [...] @@ -760,6 +761,55 @@ cmd_set_branch() { fi } +# +# Configures a submodule's remote url +# +# $@ = requested path, requested url +# +cmd_set_url() { + while test $# -ne 0 + do + case "$1" in + -q|--quiet) + GIT_QUIET=1 + ;; + --) + shift + break + ;; + -*) + usage + ;; + *) + break + ;; + esac + shift + done + + if test $# -ne 2 + then + usage + fi + + # we can't use `git submodule--helper name` here because internally, it + # hashes the path so a trailing slash could lead to an unintentional no match + name="$(git submodule--helper list "$1" | cut -f2)" + if test -z "$name" + then + exit 1 + fi + + url="$2" + if test -z "$url" + then + exit 1 + fi + + git submodule--helper config submodule."$name".url "$url" + git submodule--helper sync ${GIT_QUIET:+--quiet} "$name" +} + # # Show commit summary for submodules in index or working tree # @@ -1059,7 +1109,7 @@ cmd_absorbgitdirs() while test $# != 0 && test -z "$command" do case "$1" in - add | foreach | init | deinit | update | set-branch | status | summary | sync | absorbgitdirs) + add | foreach | init | deinit | update | set-branch | set-url | status | summary | sync | absorbgitdirs) command=$1 ;; -q|--quiet) diff --git a/t/t7420-submodule-set-url.sh b/t/t7420-submodule-set-url.sh new file mode 100755 index 00000000000000..ef0cb6e8e18537 --- /dev/null +++ b/t/t7420-submodule-set-url.sh @@ -0,0 +1,55 @@ +#!/bin/sh +# +# Copyright (c) 2019 Denton Liu +# + +test_description='Test submodules set-url subcommand + +This test verifies that the set-url subcommand of git-submodule is working +as expected. +' + +TEST_NO_CREATE_REPO=1 +. ./test-lib.sh + +test_expect_success 'submodule config cache setup' ' + mkdir submodule && + ( + cd submodule && + git init && + echo a >file && + git add file && + git commit -ma + ) && + mkdir super && + ( + cd super && + git init && + git submodule add ../submodule && + git commit -m "add submodule" + ) +' + +test_expect_success 'test submodule set-url' ' + # add a commit and move the submodule (change the url) + ( + cd submodule && + echo b >>file && + git add file && + git commit -mb + ) && + mv submodule newsubmodule && + + git -C newsubmodule show >expect && + ( + cd super && + test_must_fail git submodule update --remote && + git submodule set-url submodule ../newsubmodule && + grep -F "url = ../newsubmodule" .gitmodules && + git submodule update --remote + ) && + git -C super/submodule show >actual && + test_cmp expect actual +' + +test_done From 0115e5d929d06ad41eff83742a3e6a1e91ecc0c4 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Tue, 29 Oct 2019 09:54:32 -0700 Subject: [PATCH 102/953] git-diff.txt: document return code of `--no-index` Within diff_no_index(), we have the following: revs->diffopt.flags.exit_with_status = 1; ... /* * The return code for --no-index imitates diff(1): * 0 = no changes, 1 = changes, else error */ return diff_result_code(&revs->diffopt, 0); Which means when `git diff` is run in `--no-index` mode, `--exit-code` is implied. However, the documentation for this is missing in git-diff.txt. Add a note about how `--exit-code` is implied in the `--no-index` documentation to cover this documentation blindspot. Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano --- Documentation/git-diff.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/git-diff.txt b/Documentation/git-diff.txt index 72179d993cb9b6..37781cf175547c 100644 --- a/Documentation/git-diff.txt +++ b/Documentation/git-diff.txt @@ -36,7 +36,7 @@ two blob objects, or changes between two files on disk. running the command in a working tree controlled by Git and at least one of the paths points outside the working tree, or when running the command outside a working tree - controlled by Git. + controlled by Git. This form implies `--exit-code`. 'git diff' [] --cached [] [--] [...]:: From 391c7e40b516a0e9e7817083e0966805acffbdf3 Mon Sep 17 00:00:00 2001 From: Ralf Thielow Date: Thu, 31 Oct 2019 20:41:46 +0000 Subject: [PATCH 103/953] fetch.c: fix typo in a warning message Signed-off-by: Ralf Thielow Reviewed-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- builtin/fetch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/fetch.c b/builtin/fetch.c index 0c345b5dfe4b09..f9a934f098f344 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1411,7 +1411,7 @@ static int do_fetch(struct transport *transport, for (rm = ref_map; rm; rm = rm->next) { if (!rm->peer_ref) { if (source_ref) { - warning(_("multiple branch detected, incompatible with --set-upstream")); + warning(_("multiple branches detected, incompatible with --set-upstream")); goto skip; } else { source_ref = rm; From 116d1fa6c693e13321dc4c6abe256ca7878e55a5 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 30 Oct 2019 10:44:36 +0000 Subject: [PATCH 104/953] vreportf(): avoid relying on stdio buffering MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The MSVC runtime behavior differs from glibc's with respect to `fprintf(stderr, ...)` in that the former writes out the message character by character. In t5516, this leads to a funny problem where a `git fetch` process as well as the `git upload-pack` process spawned by it _both_ call `die()` at the same time. The output can look like this: fatal: git uploadfata-lp: raemcokte :error: upload-pnot our arcef k6: n4ot our ea4cr1e3f 36d45ea94fca1398e86a771eda009872d63adb28598f6a9 8e86a771eda009872d6ab2886 Let's avoid this predicament altogether by rendering the entire message, including the prefix and the trailing newline, into the buffer we already have (and which is still fixed size) and then write it out via `write_in_full()`. We still clip the message to at most 4095 characters. The history of `vreportf()` with regard to this issue includes the following commits: d048a96e (2007-11-09) - 'char msg[256]' is introduced to avoid interleaving 389d1767 (2009-03-25) - Buffer size increased to 1024 to avoid truncation 625a860c (2009-11-22) - Buffer size increased to 4096 to avoid truncation f4c3edc0 (2015-08-11) - Buffer removed to avoid truncation b5a9e435 (2017-01-11) - Reverts f4c3edc0 to be able to replace control chars before sending to stderr 9ac13ec9 (2006-10-11) - Another attempt to solve interleaving. This is seemingly related to d048a96e. 137a0d0e (2007-11-19) - Addresses out-of-order for display() 34df8aba (2009-03-10) - Switches xwrite() to fprintf() in recv_sideband() to support UTF-8 emulation eac14f89 (2012-01-14) - Removes the need for fprintf() for UTF-8 emulation, so it's safe to use xwrite() again 5e5be9e2 (2016-06-28) - recv_sideband() uses xwrite() again Note that we print nothing if the `vsnprintf()` call failed to render the error message; There is little we can do in that case, and it should not happen anyway. The process may have written to `stderr` and there may be something left in the buffer kept in the stdio layer. Call `fflush(stderr)` before writing the message we prepare in this function. Helped-by: Jeff King Helped-by: Alexandr Miloslavskiy Helped-by: SZEDER Gábor Helped-by: Junio C Hamano Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- usage.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/usage.c b/usage.c index 2fdb20086bd695..58fb5fff5f245c 100644 --- a/usage.c +++ b/usage.c @@ -9,14 +9,26 @@ void vreportf(const char *prefix, const char *err, va_list params) { char msg[4096]; - char *p; + char *p, *pend = msg + sizeof(msg); + size_t prefix_len = strlen(prefix); - vsnprintf(msg, sizeof(msg), err, params); - for (p = msg; *p; p++) { + if (sizeof(msg) <= prefix_len) { + fprintf(stderr, "BUG!!! too long a prefix '%s'\n", prefix); + abort(); + } + memcpy(msg, prefix, prefix_len); + p = msg + prefix_len; + if (vsnprintf(p, pend - p, err, params) < 0) + *p = '\0'; /* vsnprintf() failed, clip at prefix */ + + for (; p != pend - 1 && *p; p++) { if (iscntrl(*p) && *p != '\t' && *p != '\n') *p = '?'; } - fprintf(stderr, "%s%s\n", prefix, msg); + + *(p++) = '\n'; /* we no longer need a NUL */ + fflush(stderr); + write_in_full(2, msg, p - msg); } static NORETURN void usage_builtin(const char *err, va_list params) From 8dfb04ae964868dda758997e5e7da29edff6164b Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 30 Oct 2019 10:49:37 +0000 Subject: [PATCH 105/953] update-index: optionally leave skip-worktree entries alone While `git update-index` mostly ignores paths referring to index entries whose skip-worktree bit is set, in b4d1690df11 (Teach Git to respect skip-worktree bit (reading part), 2009-08-20), for reasons that are not entirely obvious, the `--remove` option was made special: it _does_ remove index entries even if their skip-worktree bit is set. Seeing as this behavior has been in place for a decade now, it does not make sense to change it. However, in preparation for fixing a bug in `git stash` where it pretends that skip-worktree entries have actually been removed, we need a mode where `git update-index` leaves all skip-worktree entries alone, even if the `--remove` option was passed. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- Documentation/git-update-index.txt | 6 ++++++ builtin/update-index.c | 6 +++++- t/t7012-skip-worktree-writing.sh | 15 +++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Documentation/git-update-index.txt b/Documentation/git-update-index.txt index 1c4d146a41ce09..08393445e754d9 100644 --- a/Documentation/git-update-index.txt +++ b/Documentation/git-update-index.txt @@ -16,6 +16,7 @@ SYNOPSIS [--chmod=(+|-)x] [--[no-]assume-unchanged] [--[no-]skip-worktree] + [--[no-]ignore-skip-worktree-entries] [--[no-]fsmonitor-valid] [--ignore-submodules] [--[no-]split-index] @@ -113,6 +114,11 @@ you will need to handle the situation manually. set and unset the "skip-worktree" bit for the paths. See section "Skip-worktree bit" below for more information. + +--[no-]ignore-skip-worktree-entries:: + Do not remove skip-worktree (AKA "index-only") entries even when + the `--remove` option was specified. + --[no-]fsmonitor-valid:: When one of these flags is specified, the object name recorded for the paths are not updated. Instead, these options diff --git a/builtin/update-index.c b/builtin/update-index.c index dff2f4b837208d..074d563df08570 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -35,6 +35,7 @@ static int verbose; static int mark_valid_only; static int mark_skip_worktree_only; static int mark_fsmonitor_only; +static int ignore_skip_worktree_entries; #define MARK_FLAG 1 #define UNMARK_FLAG 2 static struct strbuf mtime_dir = STRBUF_INIT; @@ -381,7 +382,8 @@ static int process_path(const char *path, struct stat *st, int stat_errno) * so updating it does not make sense. * On the other hand, removing it from index should work */ - if (allow_remove && remove_file_from_cache(path)) + if (!ignore_skip_worktree_entries && allow_remove && + remove_file_from_cache(path)) return error("%s: cannot remove from the index", path); return 0; } @@ -1013,6 +1015,8 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) {OPTION_SET_INT, 0, "no-skip-worktree", &mark_skip_worktree_only, NULL, N_("clear skip-worktree bit"), PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, UNMARK_FLAG}, + OPT_BOOL(0, "ignore-skip-worktree-entries", &ignore_skip_worktree_entries, + N_("do not touch index-only entries")), OPT_SET_INT(0, "info-only", &info_only, N_("add to index only; do not add content to object database"), 1), OPT_SET_INT(0, "force-remove", &force_remove, diff --git a/t/t7012-skip-worktree-writing.sh b/t/t7012-skip-worktree-writing.sh index 9d1abe50eff677..7476781979c3ff 100755 --- a/t/t7012-skip-worktree-writing.sh +++ b/t/t7012-skip-worktree-writing.sh @@ -134,6 +134,21 @@ test_expect_success 'git-clean, dirty case' ' test_i18ncmp expected result ' +test_expect_success '--ignore-skip-worktree-entries leaves worktree alone' ' + test_commit keep-me && + git update-index --skip-worktree keep-me.t && + rm keep-me.t && + + : ignoring the worktree && + git update-index --remove --ignore-skip-worktree-entries keep-me.t && + git diff-index --cached --exit-code HEAD && + + : not ignoring the worktree, a deletion is staged && + git update-index --remove keep-me.t && + test_must_fail git diff-index --cached --exit-code HEAD \ + --diff-filter=D -- keep-me.t +' + #TODO test_expect_failure 'git-apply adds file' false #TODO test_expect_failure 'git-apply updates file' false #TODO test_expect_failure 'git-apply removes file' false From 4a58c3d7f7a83ebcd4ede635871cab7be24f7f3f Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 30 Oct 2019 10:49:38 +0000 Subject: [PATCH 106/953] stash: handle staged changes in skip-worktree files correctly When calling `git stash` while changes were staged for files that are marked with the `skip-worktree` bit (e.g. files that are excluded in a sparse checkout), the files are recorded as _deleted_ instead. The reason is that `git stash` tries to construct the tree reflecting the worktree essentially by copying the index to a temporary one and then updating the files from the worktree. Crucially, it calls `git diff-index` to update also those files that are in the HEAD but have been unstaged in the index. However, when the temporary index is updated via `git update-index --add --remove`, skip-worktree entries mark the files as deleted by mistake. Let's use the newly-introduced `--ignore-skip-worktree-entries` option of `git update-index` to prevent exactly this from happening. Note that the regression test case deliberately avoids replicating the scenario described above and instead tries to recreate just the symptom. Reported by Dan Thompson. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- builtin/stash.c | 5 +++-- git-legacy-stash.sh | 3 ++- t/t3903-stash.sh | 11 +++++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/builtin/stash.c b/builtin/stash.c index b5a301f24d7a5f..56f3b551e4af71 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -1082,8 +1082,9 @@ static int stash_working_tree(struct stash_info *info, const struct pathspec *ps } cp_upd_index.git_cmd = 1; - argv_array_pushl(&cp_upd_index.args, "update-index", "-z", "--add", - "--remove", "--stdin", NULL); + argv_array_pushl(&cp_upd_index.args, "update-index", + "--ignore-skip-worktree-entries", + "-z", "--add", "--remove", "--stdin", NULL); argv_array_pushf(&cp_upd_index.env_array, "GIT_INDEX_FILE=%s", stash_index_path.buf); diff --git a/git-legacy-stash.sh b/git-legacy-stash.sh index f60e9b3e877b24..5398a5161d253e 100755 --- a/git-legacy-stash.sh +++ b/git-legacy-stash.sh @@ -193,7 +193,8 @@ create_stash () { GIT_INDEX_FILE="$TMPindex" && export GIT_INDEX_FILE && git diff-index --name-only -z HEAD -- "$@" >"$TMP-stagenames" && - git update-index -z --add --remove --stdin <"$TMP-stagenames" && + git update-index --ignore-skip-worktree-entries \ + -z --add --remove --stdin <"$TMP-stagenames" && git write-tree && rm -f "$TMPindex" ) ) || diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh index b8e337893f3e1e..1e977145b83766 100755 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@ -1241,4 +1241,15 @@ test_expect_success 'stash --keep-index with file deleted in index does not resu test_path_is_missing to-remove ' +test_expect_success 'stash handles skip-worktree entries nicely' ' + test_commit A && + echo changed >A.t && + git add A.t && + git update-index --skip-worktree A.t && + rm A.t && + git stash && + + git rev-parse --verify refs/stash:A.t +' + test_done From 4ed5562925539ef76b6e4b2002b98a8e734cf223 Mon Sep 17 00:00:00 2001 From: Emily Shaffer Date: Thu, 31 Oct 2019 14:03:36 -0700 Subject: [PATCH 107/953] myfirstcontrib: add 'psuh' to command-list.txt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Users can discover commands and their brief usage by running 'git help git' or 'git help -a'; both of these pages list all available commands based on the contents of 'command-list.txt'. That means adding a new command there is an important part of the new command process, and therefore belongs in the new command tutorial. Teach new users how to add their command, and include a brief overview of how to discover which attributes to place on the command in the list. Since 'git psuh' prints some workspace info, doesn't modify anything, and is targeted as a user-facing porcelain command, list it as a 'mainporcelain' and 'info' command. As the usage string is required to generate this documentation, don't add the command to the list until after the usage string is added to the tutorial. Reported-by: SZEDER Gábor Signed-off-by: Emily Shaffer Signed-off-by: Junio C Hamano --- Documentation/MyFirstContribution.txt | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Documentation/MyFirstContribution.txt b/Documentation/MyFirstContribution.txt index 5e9b808f5f093d..12b7256454b35a 100644 --- a/Documentation/MyFirstContribution.txt +++ b/Documentation/MyFirstContribution.txt @@ -534,6 +534,28 @@ you want to pass as a parameter something which would usually be interpreted as a flag.) `parse_options()` will terminate parsing when it reaches `--` and give you the rest of the options afterwards, untouched. +Now that you have a usage hint, you can teach Git how to show it in the general +command list shown by `git help git` or `git help -a`, which is generated from +`command-list.txt`. Find the line for 'git-pull' so you can add your 'git-psuh' +line above it in alphabetical order. Now, we can add some attributes about the +command which impacts where it shows up in the aforementioned help commands. The +top of `command-list.txt` shares some information about what each attribute +means; in those help pages, the commands are sorted according to these +attributes. `git psuh` is user-facing, or porcelain - so we will mark it as +"mainporcelain". For "mainporcelain" commands, the comments at the top of +`command-list.txt` indicate we can also optionally add an attribute from another +list; since `git psuh` shows some information about the user's workspace but +doesn't modify anything, let's mark it as "info". Make sure to keep your +attributes in the same style as the rest of `command-list.txt` using spaces to +align and delineate them: + +---- +git-prune-packed plumbingmanipulators +git-psuh mainporcelain info +git-pull mainporcelain remote +git-push mainporcelain remote +---- + Build again. Now, when you run with `-h`, you should see your usage printed and your command terminated before anything else interesting happens. Great! From 3ada78de3f8dbe2b0a2b67cade25d29a86f734c3 Mon Sep 17 00:00:00 2001 From: Emily Shaffer Date: Thu, 31 Oct 2019 14:03:37 -0700 Subject: [PATCH 108/953] myfirstcontrib: add dependency installation step Indicate that the user needs some dependencies before the build will run happily on their machine; this dependency list doesn't seem to be made clear anywhere else in the project documentation. Then, so the user can be certain any build failures are due to their code and not their environment, perform a build on a clean checkout of 'master'. Also, move the note about build parallelization up here, so that it appears next to the very first build invocation in the tutorial. Reported-by: Heba Waly Signed-off-by: Emily Shaffer Signed-off-by: Junio C Hamano --- Documentation/MyFirstContribution.txt | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/Documentation/MyFirstContribution.txt b/Documentation/MyFirstContribution.txt index 12b7256454b35a..5ce94e077cf489 100644 --- a/Documentation/MyFirstContribution.txt +++ b/Documentation/MyFirstContribution.txt @@ -38,6 +38,26 @@ $ git clone https://github.com/git/git git $ cd git ---- +[[dependencies]] +=== Installing Dependencies + +To build Git from source, you need to have a handful of dependencies installed +on your system. For a hint of what's needed, you can take a look at +`INSTALL`, paying close attention to the section about Git's dependencies on +external programs and libraries. That document mentions a way to "test-drive" +our freshly built Git without installing; that's the method we'll be using in +this tutorial. + +Make sure that your environment has everything you need by building your brand +new clone of Git from the above step: + +---- +$ make +---- + +NOTE: The Git build is parallelizable. `-j#` is not included above but you can +use it as you prefer, here and elsewhere. + [[identify-problem]] === Identify Problem to Solve @@ -138,9 +158,6 @@ NOTE: When you are developing the Git project, it's preferred that you use the `DEVELOPER` flag; if there's some reason it doesn't work for you, you can turn it off, but it's a good idea to mention the problem to the mailing list. -NOTE: The Git build is parallelizable. `-j#` is not included above but you can -use it as you prefer, here and elsewhere. - Great, now your new command builds happily on its own. But nobody invokes it. Let's change that. From 3c8d754c4b7123e57febdcf95330a073c8eeec7e Mon Sep 17 00:00:00 2001 From: Emily Shaffer Date: Thu, 31 Oct 2019 14:03:38 -0700 Subject: [PATCH 109/953] myfirstcontrib: hint to find gitgitgadget allower GitGitGadget, a handy tool for converting pull requests against Git into Git-mailing-list-friendly-patch-emails, requires as anti-spam that all new users be "/allow"ed by an existing user once before it will do anything for that new user. While this tutorial explained that mechanism, it did not give much hint on how to go about finding someone to allow your new pull request. So, teach our new GitGitGadget user where to look for someone who can add their name to the list. The advice in this patch is based on the advice proposed for GitGitGadget: https://github.com/gitgitgadget/gitgitgadget/pull/138 Signed-off-by: Emily Shaffer Signed-off-by: Junio C Hamano --- Documentation/MyFirstContribution.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Documentation/MyFirstContribution.txt b/Documentation/MyFirstContribution.txt index 5ce94e077cf489..b55837e646c94e 100644 --- a/Documentation/MyFirstContribution.txt +++ b/Documentation/MyFirstContribution.txt @@ -785,6 +785,14 @@ will automatically run your PRs through the CI even without the permission given but you will not be able to `/submit` your changes until someone allows you to use the tool. +NOTE: You can typically find someone who can `/allow` you on GitGitGadget by +either examining recent pull requests where someone has been granted `/allow` +(https://github.com/gitgitgadget/git/pulls?utf8=%E2%9C%93&q=is%3Apr+is%3Aopen+%22%2Fallow%22[Search: +is:pr is:open "/allow"]), in which case both the author and the person who +granted the `/allow` can now `/allow` you, or by inquiring on the +https://webchat.freenode.net/#git-devel[#git-devel] IRC channel on Freenode +linking your pull request and asking for someone to `/allow` you. + If the CI fails, you can update your changes with `git rebase -i` and push your branch again: From ba51d2fb24b1a41b8cc15270a06f24c35c0fcf19 Mon Sep 17 00:00:00 2001 From: Rohit Ashiwal Date: Fri, 1 Nov 2019 19:29:58 +0530 Subject: [PATCH 110/953] rebase -i: add --ignore-whitespace flag There are two backends available for rebasing, viz, the am and the interactive. Naturally, there shall be some features that are implemented in one but not in the other. One such flag is --ignore-whitespace which indicates merge mechanism to treat lines with only whitespace changes as unchanged. Wire the interactive rebase to also understand the --ignore-whitespace flag by translating it to -Xignore-space-change. Signed-off-by: Rohit Ashiwal Signed-off-by: Junio C Hamano --- Documentation/git-rebase.txt | 12 ++++- builtin/rebase.c | 19 ++++++-- t/t3422-rebase-incompatible-options.sh | 1 - t/t3433-rebase-options-compatibility.sh | 65 +++++++++++++++++++++++++ 4 files changed, 90 insertions(+), 7 deletions(-) create mode 100755 t/t3433-rebase-options-compatibility.sh diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt index 5e4e9276479c94..a70a5cab26876c 100644 --- a/Documentation/git-rebase.txt +++ b/Documentation/git-rebase.txt @@ -371,8 +371,16 @@ If either or --root is given on the command line, then the default is `--no-fork-point`, otherwise the default is `--fork-point`. --ignore-whitespace:: + Behaves differently depending on which backend is selected. ++ +'am' backend: When applying a patch, ignore changes in whitespace in +context lines if necessary. ++ +'interactive' backend: Treat lines with only whitespace changes as +unchanged for the sake of a three-way merge. + --whitespace=