diff --git a/.editorconfig b/.editorconfig index a3c578a43cee57..2d3929b5916a14 100644 --- a/.editorconfig +++ b/.editorconfig @@ -4,7 +4,7 @@ insert_final_newline = true # The settings for C (*.c and *.h) files are mirrored in .clang-format. Keep # them in sync. -[{*.{c,h,sh,perl,pl,pm,txt,adoc},config.mak.*,Makefile}] +[{*.{c,h,sh,bash,perl,pl,pm,txt,adoc},config.mak.*,Makefile}] indent_style = tab tab_width = 8 diff --git a/.gitattributes b/.gitattributes index 4bdbbaf7e23572..1048ea7eb68b8e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -13,7 +13,7 @@ CODE_OF_CONDUCT.md -whitespace /GIT-VERSION-GEN text eol=lf /mergetools/* text eol=lf /t/oid-info/* text eol=lf -/Documentation/git-merge.txt conflict-marker-size=32 -/Documentation/gitk.txt conflict-marker-size=32 -/Documentation/user-manual.txt conflict-marker-size=32 +/Documentation/git-merge.adoc conflict-marker-size=32 +/Documentation/gitk.adoc conflict-marker-size=32 +/Documentation/user-manual.adoc conflict-marker-size=32 /t/t????-*.sh conflict-marker-size=32 diff --git a/Documentation/.gitattributes b/Documentation/.gitattributes deleted file mode 100644 index ddb030137d54ef..00000000000000 --- a/Documentation/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -*.txt whitespace diff --git a/Documentation/BreakingChanges.adoc b/Documentation/BreakingChanges.adoc index 042709a4613f73..bdfad29d8a9e3d 100644 --- a/Documentation/BreakingChanges.adoc +++ b/Documentation/BreakingChanges.adoc @@ -66,22 +66,21 @@ changes are made at a certain version boundary, and recording these decisions in this document, are necessary but not sufficient. Because such changes are expected to be numerous, and the design and implementation of them are expected to span over time, they have to -be deployable trivially at such a version boundary. +be deployable trivially at such a version boundary, prepared over long +time. The breaking changes MUST be guarded with the a compile-time switch, WITH_BREAKING_CHANGES, to help this process. When built with it, the resulting Git binary together with its documentation would behave as if these breaking changes slated for the next big version -boundary are already in effect. We may also want to have a CI job -or two to exercise the work-in-progress version of Git with these -breaking changes. +boundary are already in effect. We also have a CI job to exercise +the work-in-progress version of Git with these breaking changes. == Git 3.0 The following subsections document upcoming breaking changes for Git 3.0. There -is no planned release date for this breaking version yet. The early -adopter configuration used for changes for this release is `feature.git3`. +is no planned release date for this breaking version yet. Proposed changes and removals only include items which are "ready" to be done. In other words, this is not supposed to be a wishlist of features that should diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index ba047ed224afbd..a0e7041c54b497 100644 --- a/Documentation/CodingGuidelines +++ b/Documentation/CodingGuidelines @@ -44,7 +44,7 @@ code are expected to match the style the surrounding code already uses (even if it doesn't match the overall style of existing code). But if you must have a list of rules, here are some language -specific ones. Note that Documentation/ToolsForGit.txt document +specific ones. Note that Documentation/ToolsForGit.adoc document has a collection of tips to help you use some external tools to conform to these guidelines. @@ -755,7 +755,7 @@ Externally Visible Names Writing Documentation: Most (if not all) of the documentation pages are written in the - AsciiDoc format in *.txt files (e.g. Documentation/git.txt), and + AsciiDoc format in *.adoc files (e.g. Documentation/git.adoc), and processed into HTML and manpages (e.g. git.html and git.1 in the same directory). diff --git a/Documentation/Makefile b/Documentation/Makefile index c9a7cf662f0c43..671267a8ac7af6 100644 --- a/Documentation/Makefile +++ b/Documentation/Makefile @@ -224,6 +224,10 @@ asciidoc.conf: asciidoc.conf.in FORCE $(QUIET_GEN)$(call version_gen,"$(shell pwd)/..",$<,$@) endif +ifdef WITH_BREAKING_CHANGES +ASCIIDOC_EXTRA += -awith-breaking-changes +endif + ASCIIDOC_DEPS += docinfo.html SHELL_PATH ?= $(SHELL) diff --git a/Documentation/MyFirstContribution.adoc b/Documentation/MyFirstContribution.adoc index e41654c00a68e0..afcf4b46c11ab2 100644 --- a/Documentation/MyFirstContribution.adoc +++ b/Documentation/MyFirstContribution.adoc @@ -21,7 +21,7 @@ This tutorial aims to summarize the following documents, but the reader may find useful additional context: - `Documentation/SubmittingPatches` -- `Documentation/howto/new-command.txt` +- `Documentation/howto/new-command.adoc` [[getting-help]] === Getting Help @@ -331,7 +331,7 @@ function body: apply standard precedence rules. `git_config_get_string_tmp()` will look up a specific key ("user.name") and give you the value. There are a number of single-key lookup functions like this one; you can see them all (and more info -about how to use `git_config()`) in `Documentation/technical/api-config.txt`. +about how to use `git_config()`) in `Documentation/technical/api-config.adoc`. You should see that the name printed matches the one you see when you run: @@ -461,10 +461,10 @@ $ ./bin-wrappers/git help psuh Your new command is undocumented! Let's fix that. -Take a look at `Documentation/git-*.txt`. These are the manpages for the +Take a look at `Documentation/git-*.adoc`. These are the manpages for the subcommands that Git knows about. You can open these up and take a look to get acquainted with the format, but then go ahead and make a new file -`Documentation/git-psuh.txt`. Like with most of the documentation in the Git +`Documentation/git-psuh.adoc`. Like with most of the documentation in the Git project, help pages are written with AsciiDoc (see CodingGuidelines, "Writing Documentation" section). Use the following template to fill out your own manpage: @@ -543,7 +543,7 @@ Try and run `./bin-wrappers/git psuh -h`. Your command should crash at the end. That's because `-h` is a special case which your command should handle by printing usage. -Take a look at `Documentation/technical/api-parse-options.txt`. This is a handy +Take a look at `Documentation/technical/api-parse-options.adoc`. This is a handy tool for pulling out options you need to be able to handle, and it takes a usage string. @@ -1088,14 +1088,14 @@ This gives reviewers a summary of what they're in for when reviewing your topic. The one generated for `psuh` from the sample implementation looks like this: ---- - Documentation/git-psuh.txt | 40 +++++++++++++++++++++ - Makefile | 1 + - builtin.h | 1 + - builtin/psuh.c | 73 ++++++++++++++++++++++++++++++++++++++ - git.c | 1 + - t/t9999-psuh-tutorial.sh | 12 +++++++ + Documentation/git-psuh.adoc | 40 +++++++++++++++++++++ + Makefile | 1 + + builtin.h | 1 + + builtin/psuh.c | 73 ++++++++++++++++++++++++++++++++++++++ + git.c | 1 + + t/t9999-psuh-tutorial.sh | 12 +++++++ 6 files changed, 128 insertions(+) - create mode 100644 Documentation/git-psuh.txt + create mode 100644 Documentation/git-psuh.adoc create mode 100644 builtin/psuh.c create mode 100755 t/t9999-psuh-tutorial.sh ---- diff --git a/Documentation/MyFirstObjectWalk.adoc b/Documentation/MyFirstObjectWalk.adoc index dec8afe5b10533..d6e9dfdbbe232e 100644 --- a/Documentation/MyFirstObjectWalk.adoc +++ b/Documentation/MyFirstObjectWalk.adoc @@ -15,7 +15,7 @@ revision walk is used for operations like `git log`. === Related Reading -- `Documentation/user-manual.txt` under "Hacking Git" contains some coverage of +- `Documentation/user-manual.adoc` under "Hacking Git" contains some coverage of the revision walker in its various incarnations. - `revision.h` - https://eagain.net/articles/git-for-computer-scientists/[Git for Computer Scientists] @@ -112,7 +112,7 @@ $ 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`. +`Documentation/MyFirstContribution.adoc`. NOTE: A reference implementation can be found at https://github.com/nasamuffin/git/tree/revwalk. @@ -132,7 +132,7 @@ 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`.) +can be blobs, trees, commits, or tags. (See `Documentation/gittutorial-2.adoc`.) `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 @@ -141,7 +141,7 @@ 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` +`Documentation/revisions.adoc` 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 @@ -153,7 +153,7 @@ can be used during the walk, as well. 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 +`struct rev_info` have a mirror in `Documentation/rev-list-options.adoc`. It's a good idea to take some time and read through that document. == Basic Commit Walk @@ -710,7 +710,7 @@ 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 +`Documentation/rev-list-options.adoc`. 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 diff --git a/Documentation/RelNotes/2.49.0.adoc b/Documentation/RelNotes/2.49.0.adoc index 3d253455d373a9..a173eb193075c2 100644 --- a/Documentation/RelNotes/2.49.0.adoc +++ b/Documentation/RelNotes/2.49.0.adoc @@ -93,6 +93,18 @@ Performance, Internal Implementation, Development Support etc. * Rename processing in the recursive merge backend has seen a micro optimization. + * The path.[ch] API takes an explicit repository parameter passed + throughout the callchain, instead of relying on the_repository + singleton instance. + + * Large-object promisor protocol extension has been introduced. + + * The editorconfig file is updated to tell us that bash scripts are + similar to general Bourne shell scripts. + + * Meson-based build procedure forgot to build some docs, which has + been corrected. + Fixes since v2.48 ----------------- @@ -272,3 +284,4 @@ Fixes since v2.48 (merge 45761988ac en/doc-renormalize later to maint). (merge 832f56f06a jc/doc-boolean-synonyms later to maint). (merge 3eeed876a9 ac/doc-http-ssl-type-config later to maint). + (merge c268e3285d jc/breaking-changes-early-adopter-option later to maint). diff --git a/Documentation/build-docdep.perl b/Documentation/build-docdep.perl index 315efaa2fa2f2e..781da12b2ee8c9 100755 --- a/Documentation/build-docdep.perl +++ b/Documentation/build-docdep.perl @@ -4,15 +4,15 @@ my %include = (); my %included = (); -for my $text (<*.txt>) { - open I, '<', $text || die "cannot read: $text"; +for my $adoc (<*.adoc>) { + open I, '<', $adoc || die "cannot read: $adoc"; while () { if (/^include::/) { chomp; s/^include::\s*//; s/\[\]//; s/{build_dir}/${build_dir}/; - $include{$text}{$_} = 1; + $include{$adoc}{$_} = 1; $included{$_} = 1; } } @@ -23,14 +23,14 @@ my $changed = 1; while ($changed) { $changed = 0; - while (my ($text, $included) = each %include) { + while (my ($adoc, $included) = each %include) { for my $i (keys %$included) { - # $text has include::$i; if $i includes $j - # $text indirectly includes $j. + # $adoc has include::$i; if $i includes $j + # $adoc indirectly includes $j. if (exists $include{$i}) { for my $j (keys %{$include{$i}}) { - if (!exists $include{$text}{$j}) { - $include{$text}{$j} = 1; + if (!exists $include{$adoc}{$j}) { + $include{$adoc}{$j} = 1; $included{$j} = 1; $changed = 1; } @@ -40,10 +40,10 @@ } } -foreach my $text (sort keys %include) { - my $included = $include{$text}; - if (! exists $included{$text} && - (my $base = $text) =~ s/\.txt$//) { +foreach my $adoc (sort keys %include) { + my $included = $include{$adoc}; + if (! exists $included{$adoc} && + (my $base = $adoc) =~ s/\.adoc$//) { print "$base.html $base.xml : ", join(" ", sort keys %$included), "\n"; } } diff --git a/Documentation/config/promisor.adoc b/Documentation/config/promisor.adoc index 98c5cb2ec20d34..9192acfd243097 100644 --- a/Documentation/config/promisor.adoc +++ b/Documentation/config/promisor.adoc @@ -1,3 +1,30 @@ promisor.quiet:: If set to "true" assume `--quiet` when fetching additional objects for a partial clone. + +promisor.advertise:: + If set to "true", a server will use the "promisor-remote" + capability, see linkgit:gitprotocol-v2[5], to advertise the + promisor remotes it is using, if it uses some. Default is + "false", which means the "promisor-remote" capability is not + advertised. + +promisor.acceptFromServer:: + If set to "all", a client will accept all the promisor remotes + a server might advertise using the "promisor-remote" + capability. If set to "knownName" the client will accept + promisor remotes which are already configured on the client + and have the same name as those advertised by the client. This + is not very secure, but could be used in a corporate setup + where servers and clients are trusted to not switch name and + URLs. If set to "knownUrl", the client will accept promisor + remotes which have both the same name and the same URL + configured on the client as the name and URL advertised by the + server. This is more secure than "all" or "knownName", so it + should be used if possible instead of those options. Default + is "none", which means no promisor remote advertised by a + server will be accepted. By accepting a promisor remote, the + client agrees that the server might omit objects that are + lazily fetchable from this promisor remote from its responses + to "fetch" and "clone" requests from the client. See + linkgit:gitprotocol-v2[5]. diff --git a/Documentation/gitattributes.adoc b/Documentation/gitattributes.adoc index 26f80c3775a474..475c0f5c42fd84 100644 --- a/Documentation/gitattributes.adoc +++ b/Documentation/gitattributes.adoc @@ -543,7 +543,7 @@ If the filter command (a string value) is defined via `filter..process` then Git can process all blobs with a single filter invocation for the entire life of a single Git command. This is achieved by using the long-running process protocol -(described in technical/long-running-process-protocol.txt). +(described in Documentation/technical/long-running-process-protocol.adoc). When Git encounters the first file that needs to be cleaned or smudged, it starts the filter and performs the handshake. In the handshake, the @@ -1207,11 +1207,11 @@ integer has a meaningful effect. For example, this line in `.gitattributes` can be used to tell the merge machinery to leave much longer (instead of the usual 7-character-long) -conflict markers when merging the file `Documentation/git-merge.txt` +conflict markers when merging the file `Documentation/git-merge.adoc` results in a conflict. ------------------------ -Documentation/git-merge.txt conflict-marker-size=32 +Documentation/git-merge.adoc conflict-marker-size=32 ------------------------ diff --git a/Documentation/gitprotocol-v2.adoc b/Documentation/gitprotocol-v2.adoc index 9f6350bbf2f72a..5598c93e67c314 100644 --- a/Documentation/gitprotocol-v2.adoc +++ b/Documentation/gitprotocol-v2.adoc @@ -785,6 +785,60 @@ retrieving the header from a bundle at the indicated URI, and thus save themselves and the server(s) the request(s) needed to inspect the headers of that bundle or bundles. +promisor-remote= +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The server may advertise some promisor remotes it is using or knows +about to a client which may want to use them as its promisor remotes, +instead of this repository. In this case should be of the +form: + + pr-infos = pr-info | pr-infos ";" pr-info + + pr-info = "name=" pr-name | "name=" pr-name "," "url=" pr-url + +where `pr-name` is the urlencoded name of a promisor remote, and +`pr-url` the urlencoded URL of that promisor remote. + +In this case, if the client decides to use one or more promisor +remotes the server advertised, it can reply with +"promisor-remote=" where should be of the form: + + pr-names = pr-name | pr-names ";" pr-name + +where `pr-name` is the urlencoded name of a promisor remote the server +advertised and the client accepts. + +Note that, everywhere in this document, `pr-name` MUST be a valid +remote name, and the ';' and ',' characters MUST be encoded if they +appear in `pr-name` or `pr-url`. + +If the server doesn't know any promisor remote that could be good for +a client to use, or prefers a client not to use any promisor remote it +uses or knows about, it shouldn't advertise the "promisor-remote" +capability at all. + +In this case, or if the client doesn't want to use any promisor remote +the server advertised, the client shouldn't advertise the +"promisor-remote" capability at all in its reply. + +The "promisor.advertise" and "promisor.acceptFromServer" configuration +options can be used on the server and client side to control what they +advertise or accept respectively. See the documentation of these +configuration options for more information. + +Note that in the future it would be nice if the "promisor-remote" +protocol capability could be used by the server, when responding to +`git fetch` or `git clone`, to advertise better-connected remotes that +the client can use as promisor remotes, instead of this repository, so +that the client can lazily fetch objects from these other +better-connected remotes. This would require the server to omit in its +response the objects available on the better-connected remotes that +the client has accepted. This hasn't been implemented yet though. So +for now this "promisor-remote" capability is useful only when the +server advertises some promisor remotes it already uses to borrow +objects from. + GIT --- Part of the linkgit:git[1] suite diff --git a/Documentation/gitrepository-layout.adoc b/Documentation/gitrepository-layout.adoc index 6348ef1dcdf842..7421ef956d35ac 100644 --- a/Documentation/gitrepository-layout.adoc +++ b/Documentation/gitrepository-layout.adoc @@ -152,6 +152,7 @@ config.worktree:: working directory in multiple working directory setup (see linkgit:git-worktree[1]). +ifndef::with-breaking-changes[] branches:: A deprecated way to store shorthands to be used to specify a URL to 'git fetch', 'git pull' and 'git push'. @@ -164,6 +165,7 @@ branches:: "$GIT_COMMON_DIR/branches" will be used instead. + Git will stop reading remotes from this directory in Git 3.0. +endif::with-breaking-changes[] hooks:: Hooks are customization scripts used by various Git @@ -231,6 +233,7 @@ info/sparse-checkout:: This file stores sparse checkout patterns. See also: linkgit:git-read-tree[1]. +ifndef::with-breaking-changes[] remotes:: Stores shorthands for URL and default refnames for use when interacting with remote repositories via 'git fetch', @@ -241,6 +244,7 @@ remotes:: "$GIT_COMMON_DIR/remotes" will be used instead. + Git will stop reading remotes from this directory in Git 3.0. +endif::with-breaking-changes[] logs:: Records of changes made to refs are stored in this directory. diff --git a/Documentation/howto/howto-index.sh b/Documentation/howto/howto-index.sh index eecd123a936079..ace49830a8234f 100755 --- a/Documentation/howto/howto-index.sh +++ b/Documentation/howto/howto-index.sh @@ -9,9 +9,9 @@ people describing how they use Git in their workflow. EOF -for txt +for adoc do - title=$(expr "$txt" : '.*/\(.*\)\.txt$') + title=$(expr "$adoc" : '.*/\(.*\)\.adoc$') from=$(sed -ne ' /^$/q /^From:[ ]/{ @@ -21,7 +21,7 @@ do s/^/by / p } - ' "$txt") + ' "$adoc") abstract=$(sed -ne ' /^Abstract:[ ]/{ @@ -39,13 +39,13 @@ do x p q - }' "$txt") + }' "$adoc") - if grep 'Content-type: text/asciidoc' >/dev/null $txt + if grep 'Content-type: text/asciidoc' >/dev/null $adoc then - file=$(expr "$txt" : '\(.*\)\.txt$').html + file=$(expr "$adoc" : '\(.*\)\.adoc$').html else - file="$txt" + file="$adoc" fi echo "* link:howto/$(basename "$file")[$title] $from diff --git a/Documentation/howto/meson.build b/Documentation/howto/meson.build index 92a08b13eed444..81000028c08ee6 100644 --- a/Documentation/howto/meson.build +++ b/Documentation/howto/meson.build @@ -1,20 +1,20 @@ howto_sources = [ - 'coordinate-embargoed-releases.txt', - 'keep-canonical-history-correct.txt', - 'maintain-git.txt', - 'new-command.txt', - 'rebase-from-internal-branch.txt', - 'rebuild-from-update-hook.txt', - 'recover-corrupted-blob-object.txt', - 'recover-corrupted-object-harder.txt', - 'revert-a-faulty-merge.txt', - 'revert-branch-rebase.txt', - 'separating-topic-branches.txt', - 'setup-git-server-over-http.txt', - 'update-hook-example.txt', - 'use-git-daemon.txt', - 'using-merge-subtree.txt', - 'using-signed-tag-in-pull-request.txt', + 'coordinate-embargoed-releases.adoc', + 'keep-canonical-history-correct.adoc', + 'maintain-git.adoc', + 'new-command.adoc', + 'rebase-from-internal-branch.adoc', + 'rebuild-from-update-hook.adoc', + 'recover-corrupted-blob-object.adoc', + 'recover-corrupted-object-harder.adoc', + 'revert-a-faulty-merge.adoc', + 'revert-branch-rebase.adoc', + 'separating-topic-branches.adoc', + 'setup-git-server-over-http.adoc', + 'update-hook-example.adoc', + 'use-git-daemon.adoc', + 'using-merge-subtree.adoc', + 'using-signed-tag-in-pull-request.adoc', ] howto_index = custom_target( @@ -26,7 +26,7 @@ howto_index = custom_target( env: script_environment, capture: true, input: howto_sources, - output: 'howto-index.txt', + output: 'howto-index.adoc', ) custom_target( diff --git a/Documentation/howto/new-command.adoc b/Documentation/howto/new-command.adoc index 880c51112ba478..ac73c98be72ded 100644 --- a/Documentation/howto/new-command.adoc +++ b/Documentation/howto/new-command.adoc @@ -48,7 +48,7 @@ binary); this organization makes it easy for people reading the code to find things. See the CodingGuidelines document for other guidance on what we consider -good practice in C and shell, and api-builtin.txt for the support +good practice in C and shell, and builtin.h for the support functions available to built-in commands written in C. What every extension command needs diff --git a/Documentation/meson.build b/Documentation/meson.build index 221678cd06c45e..138b03dae02a5c 100644 --- a/Documentation/meson.build +++ b/Documentation/meson.build @@ -285,6 +285,10 @@ elif docs_backend == 'asciidoctor' ] endif +if get_option('breaking_changes') + asciidoc_common_options += ['--attribute', 'with-breaking-changes'] +endif + xmlto = find_program('xmlto', dirs: program_path) cmd_lists = [ diff --git a/Documentation/technical/api-simple-ipc.adoc b/Documentation/technical/api-simple-ipc.adoc index c4fb152b23291c..972178b042bc99 100644 --- a/Documentation/technical/api-simple-ipc.adoc +++ b/Documentation/technical/api-simple-ipc.adoc @@ -36,7 +36,7 @@ Comparison with sub-process model --------------------------------- The Simple-IPC mechanism differs from the existing `sub-process.c` -model (Documentation/technical/long-running-process-protocol.txt) and +model (Documentation/technical/long-running-process-protocol.adoc) and used by applications like Git-LFS. In the LFS-style sub-process model, the helper is started by the foreground process, communication happens via a pair of file descriptors bound to the stdin/stdout of the diff --git a/Documentation/technical/hash-function-transition.adoc b/Documentation/technical/hash-function-transition.adoc index 7102c7c8f5d66d..f047fd80cadd1e 100644 --- a/Documentation/technical/hash-function-transition.adoc +++ b/Documentation/technical/hash-function-transition.adoc @@ -394,7 +394,7 @@ inflated again in step 3, for a total of two inflations. Step 4 is probably necessary for good read-time performance. "git pack-objects" on the server optimizes the pack file for good data -locality (see Documentation/technical/pack-heuristics.txt). +locality (see Documentation/technical/pack-heuristics.adoc). Details of this process are likely to change. It will take some experimenting to get this to perform well. diff --git a/Documentation/technical/large-object-promisors.adoc b/Documentation/technical/large-object-promisors.adoc new file mode 100644 index 00000000000000..dea8dafa669908 --- /dev/null +++ b/Documentation/technical/large-object-promisors.adoc @@ -0,0 +1,656 @@ +Large Object Promisors +====================== + +Since Git has been created, users have been complaining about issues +with storing large files in Git. Some solutions have been created to +help, but they haven't helped much with some issues. + +Git currently supports multiple promisor remotes, which could help +with some of these remaining issues, but it's very hard to use them to +help, because a number of important features are missing. + +The goal of the effort described in this document is to add these +important features. + +We will call a "Large Object Promisor", or "LOP" in short, a promisor +remote which is used to store only large blobs and which is separate +from the main remote that should store the other Git objects and the +rest of the repos. + +By extension, we will also call "Large Object Promisor", or LOP, the +effort described in this document to add a set of features to make it +easier to handle large blobs/files in Git by using LOPs. + +This effort aims to especially improve things on the server side, and +especially for large blobs that are already compressed in a binary +format. + +This effort aims to provide an alternative to Git LFS +(https://git-lfs.com/) and similar tools like git-annex +(https://git-annex.branchable.com/) for handling large files, even +though a complete alternative would very likely require other efforts +especially on the client side, where it would likely help to implement +a new object representation for large blobs as discussed in: + +https://lore.kernel.org/git/xmqqbkdometi.fsf@gitster.g/ + +0) Non goals +------------ + +- We will not discuss those client side improvements here, as they + would require changes in different parts of Git than this effort. ++ +So we don't pretend to fully replace Git LFS with only this effort, +but we nevertheless believe that it can significantly improve the +current situation on the server side, and that other separate +efforts could also improve the situation on the client side. + +- In the same way, we are not going to discuss all the possible ways + to implement a LOP or their underlying object storage, or to + optimize how LOP works. ++ +Our opinion is that the simplest solution for now is for LOPs to use +object storage through a remote helper (see section II.2 below for +more details) to store their objects. So we consider that this is the +default implementation. If there are improvements on top of this, +that's great, but our opinion is that such improvements are not +necessary for LOPs to already be useful. Such improvements are likely +a different technical topic, and can be taken care of separately +anyway. ++ +So in particular we are not going to discuss pluggable ODBs or other +object database backends that could chunk large blobs, dedup the +chunks and store them efficiently. Sure, that would be a nice +improvement to store large blobs on the server side, but we believe +it can just be a separate effort as it's also not technically very +related to this effort. ++ +We are also not going to discuss data transfer improvements between +LOPs and clients or servers. Sure, there might be some easy and very +effective optimizations there (as we know that objects on LOPs are +very likely incompressible and not deltifying well), but this can be +dealt with separately in a separate effort. + +In other words, the goal of this document is not to talk about all the +possible ways to optimize how Git could handle large blobs, but to +describe how a LOP based solution can already work well and alleviate +a number of current issues in the context of Git clients and servers +sharing Git objects. + +Even if LOPs are used not very efficiently, they can still be useful +and worth using in some cases, as we will see in more details +later in this document: + + - they can make it simpler for clients to use promisor remotes and + therefore avoid fetching a lot of large blobs they might not need + locally, + + - they can make it significantly cheaper or easier for servers to + host a significant part of the current repository content, and + even more to host content with larger blobs or more large blobs + than currently. + +I) Issues with the current situation +------------------------------------ + +- Some statistics made on GitLab repos have shown that more than 75% + of the disk space is used by blobs that are larger than 1MB and + often in a binary format. + +- So even if users could use Git LFS or similar tools to store a lot + of large blobs out of their repos, it's a fact that in practice they + don't do it as much as they probably should. + +- On the server side ideally, the server should be able to decide for + itself how it stores things. It should not depend on users deciding + to use tools like Git LFS on some blobs or not. + +- It's much more expensive to store large blobs that don't delta + compress well on regular fast seeking drives (like SSDs) than on + object storage (like Amazon S3 or GCP Buckets). Using fast drives + for regular Git repos makes sense though, as serving regular Git + content (blobs containing text or code) needs drives where seeking + is fast, but the content is relatively small. On the other hand, + object storage for Git LFS blobs makes sense as seeking speed is not + as important when dealing with large files, while costs are more + important. So the fact that users don't use Git LFS or similar tools + for a significant number of large blobs has likely some bad + consequences on the cost of repo storage for most Git hosting + platforms. + +- Having large blobs handled in the same way as other blobs and Git + objects in Git repos instead of on object storage also has a cost in + increased memory and CPU usage, and therefore decreased performance, + when creating packfiles. (This is because Git tries to use delta + compression or zlib compression which is unlikely to work well on + already compressed binary content.) So it's not just a storage cost + increase. + +- When a large blob has been committed into a repo, it might not be + possible to remove this blob from the repo without rewriting + history, even if the user then decides to use Git LFS or a similar + tool to handle it. + +- In fact Git LFS and similar tools are not very flexible in letting + users change their minds about the blobs they should handle or not. + +- Even when users are using Git LFS or similar tools, they are often + complaining that these tools require significant effort to set up, + learn and use correctly. + +II) Main features of the "Large Object Promisors" solution +---------------------------------------------------------- + +The main features below should give a rough overview of how the +solution may work. Details about needed elements can be found in +following sections. + +Even if each feature below is very useful for the full solution, it is +very likely to be also useful on its own in some cases where the full +solution is not required. However, we'll focus primarily on the big +picture here. + +Also each feature doesn't need to be implemented entirely in Git +itself. Some could be scripts, hooks or helpers that are not part of +the Git repo. It would be helpful if those could be shared and +improved on collaboratively though. So we want to encourage sharing +them. + +1) Large blobs are stored on LOPs +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Large blobs should be stored on special promisor remotes that we will +call "Large Object Promisors" or LOPs. These LOPs should be additional +remotes dedicated to contain large blobs especially those in binary +format. They should be used along with main remotes that contain the +other objects. + +Note 1 +++++++ + +To clarify, a LOP is a normal promisor remote, except that: + +- it should store only large blobs, + +- it should be separate from the main remote, so that the main remote + can focus on serving other objects and the rest of the repos (see + feature 4) below) and can use the LOP as a promisor remote for + itself. + +Note 2 +++++++ + +Git already makes it possible for a main remote to also be a promisor +remote storing both regular objects and large blobs for a client that +clones from it with a filter on blob size. But here we explicitly want +to avoid that. + +Rationale ++++++++++ + +LOPs aim to be good at handling large blobs while main remotes are +already good at handling other objects. + +Implementation +++++++++++++++ + +Git already has support for multiple promisor remotes, see +link:partial-clone.html#using-many-promisor-remotes[the partial clone documentation]. + +Also, Git already has support for partial clone using a filter on the +size of the blobs (with `git clone --filter=blob:limit=`). Most +of the other main features below are based on these existing features +and are about making them easy and efficient to use for the purpose of +better handling large blobs. + +2) LOPs can use object storage +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +LOPs can be implemented using object storage, like an Amazon S3 or GCP +Bucket or MinIO (which is open source under the GNU AGPLv3 license) to +actually store the large blobs, and can be accessed through a Git +remote helper (see linkgit:gitremote-helpers[7]) which makes the +underlying object storage appear like a remote to Git. + +Note +++++ + +A LOP can be a promisor remote accessed using a remote helper by +both some clients and the main remote. + +Rationale ++++++++++ + +This looks like the simplest way to create LOPs that can cheaply +handle many large blobs. + +Implementation +++++++++++++++ + +Remote helpers are quite easy to write as shell scripts, but it might +be more efficient and maintainable to write them using other languages +like Go. + +Some already exist under open source licenses, for example: + + - https://github.com/awslabs/git-remote-s3 + - https://gitlab.com/eric.p.ju/git-remote-gs + +Other ways to implement LOPs are certainly possible, but the goal of +this document is not to discuss how to best implement a LOP or its +underlying object storage (see the "0) Non goals" section above). + +3) LOP object storage can be Git LFS storage +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The underlying object storage that a LOP uses could also serve as +storage for large files handled by Git LFS. + +Rationale ++++++++++ + +This would simplify the server side if it wants to both use a LOP and +act as a Git LFS server. + +4) A main remote can offload to a LOP with a configurable threshold +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +On the server side, a main remote should have a way to offload to a +LOP all its blobs with a size over a configurable threshold. + +Rationale ++++++++++ + +This makes it easy to set things up and to clean things up. For +example, an admin could use this to manually convert a repo not using +LOPs to a repo using a LOP. On a repo already using a LOP but where +some users would sometimes push large blobs, a cron job could use this +to regularly make sure the large blobs are moved to the LOP. + +Implementation +++++++++++++++ + +Using something based on `git repack --filter=...` to separate the +blobs we want to offload from the other Git objects could be a good +idea. The missing part is to connect to the LOP, check if the blobs we +want to offload are already there and if not send them. + +5) A main remote should try to remain clean from large blobs +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +A main remote should try to avoid containing a lot of oversize +blobs. For that purpose, it should offload as needed to a LOP and it +should have ways to prevent oversize blobs to be fetched, and also +perhaps pushed, into it. + +Rationale ++++++++++ + +A main remote containing many oversize blobs would defeat the purpose +of LOPs. + +Implementation +++++++++++++++ + +The way to offload to a LOP discussed in 4) above can be used to +regularly offload oversize blobs. About preventing oversize blobs from +being fetched into the repo see 6) below. About preventing oversize +blob pushes, a pre-receive hook could be used. + +Also there are different scenarios in which large blobs could get +fetched into the main remote, for example: + +- A client that doesn't implement the "promisor-remote" protocol + (described in 6) below) clones from the main remote. + +- The main remote gets a request for information about a large blob + and is not able to get that information without fetching the blob + from the LOP. + +It might not be possible to completely prevent all these scenarios +from happening. So the goal here should be to implement features that +make the fetching of large blobs less likely. For example adding a +`remote-object-info` command in the `git cat-file --batch` protocol +and its variants might make it possible for a main repo to respond to +some requests about large blobs without fetching them. + +6) A protocol negotiation should happen when a client clones +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +When a client clones from a main repo, there should be a protocol +negotiation so that the server can advertise one or more LOPs and so +that the client and the server can discuss if the client could +directly use a LOP the server is advertising. If the client and the +server can agree on that, then the client would be able to get the +large blobs directly from the LOP and the server would not need to +fetch those blobs from the LOP to be able to serve the client. + +Note +++++ + +For fetches instead of clones, a protocol negotiation might not always +happen, see the "What about fetches?" FAQ entry below for details. + +Rationale ++++++++++ + +Security, configurability and efficiency of setting things up. + +Implementation +++++++++++++++ + +A "promisor-remote" protocol v2 capability looks like a good way to +implement this. The way the client and server use this capability +could be controlled by configuration variables. + +Information that the server could send to the client through that +protocol could be things like: LOP name, LOP URL, filter-spec (for +example `blob:limit=`) or just size limit that should be used as +a filter when cloning, token to be used with the LOP, etc. + +7) A client can offload to a LOP +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +When a client is using a LOP that is also a LOP of its main remote, +the client should be able to offload some large blobs it has fetched, +but might not need anymore, to the LOP. + +Note +++++ + +It might depend on the context if it should be OK or not for clients +to offload large blobs they have created, instead of fetched, directly +to the LOP without the main remote checking them in some ways +(possibly using hooks or other tools). + +This should be discussed and refined when we get closer to +implementing this feature. + +Rationale ++++++++++ + +On the client, the easiest way to deal with unneeded large blobs is to +offload them. + +Implementation +++++++++++++++ + +This is very similar to what 4) above is about, except on the client +side instead of the server side. So a good solution to 4) could likely +be adapted to work on the client side too. + +There might be some security issues here, as there is no negotiation, +but they might be mitigated if the client can reuse a token it got +when cloning (see 6) above). Also if the large blobs were fetched from +a LOP, it is likely, and can easily be confirmed, that the LOP still +has them, so that they can just be removed from the client. + +III) Benefits of using LOPs +--------------------------- + +Many benefits are related to the issues discussed in "I) Issues with +the current situation" above: + +- No need to rewrite history when deciding which blobs are worth + handling separately than other objects, or when moving or removing + the threshold. + +- If the protocol between client and server is developed and secured + enough, then many details might be setup on the server side only and + all the clients could then easily get all the configuration + information and use it to set themselves up mostly automatically. + +- Storage costs benefits on the server side. + +- Reduced memory and CPU needs on main remotes on the server side. + +- Reduced storage needs on the client side. + +IV) FAQ +------- + +What about using multiple LOPs on the server and client side? +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +That could perhaps be useful in some cases, but for now it's more +likely that in most cases a single LOP will be advertised by the +server and should be used by the client. + +A case where it could be useful for a server to advertise multiple +LOPs is if a LOP is better for some users while a different LOP is +better for other users. For example some clients might have a better +connection to a LOP than others. + +In those cases it's the responsibility of the server to have some +documentation to help clients. It could say for example something like +"Users in this part of the world might want to pick only LOP A as it +is likely to be better connected to them, while users in other parts +of the world should pick only LOP B for the same reason." + +When should we trust or not trust the LOPs advertised by the server? +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +In some contexts, like in corporate setup where the server and all the +clients are parts of an internal network in a company where admins +have all the rights on every system, it's OK, and perhaps even a good +thing, if the clients fully trust the server, as it can help ensure +that all the clients are on the same page. + +There are also contexts in which clients trust a code hosting platform +serving them some repos, but might not fully trust other users +managing or contributing to some of these repos. For example, the code +hosting platform could have hooks in place to check that any object it +receives doesn't contain malware or otherwise bad content. In this +case it might be OK for the client to use a main remote and its LOP if +they are both hosted by the code hosting platform, but not if the LOP +is hosted elsewhere (where the content is not checked). + +In other contexts, a client should just not trust a server. + +So there should be different ways to configure how the client should +behave when a server advertises a LOP to it at clone time. + +As the basic elements that a server can advertise about a LOP are a +LOP name and a LOP URL, the client should base its decision about +accepting a LOP on these elements. + +One simple way to be very strict in the LOP it accepts is for example +for the client to check that the LOP is already configured on the +client with the same name and URL as what the server advertises. + +In general default and "safe" settings should require that the LOP are +configured on the client separately from the "promisor-remote" +protocol and that the client accepts a LOP only when information about +it from the protocol matches what has been already configured +separately. + +What about LOP names? +~~~~~~~~~~~~~~~~~~~~~ + +In some contexts, for example if the clients sometimes fetch from each +other, it can be a good idea for all the clients to use the same names +for all the remotes they use, including LOPs. + +In other contexts, each client might want to be able to give the name +it wants to each remote, including each LOP, it interacts with. + +So there should be different ways to configure how the client accepts +or not the LOP name the server advertises. + +If a default or "safe" setting is used, then as such a setting should +require that the LOP be configured separately, then the name would be +configured separately and there is no risk that the server could +dictate a name to a client. + +Could the main remote be bogged down by old or paranoid clients? +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Yes, it could happen if there are too many clients that are either +unwilling to trust the main remote or that just don't implement the +"promisor-remote" protocol because they are too old or not fully +compatible with the 'git' client. + +When serving such a client, the main remote has no other choice than +to first fetch from its LOP, to then be able to provide to the client +everything it requested. So the main remote, even if it has cleanup +mechanisms (see section II.4 above), would be burdened at least +temporarily with the large blobs it had to fetch from its LOP. + +Not behaving like this would be breaking backward compatibility, and +could be seen as segregating clients. For example, it might be +possible to implement a special mode that allows the server to just +reject clients that don't implement the "promisor-remote" protocol or +aren't willing to trust the main remote. This mode might be useful in +a special context like a corporate environment. There is no plan to +implement such a mode though, and this should be discussed separately +later anyway. + +A better way to proceed is probably for the main remote to show a +message telling clients that don't implement the protocol or are +unwilling to accept the advertised LOP(s) that they would get faster +clone and fetches by upgrading client software or properly setting +them up to accept LOP(s). + +Waiting for clients to upgrade, monitoring these upgrades and limiting +the use of LOPs to repos that are not very frequently accessed might +be other good ways to make sure that some benefits are still reaped +from LOPs. Over time, as more and more clients upgrade and benefit +from LOPs, using them in more and more frequently accessed repos will +become worth it. + +Corporate environments, where it might be easier to make sure that all +the clients are up-to-date and properly configured, could hopefully +benefit more and earlier from using LOPs. + +What about fetches? +~~~~~~~~~~~~~~~~~~~ + +There are different kinds of fetches. A regular fetch happens when +some refs have been updated on the server and the client wants the ref +updates and possibly the new objects added with them. A "backfill" or +"lazy" fetch, on the contrary, happens when the client needs to use +some objects it already knows about but doesn't have because they are +on a promisor remote. + +Regular fetch ++++++++++++++ + +In a regular fetch, the client will contact the main remote and a +protocol negotiation will happen between them. It's a good thing that +a protocol negotiation happens every time, as the configuration on the +client or the main remote could have changed since the previous +protocol negotiation. In this case, the new protocol negotiation +should ensure that the new fetch will happen in a way that satisfies +the new configuration of both the client and the server. + +In most cases though, the configurations on the client and the main +remote will not have changed between 2 fetches or between the initial +clone and a subsequent fetch. This means that the result of a new +protocol negotiation will be the same as the previous result, so the +new fetch will happen in the same way as the previous clone or fetch, +using, or not using, the same LOP(s) as last time. + +"Backfill" or "lazy" fetch +++++++++++++++++++++++++++ + +When there is a backfill fetch, the client doesn't necessarily contact +the main remote first. It will try to fetch from its promisor remotes +in the order they appear in the config file, except that a remote +configured using the `extensions.partialClone` config variable will be +tried last. See +link:partial-clone.html#using-many-promisor-remotes[the partial clone documentation]. + +This is not new with this effort. In fact this is how multiple remotes +have already been working for around 5 years. + +When using LOPs, having the main remote configured using +`extensions.partialClone`, so it's tried last, makes sense, as missing +objects should only be large blobs that are on LOPs. + +This means that a protocol negotiation will likely not happen as the +missing objects will be fetched from the LOPs, and then there will be +nothing left to fetch from the main remote. + +To secure that, it could be a good idea for LOPs to require a token +from the client when it fetches from them. The client could get the +token when performing a protocol negotiation with the main remote (see +section II.6 above). + +V) Future improvements +---------------------- + +It is expected that at the beginning using LOPs will be mostly worth +it either in a corporate context where the Git version that clients +use can easily be controlled, or on repos that are infrequently +accessed. (See the "Could the main remote be bogged down by old or +paranoid clients?" section in the FAQ above.) + +Over time, as more and more clients upgrade to a version that +implements the "promisor-remote" protocol v2 capability described +above in section II.6), it will be worth it to use LOPs more widely. + +A lot of improvements may also help using LOPs more widely. Some of +these improvements are part of the scope of this document like the +following: + + - Implementing a "remote-object-info" command in the + `git cat-file --batch` protocol and its variants to allow main + remotes to respond to requests about large blobs without fetching + them. (Eric Ju has started working on this based on previous work + by Calvin Wan.) + + - Creating better cleanup and offload mechanisms for main remotes + and clients to prevent accumulation of large blobs. + + - Developing more sophisticated protocol negotiation capabilities + between clients and servers for handling LOPs, for example adding + a filter-spec (e.g., blob:limit=) or size limit for + filtering when cloning, or adding a token for LOP authentication. + + - Improving security measures for LOP access, particularly around + token handling and authentication. + + - Developing standardized ways to configure and manage multiple LOPs + across different environments. Especially in the case where + different LOPs serve the same content to clients in different + geographical locations, there is a need for replication or + synchronization between LOPs. + +Some improvements, including some that have been mentioned in the "0) +Non Goals" section of this document, are out of the scope of this +document: + + - Implementing a new object representation for large blobs on the + client side. + + - Developing pluggable ODBs or other object database backends that + could chunk large blobs, dedup the chunks and store them + efficiently. + + - Optimizing data transfer between LOPs and clients/servers, + particularly for incompressible and non-deltifying content. + + - Creating improved client side tools for managing large objects + more effectively, for example tools for migrating from Git LFS or + git-annex, or tools to find which objects could be offloaded and + how much disk space could be reclaimed by offloading them. + +Some improvements could be seen as part of the scope of this document, +but might already have their own separate projects from the Git +project, like: + + - Improving existing remote helpers to access object storage or + developing new ones. + + - Improving existing object storage solutions or developing new + ones. + +Even though all the above improvements may help, this document and the +LOP effort should try to focus, at least first, on a relatively small +number of improvements mostly those that are in its current scope. + +For example introducing pluggable ODBs and a new object database +backend is likely a multi-year effort on its own that can happen +separately in parallel. It has different technical requirements, +touches other part of the Git code base and should have its own design +document(s). diff --git a/Documentation/technical/meson.build b/Documentation/technical/meson.build index 3a65ee59b3cd2c..a13aafcfbb8c75 100644 --- a/Documentation/technical/meson.build +++ b/Documentation/technical/meson.build @@ -1,37 +1,37 @@ api_docs = [ - 'api-error-handling.txt', - 'api-merge.txt', - 'api-parse-options.txt', - 'api-simple-ipc.txt', - 'api-trace2.txt', + 'api-error-handling.adoc', + 'api-merge.adoc', + 'api-parse-options.adoc', + 'api-simple-ipc.adoc', + 'api-trace2.adoc', ] articles = [ - 'bitmap-format.txt', - 'build-systems.txt', - 'bundle-uri.txt', - 'commit-graph.txt', - 'directory-rename-detection.txt', - 'hash-function-transition.txt', - 'long-running-process-protocol.txt', - 'multi-pack-index.txt', - 'packfile-uri.txt', - 'pack-heuristics.txt', - 'parallel-checkout.txt', - 'partial-clone.txt', - 'platform-support.txt', - 'racy-git.txt', - 'reftable.txt', - 'remembering-renames.txt', - 'repository-version.txt', - 'rerere.txt', - 'scalar.txt', - 'send-pack-pipeline.txt', - 'shallow.txt', - 'sparse-checkout.txt', - 'sparse-index.txt', - 'trivial-merge.txt', - 'unit-tests.txt', + 'bitmap-format.adoc', + 'build-systems.adoc', + 'bundle-uri.adoc', + 'commit-graph.adoc', + 'directory-rename-detection.adoc', + 'hash-function-transition.adoc', + 'long-running-process-protocol.adoc', + 'multi-pack-index.adoc', + 'packfile-uri.adoc', + 'pack-heuristics.adoc', + 'parallel-checkout.adoc', + 'partial-clone.adoc', + 'platform-support.adoc', + 'racy-git.adoc', + 'reftable.adoc', + 'remembering-renames.adoc', + 'repository-version.adoc', + 'rerere.adoc', + 'scalar.adoc', + 'send-pack-pipeline.adoc', + 'shallow.adoc', + 'sparse-checkout.adoc', + 'sparse-index.adoc', + 'trivial-merge.adoc', + 'unit-tests.adoc', ] api_index = custom_target( @@ -43,7 +43,7 @@ api_index = custom_target( ], env: script_environment, input: api_docs, - output: 'api-index.txt', + output: 'api-index.adoc', ) custom_target( diff --git a/Documentation/technical/partial-clone.adoc b/Documentation/technical/partial-clone.adoc index bf5ec5c82d9e0f..e513e391ea82ca 100644 --- a/Documentation/technical/partial-clone.adoc +++ b/Documentation/technical/partial-clone.adoc @@ -85,7 +85,7 @@ See "filter" in linkgit:gitprotocol-pack[5]. server to request filtering during packfile construction. + There are various filters available to accommodate different situations. -See "--filter=" in Documentation/rev-list-options.txt. +See "--filter=" in Documentation/rev-list-options.adoc. - On the server pack-objects applies the requested filter-spec as it creates "filtered" packfiles for the client. diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN index 7fb7fff6dda300..8979fb2803285a 100755 --- a/GIT-VERSION-GEN +++ b/GIT-VERSION-GEN @@ -1,6 +1,6 @@ #!/bin/sh -DEF_VER=v2.49.0-rc1 +DEF_VER=v2.49.0-rc2 LF=' ' diff --git a/Makefile b/Makefile index 6eb1525e1d775a..cf02ea28c01d4c 100644 --- a/Makefile +++ b/Makefile @@ -194,7 +194,7 @@ include shared.mak # Linux, kernel 2.6.11 or newer is required for reliable sub-second file times # on file systems with exactly 1 ns or 1 s resolution. If you intend to use Git # on other file systems (e.g. CEPH, CIFS, NTFS, UDF), don't enable USE_NSEC. See -# Documentation/technical/racy-git.txt for details. +# Documentation/technical/racy-git.adoc for details. # # Define USE_ST_TIMESPEC if your "struct stat" uses "st_ctimespec" instead of # "st_ctim" @@ -1364,6 +1364,9 @@ CLAR_TEST_SUITES += u-example-decorate CLAR_TEST_SUITES += u-hash CLAR_TEST_SUITES += u-hashmap CLAR_TEST_SUITES += u-mem-pool +CLAR_TEST_SUITES += u-oid-array +CLAR_TEST_SUITES += u-oidmap +CLAR_TEST_SUITES += u-oidtree CLAR_TEST_SUITES += u-prio-queue CLAR_TEST_SUITES += u-reftable-tree CLAR_TEST_SUITES += u-strbuf @@ -1374,10 +1377,8 @@ CLAR_TEST_PROG = $(UNIT_TEST_BIN)/unit-tests$(X) CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES)) CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/clar/clar.o CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o +CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o -UNIT_TEST_PROGRAMS += t-oid-array -UNIT_TEST_PROGRAMS += t-oidmap -UNIT_TEST_PROGRAMS += t-oidtree UNIT_TEST_PROGRAMS += t-reftable-basics UNIT_TEST_PROGRAMS += t-reftable-block UNIT_TEST_PROGRAMS += t-reftable-merged @@ -1390,7 +1391,6 @@ UNIT_TEST_PROGRAMS += t-trailer UNIT_TEST_PROGRAMS += t-urlmatch-normalization UNIT_TEST_PROGS = $(patsubst %,$(UNIT_TEST_BIN)/%$X,$(UNIT_TEST_PROGRAMS)) UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/test-lib.o -UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/lib-reftable.o # xdiff and reftable libs may in turn depend on what is in libgit.a diff --git a/README.md b/README.md index 5f7354536e4442..da4c2988ecaa0f 100644 --- a/README.md +++ b/README.md @@ -90,15 +90,15 @@ Please read the file [INSTALL][] for installation instructions. Many Git online resources are accessible from including full documentation and Git related tools. -See [Documentation/gittutorial.txt][] to get started, then see -[Documentation/giteveryday.txt][] for a useful minimum set of commands, and -`Documentation/git-.txt` for documentation of each command. +See [Documentation/gittutorial.adoc][] to get started, then see +[Documentation/giteveryday.adoc][] for a useful minimum set of commands, and +`Documentation/git-.adoc` for documentation of each command. If git has been correctly installed, then the tutorial can also be read with `man gittutorial` or `git help tutorial`, and the documentation of each command with `man git-` or `git help `. -CVS users may also want to read [Documentation/gitcvs-migration.txt][] +CVS users may also want to read [Documentation/gitcvs-migration.adoc][] (`man gitcvs-migration` or `git help cvs-migration` if git is installed). @@ -140,9 +140,9 @@ and the name as (depending on your mood): - "goddamn idiotic truckload of sh*t": when it breaks [INSTALL]: INSTALL -[Documentation/gittutorial.txt]: Documentation/gittutorial.txt -[Documentation/giteveryday.txt]: Documentation/giteveryday.txt -[Documentation/gitcvs-migration.txt]: Documentation/gitcvs-migration.txt +[Documentation/gittutorial.adoc]: Documentation/gittutorial.adoc +[Documentation/giteveryday.adoc]: Documentation/giteveryday.adoc +[Documentation/gitcvs-migration.adoc]: Documentation/gitcvs-migration.adoc [Documentation/SubmittingPatches]: Documentation/SubmittingPatches [Documentation/CodingGuidelines]: Documentation/CodingGuidelines [po/README.md]: po/README.md diff --git a/advice.h b/advice.h index 31f510867413e4..a346054b31e804 100644 --- a/advice.h +++ b/advice.h @@ -7,7 +7,7 @@ struct string_list; * To add a new advice, you need to: * Define a new advice_type. * Add a new entry to advice_setting array. - * Add the new config variable to Documentation/config/advice.txt. + * Add the new config variable to Documentation/config/advice.adoc. * Call advise_if_enabled to print your advice. */ enum advice_type { diff --git a/apply.c b/apply.c index 6f74abb4624e4d..df4843830d04a2 100644 --- a/apply.c +++ b/apply.c @@ -82,7 +82,7 @@ static int parse_whitespace_option(struct apply_state *state, const char *option } /* * Please update $__git_whitespacelist in git-completion.bash, - * Documentation/git-apply.txt, and Documentation/git-am.txt + * Documentation/git-apply.adoc, and Documentation/git-am.adoc * when you add new options. */ return error(_("unrecognized whitespace option '%s'"), option); diff --git a/bisect.c b/bisect.c index 7a3c77c6d84da0..269a98bf978de6 100644 --- a/bisect.c +++ b/bisect.c @@ -930,7 +930,7 @@ static enum bisect_error check_good_are_ancestors_of_bad(struct repository *r, if (!current_bad_oid) return error(_("a %s revision is needed"), term_bad); - filename = git_pathdup("BISECT_ANCESTORS_OK"); + filename = repo_git_path(the_repository, "BISECT_ANCESTORS_OK"); /* Check if file BISECT_ANCESTORS_OK exists. */ if (!stat(filename, &st) && S_ISREG(st.st_mode)) diff --git a/branch.c b/branch.c index 77716966feb918..91297d55ac9f60 100644 --- a/branch.c +++ b/branch.c @@ -397,7 +397,7 @@ static void prepare_checked_out_branches(void) worktrees = get_worktrees(); while (worktrees[i]) { - char *old; + char *old, *wt_gitdir; struct wt_status_state state = { 0 }; struct worktree *wt = worktrees[i++]; struct string_list update_refs = STRING_LIST_INIT_DUP; @@ -437,7 +437,8 @@ static void prepare_checked_out_branches(void) } wt_status_state_free_buffers(&state); - if (!sequencer_get_update_refs_state(get_worktree_git_dir(wt), + wt_gitdir = get_worktree_git_dir(wt); + if (!sequencer_get_update_refs_state(wt_gitdir, &update_refs)) { struct string_list_item *item; for_each_string_list_item(item, &update_refs) { @@ -448,6 +449,8 @@ static void prepare_checked_out_branches(void) } string_list_clear(&update_refs, 1); } + + free(wt_gitdir); } free_worktrees(worktrees); diff --git a/builtin.h b/builtin.h index 5f64730cf0273d..c738795a4ff8b7 100644 --- a/builtin.h +++ b/builtin.h @@ -63,7 +63,7 @@ * * . Add tests to `t/` directory. * - * . Write documentation in `Documentation/git-foo.txt`. + * . Write documentation in `Documentation/git-foo.adoc`. * * . Add an entry for `git-foo` to `command-list.txt`. * diff --git a/builtin/am.c b/builtin/am.c index 390b463144202d..2921bb89ef16e6 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -158,7 +158,7 @@ static void am_state_init(struct am_state *state) memset(state, 0, sizeof(*state)); - state->dir = git_pathdup("rebase-apply"); + state->dir = repo_git_path(the_repository, "rebase-apply"); state->prec = 4; diff --git a/builtin/clone.c b/builtin/clone.c index f9a2ecbe9cc944..f14229abf450c0 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -835,7 +835,7 @@ static void write_refspec_config(const char *src_ref_prefix, static void dissociate_from_references(void) { - char *alternates = git_pathdup("objects/info/alternates"); + char *alternates = repo_git_path(the_repository, "objects/info/alternates"); if (!access(alternates, F_OK)) { struct child_process cmd = CHILD_PROCESS_INIT; @@ -1219,7 +1219,7 @@ int cmd_clone(int argc, strbuf_reset(&buf); strbuf_addf(&buf, "%s/refs", git_dir); - safe_create_dir(buf.buf, 1); + safe_create_dir(the_repository, buf.buf, 1); /* * additional config can be injected with -c, make sure it's included diff --git a/builtin/commit.c b/builtin/commit.c index 98601c1a31df19..20bdd93c439d6b 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -352,6 +352,7 @@ static const char *prepare_index(const char **argv, const char *prefix, struct pathspec pathspec; int refresh_flags = REFRESH_QUIET; const char *ret; + char *path = NULL; if (is_status) refresh_flags |= REFRESH_UNMERGED; @@ -524,9 +525,9 @@ static const char *prepare_index(const char **argv, const char *prefix, if (write_locked_index(the_repository->index, &index_lock, 0)) die(_("unable to write new index file")); - hold_lock_file_for_update(&false_lock, - git_path("next-index-%"PRIuMAX, - (uintmax_t) getpid()), + path = repo_git_path(the_repository, "next-index-%"PRIuMAX, + (uintmax_t) getpid()); + hold_lock_file_for_update(&false_lock, path, LOCK_DIE_ON_ERROR); create_base_index(current_head); @@ -542,6 +543,7 @@ static const char *prepare_index(const char **argv, const char *prefix, out: string_list_clear(&partial, 0); clear_pathspec(&pathspec); + free(path); return ret; } diff --git a/builtin/config.c b/builtin/config.c index 16e6e3055598f1..53a90094e31454 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -775,13 +775,13 @@ static void location_options_init(struct config_location_options *opts, opts->source.file = opts->file_to_free = git_system_config(); opts->source.scope = CONFIG_SCOPE_SYSTEM; } else if (opts->use_local_config) { - opts->source.file = opts->file_to_free = git_pathdup("config"); + opts->source.file = opts->file_to_free = repo_git_path(the_repository, "config"); opts->source.scope = CONFIG_SCOPE_LOCAL; } else if (opts->use_worktree_config) { struct worktree **worktrees = get_worktrees(); if (the_repository->repository_format_worktree_config) opts->source.file = opts->file_to_free = - git_pathdup("config.worktree"); + repo_git_path(the_repository, "config.worktree"); else if (worktrees[0] && worktrees[1]) die(_("--worktree cannot be used with multiple " "working trees unless the config\n" @@ -790,7 +790,7 @@ static void location_options_init(struct config_location_options *opts, "section in \"git help worktree\" for details")); else opts->source.file = opts->file_to_free = - git_pathdup("config"); + repo_git_path(the_repository, "config"); opts->source.scope = CONFIG_SCOPE_LOCAL; free_worktrees(worktrees); } else if (opts->source.file) { @@ -1087,7 +1087,7 @@ static int show_editor(struct config_location_options *opts) git_config(git_default_config, NULL); config_file = opts->source.file ? xstrdup(opts->source.file) : - git_pathdup("config"); + repo_git_path(the_repository, "config"); if (opts->use_global_config) { int fd = open(config_file, O_CREAT | O_EXCL | O_WRONLY, 0666); if (fd >= 0) { diff --git a/builtin/fast-import.c b/builtin/fast-import.c index d6a368a5665203..397a6f46ad85d5 100644 --- a/builtin/fast-import.c +++ b/builtin/fast-import.c @@ -328,7 +328,7 @@ static void write_branch_report(FILE *rpt, struct branch *b) static void write_crash_report(const char *err) { - char *loc = git_pathdup("fast_import_crash_%"PRIuMAX, (uintmax_t) getpid()); + char *loc = repo_git_path(the_repository, "fast_import_crash_%"PRIuMAX, (uintmax_t) getpid()); FILE *rpt = fopen(loc, "w"); struct branch *b; unsigned long lu; @@ -3280,7 +3280,7 @@ static char* make_fast_import_path(const char *path) { if (!relative_marks_paths || is_absolute_path(path)) return prefix_filename(global_prefix, path); - return git_pathdup("info/fast-import/%s", path); + return repo_git_path(the_repository, "info/fast-import/%s", path); } static void option_import_marks(const char *marks, diff --git a/builtin/fetch.c b/builtin/fetch.c index 1c740d5aac32df..95fd0018b981fb 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1777,7 +1777,9 @@ static int do_fetch(struct transport *transport, if (uses_remote_tracking(transport, rs)) { must_list_refs = 1; - strvec_push(&transport_ls_refs_options.ref_prefixes, "HEAD"); + if (transport_ls_refs_options.ref_prefixes.nr) + strvec_push(&transport_ls_refs_options.ref_prefixes, + "HEAD"); } if (must_list_refs) { diff --git a/builtin/fsck.c b/builtin/fsck.c index 7a4dcb0716052f..eea1d43647f224 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -326,7 +326,7 @@ static void check_unreachable_object(struct object *obj) printable_type(&obj->oid, obj->type), describe_object(&obj->oid)); if (write_lost_and_found) { - char *filename = git_pathdup("lost-found/%s/%s", + char *filename = repo_git_path(the_repository, "lost-found/%s/%s", obj->type == OBJ_COMMIT ? "commit" : "other", describe_object(&obj->oid)); FILE *f; @@ -1057,7 +1057,7 @@ int cmd_fsck(int argc, struct worktree *wt = *p; struct index_state istate = INDEX_STATE_INIT(the_repository); - char *path; + char *path, *wt_gitdir; /* * Make a copy since the buffer is reusable @@ -1065,9 +1065,13 @@ int cmd_fsck(int argc, * while we're examining the index. */ path = xstrdup(worktree_git_path(the_repository, wt, "index")); - read_index_from(&istate, path, get_worktree_git_dir(wt)); + wt_gitdir = get_worktree_git_dir(wt); + + read_index_from(&istate, path, wt_gitdir); fsck_index(&istate, path, wt->is_current); + discard_index(&istate); + free(wt_gitdir); free(path); } free_worktrees(worktrees); diff --git a/builtin/gc.c b/builtin/gc.c index 409d454a4b7113..99431fd46744cd 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -99,9 +99,11 @@ static void process_log_file(void) /* There was some error recorded in the lock file */ commit_lock_file(&log_lock); } else { + char *path = repo_git_path(the_repository, "gc.log"); /* No error, clean up any old gc.log */ - unlink(git_path("gc.log")); + unlink(path); rollback_lock_file(&log_lock); + free(path); } } @@ -300,8 +302,11 @@ static int too_many_loose_objects(struct gc_config *cfg) int num_loose = 0; int needed = 0; const unsigned hexsz_loose = the_hash_algo->hexsz - 2; + char *path; - dir = opendir(git_path("objects/17")); + path = repo_git_path(the_repository, "objects/17"); + dir = opendir(path); + free(path); if (!dir) return 0; @@ -550,7 +555,7 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid) if (xgethostname(my_host, sizeof(my_host))) xsnprintf(my_host, sizeof(my_host), "unknown"); - pidfile_path = git_pathdup("gc.pid"); + pidfile_path = repo_git_path(the_repository, "gc.pid"); fd = hold_lock_file_for_update(&lock, pidfile_path, LOCK_DIE_ON_ERROR); if (!force) { @@ -611,7 +616,7 @@ static int report_last_gc_error(void) int ret = 0; ssize_t len; struct stat st; - char *gc_log_path = git_pathdup("gc.log"); + char *gc_log_path = repo_git_path(the_repository, "gc.log"); if (stat(gc_log_path, &st)) { if (errno == ENOENT) @@ -826,11 +831,12 @@ struct repository *repo UNUSED) } if (daemonized) { - hold_lock_file_for_update(&log_lock, - git_path("gc.log"), + char *path = repo_git_path(the_repository, "gc.log"); + hold_lock_file_for_update(&log_lock, path, LOCK_DIE_ON_ERROR); dup2(get_lock_file_fd(&log_lock), 2); atexit(process_log_file_at_exit); + free(path); } gc_before_repack(&opts, &cfg); @@ -892,8 +898,11 @@ struct repository *repo UNUSED) warning(_("There are too many unreachable loose objects; " "run 'git prune' to remove them.")); - if (!daemonized) - unlink(git_path("gc.log")); + if (!daemonized) { + char *path = repo_git_path(the_repository, "gc.log"); + unlink(path); + free(path); + } out: gc_config_release(&cfg); diff --git a/builtin/init-db.c b/builtin/init-db.c index 096f96b9c4a203..196dccdd77acb8 100644 --- a/builtin/init-db.c +++ b/builtin/init-db.c @@ -132,8 +132,8 @@ int cmd_init_db(int argc, * and we know shared_repository should always be 0; * but just in case we play safe. */ - saved = get_shared_repository(); - set_shared_repository(0); + saved = repo_settings_get_shared_repository(the_repository); + repo_settings_set_shared_repository(the_repository, 0); switch (safe_create_leading_directories_const(argv[0])) { case SCLD_OK: case SCLD_PERMS: @@ -145,7 +145,7 @@ int cmd_init_db(int argc, die_errno(_("cannot mkdir %s"), argv[0]); break; } - set_shared_repository(saved); + repo_settings_set_shared_repository(the_repository, saved); if (mkdir(argv[0], 0777) < 0) die_errno(_("cannot mkdir %s"), argv[0]); mkdir_tried = 1; @@ -175,7 +175,7 @@ int cmd_init_db(int argc, } if (init_shared_repository != -1) - set_shared_repository(init_shared_repository); + repo_settings_set_shared_repository(the_repository, init_shared_repository); /* * GIT_WORK_TREE makes sense only in conjunction with GIT_DIR diff --git a/builtin/log.c b/builtin/log.c index e41f88945eb4ed..04a6ef97bc1442 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -2309,8 +2309,8 @@ int cmd_format_patch(int argc, * We consider as 'outside of gitdir', therefore avoid * applying adjust_shared_perm in s-c-l-d. */ - saved = get_shared_repository(); - set_shared_repository(0); + saved = repo_settings_get_shared_repository(the_repository); + repo_settings_set_shared_repository(the_repository, 0); switch (safe_create_leading_directories_const(output_directory)) { case SCLD_OK: case SCLD_EXISTS: @@ -2319,7 +2319,7 @@ int cmd_format_patch(int argc, die(_("could not create leading directories " "of '%s'"), output_directory); } - set_shared_repository(saved); + repo_settings_set_shared_repository(the_repository, saved); if (mkdir(output_directory, 0777) < 0 && errno != EEXIST) die_errno(_("could not create directory '%s'"), output_directory); diff --git a/builtin/notes.c b/builtin/notes.c index d051abf6dff8f2..ff61ec5f2da953 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -197,7 +197,7 @@ static void prepare_note_data(const struct object_id *object, struct note_data * struct strbuf buf = STRBUF_INIT; /* write the template message before editing: */ - d->edit_path = git_pathdup("NOTES_EDITMSG"); + d->edit_path = repo_git_path(the_repository, "NOTES_EDITMSG"); fd = xopen(d->edit_path, O_CREAT | O_TRUNC | O_WRONLY, 0600); if (d->msg_nr) @@ -979,6 +979,8 @@ static int merge(int argc, const char **argv, const char *prefix, else { /* Merge has unresolved conflicts */ struct worktree **worktrees; const struct worktree *wt; + char *path; + /* Update .git/NOTES_MERGE_PARTIAL with partial merge result */ refs_update_ref(get_main_ref_store(the_repository), msg.buf, "NOTES_MERGE_PARTIAL", &result_oid, NULL, @@ -994,10 +996,13 @@ static int merge(int argc, const char **argv, const char *prefix, if (refs_update_symref(get_main_ref_store(the_repository), "NOTES_MERGE_REF", notes_ref, NULL)) die(_("failed to store link to current notes ref (%s)"), notes_ref); + + path = repo_git_path(the_repository, NOTES_MERGE_WORKTREE); fprintf(stderr, _("Automatic notes merge failed. Fix conflicts in %s " "and commit the result with 'git notes merge --commit', " "or abort the merge with 'git notes merge --abort'.\n"), - git_path(NOTES_MERGE_WORKTREE)); + path); + free(path); } free_notes(t); diff --git a/builtin/rebase.c b/builtin/rebase.c index 6c9eaf3788c900..d4715ed35d77ed 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -644,7 +644,7 @@ static int run_am(struct rebase_options *opts) return run_command(&am); } - rebased_patches = xstrdup(git_path("rebased-patches")); + rebased_patches = repo_git_path(the_repository, "rebased-patches"); format_patch.out = open(rebased_patches, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (format_patch.out < 0) { diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 129305700c7576..7b28fc9df6ec0b 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -1435,7 +1435,8 @@ static const char *push_to_checkout(unsigned char *hash, static const char *update_worktree(unsigned char *sha1, const struct worktree *worktree) { - const char *retval, *git_dir; + const char *retval; + char *git_dir; struct strvec env = STRVEC_INIT; int invoked_hook; @@ -1453,6 +1454,7 @@ static const char *update_worktree(unsigned char *sha1, const struct worktree *w retval = push_to_deploy(sha1, &env, worktree->path); strvec_clear(&env); + free(git_dir); return retval; } diff --git a/builtin/refs.c b/builtin/refs.c index c459507d514b37..44d592a94cf381 100644 --- a/builtin/refs.c +++ b/builtin/refs.c @@ -8,7 +8,7 @@ #include "worktree.h" #define REFS_MIGRATE_USAGE \ - N_("git refs migrate --ref-format= [--dry-run]") + N_("git refs migrate --ref-format= [--no-reflog] [--dry-run]") #define REFS_VERIFY_USAGE \ N_("git refs verify [--strict] [--verbose]") diff --git a/builtin/remote.c b/builtin/remote.c index 816d482340110b..1b7aad88380735 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -644,9 +644,11 @@ static int migrate_file(struct remote *remote) git_config_set_multivar(buf.buf, remote->fetch.items[i].raw, "^$", 0); #ifndef WITH_BREAKING_CHANGES if (remote->origin == REMOTE_REMOTES) - unlink_or_warn(git_path("remotes/%s", remote->name)); + unlink_or_warn(repo_git_path_replace(the_repository, &buf, + "remotes/%s", remote->name)); else if (remote->origin == REMOTE_BRANCHES) - unlink_or_warn(git_path("branches/%s", remote->name)); + unlink_or_warn(repo_git_path_replace(the_repository, &buf, + "branches/%s", remote->name)); #endif /* WITH_BREAKING_CHANGES */ strbuf_release(&buf); diff --git a/builtin/replace.c b/builtin/replace.c index a4eaadff91f1be..15ec0922ce14d8 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -345,7 +345,7 @@ static int edit_and_replace(const char *object_ref, int force, int raw) } strbuf_release(&ref); - tmpfile = git_pathdup("REPLACE_EDITOBJ"); + tmpfile = repo_git_path(the_repository, "REPLACE_EDITOBJ"); if (export_object(&old_oid, type, raw, tmpfile)) { free(tmpfile); return -1; diff --git a/builtin/rerere.c b/builtin/rerere.c index 41127e24e53098..1312e79d89f38e 100644 --- a/builtin/rerere.c +++ b/builtin/rerere.c @@ -4,9 +4,9 @@ #include "config.h" #include "gettext.h" #include "parse-options.h" - -#include "string-list.h" #include "rerere.h" +#include "strbuf.h" +#include "string-list.h" #include "xdiff/xdiff.h" #include "xdiff-interface.h" #include "pathspec.h" @@ -112,15 +112,18 @@ int cmd_rerere(int argc, merge_rr.items[i].util = NULL; } } else if (!strcmp(argv[0], "diff")) { + struct strbuf buf = STRBUF_INIT; if (setup_rerere(the_repository, &merge_rr, flags | RERERE_READONLY) < 0) return 0; for (size_t i = 0; i < merge_rr.nr; i++) { const char *path = merge_rr.items[i].string; const struct rerere_id *id = merge_rr.items[i].util; - if (diff_two(rerere_path(id, "preimage"), path, path, path)) - die(_("unable to generate diff for '%s'"), rerere_path(id, NULL)); + if (diff_two(rerere_path(&buf, id, "preimage"), path, path, path)) + die(_("unable to generate diff for '%s'"), rerere_path(&buf, id, NULL)); } + + strbuf_release(&buf); } else usage_with_options(rerere_usage, options); diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index 428c866c05f4a4..490da33beccf72 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -789,8 +789,8 @@ int cmd_rev_parse(int argc, if (!strcmp(arg, "--git-path")) { if (!argv[i + 1]) die(_("--git-path requires an argument")); - strbuf_reset(&buf); - print_path(git_path("%s", argv[i + 1]), prefix, + print_path(repo_git_path_replace(the_repository, &buf, + "%s", argv[i + 1]), prefix, format, DEFAULT_RELATIVE_IF_SHARED); i++; @@ -1083,7 +1083,7 @@ int cmd_rev_parse(int argc, die(_("Could not read the index")); if (the_repository->index->split_index) { const struct object_id *oid = &the_repository->index->split_index->base_oid; - const char *path = git_path("sharedindex.%s", oid_to_hex(oid)); + const char *path = repo_git_path_replace(the_repository, &buf, "sharedindex.%s", oid_to_hex(oid)); print_path(path, prefix, format, DEFAULT_RELATIVE); } continue; diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index f9b970f8a64a54..c1a8029714bfe9 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1301,7 +1301,7 @@ static void sync_submodule(const char *path, const char *prefix, remote_key = xstrfmt("remote.%s.url", default_remote); free(default_remote); - submodule_to_gitdir(&sb, path); + submodule_to_gitdir(the_repository, &sb, path); strbuf_addstr(&sb, "/config"); if (git_config_set_in_file_gently(sb.buf, remote_key, NULL, sub_origin_url)) @@ -1826,7 +1826,7 @@ static int clone_submodule(const struct module_clone_data *clone_data, connect_work_tree_and_git_dir(clone_data_path, sm_gitdir, 0); - p = git_pathdup_submodule(clone_data_path, "config"); + p = repo_submodule_path(the_repository, clone_data_path, "config"); if (!p) die(_("could not get submodule directory for '%s'"), clone_data_path); diff --git a/builtin/tag.c b/builtin/tag.c index e8a344b9264b9c..d3e0943b734759 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -667,7 +667,7 @@ int cmd_tag(int argc, if (create_tag_object) { if (force_sign_annotate && !annotate) opt.sign = 1; - path = git_pathdup("TAG_EDITMSG"); + path = repo_git_path(the_repository, "TAG_EDITMSG"); create_tag(&object, object_ref, tag, &buf, &opt, &prev, &object, &trailer_args, path); } diff --git a/builtin/worktree.c b/builtin/worktree.c index c043d4d523f578..48448a83550944 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -151,7 +151,7 @@ static int delete_git_dir(const char *id) struct strbuf sb = STRBUF_INIT; int ret; - strbuf_addstr(&sb, git_common_path("worktrees/%s", id)); + repo_common_path_append(the_repository, &sb, "worktrees/%s", id); ret = remove_dir_recursively(&sb, 0); if (ret < 0 && errno == ENOTDIR) ret = unlink(sb.buf); @@ -163,7 +163,9 @@ static int delete_git_dir(const char *id) static void delete_worktrees_dir_if_empty(void) { - rmdir(git_path("worktrees")); /* ignore failed removal */ + char *path = repo_git_path(the_repository, "worktrees"); + rmdir(path); /* ignore failed removal */ + free(path); } static void prune_worktree(const char *id, const char *reason) @@ -212,8 +214,13 @@ static void prune_worktrees(void) struct strbuf reason = STRBUF_INIT; struct strbuf main_path = STRBUF_INIT; struct string_list kept = STRING_LIST_INIT_DUP; - DIR *dir = opendir(git_path("worktrees")); + char *path; + DIR *dir; struct dirent *d; + + path = repo_git_path(the_repository, "worktrees"); + dir = opendir(path); + free(path); if (!dir) return; while ((d = readdir_skip_dot_and_dotdot(dir)) != NULL) { @@ -337,7 +344,7 @@ static void check_candidate_path(const char *path, static void copy_sparse_checkout(const char *worktree_git_dir) { - char *from_file = git_pathdup("info/sparse-checkout"); + char *from_file = repo_git_path(the_repository, "info/sparse-checkout"); char *to_file = xstrfmt("%s/info/sparse-checkout", worktree_git_dir); if (file_exists(from_file)) { @@ -353,7 +360,7 @@ static void copy_sparse_checkout(const char *worktree_git_dir) static void copy_filtered_worktree_config(const char *worktree_git_dir) { - char *from_file = git_pathdup("config.worktree"); + char *from_file = repo_git_path(the_repository, "config.worktree"); char *to_file = xstrfmt("%s/config.worktree", worktree_git_dir); if (file_exists(from_file)) { @@ -457,7 +464,7 @@ static int add_worktree(const char *path, const char *refname, BUG("How come '%s' becomes empty after sanitization?", sb.buf); strbuf_reset(&sb); name = sb_name.buf; - git_path_buf(&sb_repo, "worktrees/%s", name); + repo_git_path_replace(the_repository, &sb_repo, "worktrees/%s", name); len = sb_repo.len; if (safe_create_leading_directories_const(sb_repo.buf)) die_errno(_("could not create leading directories of '%s'"), @@ -657,8 +664,9 @@ static int can_use_local_refs(const struct add_opts *opts) if (!opts->quiet) { struct strbuf path = STRBUF_INIT; struct strbuf contents = STRBUF_INIT; + char *wt_gitdir = get_worktree_git_dir(NULL); - strbuf_add_real_path(&path, get_worktree_git_dir(NULL)); + strbuf_add_real_path(&path, wt_gitdir); strbuf_addstr(&path, "/HEAD"); strbuf_read_file(&contents, path.buf, 64); strbuf_stripspace(&contents, NULL); @@ -670,6 +678,7 @@ static int can_use_local_refs(const struct add_opts *opts) path.buf, contents.buf); strbuf_release(&path); strbuf_release(&contents); + free(wt_gitdir); } return 1; } @@ -1100,6 +1109,7 @@ static int lock_worktree(int ac, const char **av, const char *prefix, OPT_END() }; struct worktree **worktrees, *wt; + char *path; ac = parse_options(ac, av, prefix, options, git_worktree_lock_usage, 0); if (ac != 1) @@ -1120,9 +1130,11 @@ static int lock_worktree(int ac, const char **av, const char *prefix, die(_("'%s' is already locked"), av[0]); } - write_file(git_common_path("worktrees/%s/locked", wt->id), - "%s", reason); + path = repo_common_path(the_repository, "worktrees/%s/locked", wt->id); + write_file(path, "%s", reason); + free_worktrees(worktrees); + free(path); return 0; } @@ -1133,6 +1145,7 @@ static int unlock_worktree(int ac, const char **av, const char *prefix, OPT_END() }; struct worktree **worktrees, *wt; + char *path; int ret; ac = parse_options(ac, av, prefix, options, git_worktree_unlock_usage, 0); @@ -1147,8 +1160,12 @@ static int unlock_worktree(int ac, const char **av, const char *prefix, die(_("The main working tree cannot be locked or unlocked")); if (!worktree_lock_reason(wt)) die(_("'%s' is not locked"), av[0]); - ret = unlink_or_warn(git_common_path("worktrees/%s/locked", wt->id)); + + path = repo_common_path(the_repository, "worktrees/%s/locked", wt->id); + ret = unlink_or_warn(path); + free_worktrees(worktrees); + free(path); return ret; } @@ -1157,6 +1174,9 @@ static void validate_no_submodules(const struct worktree *wt) struct index_state istate = INDEX_STATE_INIT(the_repository); struct strbuf path = STRBUF_INIT; int i, found_submodules = 0; + char *wt_gitdir; + + wt_gitdir = get_worktree_git_dir(wt); if (is_directory(worktree_git_path(the_repository, wt, "modules"))) { /* @@ -1166,7 +1186,7 @@ static void validate_no_submodules(const struct worktree *wt) */ found_submodules = 1; } else if (read_index_from(&istate, worktree_git_path(the_repository, wt, "index"), - get_worktree_git_dir(wt)) > 0) { + wt_gitdir) > 0) { for (i = 0; i < istate.cache_nr; i++) { struct cache_entry *ce = istate.cache[i]; int err; @@ -1185,6 +1205,7 @@ static void validate_no_submodules(const struct worktree *wt) } discard_index(&istate); strbuf_release(&path); + free(wt_gitdir); if (found_submodules) die(_("working trees containing submodules cannot be moved or removed")); diff --git a/commit-graph.c b/commit-graph.c index 2a2999a6b88690..1021ccb983d4ee 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -2084,7 +2084,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx) return -1; } - if (adjust_shared_perm(get_tempfile_path(graph_layer))) { + if (adjust_shared_perm(the_repository, get_tempfile_path(graph_layer))) { error(_("unable to adjust shared permissions for '%s'"), get_tempfile_path(graph_layer)); return -1; diff --git a/compat/precompose_utf8.c b/compat/precompose_utf8.c index f7cc7b3be59751..12e38e0ea3c570 100644 --- a/compat/precompose_utf8.c +++ b/compat/precompose_utf8.c @@ -50,15 +50,15 @@ void probe_utf8_pathname_composition(void) int output_fd; if (precomposed_unicode != -1) return; /* We found it defined in the global config, respect it */ - git_path_buf(&path, "%s", auml_nfc); + repo_git_path_replace(the_repository, &path, "%s", auml_nfc); output_fd = open(path.buf, O_CREAT|O_EXCL|O_RDWR, 0600); if (output_fd >= 0) { close(output_fd); - git_path_buf(&path, "%s", auml_nfd); + repo_git_path_replace(the_repository, &path, "%s", auml_nfd); precomposed_unicode = access(path.buf, R_OK) ? 0 : 1; git_config_set("core.precomposeunicode", precomposed_unicode ? "true" : "false"); - git_path_buf(&path, "%s", auml_nfc); + repo_git_path_replace(the_repository, &path, "%s", auml_nfc); if (unlink(path.buf)) die_errno(_("failed to unlink '%s'"), path.buf); } diff --git a/config.c b/config.c index c41944a9efbcbb..e1a9e9aa7aa6ec 100644 --- a/config.c +++ b/config.c @@ -1437,11 +1437,6 @@ int git_default_core_config(const char *var, const char *value, return git_config_pathname(&git_attributes_file, var, value); } - if (!strcmp(var, "core.hookspath")) { - FREE_AND_NULL(git_hooks_path); - return git_config_pathname(&git_hooks_path, var, value); - } - if (!strcmp(var, "core.bare")) { is_bare_repository_cfg = git_config_bool(var, value); return 0; @@ -1652,7 +1647,7 @@ int git_default_core_config(const char *var, const char *value, return 0; } - /* Add other config variables here and to Documentation/config.txt. */ + /* Add other config variables here and to Documentation/config.adoc. */ return platform_core_config(var, value, ctx, cb); } @@ -1663,7 +1658,7 @@ static int git_default_sparse_config(const char *var, const char *value) return 0; } - /* Add other config variables here and to Documentation/config/sparse.txt. */ + /* Add other config variables here and to Documentation/config/sparse.adoc. */ return 0; } @@ -1679,7 +1674,7 @@ static int git_default_i18n_config(const char *var, const char *value) return git_config_string(&git_log_output_encoding, var, value); } - /* Add other config variables here and to Documentation/config.txt. */ + /* Add other config variables here and to Documentation/config.adoc. */ return 0; } @@ -1715,7 +1710,7 @@ static int git_default_branch_config(const char *var, const char *value) return 0; } - /* Add other config variables here and to Documentation/config.txt. */ + /* Add other config variables here and to Documentation/config.adoc. */ return 0; } @@ -1744,7 +1739,7 @@ static int git_default_push_config(const char *var, const char *value) return 0; } - /* Add other config variables here and to Documentation/config.txt. */ + /* Add other config variables here and to Documentation/config.adoc. */ return 0; } @@ -1760,7 +1755,7 @@ static int git_default_mailmap_config(const char *var, const char *value) return git_config_string(&git_mailmap_blob, var, value); } - /* Add other config variables here and to Documentation/config.txt. */ + /* Add other config variables here and to Documentation/config.adoc. */ return 0; } @@ -1773,7 +1768,7 @@ static int git_default_attr_config(const char *var, const char *value) /* * Add other attribute related config variables here and to - * Documentation/config/attr.txt. + * Documentation/config/attr.adoc. */ return 0; } @@ -1831,7 +1826,7 @@ int git_default_config(const char *var, const char *value, if (starts_with(var, "sparse.")) return git_default_sparse_config(var, value); - /* Add other config variables here and to Documentation/config.txt. */ + /* Add other config variables here and to Documentation/config.adoc. */ return 0; } diff --git a/connect.c b/connect.c index e6e25a047930e0..3280435331038e 100644 --- a/connect.c +++ b/connect.c @@ -22,6 +22,7 @@ #include "protocol.h" #include "alias.h" #include "bundle-uri.h" +#include "promisor-remote.h" static char *server_capabilities_v1; static struct strvec server_capabilities_v2 = STRVEC_INIT; @@ -487,6 +488,7 @@ void check_stateless_delimiter(int stateless_rpc, static void send_capabilities(int fd_out, struct packet_reader *reader) { const char *hash_name; + const char *promisor_remote_info; if (server_supports_v2("agent")) packet_write_fmt(fd_out, "agent=%s", git_user_agent_sanitized()); @@ -500,6 +502,13 @@ static void send_capabilities(int fd_out, struct packet_reader *reader) } else { reader->hash_algo = &hash_algos[GIT_HASH_SHA1]; } + if (server_feature_v2("promisor-remote", &promisor_remote_info)) { + char *reply = promisor_remote_reply(promisor_remote_info); + if (reply) { + packet_write_fmt(fd_out, "promisor-remote=%s", reply); + free(reply); + } + } } int get_remote_bundle_uri(int fd_out, struct packet_reader *reader, diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index 7aeda494eb0813..3fbbbec61c1688 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -1030,10 +1030,14 @@ parse_makefile_for_sources(unit-test_SOURCES ${CMAKE_SOURCE_DIR}/Makefile "UNIT_ list(TRANSFORM unit-test_SOURCES REPLACE "\\$\\(UNIT_TEST_DIR\\)/" "${CMAKE_SOURCE_DIR}/t/unit-tests/") add_library(unit-test-lib STATIC ${unit-test_SOURCES}) +parse_makefile_for_sources(clar-test_SOURCES ${CMAKE_SOURCE_DIR}/Makefile "CLAR_TEST_OBJS") +list(TRANSFORM clar-test_SOURCES REPLACE "\\$\\(UNIT_TEST_DIR\\)/" "${CMAKE_SOURCE_DIR}/t/unit-tests/") +add_library(clar-test-lib STATIC ${clar-test_SOURCES}) + parse_makefile_for_scripts(unit_test_PROGRAMS "UNIT_TEST_PROGRAMS" "") foreach(unit_test ${unit_test_PROGRAMS}) add_executable("${unit_test}" "${CMAKE_SOURCE_DIR}/t/unit-tests/${unit_test}.c") - target_link_libraries("${unit_test}" unit-test-lib common-main) + target_link_libraries("${unit_test}" unit-test-lib clar-test-lib common-main) set_target_properties("${unit_test}" PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/t/unit-tests/bin) if(MSVC) @@ -1075,13 +1079,13 @@ add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/t/unit-tests/clar.suite" VERBATIM) add_library(unit-tests-lib ${clar_test_SUITES} - "${CMAKE_SOURCE_DIR}/t/unit-tests/clar/clar.c" "${CMAKE_BINARY_DIR}/t/unit-tests/clar-decls.h" "${CMAKE_BINARY_DIR}/t/unit-tests/clar.suite" ) +target_include_directories(clar-test-lib PUBLIC "${CMAKE_BINARY_DIR}/t/unit-tests") target_include_directories(unit-tests-lib PUBLIC "${CMAKE_BINARY_DIR}/t/unit-tests") -add_executable(unit-tests "${CMAKE_SOURCE_DIR}/t/unit-tests/unit-test.c") -target_link_libraries(unit-tests unit-tests-lib common-main) +add_executable(unit-tests) +target_link_libraries(unit-tests unit-tests-lib clar-test-lib common-main) set_target_properties(unit-tests PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/t/unit-tests/bin) if(MSVC) diff --git a/contrib/contacts/Makefile b/contrib/contacts/Makefile index a2990f0dcb53b1..9c4ca4f3bcc7c2 100644 --- a/contrib/contacts/Makefile +++ b/contrib/contacts/Makefile @@ -34,7 +34,7 @@ GIT_CONTACTS := git-contacts GIT_CONTACTS_DOC := git-contacts.1 GIT_CONTACTS_XML := git-contacts.xml -GIT_CONTACTS_TXT := git-contacts.txt +GIT_CONTACTS_TXT := git-contacts.adoc GIT_CONTACTS_HTML := git-contacts.html doc: $(GIT_CONTACTS_DOC) $(GIT_CONTACTS_HTML) diff --git a/contrib/contacts/git-contacts.txt b/contrib/contacts/git-contacts.adoc similarity index 100% rename from contrib/contacts/git-contacts.txt rename to contrib/contacts/git-contacts.adoc diff --git a/contrib/contacts/meson.build b/contrib/contacts/meson.build index 6ec92f47c43994..73d82dfe52b85f 100644 --- a/contrib/contacts/meson.build +++ b/contrib/contacts/meson.build @@ -16,7 +16,7 @@ if get_option('docs').contains('man') '@INPUT@', ], depends: documentation_deps, - input: 'git-contacts.txt', + input: 'git-contacts.adoc', output: 'git-contacts.xml', ) @@ -47,7 +47,7 @@ if get_option('docs').contains('html') '@INPUT@', ], depends: documentation_deps, - input: 'git-contacts.txt', + input: 'git-contacts.adoc', output: 'git-contacts.html', install: true, install_dir: get_option('datadir') / 'doc/git-doc', diff --git a/contrib/long-running-filter/example.pl b/contrib/long-running-filter/example.pl index a677569ddd95f4..4b83e4c5e89427 100755 --- a/contrib/long-running-filter/example.pl +++ b/contrib/long-running-filter/example.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # # Example implementation for the Git filter protocol version 2 -# See Documentation/gitattributes.txt, section "Filter Protocol" +# See Documentation/gitattributes.adoc, section "Filter Protocol" # # Please note, this pass-thru filter is a minimal skeleton. No proper # error handling was implemented. diff --git a/contrib/subtree/Makefile b/contrib/subtree/Makefile index cd4d4d05346489..dab2dfc08ee222 100644 --- a/contrib/subtree/Makefile +++ b/contrib/subtree/Makefile @@ -50,7 +50,7 @@ GIT_SUBTREE := git-subtree GIT_SUBTREE_DOC := git-subtree.1 GIT_SUBTREE_XML := git-subtree.xml -GIT_SUBTREE_TXT := git-subtree.txt +GIT_SUBTREE_TXT := git-subtree.adoc GIT_SUBTREE_HTML := git-subtree.html GIT_SUBTREE_TEST := ../../git-subtree diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.adoc similarity index 100% rename from contrib/subtree/git-subtree.txt rename to contrib/subtree/git-subtree.adoc diff --git a/contrib/subtree/meson.build b/contrib/subtree/meson.build index a752a188df1894..9c72b2362595a6 100644 --- a/contrib/subtree/meson.build +++ b/contrib/subtree/meson.build @@ -32,7 +32,7 @@ if get_option('docs').contains('man') '@INPUT@', ], depends: documentation_deps, - input: 'git-subtree.txt', + input: 'git-subtree.adoc', output: 'git-subtree.xml', ) @@ -63,7 +63,7 @@ if get_option('docs').contains('html') '@INPUT@', ], depends: documentation_deps, - input: 'git-subtree.txt', + input: 'git-subtree.adoc', output: 'git-subtree.html', install: true, install_dir: get_option('datadir') / 'doc/git-doc', diff --git a/copy.c b/copy.c index d9d20920126905..b668209b6c24fd 100644 --- a/copy.c +++ b/copy.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "copy.h" #include "path.h" @@ -57,7 +59,7 @@ int copy_file(const char *dst, const char *src, int mode) if (close(fdo) != 0) return error_errno("%s: close error", dst); - if (!status && adjust_shared_perm(dst)) + if (!status && adjust_shared_perm(the_repository, dst)) return -1; return status; diff --git a/diff.h b/diff.h index 0a566f5531ac42..ff0348e4a9a022 100644 --- a/diff.h +++ b/diff.h @@ -333,7 +333,7 @@ struct diff_options { int xdl_opts; int ignore_driver_algorithm; - /* see Documentation/diff-options.txt */ + /* see Documentation/diff-options.adoc */ char **anchors; size_t anchors_nr, anchors_alloc; diff --git a/diffcore.h b/diffcore.h index 2feb3250313125..9c0a0e7aaff85a 100644 --- a/diffcore.h +++ b/diffcore.h @@ -107,7 +107,7 @@ struct diff_filepair { struct diff_filespec *one; struct diff_filespec *two; unsigned short int score; - char status; /* M C R A D U etc. (see Documentation/diff-format.txt or DIFF_STATUS_* in diff.h) */ + char status; /* M C R A D U etc. (see Documentation/diff-format.adoc or DIFF_STATUS_* in diff.h) */ unsigned broken_pair : 1; unsigned renamed_pair : 1; unsigned is_unmerged : 1; diff --git a/dir.c b/dir.c index 1ed84b7a2f67ac..29b952e94c2be3 100644 --- a/dir.c +++ b/dir.c @@ -3494,7 +3494,7 @@ void setup_standard_excludes(struct dir_struct *dir) char *get_sparse_checkout_filename(void) { - return git_pathdup("info/sparse-checkout"); + return repo_git_path(the_repository, "info/sparse-checkout"); } int get_sparse_checkout_patterns(struct pattern_list *pl) diff --git a/editor.c b/editor.c index 057ec58be4832c..3bb253f5c63f36 100644 --- a/editor.c +++ b/editor.c @@ -150,10 +150,8 @@ int strbuf_edit_interactively(struct repository *r, struct strbuf sb = STRBUF_INIT; int fd, res = 0; - if (!is_absolute_path(path)) { - strbuf_repo_git_path(&sb, r, "%s", path); - path = sb.buf; - } + if (!is_absolute_path(path)) + path = repo_git_path_append(r, &sb, "%s", path); fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd < 0) diff --git a/environment.c b/environment.c index e5b361bb5de4c6..9e4c7781be049a 100644 --- a/environment.c +++ b/environment.c @@ -43,7 +43,6 @@ char *git_log_output_encoding; char *apply_default_whitespace; char *apply_default_ignorewhitespace; char *git_attributes_file; -char *git_hooks_path; int zlib_compression_level = Z_BEST_SPEED; int pack_compression_level = Z_DEFAULT_COMPRESSION; int fsync_object_files = -1; @@ -208,32 +207,6 @@ const char *get_commit_output_encoding(void) return git_commit_encoding ? git_commit_encoding : "UTF-8"; } -static int the_shared_repository = PERM_UMASK; -static int need_shared_repository_from_config = 1; - -void set_shared_repository(int value) -{ - the_shared_repository = value; - need_shared_repository_from_config = 0; -} - -int get_shared_repository(void) -{ - if (need_shared_repository_from_config) { - const char *var = "core.sharedrepository"; - const char *value; - if (!git_config_get_value(var, &value)) - the_shared_repository = git_config_perm(var, value); - need_shared_repository_from_config = 0; - } - return the_shared_repository; -} - -void reset_shared_repository(void) -{ - need_shared_repository_from_config = 1; -} - int use_optional_locks(void) { return git_env_bool(GIT_OPTIONAL_LOCKS_ENVIRONMENT, 1); diff --git a/environment.h b/environment.h index 2f43340f0b553a..45e690f203fd1d 100644 --- a/environment.h +++ b/environment.h @@ -134,16 +134,6 @@ void setup_git_env(const char *git_dir); */ int have_git_dir(void); -/* - * Accessors for the core.sharedrepository config which lazy-load the value - * from the config (if not already set). The "reset" function can be - * used to unset "set" or cached value, meaning that the value will be loaded - * fresh from the config file on the next call to get_shared_repository(). - */ -void set_shared_repository(int value); -int get_shared_repository(void); -void reset_shared_repository(void); - extern int is_bare_repository_cfg; int is_bare_repository(void); extern char *git_work_tree_cfg; @@ -160,7 +150,6 @@ extern int warn_on_object_refname_ambiguity; extern char *apply_default_whitespace; extern char *apply_default_ignorewhitespace; extern char *git_attributes_file; -extern char *git_hooks_path; extern int zlib_compression_level; extern int pack_compression_level; extern size_t packed_git_window_size; diff --git a/fsck.h b/fsck.h index a44c231a5f1391..a95ae7eb847c49 100644 --- a/fsck.h +++ b/fsck.h @@ -15,7 +15,7 @@ enum fsck_msg_type { }; /* - * Documentation/fsck-msgids.txt documents these; when + * Documentation/fsck-msgids.adoc documents these; when * modifying this list in any way, make sure to keep the * two in sync. */ diff --git a/hook.c b/hook.c index 9ddbdee06d5774..b3de1048bf44b9 100644 --- a/hook.c +++ b/hook.c @@ -16,8 +16,7 @@ const char *find_hook(struct repository *r, const char *name) int found_hook; - strbuf_reset(&path); - strbuf_repo_git_path(&path, r, "hooks/%s", name); + repo_git_path_replace(r, &path, "hooks/%s", name); found_hook = access(path.buf, X_OK) >= 0; #ifdef STRIP_EXTENSION if (!found_hook) { diff --git a/http-backend.c b/http-backend.c index 33cf3782826f6c..50b2858fad634a 100644 --- a/http-backend.c +++ b/http-backend.c @@ -183,7 +183,7 @@ static void send_strbuf(struct strbuf *hdr, static void send_local_file(struct strbuf *hdr, const char *the_type, const char *name) { - char *p = git_pathdup("%s", name); + char *p = repo_git_path(the_repository, "%s", name); size_t buf_alloc = 8192; char *buf = xmalloc(buf_alloc); int fd; diff --git a/list-objects-filter-options.h b/list-objects-filter-options.h index 55fab8563d20a5..7b2108b98662c9 100644 --- a/list-objects-filter-options.h +++ b/list-objects-filter-options.h @@ -82,7 +82,7 @@ void list_objects_filter_init(struct list_objects_filter_options *filter_options * "filter" SP * * The filter keyword will be used by many commands. - * See Documentation/rev-list-options.txt for allowed values for . + * See Documentation/rev-list-options.adoc for allowed values for . * * Capture the given arg as the "filter_spec". This can be forwarded to * subordinate commands when necessary (although it's better to pass it through diff --git a/loose.c b/loose.c index 897ba389daa18c..bb602aaa366bf7 100644 --- a/loose.c +++ b/loose.c @@ -75,7 +75,7 @@ static int load_one_loose_object_map(struct repository *repo, struct object_dire insert_loose_map(dir, repo->hash_algo->empty_blob, repo->compat_hash_algo->empty_blob); insert_loose_map(dir, repo->hash_algo->null_oid, repo->compat_hash_algo->null_oid); - strbuf_git_common_path(&path, repo, "objects/loose-object-idx"); + repo_common_path_replace(repo, &path, "objects/loose-object-idx"); fp = fopen(path.buf, "rb"); if (!fp) { strbuf_release(&path); @@ -133,7 +133,7 @@ int repo_write_loose_object_map(struct repository *repo) if (!should_use_loose_object_map(repo)) return 0; - strbuf_git_common_path(&path, repo, "objects/loose-object-idx"); + repo_common_path_replace(repo, &path, "objects/loose-object-idx"); fd = hold_lock_file_for_update_timeout(&lock, path.buf, LOCK_DIE_ON_ERROR, -1); iter = kh_begin(map); if (write_in_full(fd, loose_object_header, strlen(loose_object_header)) < 0) @@ -174,7 +174,7 @@ static int write_one_object(struct repository *repo, const struct object_id *oid struct stat st; struct strbuf buf = STRBUF_INIT, path = STRBUF_INIT; - strbuf_git_common_path(&path, repo, "objects/loose-object-idx"); + repo_common_path_replace(repo, &path, "objects/loose-object-idx"); hold_lock_file_for_update_timeout(&lock, path.buf, LOCK_DIE_ON_ERROR, -1); fd = open(path.buf, O_WRONLY | O_CREAT | O_APPEND, 0666); @@ -190,7 +190,7 @@ static int write_one_object(struct repository *repo, const struct object_id *oid goto errout; if (close(fd)) goto errout; - adjust_shared_perm(path.buf); + adjust_shared_perm(repo, path.buf); rollback_lock_file(&lock); strbuf_release(&buf); strbuf_release(&path); diff --git a/midx-write.c b/midx-write.c index 61b59d557d3ba4..48d6558253ec93 100644 --- a/midx-write.c +++ b/midx-write.c @@ -1336,7 +1336,7 @@ static int write_midx_internal(struct repository *r, const char *object_dir, return -1; } - if (adjust_shared_perm(get_tempfile_path(incr))) { + if (adjust_shared_perm(r, get_tempfile_path(incr))) { error(_("unable to adjust shared permissions for '%s'"), get_tempfile_path(incr)); return -1; diff --git a/notes-merge.c b/notes-merge.c index 8d701ed428aa62..67a472020dedd9 100644 --- a/notes-merge.c +++ b/notes-merge.c @@ -275,41 +275,45 @@ static void diff_tree_local(struct notes_merge_options *o, static void check_notes_merge_worktree(struct notes_merge_options *o) { + struct strbuf buf = STRBUF_INIT; + if (!o->has_worktree) { /* * Must establish NOTES_MERGE_WORKTREE. * Abort if NOTES_MERGE_WORKTREE already exists */ - if (file_exists(git_path(NOTES_MERGE_WORKTREE)) && - !is_empty_dir(git_path(NOTES_MERGE_WORKTREE))) { + if (file_exists(repo_git_path_replace(the_repository, &buf, NOTES_MERGE_WORKTREE)) && + !is_empty_dir(repo_git_path_replace(the_repository, &buf, NOTES_MERGE_WORKTREE))) { if (advice_enabled(ADVICE_RESOLVE_CONFLICT)) die(_("You have not concluded your previous " "notes merge (%s exists).\nPlease, use " "'git notes merge --commit' or 'git notes " "merge --abort' to commit/abort the " "previous merge before you start a new " - "notes merge."), git_path("NOTES_MERGE_*")); + "notes merge."), repo_git_path_replace(the_repository, &buf, "NOTES_MERGE_*")); else die(_("You have not concluded your notes merge " - "(%s exists)."), git_path("NOTES_MERGE_*")); + "(%s exists)."), repo_git_path_replace(the_repository, &buf, "NOTES_MERGE_*")); } - if (safe_create_leading_directories_const(git_path( + if (safe_create_leading_directories_const(repo_git_path_replace(the_repository, &buf, NOTES_MERGE_WORKTREE "/.test"))) die_errno("unable to create directory %s", - git_path(NOTES_MERGE_WORKTREE)); + repo_git_path_replace(the_repository, &buf, NOTES_MERGE_WORKTREE)); o->has_worktree = 1; - } else if (!file_exists(git_path(NOTES_MERGE_WORKTREE))) + } else if (!file_exists(repo_git_path_replace(the_repository, &buf, NOTES_MERGE_WORKTREE))) /* NOTES_MERGE_WORKTREE should already be established */ die("missing '%s'. This should not happen", - git_path(NOTES_MERGE_WORKTREE)); + repo_git_path_replace(the_repository, &buf, NOTES_MERGE_WORKTREE)); + + strbuf_release(&buf); } static void write_buf_to_worktree(const struct object_id *obj, const char *buf, unsigned long size) { int fd; - char *path = git_pathdup(NOTES_MERGE_WORKTREE "/%s", oid_to_hex(obj)); + char *path = repo_git_path(the_repository, NOTES_MERGE_WORKTREE "/%s", oid_to_hex(obj)); if (safe_create_leading_directories_const(path)) die_errno("unable to create directory for '%s'", path); @@ -695,7 +699,7 @@ int notes_merge_commit(struct notes_merge_options *o, const char *msg = strstr(buffer, "\n\n"); int baselen; - git_path_buf(&path, NOTES_MERGE_WORKTREE); + repo_git_path_replace(the_repository, &path, NOTES_MERGE_WORKTREE); if (o->verbosity >= 3) printf("Committing notes in notes merge worktree at %s\n", path.buf); @@ -757,7 +761,7 @@ int notes_merge_abort(struct notes_merge_options *o) struct strbuf buf = STRBUF_INIT; int ret; - git_path_buf(&buf, NOTES_MERGE_WORKTREE); + repo_git_path_replace(the_repository, &buf, NOTES_MERGE_WORKTREE); if (o->verbosity >= 3) printf("Removing notes merge worktree at %s/*\n", buf.buf); ret = remove_dir_recursively(&buf, REMOVE_DIR_KEEP_TOPLEVEL); diff --git a/object-file.c b/object-file.c index f00850961411a7..4d29bf2e3d2415 100644 --- a/object-file.c +++ b/object-file.c @@ -394,7 +394,7 @@ int mkdir_in_gitdir(const char *path) } strbuf_release(&sb); } - return adjust_shared_perm(path); + return adjust_shared_perm(the_repository, path); } static enum scld_error safe_create_leading_directories_1(char *path, int share) @@ -443,7 +443,7 @@ static enum scld_error safe_create_leading_directories_1(char *path, int share) ret = SCLD_VANISHED; else ret = SCLD_FAILED; - } else if (share && adjust_shared_perm(path)) { + } else if (share && adjust_shared_perm(the_repository, path)) { ret = SCLD_PERMS; } *slash = slash_character; @@ -482,14 +482,14 @@ int odb_mkstemp(struct strbuf *temp_filename, const char *pattern) * restrictive except to remove write permission. */ int mode = 0444; - git_path_buf(temp_filename, "objects/%s", pattern); + repo_git_path_replace(the_repository, temp_filename, "objects/%s", pattern); fd = git_mkstemp_mode(temp_filename->buf, mode); if (0 <= fd) return fd; /* slow path */ /* some mkstemp implementations erase temp_filename on failure */ - git_path_buf(temp_filename, "objects/%s", pattern); + repo_git_path_replace(the_repository, temp_filename, "objects/%s", pattern); safe_create_leading_directories(temp_filename->buf); return xmkstemp_mode(temp_filename->buf, mode); } @@ -723,7 +723,7 @@ static void read_info_alternates(struct repository *r, void add_to_alternates_file(const char *reference) { struct lock_file lock = LOCK_INIT; - char *alts = git_pathdup("objects/info/alternates"); + char *alts = repo_git_path(the_repository, "objects/info/alternates"); FILE *in, *out; int found = 0; @@ -2111,7 +2111,7 @@ int finalize_object_file_flags(const char *tmpfile, const char *filename, } out: - if (adjust_shared_perm(filename)) + if (adjust_shared_perm(the_repository, filename)) return error(_("unable to set permission to '%s'"), filename); return 0; } @@ -2187,7 +2187,7 @@ static int create_tmpfile(struct strbuf *tmp, const char *filename) strbuf_add(tmp, filename, dirlen - 1); if (mkdir(tmp->buf, 0777) && errno != EEXIST) return -1; - if (adjust_shared_perm(tmp->buf)) + if (adjust_shared_perm(the_repository, tmp->buf)) return -1; /* Try again */ diff --git a/object-name.c b/object-name.c index 945d5bdef25217..76749fbfe652bf 100644 --- a/object-name.c +++ b/object-name.c @@ -1273,7 +1273,7 @@ static int peel_onion(struct repository *r, const char *name, int len, } /* - * Documentation/revisions.txt says: + * Documentation/revisions.adoc says: * '', e.g. 'v1.7.4.2-679-g3bee7fb':: * Output from `git describe`; i.e. a closest tag, optionally * followed by a dash and a number of commits, followed by a dash, a diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c index a06a1f35c619b3..34e86d49947d23 100644 --- a/pack-bitmap-write.c +++ b/pack-bitmap-write.c @@ -1072,7 +1072,7 @@ void bitmap_writer_finish(struct bitmap_writer *writer, finalize_hashfile(f, NULL, FSYNC_COMPONENT_PACK_METADATA, CSUM_HASH_IN_STREAM | CSUM_FSYNC | CSUM_CLOSE); - if (adjust_shared_perm(tmp_file.buf)) + if (adjust_shared_perm(the_repository, tmp_file.buf)) die_errno("unable to make temporary bitmap file readable"); if (rename(tmp_file.buf, filename)) diff --git a/pack-write.c b/pack-write.c index d61e29ba4ef4eb..823e40b42f2097 100644 --- a/pack-write.c +++ b/pack-write.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "environment.h" #include "gettext.h" @@ -287,7 +289,7 @@ char *write_rev_file_order(const struct git_hash_algo *hash_algo, write_rev_index_positions(f, pack_order, nr_objects); write_rev_trailer(hash_algo, f, hash); - if (adjust_shared_perm(path) < 0) + if (adjust_shared_perm(the_repository, path) < 0) die(_("failed to make %s readable"), path); finalize_hashfile(f, NULL, FSYNC_COMPONENT_PACK_METADATA, @@ -350,7 +352,7 @@ static char *write_mtimes_file(const struct git_hash_algo *hash_algo, write_mtimes_objects(f, to_pack, objects, nr_objects); write_mtimes_trailer(hash_algo, f, hash); - if (adjust_shared_perm(mtimes_name) < 0) + if (adjust_shared_perm(the_repository, mtimes_name) < 0) die(_("failed to make %s readable"), mtimes_name); finalize_hashfile(f, NULL, FSYNC_COMPONENT_PACK_METADATA, @@ -566,12 +568,12 @@ void stage_tmp_packfiles(const struct git_hash_algo *hash_algo, char *rev_tmp_name = NULL; char *mtimes_tmp_name = NULL; - if (adjust_shared_perm(pack_tmp_name)) + if (adjust_shared_perm(the_repository, pack_tmp_name)) die_errno("unable to make temporary pack file readable"); *idx_tmp_name = (char *)write_idx_file(hash_algo, NULL, written_list, nr_written, pack_idx_opts, hash); - if (adjust_shared_perm(*idx_tmp_name)) + if (adjust_shared_perm(the_repository, *idx_tmp_name)) die_errno("unable to make temporary index file readable"); rev_tmp_name = write_rev_file(hash_algo, NULL, written_list, nr_written, diff --git a/parse-options.h b/parse-options.h index fca944d9a93d64..997ffbee8050d7 100644 --- a/parse-options.h +++ b/parse-options.h @@ -6,7 +6,7 @@ struct repository; /** - * Refer to Documentation/technical/api-parse-options.txt for the API doc. + * Refer to Documentation/technical/api-parse-options.adoc for the API doc. */ enum parse_opt_type { diff --git a/path.c b/path.c index 6256f53b556050..baba7a9b8eaa26 100644 --- a/path.c +++ b/path.c @@ -2,8 +2,6 @@ * Utilities for paths and pathnames */ -#define USE_THE_REPOSITORY_VARIABLE - #include "git-compat-util.h" #include "abspath.h" #include "environment.h" @@ -30,7 +28,7 @@ static int get_st_mode_bits(const char *path, int *mode) return 0; } -struct strbuf *get_pathname(void) +static struct strbuf *get_pathname(void) { static struct strbuf pathname_array[4] = { STRBUF_INIT, STRBUF_INIT, STRBUF_INIT, STRBUF_INIT @@ -387,10 +385,11 @@ void report_linked_checkout_garbage(struct repository *r) strbuf_release(&sb); } -static void adjust_git_path(const struct repository *repo, +static void adjust_git_path(struct repository *repo, struct strbuf *buf, int git_dir_len) { const char *base = buf->buf + git_dir_len; + if (is_dir_file(base, "info", "grafts")) strbuf_splice(buf, 0, buf->len, repo->graft_file, strlen(repo->graft_file)); @@ -399,8 +398,8 @@ static void adjust_git_path(const struct repository *repo, repo->index_file, strlen(repo->index_file)); else if (dir_prefix(base, "objects")) replace_dir(buf, git_dir_len + 7, repo->objects->odb->path); - else if (git_hooks_path && dir_prefix(base, "hooks")) - replace_dir(buf, git_dir_len + 5, git_hooks_path); + else if (repo_settings_get_hooks_path(repo) && dir_prefix(base, "hooks")) + replace_dir(buf, git_dir_len + 5, repo_settings_get_hooks_path(repo)); else if (repo->different_commondir) update_common_dir(buf, git_dir_len, repo->commondir); } @@ -414,12 +413,12 @@ static void strbuf_worktree_gitdir(struct strbuf *buf, else if (!wt->id) strbuf_addstr(buf, repo->commondir); else - strbuf_git_common_path(buf, repo, "worktrees/%s", wt->id); + repo_common_path_append(repo, buf, "worktrees/%s", wt->id); } -void repo_git_pathv(const struct repository *repo, - const struct worktree *wt, struct strbuf *buf, - const char *fmt, va_list args) +static void repo_git_pathv(struct repository *repo, + const struct worktree *wt, struct strbuf *buf, + const char *fmt, va_list args) { int gitdir_len; strbuf_worktree_gitdir(buf, repo, wt); @@ -432,7 +431,7 @@ void repo_git_pathv(const struct repository *repo, strbuf_cleanup_path(buf); } -char *repo_git_path(const struct repository *repo, +char *repo_git_path(struct repository *repo, const char *fmt, ...) { struct strbuf path = STRBUF_INIT; @@ -443,14 +442,27 @@ char *repo_git_path(const struct repository *repo, return strbuf_detach(&path, NULL); } -void strbuf_repo_git_path(struct strbuf *sb, - const struct repository *repo, - const char *fmt, ...) +const char *repo_git_path_append(struct repository *repo, + struct strbuf *sb, + const char *fmt, ...) { va_list args; va_start(args, fmt); repo_git_pathv(repo, NULL, sb, fmt, args); va_end(args); + return sb->buf; +} + +const char *repo_git_path_replace(struct repository *repo, + struct strbuf *sb, + const char *fmt, ...) +{ + va_list args; + strbuf_reset(sb); + va_start(args, fmt); + repo_git_pathv(repo, NULL, sb, fmt, args); + va_end(args); + return sb->buf; } char *mkpathdup(const char *fmt, ...) @@ -506,39 +518,56 @@ char *repo_worktree_path(const struct repository *repo, const char *fmt, ...) struct strbuf path = STRBUF_INIT; va_list args; + va_start(args, fmt); + do_worktree_path(repo, &path, fmt, args); + va_end(args); + + return strbuf_detach(&path, NULL); +} + +const char *repo_worktree_path_append(const struct repository *repo, + struct strbuf *sb, + const char *fmt, ...) +{ + va_list args; + if (!repo->worktree) return NULL; va_start(args, fmt); - do_worktree_path(repo, &path, fmt, args); + do_worktree_path(repo, sb, fmt, args); va_end(args); - return strbuf_detach(&path, NULL); + return sb->buf; } -void strbuf_repo_worktree_path(struct strbuf *sb, - const struct repository *repo, - const char *fmt, ...) +const char *repo_worktree_path_replace(const struct repository *repo, + struct strbuf *sb, + const char *fmt, ...) { va_list args; + strbuf_reset(sb); if (!repo->worktree) - return; + return NULL; va_start(args, fmt); do_worktree_path(repo, sb, fmt, args); va_end(args); + + return sb->buf; } /* Returns 0 on success, negative on failure. */ -static int do_submodule_path(struct strbuf *buf, const char *path, +static int do_submodule_path(struct repository *repo, + struct strbuf *buf, const char *path, const char *fmt, va_list args) { struct strbuf git_submodule_common_dir = STRBUF_INIT; struct strbuf git_submodule_dir = STRBUF_INIT; int ret; - ret = submodule_to_gitdir(&git_submodule_dir, path); + ret = submodule_to_gitdir(repo, &git_submodule_dir, path); if (ret) goto cleanup; @@ -557,13 +586,14 @@ static int do_submodule_path(struct strbuf *buf, const char *path, return ret; } -char *git_pathdup_submodule(const char *path, const char *fmt, ...) +char *repo_submodule_path(struct repository *repo, + const char *path, const char *fmt, ...) { int err; va_list args; struct strbuf buf = STRBUF_INIT; va_start(args, fmt); - err = do_submodule_path(&buf, path, fmt, args); + err = do_submodule_path(repo, &buf, path, fmt, args); va_end(args); if (err) { strbuf_release(&buf); @@ -572,22 +602,41 @@ char *git_pathdup_submodule(const char *path, const char *fmt, ...) return strbuf_detach(&buf, NULL); } -int strbuf_git_path_submodule(struct strbuf *buf, const char *path, - const char *fmt, ...) +const char *repo_submodule_path_append(struct repository *repo, + struct strbuf *buf, + const char *path, + const char *fmt, ...) { int err; va_list args; va_start(args, fmt); - err = do_submodule_path(buf, path, fmt, args); + err = do_submodule_path(repo, buf, path, fmt, args); va_end(args); + if (err) + return NULL; + return buf->buf; +} - return err; +const char *repo_submodule_path_replace(struct repository *repo, + struct strbuf *buf, + const char *path, + const char *fmt, ...) +{ + int err; + va_list args; + strbuf_reset(buf); + va_start(args, fmt); + err = do_submodule_path(repo, buf, path, fmt, args); + va_end(args); + if (err) + return NULL; + return buf->buf; } -void repo_common_pathv(const struct repository *repo, - struct strbuf *sb, - const char *fmt, - va_list args) +static void repo_common_pathv(const struct repository *repo, + struct strbuf *sb, + const char *fmt, + va_list args) { strbuf_addstr(sb, repo->commondir); if (sb->len && !is_dir_sep(sb->buf[sb->len - 1])) @@ -596,14 +645,38 @@ void repo_common_pathv(const struct repository *repo, strbuf_cleanup_path(sb); } -void strbuf_git_common_path(struct strbuf *sb, - const struct repository *repo, - const char *fmt, ...) +char *repo_common_path(const struct repository *repo, + const char *fmt, ...) { + struct strbuf sb = STRBUF_INIT; va_list args; va_start(args, fmt); + repo_common_pathv(repo, &sb, fmt, args); + va_end(args); + return strbuf_detach(&sb, NULL); +} + +const char *repo_common_path_append(const struct repository *repo, + struct strbuf *sb, + const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + repo_common_pathv(repo, sb, fmt, args); + va_end(args); + return sb->buf; +} + +const char *repo_common_path_replace(const struct repository *repo, + struct strbuf *sb, + const char *fmt, ...) +{ + va_list args; + strbuf_reset(sb); + va_start(args, fmt); repo_common_pathv(repo, sb, fmt, args); va_end(args); + return sb->buf; } static struct passwd *getpw_str(const char *username, size_t len) @@ -765,21 +838,22 @@ const char *enter_repo(const char *path, unsigned flags) return NULL; } -int calc_shared_perm(int mode) +int calc_shared_perm(struct repository *repo, + int mode) { int tweak; - if (get_shared_repository() < 0) - tweak = -get_shared_repository(); + if (repo_settings_get_shared_repository(repo) < 0) + tweak = -repo_settings_get_shared_repository(repo); else - tweak = get_shared_repository(); + tweak = repo_settings_get_shared_repository(repo); if (!(mode & S_IWUSR)) tweak &= ~0222; if (mode & S_IXUSR) /* Copy read bits to execute bits */ tweak |= (tweak & 0444) >> 2; - if (get_shared_repository() < 0) + if (repo_settings_get_shared_repository(repo) < 0) mode = (mode & ~0777) | tweak; else mode |= tweak; @@ -787,17 +861,17 @@ int calc_shared_perm(int mode) return mode; } - -int adjust_shared_perm(const char *path) +int adjust_shared_perm(struct repository *repo, + const char *path) { int old_mode, new_mode; - if (!get_shared_repository()) + if (!repo_settings_get_shared_repository(repo)) return 0; if (get_st_mode_bits(path, &old_mode) < 0) return -1; - new_mode = calc_shared_perm(old_mode); + new_mode = calc_shared_perm(repo, old_mode); if (S_ISDIR(old_mode)) { /* Copy read bits to execute bits */ new_mode |= (new_mode & 0444) >> 2; @@ -816,7 +890,7 @@ int adjust_shared_perm(const char *path) return 0; } -void safe_create_dir(const char *dir, int share) +void safe_create_dir(struct repository *repo, const char *dir, int share) { if (mkdir(dir, 0777) < 0) { if (errno != EEXIST) { @@ -824,7 +898,7 @@ void safe_create_dir(const char *dir, int share) exit(1); } } - else if (share && adjust_shared_perm(dir)) + else if (share && adjust_shared_perm(repo, dir)) die(_("Could not make %s writable by group"), dir); } diff --git a/path.h b/path.h index 9b0b5d2718e5f8..535b8456c646f2 100644 --- a/path.h +++ b/path.h @@ -25,22 +25,20 @@ char *mkpathdup(const char *fmt, ...) __attribute__((format (printf, 1, 2))); /* - * The `strbuf_git_common_path` family of functions will construct a path into a + * The `repo_common_path` family of functions will construct a path into a * repository's common git directory, which is shared by all worktrees. */ - -/* - * Constructs a path into the common git directory of repository `repo` and - * append it in the provided buffer `sb`. - */ -void strbuf_git_common_path(struct strbuf *sb, - const struct repository *repo, - const char *fmt, ...) +char *repo_common_path(const struct repository *repo, + const char *fmt, ...) + __attribute__((format (printf, 2, 3))); +const char *repo_common_path_append(const struct repository *repo, + struct strbuf *sb, + const char *fmt, ...) + __attribute__((format (printf, 3, 4))); +const char *repo_common_path_replace(const struct repository *repo, + struct strbuf *sb, + const char *fmt, ...) __attribute__((format (printf, 3, 4))); -void repo_common_pathv(const struct repository *repo, - struct strbuf *buf, - const char *fmt, - va_list args); /* * The `repo_git_path` family of functions will construct a path into a repository's @@ -54,29 +52,16 @@ void repo_common_pathv(const struct repository *repo, * For an exhaustive list of the adjustments made look at `common_list` and * `adjust_git_path` in path.c. */ - -/* - * Return a path into the git directory of repository `repo`. - */ -char *repo_git_path(const struct repository *repo, +char *repo_git_path(struct repository *repo, const char *fmt, ...) __attribute__((format (printf, 2, 3))); - -/* - * Print a path into the git directory of repository `repo` into the provided - * buffer. - */ -void repo_git_pathv(const struct repository *repo, - const struct worktree *wt, struct strbuf *buf, - const char *fmt, va_list args); - -/* - * Construct a path into the git directory of repository `repo` and append it - * to the provided buffer `sb`. - */ -void strbuf_repo_git_path(struct strbuf *sb, - const struct repository *repo, - const char *fmt, ...) +const char *repo_git_path_append(struct repository *repo, + struct strbuf *sb, + const char *fmt, ...) + __attribute__((format (printf, 3, 4))); +const char *repo_git_path_replace(struct repository *repo, + struct strbuf *sb, + const char *fmt, ...) __attribute__((format (printf, 3, 4))); /* @@ -90,40 +75,44 @@ const char *worktree_git_path(struct repository *r, __attribute__((format (printf, 3, 4))); /* - * Return a path into the worktree of repository `repo`. + * The `repo_worktree_path` family of functions will construct a path into a + * repository's worktree. * - * If the repository doesn't have a worktree NULL is returned. + * Returns a `NULL` pointer in case the repository has no worktree. */ char *repo_worktree_path(const struct repository *repo, const char *fmt, ...) __attribute__((format (printf, 2, 3))); - -/* - * Construct a path into the worktree of repository `repo` and append it - * to the provided buffer `sb`. - * - * If the repository doesn't have a worktree nothing will be appended to `sb`. - */ -void strbuf_repo_worktree_path(struct strbuf *sb, - const struct repository *repo, +const char *repo_worktree_path_append(const struct repository *repo, + struct strbuf *sb, const char *fmt, ...) __attribute__((format (printf, 3, 4))); +const char *repo_worktree_path_replace(const struct repository *repo, + struct strbuf *sb, + const char *fmt, ...) + __attribute__((format (printf, 3, 4))); /* - * Return a path into a submodule's git directory located at `path`. `path` - * must only reference a submodule of the main repository (the_repository). - */ -char *git_pathdup_submodule(const char *path, const char *fmt, ...) - __attribute__((format (printf, 2, 3))); - -/* - * Construct a path into a submodule's git directory located at `path` and - * append it to the provided buffer `sb`. `path` must only reference a - * submodule of the main repository (the_repository). + * The `repo_submodule_path` family of functions will construct a path into a + * submodule's git directory located at `path`. `path` must be a submodule path + * as found in the index and must be part of the given repository. + * + * Returns a `NULL` pointer in case the submodule cannot be found. */ -int strbuf_git_path_submodule(struct strbuf *sb, const char *path, - const char *fmt, ...) +char *repo_submodule_path(struct repository *repo, + const char *path, + const char *fmt, ...) __attribute__((format (printf, 3, 4))); +const char *repo_submodule_path_append(struct repository *repo, + struct strbuf *sb, + const char *path, + const char *fmt, ...) + __attribute__((format (printf, 4, 5))); +const char *repo_submodule_path_replace(struct repository *repo, + struct strbuf *sb, + const char *path, + const char *fmt, ...) + __attribute__((format (printf, 4, 5))); void report_linked_checkout_garbage(struct repository *r); @@ -152,8 +141,8 @@ const char *git_path_shallow(struct repository *r); int ends_with_path_components(const char *path, const char *components); -int calc_shared_perm(int mode); -int adjust_shared_perm(const char *path); +int calc_shared_perm(struct repository *repo, int mode); +int adjust_shared_perm(struct repository *repo, const char *path); char *interpolate_path(const char *path, int real_home); @@ -231,101 +220,21 @@ char *xdg_cache_home(const char *filename); * directories under $GIT_DIR. Don't use it for working tree * directories. */ -void safe_create_dir(const char *dir, int share); - -/* - * Do not use this function. It is only exported to other subsystems until we - * can get rid of the below block of functions that implicitly rely on - * `the_repository`. - */ -struct strbuf *get_pathname(void); +void safe_create_dir(struct repository *repo, const char *dir, int share); # ifdef USE_THE_REPOSITORY_VARIABLE # include "strbuf.h" # include "repository.h" -/* - * Return a statically allocated path into the main repository's - * (the_repository) common git directory. - */ -__attribute__((format (printf, 1, 2))) -static inline const char *git_common_path(const char *fmt, ...) -{ - struct strbuf *pathname = get_pathname(); - va_list args; - va_start(args, fmt); - repo_common_pathv(the_repository, pathname, fmt, args); - va_end(args); - return pathname->buf; -} - -/* - * Construct a path into the main repository's (the_repository) git directory - * and place it in the provided buffer `buf`, the contents of the buffer will - * be overridden. - */ -__attribute__((format (printf, 2, 3))) -static inline char *git_path_buf(struct strbuf *buf, const char *fmt, ...) -{ - va_list args; - strbuf_reset(buf); - va_start(args, fmt); - repo_git_pathv(the_repository, NULL, buf, fmt, args); - va_end(args); - return buf->buf; -} - -/* - * Construct a path into the main repository's (the_repository) git directory - * and append it to the provided buffer `sb`. - */ -__attribute__((format (printf, 2, 3))) -static inline void strbuf_git_path(struct strbuf *sb, const char *fmt, ...) -{ - va_list args; - va_start(args, fmt); - repo_git_pathv(the_repository, NULL, sb, fmt, args); - va_end(args); -} - -/* - * Return a statically allocated path into the main repository's - * (the_repository) git directory. - */ -__attribute__((format (printf, 1, 2))) -static inline const char *git_path(const char *fmt, ...) -{ - struct strbuf *pathname = get_pathname(); - va_list args; - va_start(args, fmt); - repo_git_pathv(the_repository, NULL, pathname, fmt, args); - va_end(args); - return pathname->buf; -} - #define GIT_PATH_FUNC(func, filename) \ const char *func(void) \ { \ static char *ret; \ if (!ret) \ - ret = git_pathdup(filename); \ + ret = repo_git_path(the_repository, filename); \ return ret; \ } -/* - * Return a path into the main repository's (the_repository) git directory. - */ -__attribute__((format (printf, 1, 2))) -static inline char *git_pathdup(const char *fmt, ...) -{ - struct strbuf path = STRBUF_INIT; - va_list args; - va_start(args, fmt); - repo_git_pathv(the_repository, NULL, &path, fmt, args); - va_end(args); - return strbuf_detach(&path, NULL); -} - # endif /* USE_THE_REPOSITORY_VARIABLE */ #endif /* PATH_H */ diff --git a/promisor-remote.c b/promisor-remote.c index c714f4f00728e4..6a0a61382f40c0 100644 --- a/promisor-remote.c +++ b/promisor-remote.c @@ -11,6 +11,8 @@ #include "strvec.h" #include "packfile.h" #include "environment.h" +#include "url.h" +#include "version.h" struct promisor_remote_config { struct promisor_remote *promisors; @@ -221,6 +223,18 @@ int repo_has_promisor_remote(struct repository *r) return !!repo_promisor_remote_find(r, NULL); } +int repo_has_accepted_promisor_remote(struct repository *r) +{ + struct promisor_remote *p; + + promisor_remote_init(r); + + for (p = r->promisor_remote_config->promisors; p; p = p->next) + if (p->accepted) + return 1; + return 0; +} + static int remove_fetched_oids(struct repository *repo, struct object_id **oids, int oid_nr, int to_free) @@ -292,3 +306,231 @@ void promisor_remote_get_direct(struct repository *repo, if (to_free) free(remaining_oids); } + +static int allow_unsanitized(char ch) +{ + if (ch == ',' || ch == ';' || ch == '%') + return 0; + return ch > 32 && ch < 127; +} + +static void promisor_info_vecs(struct repository *repo, + struct strvec *names, + struct strvec *urls) +{ + struct promisor_remote *r; + + promisor_remote_init(repo); + + for (r = repo->promisor_remote_config->promisors; r; r = r->next) { + char *url; + char *url_key = xstrfmt("remote.%s.url", r->name); + + strvec_push(names, r->name); + strvec_push(urls, git_config_get_string(url_key, &url) ? NULL : url); + + free(url); + free(url_key); + } +} + +char *promisor_remote_info(struct repository *repo) +{ + struct strbuf sb = STRBUF_INIT; + int advertise_promisors = 0; + struct strvec names = STRVEC_INIT; + struct strvec urls = STRVEC_INIT; + + git_config_get_bool("promisor.advertise", &advertise_promisors); + + if (!advertise_promisors) + return NULL; + + promisor_info_vecs(repo, &names, &urls); + + if (!names.nr) + return NULL; + + for (size_t i = 0; i < names.nr; i++) { + if (i) + strbuf_addch(&sb, ';'); + strbuf_addstr(&sb, "name="); + strbuf_addstr_urlencode(&sb, names.v[i], allow_unsanitized); + if (urls.v[i]) { + strbuf_addstr(&sb, ",url="); + strbuf_addstr_urlencode(&sb, urls.v[i], allow_unsanitized); + } + } + + strvec_clear(&names); + strvec_clear(&urls); + + return strbuf_detach(&sb, NULL); +} + +/* + * Find first index of 'nicks' where there is 'nick'. 'nick' is + * compared case insensitively to the strings in 'nicks'. If not found + * 'nicks->nr' is returned. + */ +static size_t remote_nick_find(struct strvec *nicks, const char *nick) +{ + for (size_t i = 0; i < nicks->nr; i++) + if (!strcasecmp(nicks->v[i], nick)) + return i; + return nicks->nr; +} + +enum accept_promisor { + ACCEPT_NONE = 0, + ACCEPT_KNOWN_URL, + ACCEPT_KNOWN_NAME, + ACCEPT_ALL +}; + +static int should_accept_remote(enum accept_promisor accept, + const char *remote_name, const char *remote_url, + struct strvec *names, struct strvec *urls) +{ + size_t i; + + if (accept == ACCEPT_ALL) + return 1; + + i = remote_nick_find(names, remote_name); + + if (i >= names->nr) + /* We don't know about that remote */ + return 0; + + if (accept == ACCEPT_KNOWN_NAME) + return 1; + + if (accept != ACCEPT_KNOWN_URL) + BUG("Unhandled 'enum accept_promisor' value '%d'", accept); + + if (!strcmp(urls->v[i], remote_url)) + return 1; + + warning(_("known remote named '%s' but with url '%s' instead of '%s'"), + remote_name, urls->v[i], remote_url); + + return 0; +} + +static void filter_promisor_remote(struct repository *repo, + struct strvec *accepted, + const char *info) +{ + struct strbuf **remotes; + const char *accept_str; + enum accept_promisor accept = ACCEPT_NONE; + struct strvec names = STRVEC_INIT; + struct strvec urls = STRVEC_INIT; + + if (!git_config_get_string_tmp("promisor.acceptfromserver", &accept_str)) { + if (!*accept_str || !strcasecmp("None", accept_str)) + accept = ACCEPT_NONE; + else if (!strcasecmp("KnownUrl", accept_str)) + accept = ACCEPT_KNOWN_URL; + else if (!strcasecmp("KnownName", accept_str)) + accept = ACCEPT_KNOWN_NAME; + else if (!strcasecmp("All", accept_str)) + accept = ACCEPT_ALL; + else + warning(_("unknown '%s' value for '%s' config option"), + accept_str, "promisor.acceptfromserver"); + } + + if (accept == ACCEPT_NONE) + return; + + if (accept != ACCEPT_ALL) + promisor_info_vecs(repo, &names, &urls); + + /* Parse remote info received */ + + remotes = strbuf_split_str(info, ';', 0); + + for (size_t i = 0; remotes[i]; i++) { + struct strbuf **elems; + const char *remote_name = NULL; + const char *remote_url = NULL; + char *decoded_name = NULL; + char *decoded_url = NULL; + + strbuf_strip_suffix(remotes[i], ";"); + elems = strbuf_split(remotes[i], ','); + + for (size_t j = 0; elems[j]; j++) { + int res; + strbuf_strip_suffix(elems[j], ","); + res = skip_prefix(elems[j]->buf, "name=", &remote_name) || + skip_prefix(elems[j]->buf, "url=", &remote_url); + if (!res) + warning(_("unknown element '%s' from remote info"), + elems[j]->buf); + } + + if (remote_name) + decoded_name = url_percent_decode(remote_name); + if (remote_url) + decoded_url = url_percent_decode(remote_url); + + if (decoded_name && should_accept_remote(accept, decoded_name, decoded_url, &names, &urls)) + strvec_push(accepted, decoded_name); + + strbuf_list_free(elems); + free(decoded_name); + free(decoded_url); + } + + strvec_clear(&names); + strvec_clear(&urls); + strbuf_list_free(remotes); +} + +char *promisor_remote_reply(const char *info) +{ + struct strvec accepted = STRVEC_INIT; + struct strbuf reply = STRBUF_INIT; + + filter_promisor_remote(the_repository, &accepted, info); + + if (!accepted.nr) + return NULL; + + for (size_t i = 0; i < accepted.nr; i++) { + if (i) + strbuf_addch(&reply, ';'); + strbuf_addstr_urlencode(&reply, accepted.v[i], allow_unsanitized); + } + + strvec_clear(&accepted); + + return strbuf_detach(&reply, NULL); +} + +void mark_promisor_remotes_as_accepted(struct repository *r, const char *remotes) +{ + struct strbuf **accepted_remotes = strbuf_split_str(remotes, ';', 0); + + for (size_t i = 0; accepted_remotes[i]; i++) { + struct promisor_remote *p; + char *decoded_remote; + + strbuf_strip_suffix(accepted_remotes[i], ";"); + decoded_remote = url_percent_decode(accepted_remotes[i]->buf); + + p = repo_promisor_remote_find(r, decoded_remote); + if (p) + p->accepted = 1; + else + warning(_("accepted promisor remote '%s' not found"), + decoded_remote); + + free(decoded_remote); + } + + strbuf_list_free(accepted_remotes); +} diff --git a/promisor-remote.h b/promisor-remote.h index 88cb599c391aea..263d331a551b6c 100644 --- a/promisor-remote.h +++ b/promisor-remote.h @@ -9,11 +9,13 @@ struct object_id; * Promisor remote linked list * * Information in its fields come from remote.XXX config entries or - * from extensions.partialclone. + * from extensions.partialclone, except for 'accepted' which comes + * from protocol v2 capabilities exchange. */ struct promisor_remote { struct promisor_remote *next; char *partial_clone_filter; + unsigned int accepted : 1; const char name[FLEX_ARRAY]; }; @@ -32,4 +34,37 @@ void promisor_remote_get_direct(struct repository *repo, const struct object_id *oids, int oid_nr); +/* + * Prepare a "promisor-remote" advertisement by a server. + * Check the value of "promisor.advertise" and maybe the configured + * promisor remotes, if any, to prepare information to send in an + * advertisement. + * Return value is NULL if no promisor remote advertisement should be + * made. Otherwise it contains the names and urls of the advertised + * promisor remotes separated by ';'. See gitprotocol-v2(5). + */ +char *promisor_remote_info(struct repository *repo); + +/* + * Prepare a reply to a "promisor-remote" advertisement from a server. + * Check the value of "promisor.acceptfromserver" and maybe the + * configured promisor remotes, if any, to prepare the reply. + * Return value is NULL if no promisor remote from the server + * is accepted. Otherwise it contains the names of the accepted promisor + * remotes separated by ';'. See gitprotocol-v2(5). + */ +char *promisor_remote_reply(const char *info); + +/* + * Set the 'accepted' flag for some promisor remotes. Useful on the + * server side when some promisor remotes have been accepted by the + * client. + */ +void mark_promisor_remotes_as_accepted(struct repository *repo, const char *remotes); + +/* + * Has any promisor remote been accepted by the client? + */ +int repo_has_accepted_promisor_remote(struct repository *r); + #endif /* PROMISOR_REMOTE_H */ diff --git a/pseudo-merge.h b/pseudo-merge.h index 29df8a32ecf3be..c9fbe9d3129583 100644 --- a/pseudo-merge.h +++ b/pseudo-merge.h @@ -101,7 +101,7 @@ void select_pseudo_merges(struct bitmap_writer *writer); /* * Represents a serialized view of a file containing pseudo-merge(s) - * (see Documentation/technical/bitmap-format.txt for a specification + * (see Documentation/technical/bitmap-format.adoc for a specification * of the format). */ struct pseudo_merge_map { diff --git a/reachable.c b/reachable.c index ecf7ccf5041a13..9ee04c89ec6151 100644 --- a/reachable.c +++ b/reachable.c @@ -65,8 +65,10 @@ static void add_rebase_files(struct rev_info *revs) struct worktree **worktrees = get_worktrees(); for (struct worktree **wt = worktrees; *wt; wt++) { + char *wt_gitdir = get_worktree_git_dir(*wt); + strbuf_reset(&buf); - strbuf_addstr(&buf, get_worktree_git_dir(*wt)); + strbuf_addstr(&buf, wt_gitdir); strbuf_complete(&buf, '/'); len = buf.len; for (size_t i = 0; i < ARRAY_SIZE(path); i++) { @@ -74,6 +76,8 @@ static void add_rebase_files(struct rev_info *revs) strbuf_addstr(&buf, path[i]); add_one_file(buf.buf, revs); } + + free(wt_gitdir); } strbuf_release(&buf); free_worktrees(worktrees); diff --git a/read-cache.c b/read-cache.c index 2540c8bb2f4b73..b9c420d35a66e4 100644 --- a/read-cache.c +++ b/read-cache.c @@ -3264,15 +3264,18 @@ static int clean_shared_index_files(const char *current_hex) while ((de = readdir(dir)) != NULL) { const char *sha1_hex; - const char *shared_index_path; + char *shared_index_path; if (!skip_prefix(de->d_name, "sharedindex.", &sha1_hex)) continue; if (!strcmp(sha1_hex, current_hex)) continue; - shared_index_path = git_path("%s", de->d_name); + + shared_index_path = repo_git_path(the_repository, "%s", de->d_name); if (should_delete_shared_index(shared_index_path) > 0 && unlink(shared_index_path)) warning_errno(_("unable to unlink: %s"), shared_index_path); + + free(shared_index_path); } closedir(dir); @@ -3284,6 +3287,7 @@ static int write_shared_index(struct index_state *istate, { struct split_index *si = istate->split_index; int ret, was_full = !istate->sparse_index; + char *path; move_cache_to_base_index(istate); convert_to_sparse(istate, 0); @@ -3299,18 +3303,20 @@ static int write_shared_index(struct index_state *istate, if (ret) return ret; - ret = adjust_shared_perm(get_tempfile_path(*temp)); + ret = adjust_shared_perm(the_repository, get_tempfile_path(*temp)); if (ret) { error(_("cannot fix permission bits on '%s'"), get_tempfile_path(*temp)); return ret; } - ret = rename_tempfile(temp, - git_path("sharedindex.%s", oid_to_hex(&si->base->oid))); + + path = repo_git_path(the_repository, "sharedindex.%s", oid_to_hex(&si->base->oid)); + ret = rename_tempfile(temp, path); if (!ret) { oidcpy(&si->base_oid, &si->base->oid); clean_shared_index_files(oid_to_hex(&si->base->oid)); } + free(path); return ret; } @@ -3391,9 +3397,12 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock, if (new_shared_index) { struct tempfile *temp; int saved_errno; + char *path; /* Same initial permissions as the main .git/index file */ - temp = mks_tempfile_sm(git_path("sharedindex_XXXXXX"), 0, 0666); + path = repo_git_path(the_repository, "sharedindex_XXXXXX"); + temp = mks_tempfile_sm(path, 0, 0666); + free(path); if (!temp) { ret = do_write_locked_index(istate, lock, flags, ~WRITE_SPLIT_INDEX_EXTENSION); @@ -3414,9 +3423,10 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock, /* Freshen the shared index only if the split-index was written */ if (!ret && !new_shared_index && !is_null_oid(&si->base_oid)) { - const char *shared_index = git_path("sharedindex.%s", - oid_to_hex(&si->base_oid)); + char *shared_index = repo_git_path(the_repository, "sharedindex.%s", + oid_to_hex(&si->base_oid)); freshen_shared_index(shared_index, 1); + free(shared_index); } out: diff --git a/refs.c b/refs.c index 91da5325d74eb4..118465271d7275 100644 --- a/refs.c +++ b/refs.c @@ -2154,7 +2154,7 @@ struct ref_store *repo_get_submodule_ref_store(struct repository *repo, if (!is_nonbare_repository_dir(&submodule_sb)) goto done; - if (submodule_to_gitdir(&submodule_sb, submodule)) + if (submodule_to_gitdir(repo, &submodule_sb, submodule)) goto done; subrepo = xmalloc(sizeof(*subrepo)); @@ -2192,8 +2192,8 @@ struct ref_store *get_worktree_ref_store(const struct worktree *wt) if (wt->id) { struct strbuf common_path = STRBUF_INIT; - strbuf_git_common_path(&common_path, wt->repo, - "worktrees/%s", wt->id); + repo_common_path_append(wt->repo, &common_path, + "worktrees/%s", wt->id); refs = ref_store_init(wt->repo, wt->repo->ref_storage_format, common_path.buf, REF_STORE_ALL_CAPS); strbuf_release(&common_path); diff --git a/refs.h b/refs.h index 2ed14fdb16f8e3..8442e89883a6ce 100644 --- a/refs.h +++ b/refs.h @@ -577,7 +577,7 @@ int refs_for_each_reflog(struct ref_store *refs, each_reflog_fn fn, void *cb_dat /* * Return 0 iff refname has the correct format for a refname according - * to the rules described in Documentation/git-check-ref-format.txt. + * to the rules described in Documentation/git-check-ref-format.adoc. * If REFNAME_ALLOW_ONELEVEL is set in flags, then accept one-level * reference names. If REFNAME_REFSPEC_PATTERN is set in flags, then * allow a single "*" wildcard character in the refspec. No leading or diff --git a/refs/files-backend.c b/refs/files-backend.c index 09f3969327108b..0559a4f10cbde8 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -1831,7 +1831,7 @@ static int log_ref_setup(struct files_ref_store *refs, } if (*logfd >= 0) - adjust_shared_perm(logfile); + adjust_shared_perm(the_repository, logfile); free(logfile); return 0; @@ -3488,8 +3488,8 @@ static int files_ref_store_create_on_disk(struct ref_store *ref_store, * they do not understand the reference format extension. */ strbuf_addf(&sb, "%s/refs", ref_store->gitdir); - safe_create_dir(sb.buf, 1); - adjust_shared_perm(sb.buf); + safe_create_dir(the_repository, sb.buf, 1); + adjust_shared_perm(the_repository, sb.buf); /* * There is no need to create directories for common refs when creating @@ -3501,11 +3501,11 @@ static int files_ref_store_create_on_disk(struct ref_store *ref_store, */ strbuf_reset(&sb); files_ref_path(refs, &sb, "refs/heads"); - safe_create_dir(sb.buf, 1); + safe_create_dir(the_repository, sb.buf, 1); strbuf_reset(&sb); files_ref_path(refs, &sb, "refs/tags"); - safe_create_dir(sb.buf, 1); + safe_create_dir(the_repository, sb.buf, 1); } strbuf_release(&sb); diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c index 7e90e13f745e75..771f50df382af3 100644 --- a/refs/reftable-backend.c +++ b/refs/reftable-backend.c @@ -380,7 +380,7 @@ static struct ref_store *reftable_be_init(struct repository *repo, default: BUG("unknown hash algorithm %d", repo->hash_algo->format_id); } - refs->write_options.default_permissions = calc_shared_perm(0666 & ~mask); + refs->write_options.default_permissions = calc_shared_perm(the_repository, 0666 & ~mask); refs->write_options.disable_auto_compact = !git_env_bool("GIT_TEST_REFTABLE_AUTOCOMPACTION", 1); refs->write_options.lock_timeout_ms = 100; @@ -470,21 +470,21 @@ static int reftable_be_create_on_disk(struct ref_store *ref_store, struct strbuf sb = STRBUF_INIT; strbuf_addf(&sb, "%s/reftable", refs->base.gitdir); - safe_create_dir(sb.buf, 1); + safe_create_dir(the_repository, sb.buf, 1); strbuf_reset(&sb); strbuf_addf(&sb, "%s/HEAD", refs->base.gitdir); write_file(sb.buf, "ref: refs/heads/.invalid"); - adjust_shared_perm(sb.buf); + adjust_shared_perm(the_repository, sb.buf); strbuf_reset(&sb); strbuf_addf(&sb, "%s/refs", refs->base.gitdir); - safe_create_dir(sb.buf, 1); + safe_create_dir(the_repository, sb.buf, 1); strbuf_reset(&sb); strbuf_addf(&sb, "%s/refs/heads", refs->base.gitdir); write_file(sb.buf, "this repository uses the reftable format"); - adjust_shared_perm(sb.buf); + adjust_shared_perm(the_repository, sb.buf); strbuf_release(&sb); return 0; diff --git a/reftable/reader.c b/reftable/reader.c index 3f2e4b280055ff..24bae50ac2fab3 100644 --- a/reftable/reader.c +++ b/reftable/reader.c @@ -666,6 +666,8 @@ int reftable_reader_new(struct reftable_reader **out, reftable_block_done(&footer); reftable_block_done(&header); if (err) { + if (r) + reftable_free(r->name); reftable_free(r); block_source_close(source); } diff --git a/remote.c b/remote.c index c9c1384c1ddadf..e609cf5c56a772 100644 --- a/remote.c +++ b/remote.c @@ -321,10 +321,11 @@ static void read_remotes_file(struct remote_state *remote_state, struct remote *remote) { struct strbuf buf = STRBUF_INIT; - FILE *f = fopen_or_warn(git_path("remotes/%s", remote->name), "r"); + FILE *f = fopen_or_warn(repo_git_path_append(the_repository, &buf, + "remotes/%s", remote->name), "r"); if (!f) - return; + goto out; warn_about_deprecated_remote_type("remotes", remote); @@ -343,8 +344,10 @@ static void read_remotes_file(struct remote_state *remote_state, else if (skip_prefix(buf.buf, "Pull:", &v)) refspec_append(&remote->fetch, skip_spaces(v)); } - strbuf_release(&buf); fclose(f); + +out: + strbuf_release(&buf); } static void read_branches_file(struct remote_state *remote_state, @@ -352,20 +355,19 @@ static void read_branches_file(struct remote_state *remote_state, { char *frag, *to_free = NULL; struct strbuf buf = STRBUF_INIT; - FILE *f = fopen_or_warn(git_path("branches/%s", remote->name), "r"); + FILE *f = fopen_or_warn(repo_git_path_append(the_repository, &buf, + "branches/%s", remote->name), "r"); if (!f) - return; + goto out; warn_about_deprecated_remote_type("branches", remote); strbuf_getline_lf(&buf, f); fclose(f); strbuf_trim(&buf); - if (!buf.len) { - strbuf_release(&buf); - return; - } + if (!buf.len) + goto out; remote->configured_in_repo = 1; remote->origin = REMOTE_BRANCHES; @@ -393,6 +395,7 @@ static void read_branches_file(struct remote_state *remote_state, refspec_appendf(&remote->push, "HEAD:refs/heads/%s", frag); remote->fetch_tags = 1; /* always auto-follow */ +out: strbuf_release(&buf); free(to_free); } diff --git a/repo-settings.c b/repo-settings.c index 633b154c20ab57..9b5595c708e6c5 100644 --- a/repo-settings.c +++ b/repo-settings.c @@ -4,6 +4,7 @@ #include "repository.h" #include "midx.h" #include "pack-objects.h" +#include "setup.h" static void repo_cfg_bool(struct repository *r, const char *key, int *dest, int def) @@ -21,7 +22,6 @@ static void repo_cfg_int(struct repository *r, const char *key, int *dest, void prepare_repo_settings(struct repository *r) { - const struct repo_settings defaults = REPO_SETTINGS_INIT; int experimental; int value; const char *strval; @@ -35,7 +35,7 @@ void prepare_repo_settings(struct repository *r) if (r->settings.initialized) return; - memcpy(&r->settings, &defaults, sizeof(defaults)); + repo_settings_clear(r); r->settings.initialized++; /* Booleans config or default, cascades to other settings */ @@ -146,6 +146,14 @@ void prepare_repo_settings(struct repository *r) r->settings.packed_git_limit = ulongval; } +void repo_settings_clear(struct repository *r) +{ + struct repo_settings empty = REPO_SETTINGS_INIT; + FREE_AND_NULL(r->settings.fsmonitor); + FREE_AND_NULL(r->settings.hooks_path); + r->settings = empty; +} + enum log_refs_config repo_settings_get_log_all_ref_updates(struct repository *repo) { const char *value; @@ -170,3 +178,35 @@ int repo_settings_get_warn_ambiguous_refs(struct repository *repo) &repo->settings.warn_ambiguous_refs, 1); return repo->settings.warn_ambiguous_refs; } + +const char *repo_settings_get_hooks_path(struct repository *repo) +{ + if (!repo->settings.hooks_path) + repo_config_get_pathname(repo, "core.hookspath", &repo->settings.hooks_path); + return repo->settings.hooks_path; +} + +int repo_settings_get_shared_repository(struct repository *repo) +{ + if (!repo->settings.shared_repository_initialized) { + const char *var = "core.sharedrepository"; + const char *value; + if (!repo_config_get_value(repo, var, &value)) + repo->settings.shared_repository = git_config_perm(var, value); + else + repo->settings.shared_repository = PERM_UMASK; + repo->settings.shared_repository_initialized = 1; + } + return repo->settings.shared_repository; +} + +void repo_settings_set_shared_repository(struct repository *repo, int value) +{ + repo->settings.shared_repository = value; + repo->settings.shared_repository_initialized = 1; +} + +void repo_settings_reset_shared_repository(struct repository *repo) +{ + repo->settings.shared_repository_initialized = 0; +} diff --git a/repo-settings.h b/repo-settings.h index 7e8869ac4efcb8..a31decad221169 100644 --- a/repo-settings.h +++ b/repo-settings.h @@ -37,6 +37,9 @@ struct repo_settings { int pack_use_bitmap_boundary_traversal; int pack_use_multi_pack_reuse; + int shared_repository; + int shared_repository_initialized; + /* * Does this repository have core.useReplaceRefs=true (on by * default)? This provides a repository-scoped version of this @@ -62,8 +65,11 @@ struct repo_settings { size_t delta_base_cache_limit; size_t packed_git_window_size; size_t packed_git_limit; + + char *hooks_path; }; #define REPO_SETTINGS_INIT { \ + .shared_repository = -1, \ .index_version = -1, \ .core_untracked_cache = UNTRACKED_CACHE_KEEP, \ .fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE, \ @@ -74,10 +80,18 @@ struct repo_settings { } void prepare_repo_settings(struct repository *r); +void repo_settings_clear(struct repository *r); /* Read the value for "core.logAllRefUpdates". */ enum log_refs_config repo_settings_get_log_all_ref_updates(struct repository *repo); /* Read the value for "core.warnAmbiguousRefs". */ int repo_settings_get_warn_ambiguous_refs(struct repository *repo); +/* Read the value for "core.hooksPath". */ +const char *repo_settings_get_hooks_path(struct repository *repo); + +/* Read, set or reset the value for "core.sharedRepository". */ +int repo_settings_get_shared_repository(struct repository *repo); +void repo_settings_set_shared_repository(struct repository *repo, int value); +void repo_settings_reset_shared_repository(struct repository *repo); #endif /* REPO_SETTINGS_H */ diff --git a/repository.c b/repository.c index 468fe580a5d6b6..6cf423da50adec 100644 --- a/repository.c +++ b/repository.c @@ -312,8 +312,8 @@ int repo_submodule_init(struct repository *subrepo, struct strbuf worktree = STRBUF_INIT; int ret = 0; - strbuf_repo_worktree_path(&gitdir, superproject, "%s/.git", path); - strbuf_repo_worktree_path(&worktree, superproject, "%s", path); + repo_worktree_path_append(superproject, &gitdir, "%s/.git", path); + repo_worktree_path_append(superproject, &worktree, "%s", path); if (repo_init(subrepo, gitdir.buf, worktree.buf)) { /* @@ -380,7 +380,7 @@ void repo_clear(struct repository *repo) parsed_object_pool_clear(repo->parsed_objects); FREE_AND_NULL(repo->parsed_objects); - FREE_AND_NULL(repo->settings.fsmonitor); + repo_settings_clear(repo); if (repo->config) { git_configset_clear(repo->config); diff --git a/rerere.c b/rerere.c index c42cee618bfe65..740e8ad1a0b40a 100644 --- a/rerere.c +++ b/rerere.c @@ -91,16 +91,18 @@ static void assign_variant(struct rerere_id *id) id->variant = variant; } -const char *rerere_path(const struct rerere_id *id, const char *file) +const char *rerere_path(struct strbuf *buf, const struct rerere_id *id, const char *file) { if (!file) - return git_path("rr-cache/%s", rerere_id_hex(id)); + return repo_git_path_replace(the_repository, buf, "rr-cache/%s", + rerere_id_hex(id)); if (id->variant <= 0) - return git_path("rr-cache/%s/%s", rerere_id_hex(id), file); + return repo_git_path_replace(the_repository, buf, "rr-cache/%s/%s", + rerere_id_hex(id), file); - return git_path("rr-cache/%s/%s.%d", - rerere_id_hex(id), file, id->variant); + return repo_git_path_replace(the_repository, buf, "rr-cache/%s/%s.%d", + rerere_id_hex(id), file, id->variant); } static int is_rr_file(const char *name, const char *filename, int *variant) @@ -125,8 +127,12 @@ static int is_rr_file(const char *name, const char *filename, int *variant) static void scan_rerere_dir(struct rerere_dir *rr_dir) { struct dirent *de; - DIR *dir = opendir(git_path("rr-cache/%s", rr_dir->name)); + char *path; + DIR *dir; + path = repo_git_path(the_repository, "rr-cache/%s", rr_dir->name); + dir = opendir(path); + free(path); if (!dir) return; while ((de = readdir(dir)) != NULL) { @@ -624,9 +630,10 @@ static int try_merge(struct index_state *istate, { enum ll_merge_result ret; mmfile_t base = {NULL, 0}, other = {NULL, 0}; + struct strbuf buf = STRBUF_INIT; - if (read_mmfile(&base, rerere_path(id, "preimage")) || - read_mmfile(&other, rerere_path(id, "postimage"))) { + if (read_mmfile(&base, rerere_path(&buf, id, "preimage")) || + read_mmfile(&other, rerere_path(&buf, id, "postimage"))) { ret = LL_MERGE_CONFLICT; } else { /* @@ -637,6 +644,7 @@ static int try_merge(struct index_state *istate, istate, NULL); } + strbuf_release(&buf); free(base.ptr); free(other.ptr); @@ -657,6 +665,7 @@ static int merge(struct index_state *istate, const struct rerere_id *id, const c { FILE *f; int ret; + struct strbuf buf = STRBUF_INIT; mmfile_t cur = {NULL, 0}; mmbuffer_t result = {NULL, 0}; @@ -664,8 +673,8 @@ static int merge(struct index_state *istate, const struct rerere_id *id, const c * Normalize the conflicts in path and write it out to * "thisimage" temporary file. */ - if ((handle_file(istate, path, NULL, rerere_path(id, "thisimage")) < 0) || - read_mmfile(&cur, rerere_path(id, "thisimage"))) { + if ((handle_file(istate, path, NULL, rerere_path(&buf, id, "thisimage")) < 0) || + read_mmfile(&cur, rerere_path(&buf, id, "thisimage"))) { ret = 1; goto out; } @@ -678,9 +687,9 @@ static int merge(struct index_state *istate, const struct rerere_id *id, const c * A successful replay of recorded resolution. * Mark that "postimage" was used to help gc. */ - if (utime(rerere_path(id, "postimage"), NULL) < 0) + if (utime(rerere_path(&buf, id, "postimage"), NULL) < 0) warning_errno(_("failed utime() on '%s'"), - rerere_path(id, "postimage")); + rerere_path(&buf, id, "postimage")); /* Update "path" with the resolution */ f = fopen(path, "w"); @@ -694,6 +703,7 @@ static int merge(struct index_state *istate, const struct rerere_id *id, const c out: free(cur.ptr); free(result.ptr); + strbuf_release(&buf); return ret; } @@ -720,9 +730,11 @@ static void update_paths(struct repository *r, struct string_list *update) static void remove_variant(struct rerere_id *id) { - unlink_or_warn(rerere_path(id, "postimage")); - unlink_or_warn(rerere_path(id, "preimage")); + struct strbuf buf = STRBUF_INIT; + unlink_or_warn(rerere_path(&buf, id, "postimage")); + unlink_or_warn(rerere_path(&buf, id, "preimage")); id->collection->status[id->variant] = 0; + strbuf_release(&buf); } /* @@ -739,6 +751,7 @@ static void do_rerere_one_path(struct index_state *istate, const char *path = rr_item->string; struct rerere_id *id = rr_item->util; struct rerere_dir *rr_dir = id->collection; + struct strbuf buf = STRBUF_INIT; int variant; variant = id->variant; @@ -746,12 +759,12 @@ static void do_rerere_one_path(struct index_state *istate, /* Has the user resolved it already? */ if (variant >= 0) { if (!handle_file(istate, path, NULL, NULL)) { - copy_file(rerere_path(id, "postimage"), path, 0666); + copy_file(rerere_path(&buf, id, "postimage"), path, 0666); id->collection->status[variant] |= RR_HAS_POSTIMAGE; fprintf_ln(stderr, _("Recorded resolution for '%s'."), path); free_rerere_id(rr_item); rr_item->util = NULL; - return; + goto out; } /* * There may be other variants that can cleanly @@ -787,22 +800,25 @@ static void do_rerere_one_path(struct index_state *istate, path); free_rerere_id(rr_item); rr_item->util = NULL; - return; + goto out; } /* None of the existing one applies; we need a new variant */ assign_variant(id); variant = id->variant; - handle_file(istate, path, NULL, rerere_path(id, "preimage")); + handle_file(istate, path, NULL, rerere_path(&buf, id, "preimage")); if (id->collection->status[variant] & RR_HAS_POSTIMAGE) { - const char *path = rerere_path(id, "postimage"); + const char *path = rerere_path(&buf, id, "postimage"); if (unlink(path)) die_errno(_("cannot unlink stray '%s'"), path); id->collection->status[variant] &= ~RR_HAS_POSTIMAGE; } id->collection->status[variant] |= RR_HAS_PREIMAGE; fprintf_ln(stderr, _("Recorded preimage for '%s'"), path); + +out: + strbuf_release(&buf); } static int do_plain_rerere(struct repository *r, @@ -810,6 +826,7 @@ static int do_plain_rerere(struct repository *r, { struct string_list conflict = STRING_LIST_INIT_DUP; struct string_list update = STRING_LIST_INIT_DUP; + struct strbuf buf = STRBUF_INIT; int i; find_conflict(r, &conflict); @@ -843,7 +860,7 @@ static int do_plain_rerere(struct repository *r, string_list_insert(rr, path)->util = id; /* Ensure that the directory exists. */ - mkdir_in_gitdir(rerere_path(id, NULL)); + mkdir_in_gitdir(rerere_path(&buf, id, NULL)); } for (i = 0; i < rr->nr; i++) @@ -854,6 +871,7 @@ static int do_plain_rerere(struct repository *r, string_list_clear(&conflict, 0); string_list_clear(&update, 0); + strbuf_release(&buf); return write_rr(rr, fd); } @@ -1033,6 +1051,7 @@ static int rerere_forget_one_path(struct index_state *istate, struct rerere_id *id; unsigned char hash[GIT_MAX_RAWSZ]; int ret; + struct strbuf buf = STRBUF_INIT; struct string_list_item *item; /* @@ -1056,8 +1075,8 @@ static int rerere_forget_one_path(struct index_state *istate, if (!has_rerere_resolution(id)) continue; - handle_cache(istate, path, hash, rerere_path(id, "thisimage")); - if (read_mmfile(&cur, rerere_path(id, "thisimage"))) { + handle_cache(istate, path, hash, rerere_path(&buf, id, "thisimage")); + if (read_mmfile(&cur, rerere_path(&buf, id, "thisimage"))) { free(cur.ptr); error(_("failed to update conflicted state in '%s'"), path); goto fail_exit; @@ -1074,7 +1093,7 @@ static int rerere_forget_one_path(struct index_state *istate, goto fail_exit; } - filename = rerere_path(id, "postimage"); + filename = rerere_path(&buf, id, "postimage"); if (unlink(filename)) { if (errno == ENOENT) error(_("no remembered resolution for '%s'"), path); @@ -1088,7 +1107,7 @@ static int rerere_forget_one_path(struct index_state *istate, * conflict in the working tree, run us again to record * the postimage. */ - handle_cache(istate, path, hash, rerere_path(id, "preimage")); + handle_cache(istate, path, hash, rerere_path(&buf, id, "preimage")); fprintf_ln(stderr, _("Updated preimage for '%s'"), path); /* @@ -1099,9 +1118,11 @@ static int rerere_forget_one_path(struct index_state *istate, free_rerere_id(item); item->util = id; fprintf(stderr, _("Forgot resolution for '%s'\n"), path); + strbuf_release(&buf); return 0; fail_exit: + strbuf_release(&buf); free(id); return -1; } @@ -1147,16 +1168,26 @@ int rerere_forget(struct repository *r, struct pathspec *pathspec) static timestamp_t rerere_created_at(struct rerere_id *id) { + struct strbuf buf = STRBUF_INIT; struct stat st; + timestamp_t ret; + + ret = stat(rerere_path(&buf, id, "preimage"), &st) ? (time_t) 0 : st.st_mtime; - return stat(rerere_path(id, "preimage"), &st) ? (time_t) 0 : st.st_mtime; + strbuf_release(&buf); + return ret; } static timestamp_t rerere_last_used_at(struct rerere_id *id) { + struct strbuf buf = STRBUF_INIT; struct stat st; + timestamp_t ret; + + ret = stat(rerere_path(&buf, id, "postimage"), &st) ? (time_t) 0 : st.st_mtime; - return stat(rerere_path(id, "postimage"), &st) ? (time_t) 0 : st.st_mtime; + strbuf_release(&buf); + return ret; } /* @@ -1164,9 +1195,11 @@ static timestamp_t rerere_last_used_at(struct rerere_id *id) */ static void unlink_rr_item(struct rerere_id *id) { - unlink_or_warn(rerere_path(id, "thisimage")); + struct strbuf buf = STRBUF_INIT; + unlink_or_warn(rerere_path(&buf, id, "thisimage")); remove_variant(id); id->collection->status[id->variant] = 0; + strbuf_release(&buf); } static void prune_one(struct rerere_id *id, @@ -1205,6 +1238,7 @@ void rerere_gc(struct repository *r, struct string_list *rr) timestamp_t now = time(NULL); timestamp_t cutoff_noresolve = now - 15 * 86400; timestamp_t cutoff_resolve = now - 60 * 86400; + struct strbuf buf = STRBUF_INIT; if (setup_rerere(r, rr, 0) < 0) return; @@ -1214,7 +1248,7 @@ void rerere_gc(struct repository *r, struct string_list *rr) repo_config_get_expiry_in_days(the_repository, "gc.rerereunresolved", &cutoff_noresolve, now); git_config(git_default_config, NULL); - dir = opendir(git_path("rr-cache")); + dir = opendir(repo_git_path_replace(the_repository, &buf, "rr-cache")); if (!dir) die_errno(_("unable to open rr-cache directory")); /* Collect stale conflict IDs ... */ @@ -1243,9 +1277,12 @@ void rerere_gc(struct repository *r, struct string_list *rr) /* ... and then remove the empty directories */ for (i = 0; i < to_remove.nr; i++) - rmdir(git_path("rr-cache/%s", to_remove.items[i].string)); + rmdir(repo_git_path_replace(the_repository, &buf, + "rr-cache/%s", to_remove.items[i].string)); + string_list_clear(&to_remove, 0); rollback_lock_file(&write_lock); + strbuf_release(&buf); } /* @@ -1264,10 +1301,14 @@ void rerere_clear(struct repository *r, struct string_list *merge_rr) for (i = 0; i < merge_rr->nr; i++) { struct rerere_id *id = merge_rr->items[i].util; + struct strbuf buf = STRBUF_INIT; + if (!has_rerere_resolution(id)) { unlink_rr_item(id); - rmdir(rerere_path(id, NULL)); + rmdir(rerere_path(&buf, id, NULL)); } + + strbuf_release(&buf); } unlink_or_warn(git_path_merge_rr(r)); rollback_lock_file(&write_lock); diff --git a/rerere.h b/rerere.h index 5d6cb638793a49..d4b5f7c932006a 100644 --- a/rerere.h +++ b/rerere.h @@ -32,7 +32,8 @@ int repo_rerere(struct repository *, int); * path to that filesystem entity. With "file" specified with NULL, * return the path to the directory that houses these files. */ -const char *rerere_path(const struct rerere_id *, const char *file); +const char *rerere_path(struct strbuf *buf, const struct rerere_id *, + const char *file); int rerere_forget(struct repository *, struct pathspec *); int rerere_remaining(struct repository *, struct string_list *); void rerere_clear(struct repository *, struct string_list *); diff --git a/revision.c b/revision.c index 32d949b36feb80..6c88841dcca7a4 100644 --- a/revision.c +++ b/revision.c @@ -1889,15 +1889,20 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags) for (p = worktrees; *p; p++) { struct worktree *wt = *p; struct index_state istate = INDEX_STATE_INIT(revs->repo); + char *wt_gitdir; if (wt->is_current) continue; /* current index already taken care of */ + wt_gitdir = get_worktree_git_dir(wt); + if (read_index_from(&istate, worktree_git_path(the_repository, wt, "index"), - get_worktree_git_dir(wt)) > 0) + wt_gitdir) > 0) do_add_index_objects_to_pending(revs, &istate, flags); + discard_index(&istate); + free(wt_gitdir); } free_worktrees(worktrees); } diff --git a/serve.c b/serve.c index f6dfe34a2bee6b..e3ccf1505ca1a0 100644 --- a/serve.c +++ b/serve.c @@ -10,6 +10,7 @@ #include "upload-pack.h" #include "bundle-uri.h" #include "trace2.h" +#include "promisor-remote.h" static int advertise_sid = -1; static int advertise_object_info = -1; @@ -29,6 +30,26 @@ static int agent_advertise(struct repository *r UNUSED, return 1; } +static int promisor_remote_advertise(struct repository *r, + struct strbuf *value) +{ + if (value) { + char *info = promisor_remote_info(r); + if (!info) + return 0; + strbuf_addstr(value, info); + free(info); + } + return 1; +} + +static void promisor_remote_receive(struct repository *r, + const char *remotes) +{ + mark_promisor_remotes_as_accepted(r, remotes); +} + + static int object_format_advertise(struct repository *r, struct strbuf *value) { @@ -155,6 +176,11 @@ static struct protocol_capability capabilities[] = { .advertise = bundle_uri_advertise, .command = bundle_uri_command, }, + { + .name = "promisor-remote", + .advertise = promisor_remote_advertise, + .receive = promisor_remote_receive, + }, }; void protocol_v2_advertise_capabilities(struct repository *r) diff --git a/server-info.c b/server-info.c index 31c3fdc118447d..1ca0e00d51e6c0 100644 --- a/server-info.c +++ b/server-info.c @@ -125,7 +125,7 @@ static int update_info_file(struct repository *r, char *path, uic.cur_fp = NULL; if (uic_is_stale(&uic)) { - if (adjust_shared_perm(get_tempfile_path(f)) < 0) + if (adjust_shared_perm(r, get_tempfile_path(f)) < 0) goto out; if (rename_tempfile(&f, path) < 0) goto out; diff --git a/setup.c b/setup.c index 715b0de22ae399..db955e4112291a 100644 --- a/setup.c +++ b/setup.c @@ -792,7 +792,7 @@ int upgrade_repository_format(int target_version) struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT; int ret; - strbuf_git_common_path(&sb, the_repository, "config"); + repo_common_path_append(the_repository, &sb, "config"); read_repository_format(&repo_fmt, sb.buf); strbuf_release(&sb); @@ -1831,7 +1831,7 @@ const char *setup_git_directory_gently(int *nongit_ok) * * Regardless of the state of nongit_ok, startup_info->prefix and * the GIT_PREFIX environment variable must always match. For details - * see Documentation/config/alias.txt. + * see Documentation/config/alias.adoc. */ if (nongit_ok && *nongit_ok) startup_info->have_repository = 0; @@ -2097,7 +2097,7 @@ static void copy_templates_1(struct strbuf *path, struct strbuf *template_path, * with the way the namespace under .git/ is organized, should * be really carefully chosen. */ - safe_create_dir(path->buf, 1); + safe_create_dir(the_repository, path->buf, 1); while ((de = readdir(dir)) != NULL) { struct stat st_git, st_template; int exists = 0; @@ -2251,7 +2251,7 @@ void initialize_repository_version(int hash_algo, struct strbuf config = STRBUF_INIT; struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT; - strbuf_git_common_path(&config, the_repository, "config"); + repo_common_path_append(the_repository, &config, "config"); read_repository_format(&repo_fmt, config.buf); if (repo_fmt.v1_only_extensions.nr) @@ -2273,7 +2273,7 @@ static int is_reinit(void) char junk[2]; int ret; - git_path_buf(&buf, "HEAD"); + repo_git_path_replace(the_repository, &buf, "HEAD"); ret = !access(buf.buf, R_OK) || readlink(buf.buf, junk, sizeof(junk) - 1) != -1; strbuf_release(&buf); return ret; @@ -2325,8 +2325,7 @@ static int create_default_files(const char *template_path, int init_shared_repository) { struct stat st1; - struct strbuf buf = STRBUF_INIT; - char *path; + struct strbuf path = STRBUF_INIT; int reinit; int filemode; const char *work_tree = repo_get_work_tree(the_repository); @@ -2342,7 +2341,7 @@ static int create_default_files(const char *template_path, */ copy_templates(template_path); git_config_clear(); - reset_shared_repository(); + repo_settings_reset_shared_repository(the_repository); git_config(git_default_config, NULL); reinit = is_reinit(); @@ -2352,7 +2351,8 @@ static int create_default_files(const char *template_path, * values we might have just re-read from the config. */ if (init_shared_repository != -1) - set_shared_repository(init_shared_repository); + repo_settings_set_shared_repository(the_repository, + init_shared_repository); is_bare_repository_cfg = !work_tree; @@ -2360,21 +2360,21 @@ static int create_default_files(const char *template_path, * We would have created the above under user's umask -- under * shared-repository settings, we would need to fix them up. */ - if (get_shared_repository()) { - adjust_shared_perm(repo_get_git_dir(the_repository)); + if (repo_settings_get_shared_repository(the_repository)) { + adjust_shared_perm(the_repository, repo_get_git_dir(the_repository)); } initialize_repository_version(fmt->hash_algo, fmt->ref_storage_format, reinit); /* Check filemode trustability */ - path = git_path_buf(&buf, "config"); + repo_git_path_replace(the_repository, &path, "config"); filemode = TEST_FILEMODE; - if (TEST_FILEMODE && !lstat(path, &st1)) { + if (TEST_FILEMODE && !lstat(path.buf, &st1)) { struct stat st2; - filemode = (!chmod(path, st1.st_mode ^ S_IXUSR) && - !lstat(path, &st2) && + filemode = (!chmod(path.buf, st1.st_mode ^ S_IXUSR) && + !lstat(path.buf, &st2) && st1.st_mode != st2.st_mode && - !chmod(path, st1.st_mode)); + !chmod(path.buf, st1.st_mode)); if (filemode && !reinit && (st1.st_mode & S_IXUSR)) filemode = 0; } @@ -2393,24 +2393,24 @@ static int create_default_files(const char *template_path, if (!reinit) { /* Check if symlink is supported in the work tree */ - path = git_path_buf(&buf, "tXXXXXX"); - if (!close(xmkstemp(path)) && - !unlink(path) && - !create_symlink(NULL, "testing", path) && - !lstat(path, &st1) && + repo_git_path_replace(the_repository, &path, "tXXXXXX"); + if (!close(xmkstemp(path.buf)) && + !unlink(path.buf) && + !create_symlink(NULL, "testing", path.buf) && + !lstat(path.buf, &st1) && S_ISLNK(st1.st_mode)) - unlink(path); /* good */ + unlink(path.buf); /* good */ else git_config_set("core.symlinks", "false"); /* Check if the filesystem is case-insensitive */ - path = git_path_buf(&buf, "CoNfIg"); - if (!access(path, F_OK)) + repo_git_path_replace(the_repository, &path, "CoNfIg"); + if (!access(path.buf, F_OK)) git_config_set("core.ignorecase", "true"); probe_utf8_pathname_composition(); } - strbuf_release(&buf); + strbuf_release(&path); return reinit; } @@ -2422,15 +2422,15 @@ static void create_object_directory(void) strbuf_addstr(&path, repo_get_object_directory(the_repository)); baselen = path.len; - safe_create_dir(path.buf, 1); + safe_create_dir(the_repository, path.buf, 1); strbuf_setlen(&path, baselen); strbuf_addstr(&path, "/pack"); - safe_create_dir(path.buf, 1); + safe_create_dir(the_repository, path.buf, 1); strbuf_setlen(&path, baselen); strbuf_addstr(&path, "/info"); - safe_create_dir(path.buf, 1); + safe_create_dir(the_repository, path.buf, 1); strbuf_release(&path); } @@ -2601,7 +2601,7 @@ int init_db(const char *git_dir, const char *real_git_dir, */ git_config(git_default_core_config, NULL); - safe_create_dir(git_dir, 0); + safe_create_dir(the_repository, git_dir, 0); reinit = create_default_files(template_dir, original_git_dir, &repo_fmt, init_shared_repository); @@ -2611,7 +2611,7 @@ int init_db(const char *git_dir, const char *real_git_dir, initial_branch, flags & INIT_DB_QUIET); create_object_directory(); - if (get_shared_repository()) { + if (repo_settings_get_shared_repository(the_repository)) { char buf[10]; /* We do not spell "group" and such, so that * the configuration can be read by older version @@ -2619,12 +2619,12 @@ int init_db(const char *git_dir, const char *real_git_dir, * and compatibility values for PERM_GROUP and * PERM_EVERYBODY. */ - if (get_shared_repository() < 0) + if (repo_settings_get_shared_repository(the_repository) < 0) /* force to the mode value */ - xsnprintf(buf, sizeof(buf), "0%o", -get_shared_repository()); - else if (get_shared_repository() == PERM_GROUP) + xsnprintf(buf, sizeof(buf), "0%o", -repo_settings_get_shared_repository(the_repository)); + else if (repo_settings_get_shared_repository(the_repository) == PERM_GROUP) xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_GROUP); - else if (get_shared_repository() == PERM_EVERYBODY) + else if (repo_settings_get_shared_repository(the_repository) == PERM_EVERYBODY) xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_EVERYBODY); else BUG("invalid value for shared_repository"); @@ -2636,12 +2636,12 @@ int init_db(const char *git_dir, const char *real_git_dir, int len = strlen(git_dir); if (reinit) - printf(get_shared_repository() + printf(repo_settings_get_shared_repository(the_repository) ? _("Reinitialized existing shared Git repository in %s%s\n") : _("Reinitialized existing Git repository in %s%s\n"), git_dir, len && git_dir[len-1] != '/' ? "/" : ""); else - printf(get_shared_repository() + printf(repo_settings_get_shared_repository(the_repository) ? _("Initialized empty shared Git repository in %s%s\n") : _("Initialized empty Git repository in %s%s\n"), git_dir, len && git_dir[len-1] != '/' ? "/" : ""); diff --git a/shallow.c b/shallow.c index b54244ffa90d66..4bd9342c9a745a 100644 --- a/shallow.c +++ b/shallow.c @@ -364,7 +364,9 @@ const char *setup_temporary_shallow(const struct oid_array *extra) struct strbuf sb = STRBUF_INIT; if (write_shallow_commits(&sb, 0, extra)) { - temp = xmks_tempfile(git_path("shallow_XXXXXX")); + char *path = repo_git_path(the_repository, "shallow_XXXXXX"); + temp = xmks_tempfile(path); + free(path); if (write_in_full(temp->fd, sb.buf, sb.len) < 0 || close_tempfile_gently(temp) < 0) diff --git a/simple-ipc.h b/simple-ipc.h index 3916eaf70d9863..701e005cb8e5f3 100644 --- a/simple-ipc.h +++ b/simple-ipc.h @@ -2,7 +2,7 @@ #define GIT_SIMPLE_IPC_H /* - * See Documentation/technical/api-simple-ipc.txt + * See Documentation/technical/api-simple-ipc.adoc */ enum ipc_active_state { diff --git a/submodule.c b/submodule.c index b361076c5b97a0..0530e8cf24e045 100644 --- a/submodule.c +++ b/submodule.c @@ -536,7 +536,8 @@ static struct repository *open_submodule(const char *path) struct strbuf sb = STRBUF_INIT; struct repository *out = xmalloc(sizeof(*out)); - if (submodule_to_gitdir(&sb, path) || repo_init(out, sb.buf, NULL)) { + if (submodule_to_gitdir(the_repository, &sb, path) || + repo_init(out, sb.buf, NULL)) { strbuf_release(&sb); free(out); return NULL; @@ -1315,7 +1316,7 @@ static int repo_has_absorbed_submodules(struct repository *r) int ret; struct strbuf buf = STRBUF_INIT; - strbuf_repo_git_path(&buf, r, "modules/"); + repo_git_path_append(r, &buf, "modules/"); ret = file_exists(buf.buf) && !is_empty_dir(buf.buf); strbuf_release(&buf); return ret; @@ -2572,7 +2573,8 @@ int get_superproject_working_tree(struct strbuf *buf) * Put the gitdir for a submodule (given relative to the main * repository worktree) into `buf`, or return -1 on error. */ -int submodule_to_gitdir(struct strbuf *buf, const char *submodule) +int submodule_to_gitdir(struct repository *repo, + struct strbuf *buf, const char *submodule) { const struct submodule *sub; const char *git_dir; @@ -2592,14 +2594,13 @@ int submodule_to_gitdir(struct strbuf *buf, const char *submodule) strbuf_addstr(buf, git_dir); } if (!is_git_directory(buf->buf)) { - sub = submodule_from_path(the_repository, null_oid(), - submodule); + sub = submodule_from_path(repo, null_oid(), submodule); if (!sub) { ret = -1; goto cleanup; } strbuf_reset(buf); - submodule_name_to_gitdir(buf, the_repository, sub->name); + submodule_name_to_gitdir(buf, repo, sub->name); } cleanup: @@ -2629,6 +2630,6 @@ void submodule_name_to_gitdir(struct strbuf *buf, struct repository *r, * administrators can explicitly set. Nothing has been decided, * so for now, just append the name at the end of the path. */ - strbuf_repo_git_path(buf, r, "modules/"); + repo_git_path_append(r, buf, "modules/"); strbuf_addstr(buf, submodule_name); } diff --git a/submodule.h b/submodule.h index 4deb1b5f84e71e..db980c1d083bc0 100644 --- a/submodule.h +++ b/submodule.h @@ -136,7 +136,8 @@ int push_unpushed_submodules(struct repository *r, * path of that submodule in 'buf'. Return -1 on error or when the * submodule is not initialized. */ -int submodule_to_gitdir(struct strbuf *buf, const char *submodule); +int submodule_to_gitdir(struct repository *repo, + struct strbuf *buf, const char *submodule); /* * Given a submodule name, create a path to where the submodule's gitdir lives diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c index 1cc05f043ac204..e00fce592b10ed 100644 --- a/t/helper/test-ref-store.c +++ b/t/helper/test-ref-store.c @@ -75,11 +75,10 @@ static const char **get_store(const char **argv, struct ref_store **refs) *refs = get_main_ref_store(the_repository); } else if (skip_prefix(argv[0], "submodule:", &gitdir)) { struct strbuf sb = STRBUF_INIT; - int ret; - ret = strbuf_git_path_submodule(&sb, gitdir, "objects/"); - if (ret) - die("strbuf_git_path_submodule failed: %d", ret); + if (!repo_submodule_path_append(the_repository, + &sb, gitdir, "objects/")) + die("computing submodule path failed"); add_to_alternates_memory(sb.buf); strbuf_release(&sb); diff --git a/t/helper/test-rot13-filter.c b/t/helper/test-rot13-filter.c index ff407b575ce318..722b1cbe7788bc 100644 --- a/t/helper/test-rot13-filter.c +++ b/t/helper/test-rot13-filter.c @@ -1,6 +1,6 @@ /* * Example implementation for the Git filter protocol version 2 - * See Documentation/gitattributes.txt, section "Filter Protocol" + * See Documentation/gitattributes.adoc, section "Filter Protocol" * * Usage: test-tool rot13-filter [--always-delay] --log= * diff --git a/t/meson.build b/t/meson.build index f0de32be2230f2..84a4544984084a 100644 --- a/t/meson.build +++ b/t/meson.build @@ -5,6 +5,9 @@ clar_test_suites = [ 'unit-tests/u-hashmap.c', 'unit-tests/u-mem-pool.c', 'unit-tests/u-mingw.c', + 'unit-tests/u-oid-array.c', + 'unit-tests/u-oidmap.c', + 'unit-tests/u-oidtree.c', 'unit-tests/u-prio-queue.c', 'unit-tests/u-reftable-tree.c', 'unit-tests/u-strbuf.c', @@ -15,6 +18,7 @@ clar_test_suites = [ clar_sources = [ 'unit-tests/clar/clar.c', 'unit-tests/unit-test.c', + 'unit-tests/lib-oid.c' ] clar_decls_h = custom_target( @@ -49,9 +53,6 @@ clar_unit_tests = executable('unit-tests', test('unit-tests', clar_unit_tests) unit_test_programs = [ - 'unit-tests/t-oid-array.c', - 'unit-tests/t-oidmap.c', - 'unit-tests/t-oidtree.c', 'unit-tests/t-reftable-basics.c', 'unit-tests/t-reftable-block.c', 'unit-tests/t-reftable-merged.c', @@ -69,7 +70,6 @@ foreach unit_test_program : unit_test_programs unit_test = executable(unit_test_name, sources: [ 'unit-tests/test-lib.c', - 'unit-tests/lib-oid.c', 'unit-tests/lib-reftable.c', unit_test_program, ], @@ -732,6 +732,7 @@ integration_tests = [ 't5703-upload-pack-ref-in-want.sh', 't5704-protocol-violations.sh', 't5705-session-id-in-capabilities.sh', + 't5710-promisor-remote-capability.sh', 't5730-protocol-v2-bundle-uri-file.sh', 't5731-protocol-v2-bundle-uri-git.sh', 't5732-protocol-v2-bundle-uri-http.sh', diff --git a/t/t0450-txt-doc-vs-help.sh b/t/t0450-txt-doc-vs-help.sh index 853101b86ef53d..2f7504ae7e9090 100755 --- a/t/t0450-txt-doc-vs-help.sh +++ b/t/t0450-txt-doc-vs-help.sh @@ -1,6 +1,6 @@ #!/bin/sh -test_description='assert (unbuilt) Documentation/*.txt and -h output +test_description='assert (unbuilt) Documentation/*.adoc and -h output Run this with --debug to see a summary of where we still fail to make the two versions consistent with one another.' @@ -11,11 +11,11 @@ test_expect_success 'setup: list of builtins' ' git --list-cmds=builtins >builtins ' -test_expect_success 'list of txt and help mismatches is sorted' ' - sort -u "$TEST_DIRECTORY"/t0450/txt-help-mismatches >expect && - if ! test_cmp expect "$TEST_DIRECTORY"/t0450/txt-help-mismatches +test_expect_success 'list of adoc and help mismatches is sorted' ' + sort -u "$TEST_DIRECTORY"/t0450/adoc-help-mismatches >expect && + if ! test_cmp expect "$TEST_DIRECTORY"/t0450/adoc-help-mismatches then - BUG "please keep the list of txt and help mismatches sorted" + BUG "please keep the list of adoc and help mismatches sorted" fi ' @@ -40,20 +40,20 @@ help_to_synopsis () { echo "$out" } -builtin_to_txt () { - echo "$GIT_BUILD_DIR/Documentation/git-$1.txt" +builtin_to_adoc () { + echo "$GIT_BUILD_DIR/Documentation/git-$1.adoc" } -txt_to_synopsis () { +adoc_to_synopsis () { builtin="$1" && out_dir="out/$builtin" && - out="$out_dir/txt.synopsis" && + out="$out_dir/adoc.synopsis" && if test -f "$out" then echo "$out" && return 0 fi && - b2t="$(builtin_to_txt "$builtin")" && + b2t="$(builtin_to_adoc "$builtin")" && sed -n \ -E '/^\[(verse|synopsis)\]$/,/^$/ { /^$/d; @@ -109,29 +109,29 @@ do fi ' - txt="$(builtin_to_txt "$builtin")" && - preq="$(echo BUILTIN_TXT_$builtin | tr '[:lower:]-' '[:upper:]_')" && + adoc="$(builtin_to_adoc "$builtin")" && + preq="$(echo BUILTIN_ADOC_$builtin | tr '[:lower:]-' '[:upper:]_')" && - if test -f "$txt" + if test -f "$adoc" then test_set_prereq "$preq" fi && - # *.txt output assertions - test_expect_success "$preq" "$builtin *.txt SYNOPSIS has dashed labels" ' - check_dashed_labels "$(txt_to_synopsis "$builtin")" + # *.adoc output assertions + test_expect_success "$preq" "$builtin *.adoc SYNOPSIS has dashed labels" ' + check_dashed_labels "$(adoc_to_synopsis "$builtin")" ' - # *.txt output consistency assertions + # *.adoc output consistency assertions result= - if grep -q "^$builtin$" "$TEST_DIRECTORY"/t0450/txt-help-mismatches + if grep -q "^$builtin$" "$TEST_DIRECTORY"/t0450/adoc-help-mismatches then result=failure else result=success fi && test_expect_$result "$preq" "$builtin -h output and SYNOPSIS agree" ' - t2s="$(txt_to_synopsis "$builtin")" && + t2s="$(adoc_to_synopsis "$builtin")" && if test "$builtin" = "merge-tree" then test_when_finished "rm -f t2s.new" && @@ -140,17 +140,17 @@ do fi && h2s="$(help_to_synopsis "$builtin")" && - # The *.txt and -h use different spacing for the + # The *.adoc and -h use different spacing for the # alignment of continued usage output, normalize it. - align_after_nl "$builtin" <"$t2s" >txt && + align_after_nl "$builtin" <"$t2s" >adoc && align_after_nl "$builtin" <"$h2s" >help && - test_cmp txt help + test_cmp adoc help ' - if test_have_prereq "$preq" && test -e txt && test -e help + if test_have_prereq "$preq" && test -e adoc && test -e help then test_debug ' - if test_cmp txt help >cmp 2>/dev/null + if test_cmp adoc help >cmp 2>/dev/null then echo "=== DONE: $builtin ===" else @@ -161,7 +161,7 @@ do # Not in test_expect_success in case --run is being # used with --debug - rm -f txt help tmp 2>/dev/null + rm -f adoc help tmp 2>/dev/null fi done expect && + git for-each-ref >actual && + + test_cmp expect actual + ) +' + test_done diff --git a/t/t5710-promisor-remote-capability.sh b/t/t5710-promisor-remote-capability.sh new file mode 100755 index 00000000000000..d2cc69a17e4668 --- /dev/null +++ b/t/t5710-promisor-remote-capability.sh @@ -0,0 +1,312 @@ +#!/bin/sh + +test_description='handling of promisor remote advertisement' + +. ./test-lib.sh + +GIT_TEST_MULTI_PACK_INDEX=0 +GIT_TEST_MULTI_PACK_INDEX_WRITE_INCREMENTAL=0 + +# Setup the repository with three commits, this way HEAD is always +# available and we can hide commit 1 or 2. +test_expect_success 'setup: create "template" repository' ' + git init template && + test_commit -C template 1 && + test_commit -C template 2 && + test_commit -C template 3 && + test-tool genrandom foo 10240 >template/foo && + git -C template add foo && + git -C template commit -m foo +' + +# A bare repo will act as a server repo with unpacked objects. +test_expect_success 'setup: create bare "server" repository' ' + git clone --bare --no-local template server && + mv server/objects/pack/pack-* . && + packfile=$(ls pack-*.pack) && + git -C server unpack-objects --strict <"$packfile" +' + +check_missing_objects () { + git -C "$1" rev-list --objects --all --missing=print > all.txt && + perl -ne 'print if s/^[?]//' all.txt >missing.txt && + test_line_count = "$2" missing.txt && + if test "$2" -lt 2 + then + test "$3" = "$(cat missing.txt)" + else + test -f "$3" && + sort <"$3" >expected_sorted && + sort actual_sorted && + test_cmp expected_sorted actual_sorted + fi +} + +initialize_server () { + count="$1" + missing_oids="$2" + + # Repack everything first + git -C server -c repack.writebitmaps=false repack -a -d && + + # Remove promisor file in case they exist, useful when reinitializing + rm -rf server/objects/pack/*.promisor && + + # Repack without the largest object and create a promisor pack on server + git -C server -c repack.writebitmaps=false repack -a -d \ + --filter=blob:limit=5k --filter-to="$(pwd)/pack" && + promisor_file=$(ls server/objects/pack/*.pack | sed "s/\.pack/.promisor/") && + >"$promisor_file" && + + # Check objects missing on the server + check_missing_objects server "$count" "$missing_oids" +} + +copy_to_lop () { + oid_path="$(test_oid_to_path $1)" && + path="server/objects/$oid_path" && + path2="lop/objects/$oid_path" && + mkdir -p $(dirname "$path2") && + cp "$path" "$path2" +} + +test_expect_success "setup for testing promisor remote advertisement" ' + # Create another bare repo called "lop" (for Large Object Promisor) + git init --bare lop && + + # Copy the largest object from server to lop + obj="HEAD:foo" && + oid="$(git -C server rev-parse $obj)" && + copy_to_lop "$oid" && + + initialize_server 1 "$oid" && + + # Configure lop as promisor remote for server + git -C server remote add lop "file://$(pwd)/lop" && + git -C server config remote.lop.promisor true && + + git -C lop config uploadpack.allowFilter true && + git -C lop config uploadpack.allowAnySHA1InWant true && + git -C server config uploadpack.allowFilter true && + git -C server config uploadpack.allowAnySHA1InWant true +' + +test_expect_success "clone with promisor.advertise set to 'true'" ' + git -C server config promisor.advertise true && + + # Clone from server to create a client + GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ + -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ + -c remote.lop.url="file://$(pwd)/lop" \ + -c promisor.acceptfromserver=All \ + --no-local --filter="blob:limit=5k" server client && + test_when_finished "rm -rf client" && + + # Check that the largest object is still missing on the server + check_missing_objects server 1 "$oid" +' + +test_expect_success "clone with promisor.advertise set to 'false'" ' + git -C server config promisor.advertise false && + + # Clone from server to create a client + GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ + -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ + -c remote.lop.url="file://$(pwd)/lop" \ + -c promisor.acceptfromserver=All \ + --no-local --filter="blob:limit=5k" server client && + test_when_finished "rm -rf client" && + + # Check that the largest object is not missing on the server + check_missing_objects server 0 "" && + + # Reinitialize server so that the largest object is missing again + initialize_server 1 "$oid" +' + +test_expect_success "clone with promisor.acceptfromserver set to 'None'" ' + git -C server config promisor.advertise true && + + # Clone from server to create a client + GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ + -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ + -c remote.lop.url="file://$(pwd)/lop" \ + -c promisor.acceptfromserver=None \ + --no-local --filter="blob:limit=5k" server client && + test_when_finished "rm -rf client" && + + # Check that the largest object is not missing on the server + check_missing_objects server 0 "" && + + # Reinitialize server so that the largest object is missing again + initialize_server 1 "$oid" +' + +test_expect_success "init + fetch with promisor.advertise set to 'true'" ' + git -C server config promisor.advertise true && + + test_when_finished "rm -rf client" && + mkdir client && + git -C client init && + git -C client config remote.lop.promisor true && + git -C client config remote.lop.fetch "+refs/heads/*:refs/remotes/lop/*" && + git -C client config remote.lop.url "file://$(pwd)/lop" && + git -C client config remote.server.url "file://$(pwd)/server" && + git -C client config remote.server.fetch "+refs/heads/*:refs/remotes/server/*" && + git -C client config promisor.acceptfromserver All && + GIT_NO_LAZY_FETCH=0 git -C client fetch --filter="blob:limit=5k" server && + + # Check that the largest object is still missing on the server + check_missing_objects server 1 "$oid" +' + +test_expect_success "clone with promisor.acceptfromserver set to 'KnownName'" ' + git -C server config promisor.advertise true && + + # Clone from server to create a client + GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ + -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ + -c remote.lop.url="file://$(pwd)/lop" \ + -c promisor.acceptfromserver=KnownName \ + --no-local --filter="blob:limit=5k" server client && + test_when_finished "rm -rf client" && + + # Check that the largest object is still missing on the server + check_missing_objects server 1 "$oid" +' + +test_expect_success "clone with 'KnownName' and different remote names" ' + git -C server config promisor.advertise true && + + # Clone from server to create a client + GIT_NO_LAZY_FETCH=0 git clone -c remote.serverTwo.promisor=true \ + -c remote.serverTwo.fetch="+refs/heads/*:refs/remotes/lop/*" \ + -c remote.serverTwo.url="file://$(pwd)/lop" \ + -c promisor.acceptfromserver=KnownName \ + --no-local --filter="blob:limit=5k" server client && + test_when_finished "rm -rf client" && + + # Check that the largest object is not missing on the server + check_missing_objects server 0 "" && + + # Reinitialize server so that the largest object is missing again + initialize_server 1 "$oid" +' + +test_expect_success "clone with promisor.acceptfromserver set to 'KnownUrl'" ' + git -C server config promisor.advertise true && + + # Clone from server to create a client + GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ + -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ + -c remote.lop.url="file://$(pwd)/lop" \ + -c promisor.acceptfromserver=KnownUrl \ + --no-local --filter="blob:limit=5k" server client && + test_when_finished "rm -rf client" && + + # Check that the largest object is still missing on the server + check_missing_objects server 1 "$oid" +' + +test_expect_success "clone with 'KnownUrl' and different remote urls" ' + ln -s lop serverTwo && + + git -C server config promisor.advertise true && + + # Clone from server to create a client + GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ + -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ + -c remote.lop.url="file://$(pwd)/serverTwo" \ + -c promisor.acceptfromserver=KnownUrl \ + --no-local --filter="blob:limit=5k" server client && + test_when_finished "rm -rf client" && + + # Check that the largest object is not missing on the server + check_missing_objects server 0 "" && + + # Reinitialize server so that the largest object is missing again + initialize_server 1 "$oid" +' + +test_expect_success "clone with promisor.advertise set to 'true' but don't delete the client" ' + git -C server config promisor.advertise true && + + # Clone from server to create a client + GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ + -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \ + -c remote.lop.url="file://$(pwd)/lop" \ + -c promisor.acceptfromserver=All \ + --no-local --filter="blob:limit=5k" server client && + + # Check that the largest object is still missing on the server + check_missing_objects server 1 "$oid" +' + +test_expect_success "setup for subsequent fetches" ' + # Generate new commit with large blob + test-tool genrandom bar 10240 >template/bar && + git -C template add bar && + git -C template commit -m bar && + + # Fetch new commit with large blob + git -C server fetch origin && + git -C server update-ref HEAD FETCH_HEAD && + git -C server rev-parse HEAD >expected_head && + + # Repack everything twice and remove .promisor files before + # each repack. This makes sure everything gets repacked + # into a single packfile. The second repack is necessary + # because the first one fetches from lop and creates a new + # packfile and its associated .promisor file. + + rm -f server/objects/pack/*.promisor && + git -C server -c repack.writebitmaps=false repack -a -d && + rm -f server/objects/pack/*.promisor && + git -C server -c repack.writebitmaps=false repack -a -d && + + # Unpack everything + rm pack-* && + mv server/objects/pack/pack-* . && + packfile=$(ls pack-*.pack) && + git -C server unpack-objects --strict <"$packfile" && + + # Copy new large object to lop + obj_bar="HEAD:bar" && + oid_bar="$(git -C server rev-parse $obj_bar)" && + copy_to_lop "$oid_bar" && + + # Reinitialize server so that the 2 largest objects are missing + printf "%s\n" "$oid" "$oid_bar" >expected_missing.txt && + initialize_server 2 expected_missing.txt && + + # Create one more client + cp -r client client2 +' + +test_expect_success "subsequent fetch from a client when promisor.advertise is true" ' + git -C server config promisor.advertise true && + + GIT_NO_LAZY_FETCH=0 git -C client pull origin && + + git -C client rev-parse HEAD >actual && + test_cmp expected_head actual && + + cat client/bar >/dev/null && + + check_missing_objects server 2 expected_missing.txt +' + +test_expect_success "subsequent fetch from a client when promisor.advertise is false" ' + git -C server config promisor.advertise false && + + GIT_NO_LAZY_FETCH=0 git -C client2 pull origin && + + git -C client2 rev-parse HEAD >actual && + test_cmp expected_head actual && + + cat client2/bar >/dev/null && + + check_missing_objects server 1 "$oid" +' + +test_done diff --git a/t/t6012-rev-list-simplify.sh b/t/t6012-rev-list-simplify.sh index de1e87f1621d5d..4cecb6224cb464 100755 --- a/t/t6012-rev-list-simplify.sh +++ b/t/t6012-rev-list-simplify.sh @@ -177,7 +177,7 @@ test_expect_success '--full-diff is not affected by --parents' ' # \ / /\ / # `---X--' `---Y--' # -# This example is explained in Documentation/rev-list-options.txt +# This example is explained in Documentation/rev-list-options.adoc test_expect_success 'setup rebuild repo' ' rm -rf .git * && diff --git a/t/t6434-merge-recursive-rename-options.sh b/t/t6434-merge-recursive-rename-options.sh index a11707835b4abe..6e913c30a136f5 100755 --- a/t/t6434-merge-recursive-rename-options.sh +++ b/t/t6434-merge-recursive-rename-options.sh @@ -22,7 +22,7 @@ R075 2-old 2-new R100 3-old 3-new Actual similarity indices are parsed from diff output. We rely on the fact that -they are rounded down (see, e.g., Documentation/diff-generate-patch.txt, which +they are rounded down (see, e.g., Documentation/diff-generate-patch.adoc, which mentions this in a different context). ' diff --git a/t/unit-tests/lib-oid.c b/t/unit-tests/lib-oid.c index 8f0ccac5328247..e0b3180f23c018 100644 --- a/t/unit-tests/lib-oid.c +++ b/t/unit-tests/lib-oid.c @@ -1,9 +1,9 @@ -#include "test-lib.h" +#include "unit-test.h" #include "lib-oid.h" #include "strbuf.h" #include "hex.h" -int init_hash_algo(void) +int cl_setup_hash_algo(void) { static int algo = -1; @@ -11,42 +11,32 @@ int init_hash_algo(void) const char *algo_name = getenv("GIT_TEST_DEFAULT_HASH"); algo = algo_name ? hash_algo_by_name(algo_name) : GIT_HASH_SHA1; - if (!check(algo != GIT_HASH_UNKNOWN)) - test_msg("BUG: invalid GIT_TEST_DEFAULT_HASH value ('%s')", - algo_name); + cl_assert(algo != GIT_HASH_UNKNOWN); } return algo; } -static int get_oid_arbitrary_hex_algop(const char *hex, struct object_id *oid, +static void cl_parse_oid(const char *hex, struct object_id *oid, const struct git_hash_algo *algop) { - int ret; size_t sz = strlen(hex); struct strbuf buf = STRBUF_INIT; - if (!check(sz <= algop->hexsz)) { - test_msg("BUG: hex string (%s) bigger than maximum allowed (%lu)", - hex, (unsigned long)algop->hexsz); - return -1; - } + cl_assert(sz <= algop->hexsz); strbuf_add(&buf, hex, sz); strbuf_addchars(&buf, '0', algop->hexsz - sz); - ret = get_oid_hex_algop(buf.buf, oid, algop); - if (!check_int(ret, ==, 0)) - test_msg("BUG: invalid hex input (%s) provided", hex); + cl_assert_equal_i(get_oid_hex_algop(buf.buf, oid, algop), 0); strbuf_release(&buf); - return ret; } -int get_oid_arbitrary_hex(const char *hex, struct object_id *oid) + +void cl_parse_any_oid(const char *hex, struct object_id *oid) { - int hash_algo = init_hash_algo(); + int hash_algo = cl_setup_hash_algo(); - if (!check_int(hash_algo, !=, GIT_HASH_UNKNOWN)) - return -1; - return get_oid_arbitrary_hex_algop(hex, oid, &hash_algos[hash_algo]); + cl_assert(hash_algo != GIT_HASH_UNKNOWN); + cl_parse_oid(hex, oid, &hash_algos[hash_algo]); } diff --git a/t/unit-tests/lib-oid.h b/t/unit-tests/lib-oid.h index 4e77c04bd224e6..4031775104906d 100644 --- a/t/unit-tests/lib-oid.h +++ b/t/unit-tests/lib-oid.h @@ -5,6 +5,7 @@ /* * Convert arbitrary hex string to object_id. + * * For example, passing "abc12" will generate * "abc1200000000000000000000000000000000000" hex of length 40 for SHA-1 and * create object_id with that. @@ -12,14 +13,16 @@ * algo is not allowed. The hash algo is decided based on GIT_TEST_DEFAULT_HASH * environment variable. */ -int get_oid_arbitrary_hex(const char *s, struct object_id *oid); + +void cl_parse_any_oid (const char *s, struct object_id *oid); /* * Returns one of GIT_HASH_{SHA1, SHA256, UNKNOWN} based on the value of * GIT_TEST_DEFAULT_HASH environment variable. The fallback value in the * absence of GIT_TEST_DEFAULT_HASH is GIT_HASH_SHA1. It also uses - * check(algo != GIT_HASH_UNKNOWN) before returning to verify if the + * cl_assert(algo != GIT_HASH_UNKNOWN) before returning to verify if the * GIT_TEST_DEFAULT_HASH's value is valid or not. */ -int init_hash_algo(void); + +int cl_setup_hash_algo(void); #endif /* LIB_OID_H */ diff --git a/t/unit-tests/t-oid-array.c b/t/unit-tests/t-oid-array.c deleted file mode 100644 index 45b59a2a51bc52..00000000000000 --- a/t/unit-tests/t-oid-array.c +++ /dev/null @@ -1,126 +0,0 @@ -#define USE_THE_REPOSITORY_VARIABLE - -#include "test-lib.h" -#include "lib-oid.h" -#include "oid-array.h" -#include "hex.h" - -static int fill_array(struct oid_array *array, const char *hexes[], size_t n) -{ - for (size_t i = 0; i < n; i++) { - struct object_id oid; - - if (!check_int(get_oid_arbitrary_hex(hexes[i], &oid), ==, 0)) - return -1; - oid_array_append(array, &oid); - } - if (!check_uint(array->nr, ==, n)) - return -1; - return 0; -} - -static int add_to_oid_array(const struct object_id *oid, void *data) -{ - struct oid_array *array = data; - - oid_array_append(array, oid); - return 0; -} - -static void t_enumeration(const char **input_args, size_t input_sz, - const char **expect_args, size_t expect_sz) -{ - struct oid_array input = OID_ARRAY_INIT, expect = OID_ARRAY_INIT, - actual = OID_ARRAY_INIT; - size_t i; - - if (fill_array(&input, input_args, input_sz)) - return; - if (fill_array(&expect, expect_args, expect_sz)) - return; - - oid_array_for_each_unique(&input, add_to_oid_array, &actual); - if (!check_uint(actual.nr, ==, expect.nr)) - return; - - for (i = 0; i < actual.nr; i++) { - if (!check(oideq(&actual.oid[i], &expect.oid[i]))) - test_msg("expected: %s\n got: %s\n index: %" PRIuMAX, - oid_to_hex(&expect.oid[i]), oid_to_hex(&actual.oid[i]), - (uintmax_t)i); - } - - oid_array_clear(&actual); - oid_array_clear(&input); - oid_array_clear(&expect); -} - -#define TEST_ENUMERATION(input, expect, desc) \ - TEST(t_enumeration(input, ARRAY_SIZE(input), expect, ARRAY_SIZE(expect)), \ - desc " works") - -static void t_lookup(const char **input_hexes, size_t n, const char *query_hex, - int lower_bound, int upper_bound) -{ - struct oid_array array = OID_ARRAY_INIT; - struct object_id oid_query; - int ret; - - if (!check_int(get_oid_arbitrary_hex(query_hex, &oid_query), ==, 0)) - return; - if (fill_array(&array, input_hexes, n)) - return; - ret = oid_array_lookup(&array, &oid_query); - - if (!check_int(ret, <=, upper_bound) || - !check_int(ret, >=, lower_bound)) - test_msg("oid query for lookup: %s", oid_to_hex(&oid_query)); - - oid_array_clear(&array); -} - -#define TEST_LOOKUP(input_hexes, query, lower_bound, upper_bound, desc) \ - TEST(t_lookup(input_hexes, ARRAY_SIZE(input_hexes), query, \ - lower_bound, upper_bound), \ - desc " works") - -static void setup(void) -{ - /* The hash algo is used by oid_array_lookup() internally */ - int algo = init_hash_algo(); - if (check_int(algo, !=, GIT_HASH_UNKNOWN)) - repo_set_hash_algo(the_repository, algo); -} - -int cmd_main(int argc UNUSED, const char **argv UNUSED) -{ - const char *arr_input[] = { "88", "44", "aa", "55" }; - const char *arr_input_dup[] = { "88", "44", "aa", "55", - "88", "44", "aa", "55", - "88", "44", "aa", "55" }; - const char *res_sorted[] = { "44", "55", "88", "aa" }; - const char *nearly_55; - - if (!TEST(setup(), "setup")) - test_skip_all("hash algo initialization failed"); - - TEST_ENUMERATION(arr_input, res_sorted, "ordered enumeration"); - TEST_ENUMERATION(arr_input_dup, res_sorted, - "ordered enumeration with duplicate suppression"); - - TEST_LOOKUP(arr_input, "55", 1, 1, "lookup"); - TEST_LOOKUP(arr_input, "33", INT_MIN, -1, "lookup non-existent entry"); - TEST_LOOKUP(arr_input_dup, "55", 3, 5, "lookup with duplicates"); - TEST_LOOKUP(arr_input_dup, "66", INT_MIN, -1, - "lookup non-existent entry with duplicates"); - - nearly_55 = init_hash_algo() == GIT_HASH_SHA1 ? - "5500000000000000000000000000000000000001" : - "5500000000000000000000000000000000000000000000000000000000000001"; - TEST_LOOKUP(((const char *[]){ "55", nearly_55 }), "55", 0, 0, - "lookup with almost duplicate values"); - TEST_LOOKUP(((const char *[]){ "55", "55" }), "55", 0, 1, - "lookup with single duplicate value"); - - return test_done(); -} diff --git a/t/unit-tests/t-oidmap.c b/t/unit-tests/t-oidmap.c deleted file mode 100644 index b22e52d08bdf77..00000000000000 --- a/t/unit-tests/t-oidmap.c +++ /dev/null @@ -1,181 +0,0 @@ -#include "test-lib.h" -#include "lib-oid.h" -#include "oidmap.h" -#include "hash.h" -#include "hex.h" - -/* - * Elements we will put in oidmap structs are made of a key: the entry.oid - * field, which is of type struct object_id, and a value: the name field (could - * be a refname for example). - */ -struct test_entry { - struct oidmap_entry entry; - char name[FLEX_ARRAY]; -}; - -static const char *const key_val[][2] = { { "11", "one" }, - { "22", "two" }, - { "33", "three" } }; - -static void setup(void (*f)(struct oidmap *map)) -{ - struct oidmap map = OIDMAP_INIT; - int ret = 0; - - for (size_t i = 0; i < ARRAY_SIZE(key_val); i++){ - struct test_entry *entry; - - FLEX_ALLOC_STR(entry, name, key_val[i][1]); - if ((ret = get_oid_arbitrary_hex(key_val[i][0], &entry->entry.oid))) { - free(entry); - break; - } - entry = oidmap_put(&map, entry); - if (!check(entry == NULL)) - free(entry); - } - - if (!ret) - f(&map); - oidmap_free(&map, 1); -} - -static void t_replace(struct oidmap *map) -{ - struct test_entry *entry, *prev; - - FLEX_ALLOC_STR(entry, name, "un"); - if (get_oid_arbitrary_hex("11", &entry->entry.oid)) - return; - prev = oidmap_put(map, entry); - if (!check(prev != NULL)) - return; - check_str(prev->name, "one"); - free(prev); - - FLEX_ALLOC_STR(entry, name, "deux"); - if (get_oid_arbitrary_hex("22", &entry->entry.oid)) - return; - prev = oidmap_put(map, entry); - if (!check(prev != NULL)) - return; - check_str(prev->name, "two"); - free(prev); -} - -static void t_get(struct oidmap *map) -{ - struct test_entry *entry; - struct object_id oid; - - if (get_oid_arbitrary_hex("22", &oid)) - return; - entry = oidmap_get(map, &oid); - if (!check(entry != NULL)) - return; - check_str(entry->name, "two"); - - if (get_oid_arbitrary_hex("44", &oid)) - return; - check(oidmap_get(map, &oid) == NULL); - - if (get_oid_arbitrary_hex("11", &oid)) - return; - entry = oidmap_get(map, &oid); - if (!check(entry != NULL)) - return; - check_str(entry->name, "one"); -} - -static void t_remove(struct oidmap *map) -{ - struct test_entry *entry; - struct object_id oid; - - if (get_oid_arbitrary_hex("11", &oid)) - return; - entry = oidmap_remove(map, &oid); - if (!check(entry != NULL)) - return; - check_str(entry->name, "one"); - check(oidmap_get(map, &oid) == NULL); - free(entry); - - if (get_oid_arbitrary_hex("22", &oid)) - return; - entry = oidmap_remove(map, &oid); - if (!check(entry != NULL)) - return; - check_str(entry->name, "two"); - check(oidmap_get(map, &oid) == NULL); - free(entry); - - if (get_oid_arbitrary_hex("44", &oid)) - return; - check(oidmap_remove(map, &oid) == NULL); -} - -static int key_val_contains(struct test_entry *entry, char seen[]) -{ - for (size_t i = 0; i < ARRAY_SIZE(key_val); i++) { - struct object_id oid; - - if (get_oid_arbitrary_hex(key_val[i][0], &oid)) - return -1; - - if (oideq(&entry->entry.oid, &oid)) { - if (seen[i]) - return 2; - seen[i] = 1; - return 0; - } - } - return 1; -} - -static void t_iterate(struct oidmap *map) -{ - struct oidmap_iter iter; - struct test_entry *entry; - char seen[ARRAY_SIZE(key_val)] = { 0 }; - int count = 0; - - oidmap_iter_init(map, &iter); - while ((entry = oidmap_iter_next(&iter))) { - int ret; - if (!check_int((ret = key_val_contains(entry, seen)), ==, 0)) { - switch (ret) { - case -1: - break; /* error message handled by get_oid_arbitrary_hex() */ - case 1: - test_msg("obtained entry was not given in the input\n" - " name: %s\n oid: %s\n", - entry->name, oid_to_hex(&entry->entry.oid)); - break; - case 2: - test_msg("duplicate entry detected\n" - " name: %s\n oid: %s\n", - entry->name, oid_to_hex(&entry->entry.oid)); - break; - default: - test_msg("BUG: invalid return value (%d) from key_val_contains()", - ret); - break; - } - } else { - count++; - } - } - check_int(count, ==, ARRAY_SIZE(key_val)); - check_int(hashmap_get_size(&map->map), ==, ARRAY_SIZE(key_val)); -} - -int cmd_main(int argc UNUSED, const char **argv UNUSED) -{ - TEST(setup(t_replace), "replace works"); - TEST(setup(t_get), "get works"); - TEST(setup(t_remove), "remove works"); - TEST(setup(t_iterate), "iterate works"); - return test_done(); -} diff --git a/t/unit-tests/t-oidtree.c b/t/unit-tests/t-oidtree.c deleted file mode 100644 index a38754b066b3ea..00000000000000 --- a/t/unit-tests/t-oidtree.c +++ /dev/null @@ -1,122 +0,0 @@ -#include "test-lib.h" -#include "lib-oid.h" -#include "oidtree.h" -#include "hash.h" -#include "hex.h" -#include "strvec.h" - -#define FILL_TREE(tree, ...) \ - do { \ - const char *hexes[] = { __VA_ARGS__ }; \ - if (fill_tree_loc(tree, hexes, ARRAY_SIZE(hexes))) \ - return; \ - } while (0) - -static int fill_tree_loc(struct oidtree *ot, const char *hexes[], size_t n) -{ - for (size_t i = 0; i < n; i++) { - struct object_id oid; - if (!check_int(get_oid_arbitrary_hex(hexes[i], &oid), ==, 0)) - return -1; - oidtree_insert(ot, &oid); - } - return 0; -} - -static void check_contains(struct oidtree *ot, const char *hex, int expected) -{ - struct object_id oid; - - if (!check_int(get_oid_arbitrary_hex(hex, &oid), ==, 0)) - return; - if (!check_int(oidtree_contains(ot, &oid), ==, expected)) - test_msg("oid: %s", oid_to_hex(&oid)); -} - -struct expected_hex_iter { - size_t i; - struct strvec expected_hexes; - const char *query; -}; - -static enum cb_next check_each_cb(const struct object_id *oid, void *data) -{ - struct expected_hex_iter *hex_iter = data; - struct object_id expected; - - if (!check_int(hex_iter->i, <, hex_iter->expected_hexes.nr)) { - test_msg("error: extraneous callback for query: ('%s'), object_id: ('%s')", - hex_iter->query, oid_to_hex(oid)); - return CB_BREAK; - } - - if (!check_int(get_oid_arbitrary_hex(hex_iter->expected_hexes.v[hex_iter->i], - &expected), ==, 0)) - ; /* the data is bogus and cannot be used */ - else if (!check(oideq(oid, &expected))) - test_msg("expected: %s\n got: %s\n query: %s", - oid_to_hex(&expected), oid_to_hex(oid), hex_iter->query); - - hex_iter->i += 1; - return CB_CONTINUE; -} - -LAST_ARG_MUST_BE_NULL -static void check_each(struct oidtree *ot, const char *query, ...) -{ - struct object_id oid; - struct expected_hex_iter hex_iter = { .expected_hexes = STRVEC_INIT, - .query = query }; - const char *arg; - va_list hex_args; - - va_start(hex_args, query); - while ((arg = va_arg(hex_args, const char *))) - strvec_push(&hex_iter.expected_hexes, arg); - va_end(hex_args); - - if (!check_int(get_oid_arbitrary_hex(query, &oid), ==, 0)) - return; - oidtree_each(ot, &oid, strlen(query), check_each_cb, &hex_iter); - - if (!check_int(hex_iter.i, ==, hex_iter.expected_hexes.nr)) - test_msg("error: could not find some 'object_id's for query ('%s')", query); - strvec_clear(&hex_iter.expected_hexes); -} - -static void setup(void (*f)(struct oidtree *ot)) -{ - struct oidtree ot; - - oidtree_init(&ot); - f(&ot); - oidtree_clear(&ot); -} - -static void t_contains(struct oidtree *ot) -{ - FILL_TREE(ot, "444", "1", "2", "3", "4", "5", "a", "b", "c", "d", "e"); - check_contains(ot, "44", 0); - check_contains(ot, "441", 0); - check_contains(ot, "440", 0); - check_contains(ot, "444", 1); - check_contains(ot, "4440", 1); - check_contains(ot, "4444", 0); -} - -static void t_each(struct oidtree *ot) -{ - FILL_TREE(ot, "f", "9", "8", "123", "321", "320", "a", "b", "c", "d", "e"); - check_each(ot, "12300", "123", NULL); - check_each(ot, "3211", NULL); /* should not reach callback */ - check_each(ot, "3210", "321", NULL); - check_each(ot, "32100", "321", NULL); - check_each(ot, "32", "320", "321", NULL); -} - -int cmd_main(int argc UNUSED, const char **argv UNUSED) -{ - TEST(setup(t_contains), "oidtree insert and contains works"); - TEST(setup(t_each), "oidtree each works"); - return test_done(); -} diff --git a/t/unit-tests/u-oid-array.c b/t/unit-tests/u-oid-array.c new file mode 100644 index 00000000000000..e48a433f2153b1 --- /dev/null +++ b/t/unit-tests/u-oid-array.c @@ -0,0 +1,129 @@ +#define USE_THE_REPOSITORY_VARIABLE + +#include "unit-test.h" +#include "lib-oid.h" +#include "oid-array.h" +#include "hex.h" + +static void fill_array(struct oid_array *array, const char *hexes[], size_t n) +{ + for (size_t i = 0; i < n; i++) { + struct object_id oid; + + cl_parse_any_oid(hexes[i], &oid); + oid_array_append(array, &oid); + } + cl_assert_equal_i(array->nr, n); +} + +static int add_to_oid_array(const struct object_id *oid, void *data) +{ + struct oid_array *array = data; + + oid_array_append(array, oid); + return 0; +} + +static void t_enumeration(const char **input_args, size_t input_sz, + const char **expect_args, size_t expect_sz) +{ + struct oid_array input = OID_ARRAY_INIT, expect = OID_ARRAY_INIT, + actual = OID_ARRAY_INIT; + size_t i; + + fill_array(&input, input_args, input_sz); + fill_array(&expect, expect_args, expect_sz); + + oid_array_for_each_unique(&input, add_to_oid_array, &actual); + cl_assert_equal_i(actual.nr, expect.nr); + + for (i = 0; i < actual.nr; i++) + cl_assert(oideq(&actual.oid[i], &expect.oid[i])); + + oid_array_clear(&actual); + oid_array_clear(&input); + oid_array_clear(&expect); +} + +#define TEST_ENUMERATION(input, expect) \ + t_enumeration(input, ARRAY_SIZE(input), expect, ARRAY_SIZE(expect)); + +static void t_lookup(const char **input_hexes, size_t n, const char *query_hex, + int lower_bound, int upper_bound) +{ + struct oid_array array = OID_ARRAY_INIT; + struct object_id oid_query; + int ret; + + cl_parse_any_oid(query_hex, &oid_query); + fill_array(&array, input_hexes, n); + ret = oid_array_lookup(&array, &oid_query); + + cl_assert(ret <= upper_bound); + cl_assert(ret >= lower_bound); + + oid_array_clear(&array); +} + +#define TEST_LOOKUP(input_hexes, query, lower_bound, upper_bound) \ + t_lookup(input_hexes, ARRAY_SIZE(input_hexes), query, \ + lower_bound, upper_bound); + +void test_oid_array__initialize(void) +{ + /* The hash algo is used by oid_array_lookup() internally */ + int algo = cl_setup_hash_algo(); + repo_set_hash_algo(the_repository, algo); +} + +static const char *arr_input[] = { "88", "44", "aa", "55" }; +static const char *arr_input_dup[] = { "88", "44", "aa", "55", + "88", "44", "aa", "55", + "88", "44", "aa", "55" }; +static const char *res_sorted[] = { "44", "55", "88", "aa" }; + +void test_oid_array__enumerate_unique(void) +{ + TEST_ENUMERATION(arr_input, res_sorted); +} + +void test_oid_array__enumerate_duplicate(void) +{ + TEST_ENUMERATION(arr_input_dup, res_sorted); +} + +void test_oid_array__lookup(void) +{ + TEST_LOOKUP(arr_input, "55", 1, 1); +} + +void test_oid_array__lookup_non_existent(void) +{ + TEST_LOOKUP(arr_input, "33", INT_MIN, -1); +} + +void test_oid_array__lookup_duplicates(void) +{ + TEST_LOOKUP(arr_input_dup, "55", 3, 5); +} + +void test_oid_array__lookup_non_existent_dup(void) +{ + TEST_LOOKUP(arr_input_dup, "66", INT_MIN, -1); +} + +void test_oid_array__lookup_almost_dup(void) +{ + const char *nearly_55; + + nearly_55 = cl_setup_hash_algo() == GIT_HASH_SHA1 ? + "5500000000000000000000000000000000000001" : + "5500000000000000000000000000000000000000000000000000000000000001"; + + TEST_LOOKUP(((const char *[]){ "55", nearly_55 }), "55", 0, 0); +} + +void test_oid_array__lookup_single_dup(void) +{ + TEST_LOOKUP(((const char *[]){ "55", "55" }), "55", 0, 1); +} diff --git a/t/unit-tests/u-oidmap.c b/t/unit-tests/u-oidmap.c new file mode 100644 index 00000000000000..dc805b7e3cb424 --- /dev/null +++ b/t/unit-tests/u-oidmap.c @@ -0,0 +1,136 @@ +#include "unit-test.h" +#include "lib-oid.h" +#include "oidmap.h" +#include "hash.h" +#include "hex.h" + +/* + * Elements we will put in oidmap structs are made of a key: the entry.oid + * field, which is of type struct object_id, and a value: the name field (could + * be a refname for example). + */ +struct test_entry { + struct oidmap_entry entry; + char name[FLEX_ARRAY]; +}; + +static const char *const key_val[][2] = { { "11", "one" }, + { "22", "two" }, + { "33", "three" } }; + +static struct oidmap map; + +void test_oidmap__initialize(void) +{ + oidmap_init(&map, 0); + + for (size_t i = 0; i < ARRAY_SIZE(key_val); i++){ + struct test_entry *entry; + + FLEX_ALLOC_STR(entry, name, key_val[i][1]); + cl_parse_any_oid(key_val[i][0], &entry->entry.oid); + cl_assert(oidmap_put(&map, entry) == NULL); + } +} + +void test_oidmap__cleanup(void) +{ + oidmap_free(&map, 1); +} + +void test_oidmap__replace(void) +{ + struct test_entry *entry, *prev; + + FLEX_ALLOC_STR(entry, name, "un"); + cl_parse_any_oid("11", &entry->entry.oid); + prev = oidmap_put(&map, entry); + cl_assert(prev != NULL); + cl_assert_equal_s(prev->name, "one"); + free(prev); + + FLEX_ALLOC_STR(entry, name, "deux"); + cl_parse_any_oid("22", &entry->entry.oid); + prev = oidmap_put(&map, entry); + cl_assert(prev != NULL); + cl_assert_equal_s(prev->name, "two"); + free(prev); +} + +void test_oidmap__get(void) +{ + struct test_entry *entry; + struct object_id oid; + + cl_parse_any_oid("22", &oid); + entry = oidmap_get(&map, &oid); + cl_assert(entry != NULL); + cl_assert_equal_s(entry->name, "two"); + + cl_parse_any_oid("44", &oid); + cl_assert(oidmap_get(&map, &oid) == NULL); + + cl_parse_any_oid("11", &oid); + entry = oidmap_get(&map, &oid); + cl_assert(entry != NULL); + cl_assert_equal_s(entry->name, "one"); +} + +void test_oidmap__remove(void) +{ + struct test_entry *entry; + struct object_id oid; + + cl_parse_any_oid("11", &oid); + entry = oidmap_remove(&map, &oid); + cl_assert(entry != NULL); + cl_assert_equal_s(entry->name, "one"); + cl_assert(oidmap_get(&map, &oid) == NULL); + free(entry); + + cl_parse_any_oid("22", &oid); + entry = oidmap_remove(&map, &oid); + cl_assert(entry != NULL); + cl_assert_equal_s(entry->name, "two"); + cl_assert(oidmap_get(&map, &oid) == NULL); + free(entry); + + cl_parse_any_oid("44", &oid); + cl_assert(oidmap_remove(&map, &oid) == NULL); +} + +static int key_val_contains(struct test_entry *entry, char seen[]) +{ + for (size_t i = 0; i < ARRAY_SIZE(key_val); i++) { + struct object_id oid; + + cl_parse_any_oid(key_val[i][0], &oid); + + if (oideq(&entry->entry.oid, &oid)) { + if (seen[i]) + return 2; + seen[i] = 1; + return 0; + } + } + return 1; +} + +void test_oidmap__iterate(void) +{ + struct oidmap_iter iter; + struct test_entry *entry; + char seen[ARRAY_SIZE(key_val)] = { 0 }; + int count = 0; + + oidmap_iter_init(&map, &iter); + while ((entry = oidmap_iter_next(&iter))) { + if (key_val_contains(entry, seen) != 0) { + cl_failf("Unexpected entry: name = %s, oid = %s", + entry->name, oid_to_hex(&entry->entry.oid)); + } + count++; + } + cl_assert_equal_i(count, ARRAY_SIZE(key_val)); + cl_assert_equal_i(hashmap_get_size(&map.map), ARRAY_SIZE(key_val)); +} diff --git a/t/unit-tests/u-oidtree.c b/t/unit-tests/u-oidtree.c new file mode 100644 index 00000000000000..e6eede27404842 --- /dev/null +++ b/t/unit-tests/u-oidtree.c @@ -0,0 +1,107 @@ +#include "unit-test.h" +#include "lib-oid.h" +#include "oidtree.h" +#include "hash.h" +#include "hex.h" +#include "strvec.h" + +static struct oidtree ot; + +#define FILL_TREE(tree, ...) \ + do { \ + const char *hexes[] = { __VA_ARGS__ }; \ + if (fill_tree_loc(tree, hexes, ARRAY_SIZE(hexes))) \ + return; \ + } while (0) + +static int fill_tree_loc(struct oidtree *ot, const char *hexes[], size_t n) +{ + for (size_t i = 0; i < n; i++) { + struct object_id oid; + cl_parse_any_oid(hexes[i], &oid); + oidtree_insert(ot, &oid); + } + return 0; +} + +static void check_contains(struct oidtree *ot, const char *hex, int expected) +{ + struct object_id oid; + + cl_parse_any_oid(hex, &oid); + cl_assert_equal_i(oidtree_contains(ot, &oid), expected); +} + +struct expected_hex_iter { + size_t i; + struct strvec expected_hexes; + const char *query; +}; + +static enum cb_next check_each_cb(const struct object_id *oid, void *data) +{ + struct expected_hex_iter *hex_iter = data; + struct object_id expected; + + cl_assert(hex_iter->i < hex_iter->expected_hexes.nr); + + cl_parse_any_oid(hex_iter->expected_hexes.v[hex_iter->i], + &expected); + cl_assert_equal_s(oid_to_hex(oid), oid_to_hex(&expected)); + hex_iter->i += 1; + return CB_CONTINUE; +} + +LAST_ARG_MUST_BE_NULL +static void check_each(struct oidtree *ot, const char *query, ...) +{ + struct object_id oid; + struct expected_hex_iter hex_iter = { .expected_hexes = STRVEC_INIT, + .query = query }; + const char *arg; + va_list hex_args; + + va_start(hex_args, query); + while ((arg = va_arg(hex_args, const char *))) + strvec_push(&hex_iter.expected_hexes, arg); + va_end(hex_args); + + cl_parse_any_oid(query, &oid); + oidtree_each(ot, &oid, strlen(query), check_each_cb, &hex_iter); + + if (hex_iter.i != hex_iter.expected_hexes.nr) + cl_failf("error: could not find some 'object_id's for query ('%s')", query); + + strvec_clear(&hex_iter.expected_hexes); +} + +void test_oidtree__initialize(void) +{ + oidtree_init(&ot); +} + +void test_oidtree__cleanup(void) +{ + oidtree_clear(&ot); +} + +void test_oidtree__contains(void) +{ + FILL_TREE(&ot, "444", "1", "2", "3", "4", "5", "a", "b", "c", "d", "e"); + check_contains(&ot, "44", 0); + check_contains(&ot, "441", 0); + check_contains(&ot, "440", 0); + check_contains(&ot, "444", 1); + check_contains(&ot, "4440", 1); + check_contains(&ot, "4444", 0); +} + +void test_oidtree__each(void) +{ + FILL_TREE(&ot, "f", "9", "8", "123", "321", "320", "a", "b", "c", "d", "e"); + check_each(&ot, "12300", "123", NULL); + check_each(&ot, "3211", NULL); /* should not reach callback */ + check_each(&ot, "3210", "321", NULL); + check_each(&ot, "32100", "321", NULL); + check_each(&ot, "32", "320", "321", NULL); +} diff --git a/t/unit-tests/unit-test.c b/t/unit-tests/unit-test.c index fa8818842a4247..5af645048adf4e 100644 --- a/t/unit-tests/unit-test.c +++ b/t/unit-tests/unit-test.c @@ -1,5 +1,7 @@ #include "unit-test.h" +#include "hex.h" #include "parse-options.h" +#include "strbuf.h" #include "string-list.h" #include "strvec.h" diff --git a/tempfile.c b/tempfile.c index ed88cf84314753..82dfa3d82f2ac9 100644 --- a/tempfile.c +++ b/tempfile.c @@ -42,6 +42,8 @@ * file created by its parent. */ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "abspath.h" #include "path.h" @@ -148,7 +150,7 @@ struct tempfile *create_tempfile_mode(const char *path, int mode) return NULL; } activate_tempfile(tempfile); - if (adjust_shared_perm(tempfile->filename.buf)) { + if (adjust_shared_perm(the_repository, tempfile->filename.buf)) { int save_errno = errno; error("cannot fix permission bits on %s", tempfile->filename.buf); delete_tempfile(&tempfile); diff --git a/tmp-objdir.c b/tmp-objdir.c index 0ea078a5c5f4eb..31d16a4c2c576e 100644 --- a/tmp-objdir.c +++ b/tmp-objdir.c @@ -207,10 +207,12 @@ static int read_dir_paths(struct string_list *out, const char *path) return 0; } -static int migrate_paths(struct strbuf *src, struct strbuf *dst, +static int migrate_paths(struct tmp_objdir *t, + struct strbuf *src, struct strbuf *dst, enum finalize_object_file_flags flags); -static int migrate_one(struct strbuf *src, struct strbuf *dst, +static int migrate_one(struct tmp_objdir *t, + struct strbuf *src, struct strbuf *dst, enum finalize_object_file_flags flags) { struct stat st; @@ -219,11 +221,11 @@ static int migrate_one(struct strbuf *src, struct strbuf *dst, return -1; if (S_ISDIR(st.st_mode)) { if (!mkdir(dst->buf, 0777)) { - if (adjust_shared_perm(dst->buf)) + if (adjust_shared_perm(t->repo, dst->buf)) return -1; } else if (errno != EEXIST) return -1; - return migrate_paths(src, dst, flags); + return migrate_paths(t, src, dst, flags); } return finalize_object_file_flags(src->buf, dst->buf, flags); } @@ -233,7 +235,8 @@ static int is_loose_object_shard(const char *name) return strlen(name) == 2 && isxdigit(name[0]) && isxdigit(name[1]); } -static int migrate_paths(struct strbuf *src, struct strbuf *dst, +static int migrate_paths(struct tmp_objdir *t, + struct strbuf *src, struct strbuf *dst, enum finalize_object_file_flags flags) { size_t src_len = src->len, dst_len = dst->len; @@ -255,7 +258,7 @@ static int migrate_paths(struct strbuf *src, struct strbuf *dst, if (is_loose_object_shard(name)) flags_copy |= FOF_SKIP_COLLISION_CHECK; - ret |= migrate_one(src, dst, flags_copy); + ret |= migrate_one(t, src, dst, flags_copy); strbuf_setlen(src, src_len); strbuf_setlen(dst, dst_len); @@ -283,7 +286,7 @@ int tmp_objdir_migrate(struct tmp_objdir *t) strbuf_addbuf(&src, &t->path); strbuf_addstr(&dst, repo_get_object_directory(t->repo)); - ret = migrate_paths(&src, &dst, 0); + ret = migrate_paths(t, &src, &dst, 0); strbuf_release(&src); strbuf_release(&dst); diff --git a/trace2.h b/trace2.h index 901f39253a6593..e4f23784e4620f 100644 --- a/trace2.h +++ b/trace2.h @@ -31,7 +31,7 @@ * * For more info about: trace2 targets, conventions for public functions and * macros, trace2 target formats and examples on trace2 API usage refer to - * Documentation/technical/api-trace2.txt + * Documentation/technical/api-trace2.adoc * */ diff --git a/trace2/tr2_sysenv.c b/trace2/tr2_sysenv.c index 01379c5cad8438..4abc218514fdbc 100644 --- a/trace2/tr2_sysenv.c +++ b/trace2/tr2_sysenv.c @@ -7,7 +7,7 @@ /* * Each entry represents a trace2 setting. - * See Documentation/technical/api-trace2.txt + * See Documentation/technical/api-trace2.adoc */ struct tr2_sysenv_entry { const char *env_var_name; diff --git a/transport.h b/transport.h index 44100fa9b7fdd6..892f19454a75d6 100644 --- a/transport.h +++ b/transport.h @@ -168,7 +168,7 @@ struct transport *transport_get(struct remote *, const char *); * Check whether a transport is allowed by the environment. * * Type should generally be the URL scheme, as described in - * Documentation/git.txt + * Documentation/git.adoc * * from_user specifies if the transport was given by the user. If unknown pass * a -1 to read from the environment to determine if the transport was given by diff --git a/unpack-trees.c b/unpack-trees.c index aff6560506f08b..222b4518b16bc1 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -2906,7 +2906,7 @@ int threeway_merge(const struct cache_entry * const *stages, * The rule is to "carry forward" what is in the index without losing * information across a "fast-forward", favoring a successful merge * over a merge failure when it makes sense. For details of the - * "carry forward" rule, please see . + * "carry forward" rule, please see . * */ int twoway_merge(const struct cache_entry * const *src, diff --git a/upload-pack.c b/upload-pack.c index 728b2477fcc71f..7498b45e2e1e21 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -32,6 +32,7 @@ #include "write-or-die.h" #include "json-writer.h" #include "strmap.h" +#include "promisor-remote.h" /* Remember to update object flag allocation in object.h */ #define THEY_HAVE (1u << 11) @@ -319,6 +320,8 @@ static void create_pack_file(struct upload_pack_data *pack_data, strvec_push(&pack_objects.args, "--delta-base-offset"); if (pack_data->use_include_tag) strvec_push(&pack_objects.args, "--include-tag"); + if (repo_has_accepted_promisor_remote(the_repository)) + strvec_push(&pack_objects.args, "--missing=allow-promisor"); if (pack_data->filter_options.choice) { const char *spec = expand_list_objects_filter_spec(&pack_data->filter_options); diff --git a/worktree.c b/worktree.c index d4a68c9c235677..6449b6798db35d 100644 --- a/worktree.c +++ b/worktree.c @@ -59,8 +59,9 @@ static void add_head_info(struct worktree *wt) static int is_current_worktree(struct worktree *wt) { char *git_dir = absolute_pathdup(repo_get_git_dir(the_repository)); - const char *wt_git_dir = get_worktree_git_dir(wt); + char *wt_git_dir = get_worktree_git_dir(wt); int is_current = !fspathcmp(git_dir, absolute_path(wt_git_dir)); + free(wt_git_dir); free(git_dir); return is_current; } @@ -127,7 +128,7 @@ struct worktree *get_linked_worktree(const char *id, if (!id) die("Missing linked worktree name"); - strbuf_git_common_path(&path, the_repository, "worktrees/%s/gitdir", id); + repo_common_path_append(the_repository, &path, "worktrees/%s/gitdir", id); if (strbuf_read_file(&worktree_path, path.buf, 0) <= 0) /* invalid gitdir file */ goto done; @@ -198,14 +199,14 @@ struct worktree **get_worktrees(void) return get_worktrees_internal(0); } -const char *get_worktree_git_dir(const struct worktree *wt) +char *get_worktree_git_dir(const struct worktree *wt) { if (!wt) - return repo_get_git_dir(the_repository); + return xstrdup(repo_get_git_dir(the_repository)); else if (!wt->id) - return repo_get_common_dir(the_repository); + return xstrdup(repo_get_common_dir(the_repository)); else - return git_common_path("worktrees/%s", wt->id); + return repo_common_path(the_repository, "worktrees/%s", wt->id); } static struct worktree *find_worktree_by_suffix(struct worktree **list, @@ -336,6 +337,7 @@ int validate_worktree(const struct worktree *wt, struct strbuf *errmsg, { struct strbuf wt_path = STRBUF_INIT; struct strbuf realpath = STRBUF_INIT; + struct strbuf buf = STRBUF_INIT; char *path = NULL; int err, ret = -1; @@ -365,7 +367,7 @@ int validate_worktree(const struct worktree *wt, struct strbuf *errmsg, if (!is_absolute_path(wt->path)) { strbuf_addf_gently(errmsg, _("'%s' file does not contain absolute path to the working tree location"), - git_common_path("worktrees/%s/gitdir", wt->id)); + repo_common_path_replace(the_repository, &buf, "worktrees/%s/gitdir", wt->id)); goto done; } @@ -387,14 +389,16 @@ int validate_worktree(const struct worktree *wt, struct strbuf *errmsg, goto done; } - strbuf_realpath(&realpath, git_common_path("worktrees/%s", wt->id), 1); + strbuf_realpath(&realpath, repo_common_path_replace(the_repository, &buf, "worktrees/%s", wt->id), 1); ret = fspathcmp(path, realpath.buf); if (ret) strbuf_addf_gently(errmsg, _("'%s' does not point back to '%s'"), - wt->path, git_common_path("worktrees/%s", wt->id)); + wt->path, repo_common_path_replace(the_repository, &buf, + "worktrees/%s", wt->id)); done: free(path); + strbuf_release(&buf); strbuf_release(&wt_path); strbuf_release(&realpath); return ret; @@ -406,11 +410,13 @@ void update_worktree_location(struct worktree *wt, const char *path_, struct strbuf path = STRBUF_INIT; struct strbuf dotgit = STRBUF_INIT; struct strbuf gitdir = STRBUF_INIT; + char *wt_gitdir; if (is_main_worktree(wt)) BUG("can't relocate main worktree"); - strbuf_realpath(&gitdir, git_common_path("worktrees/%s/gitdir", wt->id), 1); + wt_gitdir = repo_common_path(the_repository, "worktrees/%s/gitdir", wt->id); + strbuf_realpath(&gitdir, wt_gitdir, 1); strbuf_realpath(&path, path_, 1); strbuf_addf(&dotgit, "%s/.git", path.buf); if (fspathcmp(wt->path, path.buf)) { @@ -422,6 +428,7 @@ void update_worktree_location(struct worktree *wt, const char *path_, strbuf_release(&path); strbuf_release(&dotgit); strbuf_release(&gitdir); + free(wt_gitdir); } int is_worktree_being_rebased(const struct worktree *wt, @@ -510,7 +517,8 @@ int submodule_uses_worktrees(const char *path) int ret = 0; struct repository_format format = REPOSITORY_FORMAT_INIT; - submodule_gitdir = git_pathdup_submodule(path, "%s", ""); + submodule_gitdir = repo_submodule_path(the_repository, + path, "%s", ""); if (!submodule_gitdir) return 0; @@ -606,6 +614,7 @@ static void repair_gitfile(struct worktree *wt, struct strbuf backlink = STRBUF_INIT; char *dotgit_contents = NULL; const char *repair = NULL; + char *path = NULL; int err; /* missing worktree can't be repaired */ @@ -617,7 +626,8 @@ static void repair_gitfile(struct worktree *wt, goto done; } - strbuf_realpath(&repo, git_common_path("worktrees/%s", wt->id), 1); + path = repo_common_path(the_repository, "worktrees/%s", wt->id); + strbuf_realpath(&repo, path, 1); strbuf_addf(&dotgit, "%s/.git", wt->path); strbuf_addf(&gitdir, "%s/gitdir", repo.buf); dotgit_contents = xstrdup_or_null(read_gitfile_gently(dotgit.buf, &err)); @@ -647,6 +657,7 @@ static void repair_gitfile(struct worktree *wt, done: free(dotgit_contents); + free(path); strbuf_release(&repo); strbuf_release(&dotgit); strbuf_release(&gitdir); @@ -678,11 +689,13 @@ void repair_worktree_after_gitdir_move(struct worktree *wt, const char *old_path struct strbuf gitdir = STRBUF_INIT; struct strbuf dotgit = STRBUF_INIT; int is_relative_path; + char *path = NULL; if (is_main_worktree(wt)) goto done; - strbuf_realpath(&gitdir, git_common_path("worktrees/%s/gitdir", wt->id), 1); + path = repo_common_path(the_repository, "worktrees/%s/gitdir", wt->id); + strbuf_realpath(&gitdir, path, 1); if (strbuf_read_file(&dotgit, gitdir.buf, 0) < 0) goto done; @@ -701,6 +714,7 @@ void repair_worktree_after_gitdir_move(struct worktree *wt, const char *old_path done: strbuf_release(&gitdir); strbuf_release(&dotgit); + free(path); } void repair_worktrees_after_gitdir_move(const char *old_path) @@ -754,8 +768,7 @@ static ssize_t infer_backlink(const char *gitfile, struct strbuf *inferred) id++; /* advance past '/' to point at */ if (!*id) goto error; - strbuf_reset(inferred); - strbuf_git_common_path(inferred, the_repository, "worktrees/%s", id); + repo_common_path_replace(the_repository, inferred, "worktrees/%s", id); if (!is_directory(inferred->buf)) goto error; @@ -893,7 +906,11 @@ int should_prune_worktree(const char *id, struct strbuf *reason, char **wtpath, ssize_t read_result; *wtpath = NULL; - strbuf_realpath(&repo, git_common_path("worktrees/%s", id), 1); + + path = repo_common_path(the_repository, "worktrees/%s", id); + strbuf_realpath(&repo, path, 1); + FREE_AND_NULL(path); + strbuf_addf(&gitdir, "%s/gitdir", repo.buf); if (!is_directory(repo.buf)) { strbuf_addstr(reason, _("not a valid directory")); diff --git a/worktree.h b/worktree.h index 38145df80f4107..16368588a0d46b 100644 --- a/worktree.h +++ b/worktree.h @@ -39,7 +39,7 @@ int submodule_uses_worktrees(const char *path); * Return git dir of the worktree. Note that the path may be relative. * If wt is NULL, git dir of current worktree is returned. */ -const char *get_worktree_git_dir(const struct worktree *wt); +char *get_worktree_git_dir(const struct worktree *wt); /* * Search for the worktree identified unambiguously by `arg` -- typically diff --git a/wt-status.c b/wt-status.c index 9609ba260fe804..50bace8378bd15 100644 --- a/wt-status.c +++ b/wt-status.c @@ -1296,7 +1296,8 @@ static void show_am_in_progress(struct wt_status *s, static char *read_line_from_git_path(const char *filename) { struct strbuf buf = STRBUF_INIT; - FILE *fp = fopen_or_warn(git_path("%s", filename), "r"); + FILE *fp = fopen_or_warn(repo_git_path_append(the_repository, &buf, + "%s", filename), "r"); if (!fp) { strbuf_release(&buf); @@ -1390,27 +1391,33 @@ static void abbrev_oid_in_line(struct strbuf *line) static int read_rebase_todolist(const char *fname, struct string_list *lines) { - struct strbuf line = STRBUF_INIT; - FILE *f = fopen(git_path("%s", fname), "r"); + struct strbuf buf = STRBUF_INIT; + FILE *f = fopen(repo_git_path_append(the_repository, &buf, "%s", fname), "r"); + int ret; if (!f) { - if (errno == ENOENT) - return -1; + if (errno == ENOENT) { + ret = -1; + goto out; + } die_errno("Could not open file %s for reading", - git_path("%s", fname)); + repo_git_path_replace(the_repository, &buf, "%s", fname)); } - while (!strbuf_getline_lf(&line, f)) { - if (starts_with(line.buf, comment_line_str)) + while (!strbuf_getline_lf(&buf, f)) { + if (starts_with(buf.buf, comment_line_str)) continue; - strbuf_trim(&line); - if (!line.len) + strbuf_trim(&buf); + if (!buf.len) continue; - abbrev_oid_in_line(&line); - string_list_append(lines, line.buf); + abbrev_oid_in_line(&buf); + string_list_append(lines, buf.buf); } fclose(f); - strbuf_release(&line); - return 0; + + ret = 0; +out: + strbuf_release(&buf); + return ret; } static void show_rebase_information(struct wt_status *s, @@ -1441,9 +1448,12 @@ static void show_rebase_information(struct wt_status *s, i < have_done.nr; i++) status_printf_ln(s, color, " %s", have_done.items[i].string); - if (have_done.nr > nr_lines_to_show && s->hints) + if (have_done.nr > nr_lines_to_show && s->hints) { + char *path = repo_git_path(the_repository, "rebase-merge/done"); status_printf_ln(s, color, - _(" (see more in file %s)"), git_path("rebase-merge/done")); + _(" (see more in file %s)"), path); + free(path); + } } if (yet_to_do.nr == 0) diff --git a/xdiff/xdiff.h b/xdiff/xdiff.h index bb56b23f34c96c..2cecde5afe5da1 100644 --- a/xdiff/xdiff.h +++ b/xdiff/xdiff.h @@ -85,7 +85,7 @@ typedef struct s_xpparam { regex_t **ignore_regex; size_t ignore_regex_nr; - /* See Documentation/diff-options.txt. */ + /* See Documentation/diff-options.adoc. */ char **anchors; size_t anchors_nr; } xpparam_t; diff --git a/xdiff/xpatience.c b/xdiff/xpatience.c index 82f663004ec2ef..77dc411d1937ab 100644 --- a/xdiff/xpatience.c +++ b/xdiff/xpatience.c @@ -64,7 +64,7 @@ struct hashmap { /* * If 1, this entry can serve as an anchor. See - * Documentation/diff-options.txt for more information. + * Documentation/diff-options.adoc for more information. */ unsigned anchor : 1; } *entries, *first, *last;