diff --git a/.cirrus.yml b/.cirrus.yml index e114ffee1a7fb2..fef04a38402fee 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -1,15 +1,17 @@ env: CIRRUS_CLONE_DEPTH: 1 -freebsd_12_task: +freebsd_task: env: GIT_PROVE_OPTS: "--timer --jobs 10" GIT_TEST_OPTS: "--no-chain-lint --no-bin-wrappers" - MAKEFLAGS: "-j4" + GIT_SKIP_TESTS: t7815.12 + MAKEFLAGS: -j4 DEFAULT_TEST_TARGET: prove + DEFAULT_UNIT_TEST_TARGET: unit-tests-prove DEVELOPER: 1 freebsd_instance: - image_family: freebsd-12-2 + image_family: freebsd-14-3 memory: 2G install_script: pkg install -y gettext gmake perl5 @@ -19,4 +21,4 @@ freebsd_12_task: build_script: - su git -c gmake test_script: - - su git -c 'gmake test' + - su git -c 'gmake test unit-tests' diff --git a/.clang-format b/.clang-format index c592dda681fecf..86b4fe33e5cd98 100644 --- a/.clang-format +++ b/.clang-format @@ -12,7 +12,15 @@ UseTab: Always TabWidth: 8 IndentWidth: 8 ContinuationIndentWidth: 8 -ColumnLimit: 80 + +# While we do want to enforce a character limit of 80 characters, we often +# allow lines to overflow that limit to prioritize readability. Setting a +# character limit here with penalties has been finicky and creates too many +# false positives. +# +# NEEDSWORK: It would be nice if we can find optimal settings to ensure we +# can re-enable the limit here. +ColumnLimit: 0 # C Language specifics Language: Cpp @@ -32,6 +40,9 @@ AlignConsecutiveAssignments: false # double b = 3.14; AlignConsecutiveDeclarations: false +# Align consecutive macro definitions. +AlignConsecutiveMacros: true + # Align escaped newlines as far left as possible # #define A \ # int aaaa; \ @@ -72,6 +83,10 @@ AlwaysBreakAfterReturnType: None BinPackArguments: true BinPackParameters: true +# Add no space around the bit field +# unsigned bf:2; +BitFieldColonSpacing: None + # Attach braces to surrounding context except break before braces on function # definitions. # void foo() @@ -83,9 +98,9 @@ BinPackParameters: true BreakBeforeBraces: Linux # Break after operators -# int valuve = aaaaaaaaaaaaa + -# bbbbbb - -# ccccccccccc; +# int value = aaaaaaaaaaaaa + +# bbbbbb - +# ccccccccccc; BreakBeforeBinaryOperators: None BreakBeforeTernaryOperators: false @@ -96,6 +111,14 @@ BreakStringLiterals: false # Switch statement body is always indented one level more than case labels. IndentCaseLabels: false +# Indents directives before the hash. Each level uses a single space for +# indentation. +# #if FOO +# # include +# #endif +IndentPPDirectives: AfterHash +PPIndentWidth: 1 + # Don't indent a function definition or declaration if it is wrapped after the # type IndentWrappedFunctionNames: false @@ -108,22 +131,37 @@ PointerAlignment: Right # x = (int32)y; not x = (int32) y; SpaceAfterCStyleCast: false +# No space is inserted after the logical not operator +SpaceAfterLogicalNot: false + # Insert spaces before and after assignment operators # int a = 5; not int a=5; # a += 42; a+=42; SpaceBeforeAssignmentOperators: true +# Spaces will be removed before case colon. +# case 1: break; not case 1 : break; +SpaceBeforeCaseColon: false + # Put a space before opening parentheses only after control statement keywords. # void f() { # if (true) { # f(); # } # } -SpaceBeforeParens: ControlStatements +SpaceBeforeParens: ControlStatementsExceptControlMacros # Don't insert spaces inside empty '()' SpaceInEmptyParentheses: false +# No space before first '[' in arrays +# int a[5][5]; not int a [5][5]; +SpaceBeforeSquareBrackets: false + +# No space will be inserted into {} +# while (true) {} not while (true) { } +SpaceInEmptyBlock: false + # The number of spaces before trailing line comments (// - comments). # This does not affect trailing block comments (/* - comments). SpacesBeforeTrailingComments: 1 @@ -149,20 +187,30 @@ Cpp11BracedListStyle: false # A list of macros that should be interpreted as foreach loops instead of as # function calls. Taken from: -# git grep -h '^#define [^[:space:]]*for_each[^[:space:]]*(' \ -# | sed "s,^#define \([^[:space:]]*for_each[^[:space:]]*\)(.*$, - '\1'," \ -# | sort | uniq +# git grep -h '^#define [^[:space:]]*for_\?each[^[:space:]]*(' | +# sed "s/^#define / - '/; s/(.*$/'/" | sort | uniq ForEachMacros: - - 'for_each_abbrev' - 'for_each_builtin' - 'for_each_string_list_item' - 'for_each_ut' - 'for_each_wanted_builtin' + - 'hashmap_for_each_entry' + - 'hashmap_for_each_entry_from' + - 'kh_foreach' + - 'kh_foreach_value' - 'list_for_each' - 'list_for_each_dir' - 'list_for_each_prev' - 'list_for_each_prev_safe' - 'list_for_each_safe' + - 'strintmap_for_each_entry' + - 'strmap_for_each_entry' + - 'strset_for_each_entry' + +# A list of macros that should be interpreted as conditionals instead of as +# function calls. +IfMacros: + - 'if_test' # The maximum number of consecutive empty lines to keep. MaxEmptyLinesToKeep: 1 @@ -170,15 +218,11 @@ MaxEmptyLinesToKeep: 1 # No empty line at the start of a block. KeepEmptyLinesAtTheStartOfBlocks: false -# Penalties -# This decides what order things should be done if a line is too long -PenaltyBreakAssignment: 10 -PenaltyBreakBeforeFirstCallParameter: 30 -PenaltyBreakComment: 10 -PenaltyBreakFirstLessLess: 0 -PenaltyBreakString: 10 -PenaltyExcessCharacter: 100 -PenaltyReturnTypeOnItsOwnLine: 60 - # Don't sort #include's SortIncludes: false + +# Remove optional braces of control statements (if, else, for, and while) +# according to the LLVM coding style. This avoids braces on simple +# single-statement bodies of statements but keeps braces if one side of +# if/else if/.../else cascade has multi-statement body. +RemoveBracesLLVM: true diff --git a/.editorconfig b/.editorconfig index f9d819623d8321..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}] +[{*.{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 b0044cf272fec9..700743c3f5ef99 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,18 +1,19 @@ -* whitespace=!indent,trail,space -*.[ch] whitespace=indent,trail,space diff=cpp -*.sh whitespace=indent,trail,space eol=lf -*.perl eol=lf diff=perl -*.pl eof=lf diff=perl -*.pm eol=lf diff=perl -*.py eol=lf diff=python -*.bat eol=crlf +* whitespace=trail,space +*.[ch] whitespace=indent,trail,space,incomplete diff=cpp +*.sh whitespace=indent,trail,space,incomplete text eol=lf +*.perl text eol=lf diff=perl +*.pl text eof=lf diff=perl +*.pm text eol=lf diff=perl +*.py text eol=lf diff=python +*.bat text eol=crlf CODE_OF_CONDUCT.md -whitespace -/Documentation/**/*.txt eol=lf -/command-list.txt eol=lf -/GIT-VERSION-GEN eol=lf -/mergetools/* eol=lf -/t/oid-info/* 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/**/*.adoc text eol=lf whitespace=trail,space,incomplete +/command-list.txt text eol=lf +/GIT-VERSION-GEN text eol=lf +/mergetools/* text eol=lf +/t/oid-info/* text eol=lf +/Documentation/git-merge.adoc conflict-marker-size=32 +/Documentation/git-merge-file.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/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 952c7c3a2aa11e..37654cdfd7abcf 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -4,4 +4,7 @@ a mailing list (git@vger.kernel.org) for code submissions, code reviews, and bug reports. Nevertheless, you can use GitGitGadget (https://gitgitgadget.github.io/) to conveniently send your Pull Requests commits to our mailing list. +For a single-commit pull request, please *leave the pull request description +empty*: your commit message itself should describe your changes. + Please read the "guidelines for contributing" linked above! diff --git a/.github/workflows/check-style.yml b/.github/workflows/check-style.yml new file mode 100644 index 00000000000000..19a145d4ad0c5a --- /dev/null +++ b/.github/workflows/check-style.yml @@ -0,0 +1,34 @@ +name: check-style + +# Get the repository with all commits to ensure that we can analyze +# all of the commits contributed via the Pull Request. + +on: + pull_request: + types: [opened, synchronize] + +# Avoid unnecessary builds. Unlike the main CI jobs, these are not +# ci-configurable (but could be). +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + check-style: + env: + CC: clang + jobname: ClangFormat + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + with: + fetch-depth: 0 + + - run: ci/install-dependencies.sh + + - name: git clang-format + continue-on-error: true + id: check_out + run: | + ./ci/run-style-check.sh \ + "${{github.event.pull_request.base.sha}}" diff --git a/.github/workflows/check-whitespace.yml b/.github/workflows/check-whitespace.yml index ad3466ad16e36c..928fd4cfe2456d 100644 --- a/.github/workflows/check-whitespace.yml +++ b/.github/workflows/check-whitespace.yml @@ -9,42 +9,24 @@ on: pull_request: types: [opened, synchronize] +# Avoid unnecessary builds. Unlike the main CI jobs, these are not +# ci-configurable (but could be). +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: check-whitespace: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v5 with: fetch-depth: 0 - name: git log --check id: check_out run: | - log= - commit= - while read dash etc - do - case "${dash}" in - "---") - commit="${etc}" - ;; - "") - ;; - *) - if test -n "${commit}" - then - log="${log}\n${commit}" - echo "" - echo "--- ${commit}" - fi - commit= - log="${log}\n${dash} ${etc}" - echo "${dash} ${etc}" - ;; - esac - done <<< $(git log --check --pretty=format:"---% h% s" ${{github.event.pull_request.base.sha}}..) - - if test -n "${log}" - then - exit 2 - fi + ./ci/check-whitespace.sh \ + "${{github.event.pull_request.base.sha}}" \ + "$GITHUB_STEP_SUMMARY" \ + "https://github.com/${{github.repository}}" diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml new file mode 100644 index 00000000000000..cfa17d394a7dbc --- /dev/null +++ b/.github/workflows/coverity.yml @@ -0,0 +1,167 @@ +name: Coverity + +# This GitHub workflow automates submitting builds to Coverity Scan. To enable it, +# set the repository variable `ENABLE_COVERITY_SCAN_FOR_BRANCHES` (for details, see +# https://docs.github.com/en/actions/learn-github-actions/variables) to a JSON +# string array containing the names of the branches for which the workflow should be +# run, e.g. `["main", "next"]`. +# +# In addition, two repository secrets must be set (for details how to add secrets, see +# https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions): +# `COVERITY_SCAN_EMAIL` and `COVERITY_SCAN_TOKEN`. The former specifies the +# email to which the Coverity reports should be sent and the latter can be +# obtained from the Project Settings tab of the Coverity project). +# +# The workflow runs on `ubuntu-latest` by default. This can be overridden by setting +# the repository variable `ENABLE_COVERITY_SCAN_ON_OS` to a JSON string array specifying +# the operating systems, e.g. `["ubuntu-latest", "windows-latest"]`. +# +# By default, the builds are submitted to the Coverity project `git`. To override this, +# set the repository variable `COVERITY_PROJECT`. + +on: + push: + +defaults: + run: + shell: bash + +jobs: + coverity: + if: contains(fromJSON(vars.ENABLE_COVERITY_SCAN_FOR_BRANCHES || '[""]'), github.ref_name) + strategy: + matrix: + os: ${{ fromJSON(vars.ENABLE_COVERITY_SCAN_ON_OS || '["ubuntu-latest"]') }} + runs-on: ${{ matrix.os }} + env: + COVERITY_PROJECT: ${{ vars.COVERITY_PROJECT || 'git' }} + COVERITY_LANGUAGE: cxx + COVERITY_PLATFORM: overridden-below + steps: + - uses: actions/checkout@v5 + - name: install minimal Git for Windows SDK + if: contains(matrix.os, 'windows') + uses: git-for-windows/setup-git-for-windows-sdk@v1 + - run: ci/install-dependencies.sh + if: contains(matrix.os, 'ubuntu') || contains(matrix.os, 'macos') + env: + CI_JOB_IMAGE: ${{ matrix.os }} + + # The Coverity site says the tool is usually updated twice yearly, so the + # MD5 of download can be used to determine whether there's been an update. + - name: get the Coverity Build Tool hash + id: lookup + run: | + case "${{ matrix.os }}" in + *windows*) + COVERITY_PLATFORM=win64 + COVERITY_TOOL_FILENAME=cov-analysis.zip + MAKEFLAGS=-j$(nproc) + ;; + *macos*) + COVERITY_PLATFORM=macOSX + COVERITY_TOOL_FILENAME=cov-analysis.dmg + MAKEFLAGS=-j$(sysctl -n hw.physicalcpu) + ;; + *ubuntu*) + COVERITY_PLATFORM=linux64 + COVERITY_TOOL_FILENAME=cov-analysis.tgz + MAKEFLAGS=-j$(nproc) + ;; + *) + echo '::error::unhandled OS ${{ matrix.os }}' >&2 + exit 1 + ;; + esac + echo "COVERITY_PLATFORM=$COVERITY_PLATFORM" >>$GITHUB_ENV + echo "COVERITY_TOOL_FILENAME=$COVERITY_TOOL_FILENAME" >>$GITHUB_ENV + echo "MAKEFLAGS=$MAKEFLAGS" >>$GITHUB_ENV + MD5=$(curl https://scan.coverity.com/download/$COVERITY_LANGUAGE/$COVERITY_PLATFORM \ + --fail \ + --form token='${{ secrets.COVERITY_SCAN_TOKEN }}' \ + --form project="$COVERITY_PROJECT" \ + --form md5=1) + case $? in + 0) ;; # okay + 22) # 40x, i.e. access denied + echo "::error::incorrect token or project?" >&2 + exit 1 + ;; + *) # other error + echo "::error::Failed to retrieve MD5" >&2 + exit 1 + ;; + esac + echo "hash=$MD5" >>$GITHUB_OUTPUT + + # Try to cache the tool to avoid downloading 1GB+ on every run. + # A cache miss will add ~30s to create, but a cache hit will save minutes. + - name: restore the Coverity Build Tool + id: cache + uses: actions/cache/restore@v4 + with: + path: ${{ runner.temp }}/cov-analysis + key: cov-build-${{ env.COVERITY_LANGUAGE }}-${{ env.COVERITY_PLATFORM }}-${{ steps.lookup.outputs.hash }} + - name: download the Coverity Build Tool (${{ env.COVERITY_LANGUAGE }} / ${{ env.COVERITY_PLATFORM}}) + if: steps.cache.outputs.cache-hit != 'true' + run: | + curl https://scan.coverity.com/download/$COVERITY_LANGUAGE/$COVERITY_PLATFORM \ + --fail --no-progress-meter \ + --output $RUNNER_TEMP/$COVERITY_TOOL_FILENAME \ + --form token='${{ secrets.COVERITY_SCAN_TOKEN }}' \ + --form project="$COVERITY_PROJECT" + - name: extract the Coverity Build Tool + if: steps.cache.outputs.cache-hit != 'true' + run: | + case "$COVERITY_TOOL_FILENAME" in + *.tgz) + mkdir $RUNNER_TEMP/cov-analysis && + tar -xzf $RUNNER_TEMP/$COVERITY_TOOL_FILENAME --strip 1 -C $RUNNER_TEMP/cov-analysis + ;; + *.dmg) + cd $RUNNER_TEMP && + attach="$(hdiutil attach $COVERITY_TOOL_FILENAME)" && + volume="$(echo "$attach" | cut -f 3 | grep /Volumes/)" && + mkdir cov-analysis && + cd cov-analysis && + sh "$volume"/cov-analysis-macosx-*.sh && + ls -l && + hdiutil detach "$volume" + ;; + *.zip) + cd $RUNNER_TEMP && + mkdir cov-analysis-tmp && + unzip -d cov-analysis-tmp $COVERITY_TOOL_FILENAME && + mv cov-analysis-tmp/* cov-analysis + ;; + *) + echo "::error::unhandled archive type: $COVERITY_TOOL_FILENAME" >&2 + exit 1 + ;; + esac + - name: cache the Coverity Build Tool + if: steps.cache.outputs.cache-hit != 'true' + uses: actions/cache/save@v4 + with: + path: ${{ runner.temp }}/cov-analysis + key: cov-build-${{ env.COVERITY_LANGUAGE }}-${{ env.COVERITY_PLATFORM }}-${{ steps.lookup.outputs.hash }} + - name: build with cov-build + run: | + export PATH="$PATH:$RUNNER_TEMP/cov-analysis/bin" && + cov-configure --gcc && + if ! cov-build --dir cov-int make + then + cat cov-int/build-log.txt + exit 1 + fi + - name: package the build + run: tar -czvf cov-int.tgz cov-int + - name: submit the build to Coverity Scan + run: | + curl \ + --fail \ + --form token='${{ secrets.COVERITY_SCAN_TOKEN }}' \ + --form email='${{ secrets.COVERITY_SCAN_EMAIL }}' \ + --form file=@cov-int.tgz \ + --form version='${{ github.sha }}' \ + "https://scan.coverity.com/builds?project=$COVERITY_PROJECT" diff --git a/.github/workflows/l10n.yml b/.github/workflows/l10n.yml index 27f72f0ff34482..95e55134bdbed4 100644 --- a/.github/workflows/l10n.yml +++ b/.github/workflows/l10n.yml @@ -2,6 +2,12 @@ name: git-l10n on: [push, pull_request_target] +# Avoid unnecessary builds. Unlike the main CI jobs, these are not +# ci-configurable (but could be). +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: git-po-helper: if: >- @@ -23,8 +29,8 @@ jobs: base=${{ github.event.before }} head=${{ github.event.after }} fi - echo "::set-output name=base::$base" - echo "::set-output name=head::$head" + echo base=$base >>$GITHUB_OUTPUT + echo head=$head >>$GITHUB_OUTPUT - name: Run partial clone run: | git -c init.defaultBranch=master init --bare . @@ -57,9 +63,10 @@ jobs: origin \ ${{ github.ref }} \ $args - - uses: actions/setup-go@v2 + - uses: actions/setup-go@v6 with: go-version: '>=1.16' + cache: false - name: Install git-po-helper run: go install github.com/git-l10n/git-po-helper@main - name: Install other dependencies @@ -85,14 +92,13 @@ jobs: cat git-po-helper.out exit $exit_code - name: Create comment in pull request for report - uses: mshick/add-pr-comment@v1 + uses: mshick/add-pr-comment@v2 if: >- always() && github.event_name == 'pull_request_target' && env.COMMENT_BODY != '' with: repo-token: ${{ secrets.GITHUB_TOKEN }} - repo-token-user-login: 'github-actions[bot]' message: > ${{ steps.check-commits.outcome == 'failure' && 'Errors and warnings' || 'Warnings' }} found by [git-po-helper](https://github.com/git-l10n/git-po-helper#readme) in workflow diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c35200defb9357..f2e93f54611b62 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,12 +5,27 @@ on: [push, pull_request] env: DEVELOPER: 1 +# If more than one workflow run is triggered for the very same commit hash +# (which happens when multiple branches pointing to the same commit), only +# the first one is allowed to run, the second will be kept in the "queued" +# state. This allows a successful completion of the first run to be reused +# in the second run via the `skip-if-redundant` logic in the `config` job. +# +# The only caveat is that if a workflow run is triggered for the same commit +# hash that another run is already being held, that latter run will be +# canceled. For more details about the `concurrency` attribute, see: +# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#concurrency +concurrency: + group: ${{ github.sha }} + jobs: ci-config: name: config + if: vars.CI_BRANCHES == '' || contains(vars.CI_BRANCHES, github.ref_name) runs-on: ubuntu-latest outputs: enabled: ${{ steps.check-ref.outputs.enabled }}${{ steps.skip-if-redundant.outputs.enabled }} + skip_concurrent: ${{ steps.check-ref.outputs.skip_concurrent }} steps: - name: try to clone ci-config branch run: | @@ -29,22 +44,33 @@ jobs: name: check whether CI is enabled for ref run: | enabled=yes - if test -x config-repo/ci/config/allow-ref && - ! config-repo/ci/config/allow-ref '${{ github.ref }}' + if test -x config-repo/ci/config/allow-ref + then + echo "::warning::ci/config/allow-ref is deprecated; use CI_BRANCHES instead" + if ! config-repo/ci/config/allow-ref '${{ github.ref }}' + then + enabled=no + fi + fi + + skip_concurrent=yes + if test -x config-repo/ci/config/skip-concurrent && + ! config-repo/ci/config/skip-concurrent '${{ github.ref }}' then - enabled=no + skip_concurrent=no fi - echo "::set-output name=enabled::$enabled" + echo "enabled=$enabled" >>$GITHUB_OUTPUT + echo "skip_concurrent=$skip_concurrent" >>$GITHUB_OUTPUT - name: skip if the commit or tree was already tested id: skip-if-redundant - uses: actions/github-script@v3 + uses: actions/github-script@v8 if: steps.check-ref.outputs.enabled == 'yes' with: github-token: ${{secrets.GITHUB_TOKEN}} script: | try { // Figure out workflow ID, commit and tree - const { data: run } = await github.actions.getWorkflowRun({ + const { data: run } = await github.rest.actions.getWorkflowRun({ owner: context.repo.owner, repo: context.repo.repo, run_id: context.runId, @@ -54,7 +80,7 @@ jobs: const tree_id = run.head_commit.tree_id; // See whether there is a successful run for that commit or tree - const { data: runs } = await github.actions.listWorkflowRuns({ + const { data: runs } = await github.rest.actions.listWorkflowRuns({ owner: context.repo.owner, repo: context.repo.repo, per_page: 500, @@ -82,8 +108,11 @@ jobs: needs: ci-config if: needs.ci-config.outputs.enabled == 'yes' runs-on: windows-latest + concurrency: + group: windows-build-${{ github.ref }} + cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v5 - uses: git-for-windows/setup-git-for-windows-sdk@v1 - name: build shell: bash @@ -94,21 +123,24 @@ jobs: - name: zip up tracked files run: git archive -o artifacts/tracked.tar.gz HEAD - name: upload tracked files and build artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v5 with: name: windows-artifacts path: artifacts windows-test: name: win test runs-on: windows-latest - needs: [windows-build] + needs: [ci-config, windows-build] strategy: fail-fast: false matrix: nr: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + concurrency: + group: windows-test-${{ matrix.nr }}-${{ github.ref }} + cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }} steps: - name: download tracked files and build artifacts - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v6 with: name: windows-artifacts path: ${{github.workspace}} @@ -119,43 +151,42 @@ jobs: - name: test shell: bash run: . /etc/profile && ci/run-test-slice.sh ${{matrix.nr}} 10 - - name: ci/print-test-failures.sh - if: failure() + - name: print test failures + if: failure() && env.FAILED_TEST_ARTIFACTS != '' shell: bash run: ci/print-test-failures.sh - name: Upload failed tests' directories if: failure() && env.FAILED_TEST_ARTIFACTS != '' - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v5 with: - name: failed-tests-windows + name: failed-tests-windows-${{ matrix.nr }} path: ${{env.FAILED_TEST_ARTIFACTS}} vs-build: name: win+VS build needs: ci-config - if: needs.ci-config.outputs.enabled == 'yes' + if: github.event.repository.owner.login == 'git-for-windows' && needs.ci-config.outputs.enabled == 'yes' env: NO_PERL: 1 GIT_CONFIG_PARAMETERS: "'user.name=CI' 'user.email=ci@git'" runs-on: windows-latest + concurrency: + group: vs-build-${{ github.ref }} + cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v5 - uses: git-for-windows/setup-git-for-windows-sdk@v1 - name: initialize vcpkg - uses: actions/checkout@v2 + uses: actions/checkout@v5 with: repository: 'microsoft/vcpkg' path: 'compat/vcbuild/vcpkg' - name: download vcpkg artifacts - shell: powershell - run: | - $urlbase = "https://dev.azure.com/git/git/_apis/build/builds" - $id = ((Invoke-WebRequest -UseBasicParsing "${urlbase}?definitions=9&statusFilter=completed&resultFilter=succeeded&`$top=1").content | ConvertFrom-JSON).value[0].id - $downloadUrl = ((Invoke-WebRequest -UseBasicParsing "${urlbase}/$id/artifacts").content | ConvertFrom-JSON).value[0].resource.downloadUrl - (New-Object Net.WebClient).DownloadFile($downloadUrl, "compat.zip") - Expand-Archive compat.zip -DestinationPath . -Force - Remove-Item compat.zip + uses: git-for-windows/get-azure-pipelines-artifact@v0 + with: + repository: git/git + definitionId: 9 - name: add msbuild to PATH - uses: microsoft/setup-msbuild@v1 + uses: microsoft/setup-msbuild@v2 - name: copy dlls to root shell: cmd run: compat\vcbuild\vcpkg_copy_dlls.bat release @@ -177,22 +208,25 @@ jobs: - name: zip up tracked files run: git archive -o artifacts/tracked.tar.gz HEAD - name: upload tracked files and build artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v5 with: name: vs-artifacts path: artifacts vs-test: name: win+VS test runs-on: windows-latest - needs: vs-build + needs: [ci-config, vs-build] strategy: fail-fast: false matrix: nr: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + concurrency: + group: vs-test-${{ matrix.nr }}-${{ github.ref }} + cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }} steps: - uses: git-for-windows/setup-git-for-windows-sdk@v1 - name: download tracked files and build artifacts - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v6 with: name: vs-artifacts path: ${{github.workspace}} @@ -204,99 +238,218 @@ jobs: env: NO_SVN_TESTS: 1 run: . /etc/profile && ci/run-test-slice.sh ${{matrix.nr}} 10 - - name: ci/print-test-failures.sh - if: failure() + - name: print test failures + if: failure() && env.FAILED_TEST_ARTIFACTS != '' + shell: bash + run: ci/print-test-failures.sh + - name: Upload failed tests' directories + if: failure() && env.FAILED_TEST_ARTIFACTS != '' + uses: actions/upload-artifact@v5 + with: + name: failed-tests-windows-vs-${{ matrix.nr }} + path: ${{env.FAILED_TEST_ARTIFACTS}} + + windows-meson-build: + name: win+Meson build + needs: ci-config + if: needs.ci-config.outputs.enabled == 'yes' + runs-on: windows-latest + concurrency: + group: windows-meson-build-${{ github.ref }} + cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }} + steps: + - uses: actions/checkout@v5 + - uses: actions/setup-python@v6 + - name: Set up dependencies + shell: pwsh + run: pip install meson ninja + - name: Setup + shell: pwsh + run: meson setup build --vsenv -Dbuildtype=release -Dperl=disabled -Dcredential_helpers=wincred + - name: Compile + shell: pwsh + run: meson compile -C build + - name: Upload build artifacts + uses: actions/upload-artifact@v5 + with: + name: windows-meson-artifacts + path: build + windows-meson-test: + name: win+Meson test + runs-on: windows-latest + needs: [ci-config, windows-meson-build] + strategy: + fail-fast: false + matrix: + nr: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + concurrency: + group: windows-meson-test-${{ matrix.nr }}-${{ github.ref }} + cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }} + steps: + - uses: actions/checkout@v5 + - uses: actions/setup-python@v6 + - name: Set up dependencies + shell: pwsh + run: pip install meson ninja + - name: Download build artifacts + uses: actions/download-artifact@v6 + with: + name: windows-meson-artifacts + path: build + - name: Test + shell: pwsh + run: ci/run-test-slice-meson.sh build ${{matrix.nr}} 10 + - name: print test failures + if: failure() && env.FAILED_TEST_ARTIFACTS != '' shell: bash run: ci/print-test-failures.sh - name: Upload failed tests' directories if: failure() && env.FAILED_TEST_ARTIFACTS != '' - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: - name: failed-tests-windows + name: failed-tests-windows-meson-${{ matrix.nr }} path: ${{env.FAILED_TEST_ARTIFACTS}} + regular: name: ${{matrix.vector.jobname}} (${{matrix.vector.pool}}) needs: ci-config if: needs.ci-config.outputs.enabled == 'yes' + concurrency: + group: ${{ matrix.vector.jobname }}-${{ matrix.vector.pool }}-${{ github.ref }} + cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }} strategy: fail-fast: false matrix: vector: - - jobname: linux-clang - cc: clang - pool: ubuntu-latest - - jobname: linux-sha256 - cc: clang - os: ubuntu - pool: ubuntu-latest - - jobname: linux-gcc - cc: gcc - cc_package: gcc-8 - pool: ubuntu-latest - - jobname: linux-TEST-vars - cc: gcc - os: ubuntu - cc_package: gcc-8 - pool: ubuntu-latest - jobname: osx-clang cc: clang - pool: macos-latest + pool: macos-14 + - jobname: osx-reftable + cc: clang + pool: macos-14 - jobname: osx-gcc - cc: gcc - cc_package: gcc-9 - pool: macos-latest - - jobname: linux-gcc-default - cc: gcc - pool: ubuntu-latest - - jobname: linux-leaks - cc: gcc - pool: ubuntu-latest + cc: gcc-13 + pool: macos-14 + - jobname: osx-meson + cc: clang + pool: macos-14 env: CC: ${{matrix.vector.cc}} CC_PACKAGE: ${{matrix.vector.cc_package}} jobname: ${{matrix.vector.jobname}} - runs_on_pool: ${{matrix.vector.pool}} + CI_JOB_IMAGE: ${{matrix.vector.pool}} + TEST_OUTPUT_DIRECTORY: ${{github.workspace}}/t runs-on: ${{matrix.vector.pool}} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v5 - run: ci/install-dependencies.sh - run: ci/run-build-and-tests.sh - - run: ci/print-test-failures.sh - if: failure() + - name: print test failures + if: failure() && env.FAILED_TEST_ARTIFACTS != '' + run: ci/print-test-failures.sh - name: Upload failed tests' directories if: failure() && env.FAILED_TEST_ARTIFACTS != '' - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v5 with: name: failed-tests-${{matrix.vector.jobname}} path: ${{env.FAILED_TEST_ARTIFACTS}} + fuzz-smoke-test: + name: fuzz smoke test + needs: ci-config + if: needs.ci-config.outputs.enabled == 'yes' + env: + CC: clang + CI_JOB_IMAGE: ubuntu-latest + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - run: ci/install-dependencies.sh + - run: ci/run-build-and-minimal-fuzzers.sh dockerized: name: ${{matrix.vector.jobname}} (${{matrix.vector.image}}) needs: ci-config if: needs.ci-config.outputs.enabled == 'yes' + concurrency: + group: dockerized-${{ matrix.vector.jobname }}-${{ matrix.vector.image }}-${{ github.ref }} + cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }} strategy: fail-fast: false matrix: vector: - - jobname: linux-musl - image: alpine + - jobname: linux-sha256 + image: ubuntu:rolling + cc: clang + - jobname: linux-reftable + image: ubuntu:rolling + cc: clang + - jobname: linux-TEST-vars + image: ubuntu:20.04 + cc: gcc + cc_package: gcc-8 + - jobname: linux-breaking-changes + cc: gcc + image: ubuntu:rolling + - jobname: fedora-breaking-changes-meson + image: fedora:latest + - jobname: linux-leaks + image: ubuntu:rolling + cc: gcc + - jobname: linux-reftable-leaks + image: ubuntu:rolling + cc: gcc + - jobname: linux-asan-ubsan + image: ubuntu:rolling + cc: clang + - jobname: linux-meson + image: ubuntu:rolling + cc: gcc + - jobname: linux-musl-meson + image: alpine:latest + # Supported until 2025-04-02. - jobname: linux32 - os: ubuntu32 - image: daald/ubuntu32:xenial - - jobname: pedantic - image: fedora + image: i386/ubuntu:focal + # A RHEL 8 compatible distro. Supported until 2029-05-31. + - jobname: almalinux-8 + image: almalinux:8 + # Supported until 2026-08-31. + - jobname: debian-11 + image: debian:11 env: jobname: ${{matrix.vector.jobname}} + CC: ${{matrix.vector.cc}} + CI_JOB_IMAGE: ${{matrix.vector.image}} + CUSTOM_PATH: /custom runs-on: ubuntu-latest container: ${{matrix.vector.image}} steps: - - uses: actions/checkout@v1 - - run: ci/install-docker-dependencies.sh - - run: ci/run-build-and-tests.sh - - run: ci/print-test-failures.sh - if: failure() + - name: prepare libc6 for actions + if: matrix.vector.jobname == 'linux32' + run: apt -q update && apt -q -y install libc6-amd64 lib64stdc++6 + - name: install git in container + run: | + if command -v git + then + : # nothing to do + elif command -v apk + then + apk add --update git + elif command -v dnf + then + dnf -yq update && dnf -yq install git + else + apt-get -q update && apt-get -q -y install git + fi + - uses: actions/checkout@v5 + - run: ci/install-dependencies.sh + - run: useradd builder --create-home + - run: chown -R builder . + - run: chmod a+w $GITHUB_ENV && sudo --preserve-env --set-home --user=builder ci/run-build-and-tests.sh + - name: print test failures + if: failure() && env.FAILED_TEST_ARTIFACTS != '' + run: sudo --preserve-env --set-home --user=builder ci/print-test-failures.sh - name: Upload failed tests' directories if: failure() && env.FAILED_TEST_ARTIFACTS != '' - uses: actions/upload-artifact@v1 + uses: actions/upload-artifact@v5 with: name: failed-tests-${{matrix.vector.jobname}} path: ${{env.FAILED_TEST_ARTIFACTS}} @@ -305,29 +458,43 @@ jobs: if: needs.ci-config.outputs.enabled == 'yes' env: jobname: StaticAnalysis - runs-on: ubuntu-18.04 + CI_JOB_IMAGE: ubuntu-22.04 + runs-on: ubuntu-22.04 + concurrency: + group: static-analysis-${{ github.ref }} + cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v5 - run: ci/install-dependencies.sh - run: ci/run-static-analysis.sh - run: ci/check-directional-formatting.bash + rust-analysis: + needs: ci-config + if: needs.ci-config.outputs.enabled == 'yes' + env: + jobname: RustAnalysis + CI_JOB_IMAGE: ubuntu:rolling + runs-on: ubuntu-latest + container: ubuntu:rolling + concurrency: + group: rust-analysis-${{ github.ref }} + cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }} + steps: + - uses: actions/checkout@v4 + - run: ci/install-dependencies.sh + - run: ci/run-rust-checks.sh sparse: needs: ci-config if: needs.ci-config.outputs.enabled == 'yes' env: jobname: sparse - runs-on: ubuntu-20.04 + CI_JOB_IMAGE: ubuntu-22.04 + runs-on: ubuntu-22.04 + concurrency: + group: sparse-${{ github.ref }} + cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }} steps: - - name: Download a current `sparse` package - # Ubuntu's `sparse` version is too old for us - uses: git-for-windows/get-azure-pipelines-artifact@v0 - with: - repository: git/git - definitionId: 10 - artifact: sparse-20.04 - - name: Install the current `sparse` package - run: sudo dpkg -i sparse-20.04/sparse_*.deb - - uses: actions/checkout@v2 + - uses: actions/checkout@v5 - name: Install other dependencies run: ci/install-dependencies.sh - run: make sparse @@ -335,10 +502,14 @@ jobs: name: documentation needs: ci-config if: needs.ci-config.outputs.enabled == 'yes' + concurrency: + group: documentation-${{ github.ref }} + cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }} env: jobname: Documentation + CI_JOB_IMAGE: ubuntu-latest runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v5 - run: ci/install-dependencies.sh - run: ci/test-documentation.sh diff --git a/.gitignore b/.gitignore index e81de1063a4004..78a45cb5bec991 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ -/fuzz-commit-graph /fuzz_corpora -/fuzz-pack-headers -/fuzz-pack-idx +/target/ +/Cargo.lock +/GIT-BUILD-DIR /GIT-BUILD-OPTIONS /GIT-CFLAGS /GIT-LDFLAGS @@ -10,19 +10,19 @@ /GIT-PERL-HEADER /GIT-PYTHON-VARS /GIT-SCRIPT-DEFINES +/GIT-SPATCH-DEFINES +/GIT-TEST-SUITES /GIT-USER-AGENT /GIT-VERSION-FILE -/bin-wrappers/ /git /git-add -/git-add--interactive /git-am /git-annotate /git-apply /git-archimport /git-archive +/git-backfill /git-bisect -/git-bisect--helper /git-blame /git-branch /git-bugreport @@ -53,14 +53,15 @@ /git-cvsimport /git-cvsserver /git-daemon +/git-diagnose /git-diff /git-diff-files /git-diff-index +/git-diff-pairs /git-diff-tree /git-difftool /git-difftool--helper /git-describe -/git-env--helper /git-fast-export /git-fast-import /git-fetch @@ -88,6 +89,7 @@ /git-init-db /git-interpret-trailers /git-instaweb +/git-last-modified /git-log /git-ls-files /git-ls-remote @@ -129,6 +131,7 @@ /git-rebase /git-receive-pack /git-reflog +/git-refs /git-remote /git-remote-http /git-remote-https @@ -138,6 +141,8 @@ /git-remote-ext /git-repack /git-replace +/git-replay +/git-repo /git-request-pull /git-rerere /git-reset @@ -180,11 +185,14 @@ /git-verify-commit /git-verify-pack /git-verify-tag +/git-version /git-web--browse /git-whatchanged /git-worktree /git-write-tree +/scalar /git-core-*/?* +/git.res /gitweb/GITWEB-BUILD-OPTIONS /gitweb/gitweb.cgi /gitweb/static/gitweb.js @@ -192,14 +200,17 @@ /config-list.h /command-list.h /hook-list.h +/version-def.h *.tar.gz *.dsc *.deb +/git.rc /git.spec *.exe *.[aos] *.o.json *.py[co] +.build/ .depend/ *.gcda *.gcno @@ -221,10 +232,10 @@ /TAGS /cscope* /compile_commands.json +/.cache/ *.hcc *.obj *.lib -*.res *.sln *.sp *.suo @@ -245,3 +256,5 @@ Release/ /git.VC.db *.dSYM /contrib/buildsystems/out +/contrib/libgit-rs/target +/contrib/libgit-sys/target diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 00000000000000..b419a84e2cc660 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,271 @@ +default: + timeout: 2h + +stages: + - build + - test + - analyze + +workflow: + rules: + - if: $CI_PIPELINE_SOURCE == "merge_request_event" + - if: $CI_COMMIT_TAG + - if: $CI_COMMIT_REF_PROTECTED == "true" + +test:linux: + image: $image + stage: test + needs: [ ] + tags: + - saas-linux-medium-amd64 + variables: + CUSTOM_PATH: "/custom" + TEST_OUTPUT_DIRECTORY: "/tmp/test-output" + before_script: + - ./ci/install-dependencies.sh + script: + - useradd builder --create-home + - chown -R builder "${CI_PROJECT_DIR}" + - sudo --preserve-env --set-home --user=builder ./ci/run-build-and-tests.sh + after_script: + - | + if test "$CI_JOB_STATUS" != 'success' + then + sudo --preserve-env --set-home --user=builder ./ci/print-test-failures.sh + mv "$TEST_OUTPUT_DIRECTORY"/failed-test-artifacts t/ + fi + parallel: + matrix: + - jobname: linux-sha256 + image: ubuntu:rolling + CC: clang + - jobname: linux-reftable + image: ubuntu:rolling + CC: clang + - jobname: linux-breaking-changes + image: ubuntu:20.04 + CC: gcc + - jobname: fedora-breaking-changes-meson + image: fedora:latest + - jobname: linux-TEST-vars + image: ubuntu:20.04 + CC: gcc + CC_PACKAGE: gcc-8 + - jobname: linux-leaks + image: ubuntu:rolling + CC: gcc + - jobname: linux-reftable-leaks + image: ubuntu:rolling + CC: gcc + - jobname: linux-asan-ubsan + image: ubuntu:rolling + CC: clang + - jobname: linux-musl-meson + image: alpine:latest + - jobname: linux32 + image: i386/ubuntu:20.04 + - jobname: linux-meson + image: ubuntu:rolling + CC: gcc + artifacts: + paths: + - t/failed-test-artifacts + reports: + junit: build/meson-logs/testlog.junit.xml + when: on_failure + +test:osx: + image: $image + stage: test + needs: [ ] + tags: + - saas-macos-medium-m1 + variables: + TEST_OUTPUT_DIRECTORY: "/Volumes/RAMDisk" + before_script: + # Create a 4GB RAM disk that we use to store test output on. This small hack + # significantly speeds up tests by more than a factor of 2 because the + # macOS runners use network-attached storage as disks, which is _really_ + # slow with the many small writes that our tests do. + - sudo diskutil apfs create $(hdiutil attach -nomount ram://8192000) RAMDisk + - ./ci/install-dependencies.sh + script: + - ./ci/run-build-and-tests.sh + after_script: + - | + if test "$CI_JOB_STATUS" != 'success' + then + ./ci/print-test-failures.sh + mv "$TEST_OUTPUT_DIRECTORY"/failed-test-artifacts t/ + fi + parallel: + matrix: + - jobname: osx-clang + image: macos-14-xcode-15 + CC: clang + - jobname: osx-reftable + image: macos-14-xcode-15 + CC: clang + - jobname: osx-meson + image: macos-14-xcode-15 + CC: clang + artifacts: + paths: + - t/failed-test-artifacts + reports: + junit: build/meson-logs/testlog.junit.xml + when: on_failure + +.windows_before_script: &windows_before_script + # Disabling realtime monitoring fails on some of the runners, but it + # significantly speeds up test execution in the case where it works. We thus + # try our luck, but ignore any failures. + - Set-MpPreference -DisableRealtimeMonitoring $true; $true + +build:mingw64: + stage: build + tags: + - saas-windows-medium-amd64 + variables: + NO_PERL: 1 + before_script: + - *windows_before_script + - ./ci/install-sdk.ps1 -directory "git-sdk" + script: + - git-sdk/usr/bin/bash.exe -l -c 'ci/make-test-artifacts.sh artifacts' + artifacts: + paths: + - artifacts + - git-sdk + +test:mingw64: + stage: test + tags: + - saas-windows-medium-amd64 + needs: + - job: "build:mingw64" + artifacts: true + before_script: + - *windows_before_script + - git-sdk/usr/bin/bash.exe -l -c 'tar xf artifacts/artifacts.tar.gz' + - New-Item -Path .git/info -ItemType Directory + - New-Item .git/info/exclude -ItemType File -Value "/git-sdk" + script: + - git-sdk/usr/bin/bash.exe -l -c "ci/run-test-slice.sh $CI_NODE_INDEX $CI_NODE_TOTAL" + after_script: + - git-sdk/usr/bin/bash.exe -l -c 'ci/print-test-failures.sh' + parallel: 10 + +.msvc-meson: + tags: + - saas-windows-medium-amd64 + before_script: + - *windows_before_script + - choco install -y git meson ninja rust-ms + - Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1 + - refreshenv + +build:msvc-meson: + extends: .msvc-meson + stage: build + script: + - meson setup build --vsenv -Dperl=disabled -Dbackend_max_links=1 -Dcredential_helpers=wincred + - meson compile -C build + artifacts: + paths: + - build + +test:msvc-meson: + extends: .msvc-meson + stage: test + timeout: 6h + needs: + - job: "build:msvc-meson" + artifacts: true + script: + - meson test -C build --no-rebuild --print-errorlogs --slice $Env:CI_NODE_INDEX/$Env:CI_NODE_TOTAL + parallel: 10 + artifacts: + reports: + junit: build/meson-logs/testlog.junit.xml + +test:fuzz-smoke-tests: + image: ubuntu:latest + stage: test + needs: [ ] + variables: + CC: clang + before_script: + - ./ci/install-dependencies.sh + script: + - ./ci/run-build-and-minimal-fuzzers.sh + +static-analysis: + image: ubuntu:22.04 + stage: analyze + needs: [ ] + variables: + jobname: StaticAnalysis + before_script: + - ./ci/install-dependencies.sh + script: + - ./ci/run-static-analysis.sh + - ./ci/check-directional-formatting.bash + +rust-analysis: + image: ubuntu:rolling + stage: analyze + needs: [ ] + variables: + jobname: RustAnalysis + before_script: + - ./ci/install-dependencies.sh + script: + - ./ci/run-rust-checks.sh + +check-whitespace: + image: ubuntu:latest + stage: analyze + needs: [ ] + before_script: + - ./ci/install-dependencies.sh + # Since $CI_MERGE_REQUEST_TARGET_BRANCH_SHA is only defined for merged + # pipelines, we fallback to $CI_MERGE_REQUEST_DIFF_BASE_SHA, which should + # be defined in all pipelines. + script: + - | + R=${CI_MERGE_REQUEST_TARGET_BRANCH_SHA:-${CI_MERGE_REQUEST_DIFF_BASE_SHA:?}} || exit + ./ci/check-whitespace.sh "$R" + rules: + - if: $CI_PIPELINE_SOURCE == 'merge_request_event' + +check-style: + image: ubuntu:latest + stage: analyze + needs: [ ] + allow_failure: true + variables: + CC: clang + jobname: ClangFormat + before_script: + - ./ci/install-dependencies.sh + # Since $CI_MERGE_REQUEST_TARGET_BRANCH_SHA is only defined for merged + # pipelines, we fallback to $CI_MERGE_REQUEST_DIFF_BASE_SHA, which should + # be defined in all pipelines. + script: + - | + R=${CI_MERGE_REQUEST_TARGET_BRANCH_SHA:-${CI_MERGE_REQUEST_DIFF_BASE_SHA:?}} || exit + ./ci/run-style-check.sh "$R" + rules: + - if: $CI_PIPELINE_SOURCE == 'merge_request_event' + +documentation: + image: ubuntu:latest + stage: analyze + needs: [ ] + variables: + jobname: Documentation + before_script: + - ./ci/install-dependencies.sh + script: + - ./ci/test-documentation.sh diff --git a/.mailmap b/.mailmap index 07db36a9bb949c..7b3198171fad1e 100644 --- a/.mailmap +++ b/.mailmap @@ -59,12 +59,13 @@ David Reiss David S. Miller David Turner David Turner -Derrick Stolee -Derrick Stolee Derrick Stolee via GitGitGadget -Derrick Stolee +Derrick Stolee +Derrick Stolee Derrick Stolee via GitGitGadget +Derrick Stolee Deskin Miller Đoàn Trần Công Danh Doan Tran Cong Danh Dirk Süsserott +Emily Shaffer Eric Blake Eric Hanchrow Eric S. Raymond @@ -79,6 +80,9 @@ Frank Lichtenheld Fredrik Kuivinen Frédéric Heitzmann Garry Dolley +Glen Choo +Greg Hurrell +Greg Hurrell Greg Price Greg Price Heiko Voigt @@ -122,6 +126,7 @@ Jon Loeliger Jon Seymour Jonathan Nieder Jonathan del Strother +Jonathan Tan Josh Triplett Josh Triplett Julian Phillips @@ -150,6 +155,7 @@ Lars Doelle Lars Doelle Lars Noschinski Li Hong +Linus Arver Linus Torvalds Linus Torvalds Linus Torvalds @@ -165,6 +171,7 @@ Mark Rada Martin Langhoff Martin von Zweigbergk Masaya Suzuki +Matheus Tavares Matt Draisey Matt Kraai Matt McCutchen @@ -253,6 +260,7 @@ Stefan Naewe Stefan Sperling Štěpán Němec Stephen Boyd +Stephen P. Smith Steven Drake Steven Grimm Steven Grimm koreth@midwinter.com diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 0215b1fd4c05e6..e58917c50a96dc 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -130,11 +130,11 @@ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, available at [https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0]. -Community Impact Guidelines were inspired by +Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder][Mozilla CoC]. For answers to common questions about this code of conduct, see the FAQ at -[https://www.contributor-covenant.org/faq][FAQ]. Translations are available +[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at [https://www.contributor-covenant.org/translations][translations]. [homepage]: https://www.contributor-covenant.org diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 00000000000000..2f51bf5d5ff5f8 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "gitcore" +version = "0.1.0" +edition = "2018" +rust-version = "1.49.0" + +[lib] +crate-type = ["staticlib"] + +[dependencies] 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/.gitignore b/Documentation/.gitignore index 1c3771e7d72f69..dd54cc768a250c 100644 --- a/Documentation/.gitignore +++ b/Documentation/.gitignore @@ -6,13 +6,15 @@ *.pdf git.info gitman.info -howto-index.txt +howto-index.adoc doc.dep -cmds-*.txt -mergetools-*.txt -manpage-base-url.xsl -SubmittingPatches.txt +cmds-*.adoc +mergetools-*.adoc +SubmittingPatches.adoc tmp-doc-diff/ +tmp-meson-diff/ GIT-ASCIIDOCFLAGS /.build/ /GIT-EXCLUDED-PROGRAMS +/asciidoc.conf +/asciidoctor-extensions.rb diff --git a/Documentation/BreakingChanges.adoc b/Documentation/BreakingChanges.adoc new file mode 100644 index 00000000000000..f814450d2f65ac --- /dev/null +++ b/Documentation/BreakingChanges.adoc @@ -0,0 +1,335 @@ += Upcoming breaking changes + +The Git project aims to ensure backwards compatibility to the best extent +possible. Minor releases will not break backwards compatibility unless there is +a very strong reason to do so, like for example a security vulnerability. + +Regardless of that, due to the age of the Git project, it is only natural to +accumulate a backlog of backwards-incompatible changes that will eventually be +required to keep the project aligned with a changing world. These changes fall +into several categories: + +* Changes to long established defaults. +* Concepts that have been replaced with a superior design. +* Concepts, commands, configuration or options that have been lacking in major + ways and that cannot be fixed and which will thus be removed without any + replacement. + +Explicitly not included in this list are fixes to minor bugs that may cause a +change in user-visible behavior. + +The Git project irregularly releases breaking versions that deliberately break +backwards compatibility with older versions. This is done to ensure that Git +remains relevant, safe and maintainable going forward. The release cadence of +breaking versions is typically measured in multiple years. We had the following +major breaking releases in the past: + +* Git 1.6.0, released in August 2008. +* Git 2.0, released in May 2014. + +We use . release numbers these days, starting from Git 2.0. For +future releases, our plan is to increment in the release number when we +make the next breaking release. Before Git 2.0, the release numbers were +1.. with the intention to increment for "usual" breaking +releases, reserving the jump to Git 2.0 for really large backward-compatibility +breaking changes. + +The intent of this document is to track upcoming deprecations for future +breaking releases. Furthermore, this document also tracks what will _not_ be +deprecated. This is done such that the outcome of discussions document both +when the discussion favors deprecation, but also when it rejects a deprecation. + +Items should have a clear summary of the reasons why we do or do not want to +make the described change that can be easily understood without having to read +the mailing list discussions. If there are alternatives to the changed feature, +those alternatives should be pointed out to our users. + +All items should be accompanied by references to relevant mailing list threads +where the deprecation was discussed. These references use message-IDs, which +can visited via + + https://lore.kernel.org/git/$message_id/ + +to see the message and its surrounding discussion. Such a reference is there to +make it easier for you to find how the project reached consensus on the +described item back then. + +This is a living document as the environment surrounding the project changes +over time. If circumstances change, an earlier decision to deprecate or change +something may need to be revisited from time to time. So do not take items on +this list to mean "it is settled, do not waste our time bringing it up again". + +== Procedure + +Discussing the desire to make breaking changes, declaring that breaking +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, 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 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. + +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 +be changed to or replaced in case the alternative was implemented already. + +=== Changes + +* The default hash function for new repositories will be changed from "sha1" + to "sha256". SHA-1 has been deprecated by NIST in 2011 and is nowadays + recommended against in FIPS 140-2 and similar certifications. Furthermore, + there are practical attacks on SHA-1 that weaken its cryptographic properties: ++ + ** The SHAppening (2015). The first demonstration of a practical attack + against SHA-1 with 2^57 operations. + ** SHAttered (2017). Generation of two valid PDF files with 2^63 operations. + ** Birthday-Near-Collision (2019). This attack allows for chosen prefix + attacks with 2^68 operations. + ** Shambles (2020). This attack allows for chosen prefix attacks with 2^63 + operations. ++ +While we have protections in place against known attacks, it is expected +that more attacks against SHA-1 will be found by future research. Paired +with the ever-growing capability of hardware, it is only a matter of time +before SHA-1 will be considered broken completely. We want to be prepared +and will thus change the default hash algorithm to "sha256" for newly +initialized repositories. ++ +An important requirement for this change is that the ecosystem is ready to +support the "sha256" object format. This includes popular Git libraries, +applications and forges. ++ +There is no plan to deprecate the "sha1" object format at this point in time. ++ +Cf. <2f5de416-04ba-c23d-1e0b-83bb655829a7@zombino.com>, +<20170223155046.e7nxivfwqqoprsqj@LykOS.localdomain>, +. + +* The default storage format for references in newly created repositories will + be changed from "files" to "reftable". The "reftable" format provides + multiple advantages over the "files" format: ++ + ** It is impossible to store two references that only differ in casing on + case-insensitive filesystems with the "files" format. This issue is common + on Windows and macOS platforms. As the "reftable" backend does not use + filesystem paths to encode reference names this problem goes away. + ** Similarly, macOS normalizes path names that contain unicode characters, + which has the consequence that you cannot store two names with unicode + characters that are encoded differently with the "files" backend. Again, + this is not an issue with the "reftable" backend. + ** Deleting references with the "files" backend requires Git to rewrite the + complete "packed-refs" file. In large repositories with many references + this file can easily be dozens of megabytes in size, in extreme cases it + may be gigabytes. The "reftable" backend uses tombstone markers for + deleted references and thus does not have to rewrite all of its data. + ** Repository housekeeping with the "files" backend typically performs + all-into-one repacks of references. This can be quite expensive, and + consequently housekeeping is a tradeoff between the number of loose + references that accumulate and slow down operations that read references, + and compressing those loose references into the "packed-refs" file. The + "reftable" backend uses geometric compaction after every write, which + amortizes costs and ensures that the backend is always in a + well-maintained state. + ** Operations that write multiple references at once are not atomic with the + "files" backend. Consequently, Git may see in-between states when it reads + references while a reference transaction is in the process of being + committed to disk. + ** Writing many references at once is slow with the "files" backend because + every reference is created as a separate file. The "reftable" backend + significantly outperforms the "files" backend by multiple orders of + magnitude. + ** The reftable backend uses a binary format with prefix compression for + reference names. As a result, the format uses less space compared to the + "packed-refs" file. ++ +Users that get immediate benefit from the "reftable" backend could continue to +opt-in to the "reftable" format manually by setting the "init.defaultRefFormat" +config. But defaults matter, and we think that overall users will have a better +experience with less platform-specific quirks when they use the new backend by +default. ++ +A prerequisite for this change is that the ecosystem is ready to support the +"reftable" format. Most importantly, alternative implementations of Git like +JGit, libgit2 and Gitoxide need to support it. + +* In new repositories, the default branch name will be `main`. We have been + warning that the default name will change since 675704c74dd (init: + provide useful advice about init.defaultBranch, 2020-12-11). The new name + matches the default branch name used in new repositories by many of the + big Git forges. + +* Git will require Rust as a mandatory part of the build process. While Git + already started to adopt Rust in Git 2.49, all parts written in Rust are + optional for the time being. This includes: ++ + ** The Rust wrapper around libgit.a that is part of "contrib/" and which has + been introduced in Git 2.49. + ** Subsystems that have an alternative implementation in Rust to test + interoperability between our C and Rust codebase. + ** Newly written features that are not mission critical for a fully functional + Git client. ++ +These changes are meant as test balloons to allow distributors of Git to prepare +for Rust becoming a mandatory part of the build process. There will be multiple +milestones for the introduction of Rust: ++ +-- +1. Initially, with Git 2.52, support for Rust will be auto-detected by Meson and + disabled in our Makefile so that the project can sort out the initial + infrastructure. +2. In Git 2.53, both build systems will default-enable support for Rust. + Consequently, builds will break by default if Rust is not available on the + build host. The use of Rust can still be explicitly disabled via build + flags. +3. In Git 3.0, the build options will be removed and support for Rust is + mandatory. +-- ++ +You can explicitly ask both Meson and our Makefile-based system to enable Rust +by saying `meson configure -Drust=enabled` and `make WITH_RUST=YesPlease`, +respectively. ++ +The Git project will declare the last version before Git 3.0 to be a long-term +support release. This long-term release will receive important bug fixes for at +least four release cycles and security fixes for six release cycles. The Git +project will hand over maintainership of the long-term release to distributors +in case they need to extend the life of that long-term release even further. +Details of how this long-term release will be handed over to the community will +be discussed once the Git project decides to stop officially supporting it. ++ +We will evaluate the impact on downstream distributions before making Rust +mandatory in Git 3.0. If we see that the impact on downstream distributions +would be significant, we may decide to defer this change to a subsequent minor +release. This evaluation will also take into account our own experience with +how painful it is to keep Rust an optional component. + +=== Removals + +* Support for grafting commits has long been superseded by git-replace(1). + Grafts are inferior to replacement refs: ++ + ** Grafts are a local-only mechanism and cannot be shared across + repositories. + ** Grafts can lead to hard-to-diagnose problems when transferring objects + between repositories. ++ +The grafting mechanism has been marked as outdated since e650d0643b (docs: mark +info/grafts as outdated, 2014-03-05) and will be removed. ++ +Cf. <20140304174806.GA11561@sigill.intra.peff.net>. + +* The git-pack-redundant(1) command can be used to remove redundant pack files. + The subcommand is unusably slow and the reason why nobody reports it as a + performance bug is suspected to be the absence of users. We have nominated + the command for removal and have started to emit a user-visible warning in + c3b58472be (pack-redundant: gauge the usage before proposing its removal, + 2020-08-25) whenever the command is executed. ++ +So far there was a single complaint about somebody still using the command, but +that complaint did not cause us to reverse course. On the contrary, we have +doubled down on the deprecation and starting with 4406522b76 (pack-redundant: +escalate deprecation warning to an error, 2023-03-23), the command dies unless +the user passes the `--i-still-use-this` option. ++ +There have not been any subsequent complaints, so this command will finally be +removed. ++ +Cf. , + , + <20230323204047.GA9290@coredump.intra.peff.net>, + +* Support for storing shorthands for remote URLs in "$GIT_COMMON_DIR/branches/" + and "$GIT_COMMON_DIR/remotes/" has been long superseded by storing remotes in + the repository configuration. ++ +The mechanism has originally been introduced in f170e4b39d ([PATCH] fetch/pull: +short-hand notation for remote repositories., 2005-07-16) and was superseded by +6687f8fea2 ([PATCH] Use .git/remote/origin, not .git/branches/origin., +2005-08-20), where we switched from ".git/branches/" to ".git/remotes/". That +commit already mentions an upcoming deprecation of the ".git/branches/" +directory, and starting with a1d4aa7424 (Add repository-layout document., +2005-09-01) we have also marked this layout as deprecated. Eventually we also +started to migrate away from ".git/remotes/" in favor of config-based remotes, +and we have marked the directory as legacy in 3d3d282146 (Documentation: +Grammar correction, wording fixes and cleanup, 2011-08-23) ++ +As our documentation mentions, these directories are unlikely to be used in +modern repositories and most users aren't even aware of these mechanisms. They +have been deprecated for almost 20 years and 14 years respectively, and we are +not aware of any active users that have complained about this deprecation. +Furthermore, the ".git/branches/" directory is nowadays misleadingly named and +may cause confusion as "branches" are almost exclusively used in the context of +references. ++ +These features will be removed. + +* Support for "--stdin" option in the "name-rev" command was + deprecated (and hidden from the documentation) in the Git 2.40 + timeframe, in preference to its synonym "--annotate-stdin". Git 3.0 + removes the support for "--stdin" altogether. + +* The git-whatchanged(1) command has outlived its usefulness more than + 10 years ago, and takes more keystrokes to type than its rough + equivalent `git log --raw`. We have nominated the command for + removal, have changed the command to refuse to work unless the + `--i-still-use-this` option is given, and asked the users to report + when they do so. ++ +The command will be removed. + +* Support for `core.commentString=auto` has been deprecated and will + be removed in Git 3.0. ++ +cf. + +* Support for `core.preferSymlinkRefs=true` has been deprecated and will be + removed in Git 3.0. Writing symbolic refs as symbolic links will be phased + out in favor of using plain files using the textual representation of + symbolic refs. ++ +Symbolic references were initially always stored as a symbolic link. This was +changed in 9b143c6e15 (Teach update-ref about a symbolic ref stored in a +textfile., 2005-09-25), where a new textual symref format was introduced to +store those symbolic refs in a plain file. In 9f0bb90d16 +(core.prefersymlinkrefs: use symlinks for .git/HEAD, 2006-05-02), the Git +project switched the default to use the textual symrefs in favor of symbolic +links. ++ +The migration away from symbolic links has happened almost 20 years ago by now, +and there is no known reason why one should prefer them nowadays. Furthermore, +symbolic links are not supported on some platforms. ++ +Note that only the writing side for such symbolic links is deprecated. Reading +such symbolic links is still supported for now. + +== Superseded features that will not be deprecated + +Some features have gained newer replacements that aim to improve the design in +certain ways. The fact that there is a replacement does not automatically mean +that the old way of doing things will eventually be removed. This section tracks +those features with newer alternatives. + +* The features git-checkout(1) offers are covered by the pair of commands + git-restore(1) and git-switch(1). Because the use of git-checkout(1) is still + widespread, and it is not expected that this will change anytime soon, all + three commands will stay. ++ +This decision may get revisited in case we ever figure out that there are +almost no users of any of the commands anymore. ++ +Cf. , +, +<112b6568912a6de6672bf5592c3a718e@manjaro.org>. diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index b20b2f94f11abb..df72fe01772a18 100644 --- a/Documentation/CodingGuidelines +++ b/Documentation/CodingGuidelines @@ -1,5 +1,5 @@ -Like other projects, we also have some guidelines to keep to the -code. For Git in general, a few rough rules are: +Like other projects, we also have some guidelines for our code. For +Git in general, a few rough rules are: - Most importantly, we never say "It's in POSIX; we'll happily ignore your needs should your system not conform to it." @@ -24,7 +24,7 @@ code. For Git in general, a few rough rules are: "Once it _is_ in the tree, it's not really worth the patch noise to go and fix it up." - Cf. http://lkml.iu.edu/hypermail/linux/kernel/1001.3/01069.html + Cf. https://lore.kernel.org/all/20100126160632.3bdbe172.akpm@linux-foundation.org/ - Log messages to explain your changes are as important as the changes themselves. Clearly written code and in-code comments @@ -40,10 +40,13 @@ As for more concrete guidelines, just imitate the existing code contributing to). It is always preferable to match the _local_ convention. New code added to Git suite is expected to match the overall style of existing code. Modifications to existing -code is expected to match the style the surrounding code already +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 they are. +But if you must have a list of rules, here are some language +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. For shell scripts specifically (not exhaustive): @@ -159,8 +162,6 @@ For shell scripts specifically (not exhaustive): - We do not use \{m,n\}; - - We do not use -E; - - We do not use ? or + (which are \{0,1\} and \{1,\} respectively in BRE) but that goes without saying as these are ERE elements not BRE (note that \? and \+ are not even part @@ -184,8 +185,55 @@ For shell scripts specifically (not exhaustive): - Even though "local" is not part of POSIX, we make heavy use of it in our test suite. We do not use it in scripted Porcelains, and - hopefully nobody starts using "local" before they are reimplemented - in C ;-) + hopefully nobody starts using "local" before all shells that matter + support it (notably, ksh from AT&T Research does not support it yet). + + - Some versions of shell do not understand "export variable=value", + so we write "variable=value" and then "export variable" on two + separate lines. + + - Some versions of dash have broken variable assignment when prefixed + with "local", "export", and "readonly", in that the value to be + assigned goes through field splitting at $IFS unless quoted. + + (incorrect) + local variable=$value + local variable=$(command args) + + (correct) + local variable="$value" + local variable="$(command args)" + + - The common construct + + VAR=VAL command args + + to temporarily set and export environment variable VAR only while + "command args" is running is handy, but this triggers an + unspecified behaviour according to POSIX when used for a command + that is not an external command (like shell functions). Indeed, + dash 0.5.10.2-6 on Ubuntu 20.04, /bin/sh on FreeBSD 13, and AT&T + ksh all make a temporary assignment without exporting the variable, + in such a case. As it does not work portably across shells, do not + use this syntax for shell functions. A common workaround is to do + an explicit export in a subshell, like so: + + (incorrect) + VAR=VAL func args + + (correct) + ( + VAR=VAL && + export VAR && + func args + ) + + but be careful that the effect "func" makes to the variables in the + current shell will be lost across the subshell boundary. + + - Use octal escape sequences (e.g. "\302\242"), not hexadecimal (e.g. + "\xc2\xa2") in printf format strings, since hexadecimal escape + sequences are not portable. For C programs: @@ -193,6 +241,16 @@ For C programs: - We use tabs to indent, and interpret tabs as taking up to 8 spaces. + - Nested C preprocessor directives are indented after the hash by one + space per nesting level. + + #if FOO + # include + # if BAR + # include + # endif + #endif + - We try to keep to at most 80 characters per line. - As a Git developer we assume you have a reasonably modern compiler @@ -200,11 +258,28 @@ For C programs: ensure your patch is clear of all compiler warnings we care about, by e.g. "echo DEVELOPER=1 >>config.mak". + - When using DEVELOPER=1 mode, you may see warnings from the compiler + like "error: unused parameter 'foo' [-Werror=unused-parameter]", + which indicates that a function ignores its argument. If the unused + parameter can't be removed (e.g., because the function is used as a + callback and has to match a certain interface), you can annotate + the individual parameters with the UNUSED (or MAYBE_UNUSED) + keyword, like "int foo UNUSED". + - We try to support a wide range of C compilers to compile Git with, - including old ones. You should not use features from newer C + including old ones. As of Git v2.35.0 Git requires C99 (we check + "__STDC_VERSION__"). You should not use features from a newer C standard, even if your compiler groks them. - There are a few exceptions to this guideline: + New C99 features have been phased in gradually, if something's new + in C99 but not used yet don't assume that it's safe to use, some + compilers we target have only partial support for it. These are + considered safe to use: + + . since around 2007 with 2b6854c863a, we have been using + initializer elements which are not computable at load time. E.g.: + + const char *args[] = { "constant", variable, NULL }; . since early 2012 with e1327023ea, we have been using an enum definition whose last element is followed by a comma. This, like @@ -220,17 +295,39 @@ For C programs: . since early 2021 with 765dc168882, we have been using variadic macros, mostly for printf-like trace and debug macros. - These used to be forbidden, but we have not heard any breakage - report, and they are assumed to be safe. + . since late 2021 with 44ba10d6, we have had variables declared in + the for loop "for (int i = 0; i < 10; i++)". + + . since late 2023 with 8277dbe987 we have been using the bool type + from . + + C99 features we have test balloons for: + + . since late 2024 with v2.48.0-rc0~20, we have test balloons for + compound literal syntax, e.g., (struct foo){ .member = value }; + our hope is that no platforms we care about have trouble using + them, and officially adopt its wider use in mid 2026. Do not add + more use of the syntax until that happens. + + New C99 features that we cannot use yet: + + . %z and %zu as a printf() argument for a size_t (the %z being for + the POSIX-specific ssize_t). Instead you should use + printf("%"PRIuMAX, (uintmax_t)v). These days the MSVC version we + rely on supports %z, but the C library used by MinGW does not. + + . Shorthand like ".a.b = *c" in struct initializations is known to + trip up an older IBM XLC version, use ".a = { .b = *c }" instead. + See the 33665d98 (reftable: make assignments portable to AIX xlc + v12.01, 2022-03-28). - Variables have to be declared at the beginning of the block, before - the first statement (i.e. -Wdeclaration-after-statement). + the first statement (i.e. -Wdeclaration-after-statement). It is + encouraged to have a blank line between the end of the declarations + and the first statement in the block. - - Declaring a variable in the for loop "for (int i = 0; i < 10; i++)" - is still not allowed in this codebase. We are in the process of - allowing it by waiting to see that 44ba10d6 (revision: use C99 - declaration of variable in for() loop, 2021-11-14) does not get - complaints. Let's revisit this around November 2022. + - Do not explicitly initialize global variables to 0 or NULL; + instead, let BSS take care of the zero initialization. - NULL pointers shall be written as NULL, not as 0. @@ -250,6 +347,13 @@ For C programs: while( condition ) func (bar+1); + - A binary operator (other than ",") and ternary conditional "?:" + have a space on each side of the operator to separate it from its + operands. E.g. "A + 1", not "A+1". + + - A unary operator (other than "." and "->") have no space between it + and its operand. E.g. "(char *)ptr", not "(char *) ptr". + - Do not explicitly compare an integral value with constant 0 or '\0', or a pointer value with constant NULL. For instance, to validate that counted array is initialized but has no elements, write: @@ -426,8 +530,41 @@ For C programs: detail. - The first #include in C files, except in platform specific compat/ - implementations, must be either "git-compat-util.h", "cache.h" or - "builtin.h". You do not have to include more than one of these. + implementations and sha1dc/, must be . This + header file insulates other header files and source files from + platform differences, like which system header files must be + included in what order, and what C preprocessor feature macros must + be defined to trigger certain features we expect out of the system. + A collorary to this is that C files should not directly include + system header files themselves. + + There are some exceptions, because certain group of files that + implement an API all have to include the same header file that + defines the API and it is convenient to include + there. Namely: + + - the implementation of the built-in commands in the "builtin/" + directory that include "builtin.h" for the cmd_foo() prototype + definition, + + - the test helper programs in the "t/helper/" directory that include + "t/helper/test-tool.h" for the cmd__foo() prototype definition, + + - the xdiff implementation in the "xdiff/" directory that includes + "xdiff/xinclude.h" for the xdiff machinery internals, + + - the unit test programs in "t/unit-tests/" directory that include + "t/unit-tests/test-lib.h" that gives them the unit-tests + framework, and + + - the source files that implement reftable in the "reftable/" + directory that include "reftable/system.h" for the reftable + internals, + + are allowed to assume that they do not have to include + themselves, as it is included as the first + '#include' in these header files. These headers must be the first + header file to be "#include"d in them, though. - A C file must directly include the header files that declare the functions and the types it uses, except for the functions and types @@ -460,13 +597,70 @@ For C programs: Run `GIT_DEBUGGER=1 ./bin-wrappers/git foo` to simply use gdb as is, or run `GIT_DEBUGGER=" " ./bin-wrappers/git foo` to use your own debugger and arguments. Example: `GIT_DEBUGGER="ddd --gdb" - ./bin-wrappers/git log` (See `wrap-for-bin.sh`.) + ./bin-wrappers/git log` (See `bin-wrappers/wrap-for-bin.sh`.) + + - The primary data structure that a subsystem 'S' deals with is called + `struct S`. Functions that operate on `struct S` are named + `S_()` and should generally receive a pointer to `struct S` as + first parameter. E.g. + + struct strbuf; + + void strbuf_add(struct strbuf *buf, ...); + + void strbuf_reset(struct strbuf *buf); + + is preferred over: + + struct strbuf; + + void add_string(struct strbuf *buf, ...); + + void reset_strbuf(struct strbuf *buf); + + - There are several common idiomatic names for functions performing + specific tasks on a structure `S`: + + - `S_init()` initializes a structure without allocating the + structure itself. + + - `S_release()` releases a structure's contents without reinitializing + the structure for immediate reuse, and without freeing the structure + itself. + + - `S_clear()` is equivalent to `S_release()` followed by `S_init()` + such that the structure is directly usable after clearing it. When + `S_clear()` is provided, `S_init()` shall not allocate resources + that need to be released again. + + - `S_free()` releases a structure's contents and frees the + structure. + + - Function names should be clear and descriptive, accurately reflecting + their purpose or behavior. Arbitrary suffixes that do not add meaningful + context can lead to confusion, particularly for newcomers to the codebase. + + Historically, the '_1' suffix has been used in situations where: + + - A function handles one element among a group that requires similar + processing. + - A recursive function has been separated from its setup phase. + + The '_1' suffix can be used as a concise way to indicate these specific + cases. However, it is recommended to find a more descriptive name wherever + possible to improve the readability and maintainability of the code. + + - Bit fields should be defined without a space around the colon. E.g. + + unsigned my_field:1; + unsigned other_field:1; + unsigned field_with_longer_name:1; For Perl programs: - Most of the C guidelines above apply. - - We try to support Perl 5.8 and later ("use Perl 5.008"). + - We try to support Perl 5.8.1 and later ("use Perl 5.008001"). - use strict and use warnings are strongly preferred. @@ -492,20 +686,9 @@ For Perl programs: - Learn and use Git.pm if you need that functionality. - - For Emacs, it's useful to put the following in - GIT_CHECKOUT/.dir-locals.el, assuming you use cperl-mode: - - ;; note the first part is useful for C editing, too - ((nil . ((indent-tabs-mode . t) - (tab-width . 8) - (fill-column . 80))) - (cperl-mode . ((cperl-indent-level . 8) - (cperl-extra-newline-before-brace . nil) - (cperl-merge-trailing-else . t)))) - For Python scripts: - - We follow PEP-8 (http://www.python.org/dev/peps/pep-0008/). + - We follow PEP-8 (https://peps.python.org/pep-0008/). - As a minimum, we aim to be compatible with Python 2.7. @@ -541,16 +724,30 @@ Program Output Error Messages - - Do not end error messages with a full stop. + - Do not end a single-sentence error message with a full stop. - Do not capitalize the first word, only because it is the first word - in the message ("unable to open %s", not "Unable to open %s"). But + in the message ("unable to open '%s'", not "Unable to open '%s'"). But "SHA-3 not supported" is fine, because the reason the first word is capitalized is not because it is at the beginning of the sentence, but because the word would be spelled in capital letters even when it appeared in the middle of the sentence. - - Say what the error is first ("cannot open %s", not "%s: cannot open") + - Say what the error is first ("cannot open '%s'", not "%s: cannot open"). + + - Enclose the subject of an error inside a pair of single quotes, + e.g. `die(_("unable to open '%s'"), path)`. + + - Unless there is a compelling reason not to, error messages from + porcelain commands should be marked for translation, e.g. + `die(_("bad revision %s"), revision)`. + + - Error messages from the plumbing commands are sometimes meant for + machine consumption and should not be marked for translation, + e.g., `die("bad revision %s", revision)`. + + - BUG("message") are for communicating the specific error to developers, + thus should not be translated. Externally Visible Names @@ -565,7 +762,7 @@ Externally Visible Names . The variable name describes the effect of tweaking this knob. The section and variable names that consist of multiple words are - formed by concatenating the words without punctuations (e.g. `-`), + formed by concatenating the words without punctuation marks (e.g. `-`), and are broken using bumpyCaps in documentation as a hint to the reader. @@ -579,7 +776,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). @@ -599,30 +796,30 @@ Writing Documentation: - Prefer succinctness and matter-of-factly describing functionality in the abstract. E.g. - --short:: Emit output in the short-format. + `--short`:: Emit output in the short-format. and avoid something like these overly verbose alternatives: - --short:: Use this to emit output in the short-format. - --short:: You can use this to get output in the short-format. - --short:: A user who prefers shorter output could.... - --short:: Should a person and/or program want shorter output, he - she/they/it can... + `--short`:: Use this to emit output in the short-format. + `--short`:: You can use this to get output in the short-format. + `--short`:: A user who prefers shorter output could.... + `--short`:: Should a person and/or program want shorter output, he + she/they/it can... This practice often eliminates the need to involve human actors in your description, but it is a good practice regardless of the avoidance of gendered pronouns. - When it becomes awkward to stick to this style, prefer "you" when - addressing the the hypothetical user, and possibly "we" when + addressing the hypothetical user, and possibly "we" when discussing how the program might react to the user. E.g. - You can use this option instead of --xyz, but we might remove + You can use this option instead of `--xyz`, but we might remove support for it in future versions. while keeping in mind that you can probably be less verbose, e.g. - Use this instead of --xyz. This option might be removed in future + Use this instead of `--xyz`. This option might be removed in future versions. - If you still need to refer to an example person that is @@ -640,26 +837,97 @@ Writing Documentation: The same general rule as for code applies -- imitate the existing conventions. - A few commented examples follow to provide reference when writing or - modifying command usage strings and synopsis sections in the manual - pages: - Placeholders are spelled in lowercase and enclosed in angle brackets: - - --sort= - --abbrev[=] +Markup: + + Literal parts (e.g. use of command-line options, command names, + branch names, URLs, pathnames (files and directories), configuration and + environment variables) must be typeset as verbatim (i.e. wrapped with + backticks): + `--pretty=oneline` + `git rev-list` + `remote.pushDefault` + `http://git.example.com` + `.git/config` + `GIT_DIR` + `HEAD` + `umask`(2) + + An environment variable must be prefixed with "$" only when referring to its + value and not when referring to the variable itself, in this case there is + nothing to add except the backticks: + `GIT_DIR` is specified + `$GIT_DIR/hooks/pre-receive` + + Word phrases enclosed in `backtick characters` are rendered literally + and will not be further expanded. The use of `backticks` to achieve the + previous rule means that literal examples should not use AsciiDoc + escapes. + Correct: + `--pretty=oneline` + Incorrect: + `\--pretty=oneline` + + Placeholders are spelled in lowercase and enclosed in + angle brackets surrounded by underscores: + __ + __ If a placeholder has multiple words, they are separated by dashes: - - --template= + __ + __ + + When needed, use a distinctive identifier for placeholders, usually + made of a qualification and a type: + __ + __ + +Characters are also surrounded by underscores: + _LF_, _CR_, _CR_/_LF_, _NUL_, _EOF_ + + Git's Asciidoc processor has been tailored to treat backticked text + as complex synopsis. When literal and placeholders are mixed, you can + use the backtick notation which will take care of correctly typesetting + the content. + `--jobs ` + `--sort=` + `/.git` + `remote..mirror` + `ssh://[@][:]/` + +As a side effect, backquoted placeholders are correctly typeset, but +this style is not recommended. + + When documenting multiple related `git config` variables, place them on + a separate line instead of separating them by commas. For example, do + not write this: + `core.var1`, `core.var2`:: + Description common to `core.var1` and `core.var2`. + +Instead write this: + `core.var1`:: + `core.var2`:: + Description common to `core.var1` and `core.var2`. + +Synopsis Syntax + + The synopsis (a paragraph with [synopsis] attribute) is automatically + formatted by the toolchain and does not need typesetting. + + A few commented examples follow to provide reference when writing or + modifying command usage strings and synopsis sections in the manual + pages: Possibility of multiple occurrences is indicated by three dots: ... (One or more of .) Optional parts are enclosed in square brackets: - [] - (Zero or one .) + [...] + (Zero or more of .) + + An optional parameter needs to be typeset with unconstrained pairs + [] --exec-path[=] (Option with an optional argument. Note that the "=" is inside the @@ -673,15 +941,25 @@ Writing Documentation: [-q | --quiet] [--utf8 | --no-utf8] + Use spacing around "|" token(s), but not immediately after opening or + before closing a [] or () pair: + Do: [-q | --quiet] + Don't: [-q|--quiet] + + Don't use spacing around "|" tokens when they're used to separate the + alternate arguments of an option: + Do: --track[=(direct|inherit)] + Don't: --track[=(direct | inherit)] + Parentheses are used for grouping: - [( | )...] + [(|)...] (Any number of either or . Parens are needed to make it clear that "..." pertains to both and .) [(-p )...] (Any number of option -p, each with one argument.) - git remote set-head (-a | -d | ) + git remote set-head (-a|-d|) (One and only one of "-a", "-d" or "" _must_ (no square brackets) be provided.) @@ -697,37 +975,6 @@ Writing Documentation: the user would type into a shell and use 'Git' (uppercase first letter) when talking about the version control system and its properties. - A few commented examples follow to provide reference when writing or - modifying paragraphs or option/command explanations that contain options - or commands: - - Literal examples (e.g. use of command-line options, command names, - branch names, URLs, pathnames (files and directories), configuration and - environment variables) must be typeset in monospace (i.e. wrapped with - backticks): - `--pretty=oneline` - `git rev-list` - `remote.pushDefault` - `http://git.example.com` - `.git/config` - `GIT_DIR` - `HEAD` - - An environment variable must be prefixed with "$" only when referring to its - value and not when referring to the variable itself, in this case there is - nothing to add except the backticks: - `GIT_DIR` is specified - `$GIT_DIR/hooks/pre-receive` - - Word phrases enclosed in `backtick characters` are rendered literally - and will not be further expanded. The use of `backticks` to achieve the - previous rule means that literal examples should not use AsciiDoc - escapes. - Correct: - `--pretty=oneline` - Incorrect: - `\--pretty=oneline` - If some place in the documentation needs to typeset a command usage example with inline substitutions, it is fine to use +monospaced and inline substituted text+ instead of `monospaced literal text`, and with diff --git a/Documentation/DecisionMaking.adoc b/Documentation/DecisionMaking.adoc new file mode 100644 index 00000000000000..b43c472ae598ed --- /dev/null +++ b/Documentation/DecisionMaking.adoc @@ -0,0 +1,74 @@ +Decision-Making Process in the Git Project +========================================== + +Introduction +------------ +This document describes the current decision-making process in the Git +project. It is a descriptive rather than prescriptive doc; that is, we want to +describe how things work in practice rather than explicitly recommending any +particular process or changes to the current process. + +Here we document how the project makes decisions for discussions +(with or without patches), in scale larger than an individual patch +series (which is fully covered by the SubmittingPatches document). + + +Larger Discussions (with patches) +--------------------------------- +As with discussions on an individual patch series, starting a larger-scale +discussion often begins by sending a patch or series to the list. This might +take the form of an initial design doc, with implementation following in later +iterations of the series (for example, +link:https://lore.kernel.org/git/0169ce6fb9ccafc089b74ae406db0d1a8ff8ac65.1688165272.git.steadmon@google.com/[adding unit tests] or +link:https://lore.kernel.org/git/20200420235310.94493-1-emilyshaffer@google.com/[config-based hooks]), +or it might include a full implementation from the beginning. +In either case, discussion progresses the same way for an individual patch series, +until consensus is reached or the topic is dropped. + + +Larger Discussions (without patches) +------------------------------------ +Occasionally, larger discussions might occur without an associated patch series. +These may be very large-scale technical decisions that are beyond the scope of +even a single large patch series, or they may be more open-ended, +policy-oriented discussions (examples: +link:https://lore.kernel.org/git/ZZ77NQkSuiRxRDwt@nand.local/[introducing Rust] +or link:https://lore.kernel.org/git/YHofmWcIAidkvJiD@google.com/[improving submodule UX]). +In either case, discussion progresses as described above for general patch series. + +For larger discussions without a patch series or other concrete implementation, +it may be hard to judge when consensus has been reached, as there are not any +official guidelines. If discussion stalls at this point, it may be helpful to +restart discussion with an RFC patch series (such as a partial, unfinished +implementation or proof of concept) that can be more easily debated. + +When consensus is reached that it is a good idea, the original +proposer is expected to coordinate the effort to make it happen, +with help from others who were involved in the discussion, as +needed. + +For decisions that require code changes, it is often the case that the original +proposer will follow up with a patch series, although it is also common for +other interested parties to provide an implementation (or parts of the +implementation, for very large changes). + +For non-technical decisions such as community norms or processes, it is up to +the community as a whole to implement and sustain agreed-upon changes. +The project leadership committee (PLC) may help the implementation of +policy decisions. + + +Other Discussion Venues +----------------------- +Occasionally decision proposals are presented off-list, e.g. at the semi-regular +Contributors' Summit. While higher-bandwidth face-to-face discussion is often +useful for quickly reaching consensus among attendees, generally we expect to +summarize the discussion in notes that can later be presented on-list. For an +example, see the thread +link:https://lore.kernel.org/git/AC2EB721-2979-43FD-922D-C5076A57F24B@jramsay.com.au/[Notes +from Git Contributor Summit, Los Angeles (April 5, 2020)] by James Ramsay. + +We prefer that "official" discussion happens on the list so that the full +community has opportunity to engage in discussion. This also means that the +mailing list archives contain a more-or-less complete history of project +discussions and decisions. diff --git a/Documentation/Makefile b/Documentation/Makefile index 1eb9192dae825f..2699f0b24af192 100644 --- a/Documentation/Makefile +++ b/Documentation/Makefile @@ -1,6 +1,11 @@ +# The default target of this Makefile is... +all:: + # Import tree-wide shared Makefile behavior and libraries include ../shared.mak +.PHONY: FORCE + # Guard against environment variables MAN1_TXT = MAN5_TXT = @@ -15,42 +20,58 @@ OBSOLETE_HTML = -include GIT-EXCLUDED-PROGRAMS MAN1_TXT += $(filter-out \ - $(patsubst %,%.txt,$(EXCLUDED_PROGRAMS)) \ - $(addsuffix .txt, $(ARTICLES) $(SP_ARTICLES)), \ - $(wildcard git-*.txt)) -MAN1_TXT += git.txt -MAN1_TXT += gitk.txt -MAN1_TXT += gitweb.txt + $(patsubst %,%.adoc,$(EXCLUDED_PROGRAMS)) \ + $(addsuffix .adoc, $(ARTICLES) $(SP_ARTICLES)), \ + $(wildcard git-*.adoc)) +MAN1_TXT += git.adoc +MAN1_TXT += gitk.adoc +MAN1_TXT += gitweb.adoc +MAN1_TXT += scalar.adoc # man5 / man7 guides (note: new guides should also be added to command-list.txt) -MAN5_TXT += gitattributes.txt -MAN5_TXT += githooks.txt -MAN5_TXT += gitignore.txt -MAN5_TXT += gitmailmap.txt -MAN5_TXT += gitmodules.txt -MAN5_TXT += gitrepository-layout.txt -MAN5_TXT += gitweb.conf.txt - -MAN7_TXT += gitcli.txt -MAN7_TXT += gitcore-tutorial.txt -MAN7_TXT += gitcredentials.txt -MAN7_TXT += gitcvs-migration.txt -MAN7_TXT += gitdiffcore.txt -MAN7_TXT += giteveryday.txt -MAN7_TXT += gitfaq.txt -MAN7_TXT += gitglossary.txt -MAN7_TXT += gitnamespaces.txt -MAN7_TXT += gitremote-helpers.txt -MAN7_TXT += gitrevisions.txt -MAN7_TXT += gitsubmodules.txt -MAN7_TXT += gittutorial-2.txt -MAN7_TXT += gittutorial.txt -MAN7_TXT += gitworkflows.txt - -HOWTO_TXT += $(wildcard howto/*.txt) - -DOC_DEP_TXT += $(wildcard *.txt) -DOC_DEP_TXT += $(wildcard config/*.txt) +MAN5_TXT += gitattributes.adoc +MAN5_TXT += gitformat-bundle.adoc +MAN5_TXT += gitformat-chunk.adoc +MAN5_TXT += gitformat-commit-graph.adoc +MAN5_TXT += gitformat-index.adoc +MAN5_TXT += gitformat-loose.adoc +MAN5_TXT += gitformat-pack.adoc +MAN5_TXT += gitformat-signature.adoc +MAN5_TXT += githooks.adoc +MAN5_TXT += gitignore.adoc +MAN5_TXT += gitmailmap.adoc +MAN5_TXT += gitmodules.adoc +MAN5_TXT += gitprotocol-capabilities.adoc +MAN5_TXT += gitprotocol-common.adoc +MAN5_TXT += gitprotocol-http.adoc +MAN5_TXT += gitprotocol-pack.adoc +MAN5_TXT += gitprotocol-v2.adoc +MAN5_TXT += gitrepository-layout.adoc +MAN5_TXT += gitweb.conf.adoc + +MAN7_TXT += gitcli.adoc +MAN7_TXT += gitcore-tutorial.adoc +MAN7_TXT += gitcredentials.adoc +MAN7_TXT += gitcvs-migration.adoc +MAN7_TXT += gitdatamodel.adoc +MAN7_TXT += gitdiffcore.adoc +MAN7_TXT += giteveryday.adoc +MAN7_TXT += gitfaq.adoc +MAN7_TXT += gitglossary.adoc +MAN7_TXT += gitpacking.adoc +MAN7_TXT += gitnamespaces.adoc +MAN7_TXT += gitremote-helpers.adoc +MAN7_TXT += gitrevisions.adoc +MAN7_TXT += gitsubmodules.adoc +MAN7_TXT += gittutorial-2.adoc +MAN7_TXT += gittutorial.adoc +MAN7_TXT += gitworkflows.adoc + +HOWTO_TXT += $(wildcard howto/*.adoc) + +DOC_DEP_TXT += $(wildcard *.adoc) +DOC_DEP_TXT += $(wildcard config/*.adoc) +DOC_DEP_TXT += $(wildcard includes/*.adoc) ifdef MAN_FILTER MAN_TXT = $(filter $(MAN_FILTER),$(MAN1_TXT) $(MAN5_TXT) $(MAN7_TXT)) @@ -59,8 +80,8 @@ MAN_TXT = $(MAN1_TXT) $(MAN5_TXT) $(MAN7_TXT) MAN_FILTER = $(MAN_TXT) endif -MAN_XML = $(patsubst %.txt,%.xml,$(MAN_TXT)) -MAN_HTML = $(patsubst %.txt,%.html,$(MAN_TXT)) +MAN_XML = $(patsubst %.adoc,%.xml,$(MAN_TXT)) +MAN_HTML = $(patsubst %.adoc,%.html,$(MAN_TXT)) GIT_MAN_REF = master OBSOLETE_HTML += everyday.html @@ -87,32 +108,43 @@ SP_ARTICLES += howto/rebase-from-internal-branch SP_ARTICLES += howto/keep-canonical-history-correct SP_ARTICLES += howto/maintain-git SP_ARTICLES += howto/coordinate-embargoed-releases -API_DOCS = $(patsubst %.txt,%,$(filter-out technical/api-index-skel.txt technical/api-index.txt, $(wildcard technical/api-*.txt))) +API_DOCS = $(patsubst %.adoc,%,$(filter-out technical/api-index-skel.adoc technical/api-index.adoc, $(wildcard technical/api-*.adoc))) SP_ARTICLES += $(API_DOCS) +TECH_DOCS += BreakingChanges +TECH_DOCS += DecisionMaking +TECH_DOCS += ReviewingGuidelines TECH_DOCS += MyFirstContribution TECH_DOCS += MyFirstObjectWalk TECH_DOCS += SubmittingPatches -TECH_DOCS += technical/bundle-format +TECH_DOCS += ToolsForGit +TECH_DOCS += technical/bitmap-format +TECH_DOCS += technical/build-systems +TECH_DOCS += technical/bundle-uri +TECH_DOCS += technical/commit-graph +TECH_DOCS += technical/directory-rename-detection TECH_DOCS += technical/hash-function-transition -TECH_DOCS += technical/http-protocol -TECH_DOCS += technical/index-format +TECH_DOCS += technical/large-object-promisors TECH_DOCS += technical/long-running-process-protocol TECH_DOCS += technical/multi-pack-index -TECH_DOCS += technical/pack-format +TECH_DOCS += technical/packfile-uri TECH_DOCS += technical/pack-heuristics -TECH_DOCS += technical/pack-protocol TECH_DOCS += technical/parallel-checkout TECH_DOCS += technical/partial-clone -TECH_DOCS += technical/protocol-capabilities -TECH_DOCS += technical/protocol-common -TECH_DOCS += technical/protocol-v2 +TECH_DOCS += technical/platform-support TECH_DOCS += technical/racy-git TECH_DOCS += technical/reftable +TECH_DOCS += technical/remembering-renames +TECH_DOCS += technical/repository-version +TECH_DOCS += technical/rerere +TECH_DOCS += technical/scalar TECH_DOCS += technical/send-pack-pipeline TECH_DOCS += technical/shallow -TECH_DOCS += technical/signature-format +TECH_DOCS += technical/sparse-checkout +TECH_DOCS += technical/sparse-index TECH_DOCS += technical/trivial-merge +TECH_DOCS += technical/unambiguous-types +TECH_DOCS += technical/unit-tests SP_ARTICLES += $(TECH_DOCS) SP_ARTICLES += technical/api-index @@ -120,9 +152,9 @@ ARTICLES_HTML += $(patsubst %,%.html,$(ARTICLES) $(SP_ARTICLES)) HTML_FILTER ?= $(ARTICLES_HTML) $(OBSOLETE_HTML) DOC_HTML = $(MAN_HTML) $(filter $(HTML_FILTER),$(ARTICLES_HTML) $(OBSOLETE_HTML)) -DOC_MAN1 = $(patsubst %.txt,%.1,$(filter $(MAN_FILTER),$(MAN1_TXT))) -DOC_MAN5 = $(patsubst %.txt,%.5,$(filter $(MAN_FILTER),$(MAN5_TXT))) -DOC_MAN7 = $(patsubst %.txt,%.7,$(filter $(MAN_FILTER),$(MAN7_TXT))) +DOC_MAN1 = $(patsubst %.adoc,%.1,$(filter $(MAN_FILTER),$(MAN1_TXT))) +DOC_MAN5 = $(patsubst %.adoc,%.5,$(filter $(MAN_FILTER),$(MAN5_TXT))) +DOC_MAN7 = $(patsubst %.adoc,%.7,$(filter $(MAN_FILTER),$(MAN7_TXT))) prefix ?= $(HOME) bindir ?= $(prefix)/bin @@ -140,9 +172,7 @@ ASCIIDOC_EXTRA = ASCIIDOC_HTML = xhtml11 ASCIIDOC_DOCBOOK = docbook ASCIIDOC_CONF = -f asciidoc.conf -ASCIIDOC_COMMON = $(ASCIIDOC) $(ASCIIDOC_EXTRA) $(ASCIIDOC_CONF) \ - -amanversion=$(GIT_VERSION) \ - -amanmanual='Git Manual' -amansource='Git' +ASCIIDOC_COMMON = $(ASCIIDOC) $(ASCIIDOC_EXTRA) $(ASCIIDOC_CONF) ASCIIDOC_DEPS = asciidoc.conf GIT-ASCIIDOCFLAGS TXT_TO_HTML = $(ASCIIDOC_COMMON) -b $(ASCIIDOC_HTML) TXT_TO_XML = $(ASCIIDOC_COMMON) -b $(ASCIIDOC_DOCBOOK) @@ -167,6 +197,10 @@ endif -include ../config.mak.autogen -include ../config.mak +# Set GIT_VERSION_OVERRIDE such that version_gen knows to substitute +# GIT_VERSION in case it was set by the user. +GIT_VERSION_OVERRIDE := $(GIT_VERSION) + ifndef NO_MAN_BOLD_LITERAL XMLTO_EXTRA += -m manpage-bold-literal.xsl endif @@ -180,15 +214,7 @@ endif ifndef MAN_BASE_URL MAN_BASE_URL = file://$(htmldir)/ endif -XMLTO_EXTRA += -m manpage-base-url.xsl - -# If your target system uses GNU groff, it may try to render -# apostrophes as a "pretty" apostrophe using unicode. This breaks -# cut&paste, so you should set GNU_ROFF to force them to be ASCII -# apostrophes. Unfortunately does not work with non-GNU roff. -ifdef GNU_ROFF -XMLTO_EXTRA += -m manpage-quote-apos.xsl -endif +XMLTO_EXTRA += --stringparam man.base.url.for.relative.links='$(MAN_BASE_URL)' ifdef USE_ASCIIDOCTOR ASCIIDOC = asciidoctor @@ -198,16 +224,30 @@ ASCIIDOC_DOCBOOK = docbook5 ASCIIDOC_EXTRA += -acompat-mode -atabsize=8 ASCIIDOC_EXTRA += -I. -rasciidoctor-extensions ASCIIDOC_EXTRA += -alitdd='&\#x2d;&\#x2d;' +ASCIIDOC_EXTRA += -adocinfo=shared ASCIIDOC_DEPS = asciidoctor-extensions.rb GIT-ASCIIDOCFLAGS DBLATEX_COMMON = XMLTO_EXTRA += --skip-validation XMLTO_EXTRA += -x manpage.xsl + +asciidoctor-extensions.rb: asciidoctor-extensions.rb.in FORCE + $(QUIET_GEN)$(call version_gen,"$(shell pwd)/..",$<,$@) +else +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) # Shell quote; SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH)) +ASCIIDOC_EXTRA += -abuild_dir='$(shell pwd)' ifdef DEFAULT_PAGER DEFAULT_PAGER_SQ = $(subst ','\'',$(DEFAULT_PAGER)) ASCIIDOC_EXTRA += -a 'git-default-pager=$(DEFAULT_PAGER_SQ)' @@ -218,7 +258,7 @@ DEFAULT_EDITOR_SQ = $(subst ','\'',$(DEFAULT_EDITOR)) ASCIIDOC_EXTRA += -a 'git-default-editor=$(DEFAULT_EDITOR_SQ)' endif -all: html man +all:: html man html: $(DOC_HTML) @@ -258,57 +298,46 @@ install-pdf: pdf install-html: html '$(SHELL_PATH_SQ)' ./install-webdoc.sh $(DESTDIR)$(htmldir) -../GIT-VERSION-FILE: FORCE - $(QUIET_SUBDIR0)../ $(QUIET_SUBDIR1) GIT-VERSION-FILE - -ifneq ($(filter-out lint-docs clean,$(MAKECMDGOALS)),) --include ../GIT-VERSION-FILE -endif +mergetools_txt = mergetools-diff.adoc mergetools-merge.adoc # # Determine "include::" file references in asciidoc files. # docdep_prereqs = \ - mergetools-list.made $(mergetools_txt) \ + $(mergetools_txt) \ cmd-list.made $(cmds_txt) doc.dep : $(docdep_prereqs) $(DOC_DEP_TXT) build-docdep.perl - $(QUIET_GEN)$(PERL_PATH) ./build-docdep.perl >$@ $(QUIET_STDERR) + $(QUIET_GEN)$(PERL_PATH) ./build-docdep.perl "$(shell pwd)" >$@ $(QUIET_STDERR) ifneq ($(MAKECMDGOALS),clean) -include doc.dep endif -cmds_txt = cmds-ancillaryinterrogators.txt \ - cmds-ancillarymanipulators.txt \ - cmds-mainporcelain.txt \ - cmds-plumbinginterrogators.txt \ - cmds-plumbingmanipulators.txt \ - cmds-synchingrepositories.txt \ - cmds-synchelpers.txt \ - cmds-guide.txt \ - cmds-purehelpers.txt \ - cmds-foreignscminterface.txt +cmds_txt = cmds-ancillaryinterrogators.adoc \ + cmds-ancillarymanipulators.adoc \ + cmds-mainporcelain.adoc \ + cmds-plumbinginterrogators.adoc \ + cmds-plumbingmanipulators.adoc \ + cmds-synchingrepositories.adoc \ + cmds-synchelpers.adoc \ + cmds-guide.adoc \ + cmds-developerinterfaces.adoc \ + cmds-userinterfaces.adoc \ + cmds-purehelpers.adoc \ + cmds-foreignscminterface.adoc $(cmds_txt): cmd-list.made -cmd-list.made: cmd-list.perl ../command-list.txt $(MAN1_TXT) - $(QUIET_GEN)$(PERL_PATH) ./cmd-list.perl ../command-list.txt $(cmds_txt) $(QUIET_STDERR) && \ +cmd-list.made: cmd-list.sh ../command-list.txt $(MAN1_TXT) + $(QUIET_GEN)$(SHELL_PATH) ./cmd-list.sh .. . $(cmds_txt) && \ date >$@ -mergetools_txt = mergetools-diff.txt mergetools-merge.txt - -$(mergetools_txt): mergetools-list.made - -mergetools-list.made: ../git-mergetool--lib.sh $(wildcard ../mergetools/*) - $(QUIET_GEN) \ - $(SHELL_PATH) -c 'MERGE_TOOLS_DIR=../mergetools && \ - . ../git-mergetool--lib.sh && \ - show_tool_names can_diff "* " || :' >mergetools-diff.txt && \ - $(SHELL_PATH) -c 'MERGE_TOOLS_DIR=../mergetools && \ - . ../git-mergetool--lib.sh && \ - show_tool_names can_merge "* " || :' >mergetools-merge.txt && \ - date >$@ +mergetools-%.adoc: generate-mergetool-list.sh ../git-mergetool--lib.sh $(wildcard ../mergetools/*) +mergetools-diff.adoc: + $(QUIET_GEN)$(SHELL_PATH) ./generate-mergetool-list.sh .. diff $@ +mergetools-merge.adoc: + $(QUIET_GEN)$(SHELL_PATH) ./generate-mergetool-list.sh .. merge $@ TRACK_ASCIIDOCFLAGS = $(subst ','\'',$(ASCIIDOC_COMMON):$(ASCIIDOC_HTML):$(ASCIIDOC_DOCBOOK)) @@ -324,41 +353,49 @@ clean: $(RM) *.xml *.xml+ *.html *.html+ *.1 *.5 *.7 $(RM) *.texi *.texi+ *.texi++ git.info gitman.info $(RM) *.pdf - $(RM) howto-index.txt howto/*.html doc.dep - $(RM) technical/*.html technical/api-index.txt - $(RM) SubmittingPatches.txt + $(RM) howto-index.adoc howto/*.html doc.dep + $(RM) technical/*.html technical/api-index.adoc + $(RM) SubmittingPatches.adoc $(RM) $(cmds_txt) $(mergetools_txt) *.made - $(RM) manpage-base-url.xsl $(RM) GIT-ASCIIDOCFLAGS + $(RM) asciidoc.conf asciidoctor-extensions.rb + $(RM) -rf tmp-meson-diff + +docinfo.html: docinfo-html.in + $(QUIET_GEN)$(RM) $@ && cat $< >$@ -$(MAN_HTML): %.html : %.txt $(ASCIIDOC_DEPS) +$(MAN_HTML): %.html : %.adoc $(ASCIIDOC_DEPS) $(QUIET_ASCIIDOC)$(TXT_TO_HTML) -d manpage -o $@ $< -$(OBSOLETE_HTML): %.html : %.txto $(ASCIIDOC_DEPS) +$(OBSOLETE_HTML): %.html : %.adoco $(ASCIIDOC_DEPS) $(QUIET_ASCIIDOC)$(TXT_TO_HTML) -o $@ $< -manpage-base-url.xsl: manpage-base-url.xsl.in - $(QUIET_GEN)sed "s|@@MAN_BASE_URL@@|$(MAN_BASE_URL)|" $< > $@ +manpage-prereqs := $(wildcard manpage*.xsl) +manpage-cmd = $(QUIET_XMLTO)$(XMLTO) -m $(MANPAGE_XSL) $(XMLTO_EXTRA) man $< -%.1 %.5 %.7 : %.xml manpage-base-url.xsl $(wildcard manpage*.xsl) - $(QUIET_XMLTO)$(XMLTO) -m $(MANPAGE_XSL) $(XMLTO_EXTRA) man $< +%.1 : %.xml $(manpage-prereqs) + $(manpage-cmd) +%.5 : %.xml $(manpage-prereqs) + $(manpage-cmd) +%.7 : %.xml $(manpage-prereqs) + $(manpage-cmd) -%.xml : %.txt $(ASCIIDOC_DEPS) +%.xml : %.adoc $(ASCIIDOC_DEPS) $(QUIET_ASCIIDOC)$(TXT_TO_XML) -d manpage -o $@ $< -user-manual.xml: user-manual.txt user-manual.conf asciidoctor-extensions.rb GIT-ASCIIDOCFLAGS +user-manual.xml: user-manual.adoc $(ASCIIDOC_DEPS) $(QUIET_ASCIIDOC)$(TXT_TO_XML) -d book -o $@ $< -technical/api-index.txt: technical/api-index-skel.txt \ - technical/api-index.sh $(patsubst %,%.txt,$(API_DOCS)) - $(QUIET_GEN)cd technical && '$(SHELL_PATH_SQ)' ./api-index.sh +technical/api-index.adoc: technical/api-index-skel.adoc \ + technical/api-index.sh $(patsubst %,%.adoc,$(API_DOCS)) + $(QUIET_GEN)'$(SHELL_PATH_SQ)' technical/api-index.sh ./technical ./technical/api-index.adoc technical/%.html: ASCIIDOC_EXTRA += -a git-relative-html-prefix=../ -$(patsubst %,%.html,$(API_DOCS) technical/api-index $(TECH_DOCS)): %.html : %.txt \ - asciidoc.conf GIT-ASCIIDOCFLAGS - $(QUIET_ASCIIDOC)$(TXT_TO_HTML) $*.txt +$(patsubst %,%.html,$(API_DOCS) technical/api-index $(TECH_DOCS)): %.html : %.adoc \ + $(ASCIIDOC_DEPS) + $(QUIET_ASCIIDOC)$(TXT_TO_HTML) $*.adoc -SubmittingPatches.txt: SubmittingPatches +SubmittingPatches.adoc: SubmittingPatches $(QUIET_GEN) cp $< $@ XSLT = docbook.xsl @@ -373,9 +410,9 @@ user-manual.html: user-manual.xml $(XSLT) git.info: user-manual.texi $(QUIET_MAKEINFO)$(MAKEINFO) --no-split -o $@ user-manual.texi -user-manual.texi: user-manual.xml +user-manual.texi: user-manual.xml fix-texi.sh $(QUIET_DB2TEXI)$(DOCBOOK2X_TEXI) user-manual.xml --encoding=UTF-8 --to-stdout >$@+ && \ - $(PERL_PATH) fix-texi.perl <$@+ >$@ && \ + $(SHELL_PATH) fix-texi.sh <$@+ >$@ && \ $(RM) $@+ user-manual.pdf: user-manual.xml @@ -390,21 +427,21 @@ gitman.texi: $(MAN_XML) cat-texi.perl texi.xsl $(RM) $@+ gitman.info: gitman.texi - $(QUIET_MAKEINFO)$(MAKEINFO) --no-split --no-validate $*.texi + $(QUIET_MAKEINFO)$(MAKEINFO) --no-split --no-validate $< -$(patsubst %.txt,%.texi,$(MAN_TXT)): %.texi : %.xml +$(patsubst %.adoc,%.texi,$(MAN_TXT)): %.texi : %.xml $(QUIET_DB2TEXI)$(DOCBOOK2X_TEXI) --to-stdout $*.xml >$@ -howto-index.txt: howto-index.sh $(HOWTO_TXT) - $(QUIET_GEN)'$(SHELL_PATH_SQ)' ./howto-index.sh $(sort $(HOWTO_TXT)) >$@ +howto-index.adoc: howto/howto-index.sh $(HOWTO_TXT) + $(QUIET_GEN)'$(SHELL_PATH_SQ)' ./howto/howto-index.sh $(sort $(HOWTO_TXT)) >$@ -$(patsubst %,%.html,$(ARTICLES)) : %.html : %.txt - $(QUIET_ASCIIDOC)$(TXT_TO_HTML) $*.txt +$(patsubst %,%.html,$(ARTICLES)) : %.html : %.adoc $(ASCIIDOC_DEPS) + $(QUIET_ASCIIDOC)$(TXT_TO_HTML) $*.adoc WEBDOC_DEST = /pub/software/scm/git/docs howto/%.html: ASCIIDOC_EXTRA += -a git-relative-html-prefix=../ -$(patsubst %.txt,%.html,$(HOWTO_TXT)): %.html : %.txt GIT-ASCIIDOCFLAGS +$(patsubst %.adoc,%.html,$(HOWTO_TXT)): %.html : %.adoc $(ASCIIDOC_DEPS) $(QUIET_ASCIIDOC) \ sed -e '1,/^$$/d' $< | \ $(TXT_TO_HTML) - >$@ @@ -435,9 +472,9 @@ print-man1: @for i in $(MAN1_TXT); do echo $$i; done ## Lint: gitlink -LINT_DOCS_GITLINK = $(patsubst %.txt,.build/lint-docs/gitlink/%.ok,$(HOWTO_TXT) $(DOC_DEP_TXT)) +LINT_DOCS_GITLINK = $(patsubst %.adoc,.build/lint-docs/gitlink/%.ok,$(HOWTO_TXT) $(DOC_DEP_TXT)) $(LINT_DOCS_GITLINK): lint-gitlink.perl -$(LINT_DOCS_GITLINK): .build/lint-docs/gitlink/%.ok: %.txt +$(LINT_DOCS_GITLINK): .build/lint-docs/gitlink/%.ok: %.adoc $(call mkdir_p_parent_template) $(QUIET_LINT_GITLINK)$(PERL_PATH) lint-gitlink.perl \ $< \ @@ -449,27 +486,81 @@ $(LINT_DOCS_GITLINK): .build/lint-docs/gitlink/%.ok: %.txt lint-docs-gitlink: $(LINT_DOCS_GITLINK) ## Lint: man-end-blurb -LINT_DOCS_MAN_END_BLURB = $(patsubst %.txt,.build/lint-docs/man-end-blurb/%.ok,$(MAN_TXT)) +LINT_DOCS_MAN_END_BLURB = $(patsubst %.adoc,.build/lint-docs/man-end-blurb/%.ok,$(MAN_TXT)) $(LINT_DOCS_MAN_END_BLURB): lint-man-end-blurb.perl -$(LINT_DOCS_MAN_END_BLURB): .build/lint-docs/man-end-blurb/%.ok: %.txt +$(LINT_DOCS_MAN_END_BLURB): .build/lint-docs/man-end-blurb/%.ok: %.adoc $(call mkdir_p_parent_template) $(QUIET_LINT_MANEND)$(PERL_PATH) lint-man-end-blurb.perl $< >$@ .PHONY: lint-docs-man-end-blurb ## Lint: man-section-order -LINT_DOCS_MAN_SECTION_ORDER = $(patsubst %.txt,.build/lint-docs/man-section-order/%.ok,$(MAN_TXT)) +LINT_DOCS_MAN_SECTION_ORDER = $(patsubst %.adoc,.build/lint-docs/man-section-order/%.ok,$(MAN_TXT)) $(LINT_DOCS_MAN_SECTION_ORDER): lint-man-section-order.perl -$(LINT_DOCS_MAN_SECTION_ORDER): .build/lint-docs/man-section-order/%.ok: %.txt +$(LINT_DOCS_MAN_SECTION_ORDER): .build/lint-docs/man-section-order/%.ok: %.adoc $(call mkdir_p_parent_template) $(QUIET_LINT_MANSEC)$(PERL_PATH) lint-man-section-order.perl $< >$@ .PHONY: lint-docs-man-section-order lint-docs-man-section-order: $(LINT_DOCS_MAN_SECTION_ORDER) +.PHONY: lint-docs-fsck-msgids +LINT_DOCS_FSCK_MSGIDS = .build/lint-docs/fsck-msgids.ok +$(LINT_DOCS_FSCK_MSGIDS): lint-fsck-msgids.perl +$(LINT_DOCS_FSCK_MSGIDS): ../fsck.h fsck-msgids.adoc + $(call mkdir_p_parent_template) + $(QUIET_GEN)$(PERL_PATH) lint-fsck-msgids.perl \ + ../fsck.h fsck-msgids.adoc $@ +lint-docs-fsck-msgids: $(LINT_DOCS_FSCK_MSGIDS) + +## Lint: delimited sections +LINT_DOCS_DELIMITED_SECTIONS = $(patsubst %.adoc,.build/lint-docs/delimited-sections/%.ok,$(MAN_TXT)) +$(LINT_DOCS_DELIMITED_SECTIONS): lint-delimited-sections.perl +$(LINT_DOCS_DELIMITED_SECTIONS): .build/lint-docs/delimited-sections/%.ok: %.adoc + $(call mkdir_p_parent_template) + $(QUIET_LINT_DELIMSEC)$(PERL_PATH) lint-delimited-sections.perl $< >$@ +.PHONY: lint-docs-delimited-sections +lint-docs-delimited-sections: $(LINT_DOCS_DELIMITED_SECTIONS) + +## Lint: Documentation style +LINT_DOCS_DOC_STYLE = $(patsubst %.adoc,.build/lint-docs/doc-style/%.ok,$(DOC_DEP_TXT)) +$(LINT_DOCS_DOC_STYLE): lint-documentation-style.perl +$(LINT_DOCS_DOC_STYLE): .build/lint-docs/doc-style/%.ok: %.adoc + $(call mkdir_p_parent_template) + $(QUIET_LINT_DOCSTYLE)$(PERL_PATH) lint-documentation-style.perl $< >$@ +.PHONY: lint-docs-doc-style +lint-docs-doc-style: $(LINT_DOCS_DOC_STYLE) + +lint-docs-manpages: + $(QUIET_GEN)./lint-manpages.sh + +.PHONY: lint-docs-meson +lint-docs-meson: + @# awk acts up when trying to match single quotes, so we use \047 instead. + @mkdir -p tmp-meson-diff && \ + awk "/^manpages = {$$/ {flag=1 ; next } /^}$$/ { flag=0 } flag { gsub(/^ \047/, \"\"); gsub(/\047 : [157],\$$/, \"\"); print }" meson.build | \ + grep -v -e '#' -e '^$$' | \ + sort >tmp-meson-diff/meson.adoc && \ + ls git*.adoc scalar.adoc | \ + grep -v -e git-bisect-lk2009.adoc \ + -e git-pack-redundant.adoc \ + -e git-tools.adoc \ + -e git-whatchanged.adoc \ + >tmp-meson-diff/actual.adoc && \ + if ! cmp tmp-meson-diff/meson.adoc tmp-meson-diff/actual.adoc; then \ + echo "Meson man pages differ from actual man pages:"; \ + diff -u tmp-meson-diff/meson.adoc tmp-meson-diff/actual.adoc; \ + exit 1; \ + fi + ## Lint: list of targets above .PHONY: lint-docs +lint-docs: lint-docs-fsck-msgids lint-docs: lint-docs-gitlink lint-docs: lint-docs-man-end-blurb lint-docs: lint-docs-man-section-order +lint-docs: lint-docs-delimited-sections +lint-docs: lint-docs-doc-style +lint-docs: lint-docs-manpages +lint-docs: lint-docs-meson ifeq ($(wildcard po/Makefile),po/Makefile) doc-l10n install-l10n:: diff --git a/Documentation/MyFirstContribution.adoc b/Documentation/MyFirstContribution.adoc new file mode 100644 index 00000000000000..f186dfbc898fd4 --- /dev/null +++ b/Documentation/MyFirstContribution.adoc @@ -0,0 +1,1424 @@ +My First Contribution to the Git Project +======================================== +:sectanchors: + +[[summary]] +== Summary + +This is a tutorial demonstrating the end-to-end workflow of creating a change to +the Git tree, sending it for review, and making changes based on comments. + +[[prerequisites]] +=== Prerequisites + +This tutorial assumes you're already fairly familiar with using Git to manage +source code. The Git workflow steps will largely remain unexplained. + +[[related-reading]] +=== Related Reading + +This tutorial aims to summarize the following documents, but the reader may find +useful additional context: + +- `Documentation/SubmittingPatches` +- `Documentation/howto/new-command.adoc` + +[[getting-help]] +=== Getting Help + +If you get stuck, you can seek help in the following places. + +==== git@vger.kernel.org + +This is the main Git project mailing list where code reviews, version +announcements, design discussions, and more take place. Those interested in +contributing are welcome to post questions here. The Git list requires +plain-text-only emails and prefers inline and bottom-posting when replying to +mail; you will be CC'd in all replies to you. Optionally, you can subscribe to +the list by sending an email to +(see https://subspace.kernel.org/subscribing.html for details). +The https://lore.kernel.org/git[archive] of this mailing list is +available to view in a browser. + +==== https://web.libera.chat/#git-devel[#git-devel] on Libera Chat + +This IRC channel is for conversations between Git contributors. If someone is +currently online and knows the answer to your question, you can receive help +in real time. Otherwise, you can read the +https://colabti.org/irclogger/irclogger_logs/git-devel[scrollback] to see +whether someone answered you. IRC does not allow offline private messaging, so +if you try to private message someone and then log out of IRC, they cannot +respond to you. It's better to ask your questions in the channel so that you +can be answered if you disconnect and so that others can learn from the +conversation. + +==== https://discord.gg/GRFVkzgxRd[#discord] on Discord +This is an unofficial Git Discord server for everyone, from people just +starting out with Git to those who develop it. It's a great place to ask +questions, share tips, and connect with the broader Git community in real time. + +The server has channels for general discussions and specific channels for those +who use Git and those who develop it. The server's search functionality also +allows you to find previous conversations and answers to common questions. + +[[getting-started]] +== Getting Started + +[[cloning]] +=== Clone the Git Repository + +Git is mirrored in a number of locations. Clone the repository from one of them; +https://git-scm.com/downloads suggests one of the best places to clone from is +the mirror on GitHub. + +---- +$ git clone https://github.com/git/git git +$ cd git +---- + +[[dependencies]] +=== Installing Dependencies + +To build Git from source, you need to have a handful of dependencies installed +on your system. For a hint of what's needed, you can take a look at +`INSTALL`, paying close attention to the section about Git's dependencies on +external programs and libraries. That document mentions a way to "test-drive" +our freshly built Git without installing; that's the method we'll be using in +this tutorial. + +Make sure that your environment has everything you need by building your brand +new clone of Git from the above step: + +---- +$ make +---- + +NOTE: The Git build is parallelizable. `-j#` is not included above but you can +use it as you prefer, here and elsewhere. + +[[identify-problem]] +=== Identify Problem to Solve + +//// +Use + to indicate fixed-width here; couldn't get ` to work nicely with the +quotes around "Pony Saying 'Um, Hello'". +//// +In this tutorial, we will add a new command, +git psuh+, short for ``Pony Saying +`Um, Hello''' - a feature which has gone unimplemented despite a high frequency +of invocation during users' typical daily workflow. + +(We've seen some other effort in this space with the implementation of popular +commands such as `sl`.) + +[[setup-workspace]] +=== Set Up Your Workspace + +Let's start by making a development branch to work on our changes. Per +`Documentation/SubmittingPatches`, since a brand new command is a new feature, +it's fine to base your work on `master`. However, in the future for bugfixes, +etc., you should check that document and base it on the appropriate branch. + +For the purposes of this document, we will base all our work on the `master` +branch of the upstream project. Create the `psuh` branch you will use for +development like so: + +---- +$ git checkout -b psuh origin/master +---- + +We'll make a number of commits here in order to demonstrate how to send a topic +with multiple patches up for review simultaneously. + +[[code-it-up]] +== Code It Up! + +NOTE: A reference implementation can be found at +https://github.com/nasamuffin/git/tree/psuh. + +[[add-new-command]] +=== Adding a New Command + +Lots of the subcommands are written as builtins, which means they are +implemented in C and compiled into the main `git` executable. Implementing the +very simple `psuh` command as a built-in will demonstrate the structure of the +codebase, the internal API, and the process of working together as a contributor +with the reviewers and maintainer to integrate this change into the system. + +Built-in subcommands are typically implemented in a function named "cmd_" +followed by the name of the subcommand, in a source file named after the +subcommand and contained within `builtin/`. So it makes sense to implement your +command in `builtin/psuh.c`. Create that file, and within it, write the entry +point for your command in a function matching the style and signature: + +---- +int cmd_psuh(int argc UNUSED, const char **argv UNUSED, + const char *prefix UNUSED, struct repository *repo UNUSED) +---- + +A few things to note: + +* A subcommand implementation takes its command line arguments + in `int argc` + `const char **argv`, like `main()` would. + +* It also takes two extra parameters, `prefix` and `repo`. What + they mean will not be discussed until much later. + +* Because this first example will not use any of the parameters, + your compiler will give warnings on unused parameters. As the + list of these four parameters is mandated by the API to add + new built-in commands, you cannot omit them. Instead, you add + `UNUSED` to each of them to tell the compiler that you *know* + you are not (yet) using it. + +We'll also need to add the declaration of psuh; open up `builtin.h`, find the +declaration for `cmd_pull`, and add a new line for `psuh` immediately before it, +in order to keep the declarations alphabetically sorted: + +---- +int cmd_psuh(int argc, const char **argv, const char *prefix, struct repository *repo); +---- + +Be sure to `#include "builtin.h"` in your `psuh.c`. You'll also need to +`#include "gettext.h"` to use functions related to printing output text. + +Go ahead and add some throwaway printf to the `cmd_psuh` function. This is a +decent starting point as we can now add build rules and register the command. + +NOTE: Your throwaway text, as well as much of the text you will be adding over +the course of this tutorial, is user-facing. That means it needs to be +localizable. Take a look at `po/README` under "Marking strings for translation". +Throughout the tutorial, we will mark strings for translation as necessary; you +should also do so when writing your user-facing commands in the future. + +---- +int cmd_psuh(int argc UNUSED, const char **argv UNUSED, + const char *prefix UNUSED, struct repository *repo UNUSED) +{ + printf(_("Pony saying hello goes here.\n")); + return 0; +} +---- + +Let's try to build it. Open `Makefile`, find where `builtin/pull.o` is added +to `BUILTIN_OBJS`, and add `builtin/psuh.o` in the same way next to it in +alphabetical order. Once you've done so, move to the top-level directory and +build simply with `make`. Also add the `DEVELOPER=1` variable to turn on +some additional warnings: + +---- +$ echo DEVELOPER=1 >config.mak +$ make +---- + +NOTE: When you are developing the Git project, it's preferred that you use the +`DEVELOPER` flag; if there's some reason it doesn't work for you, you can turn +it off, but it's a good idea to mention the problem to the mailing list. + +Great, now your new command builds happily on its own. But nobody invokes it. +Let's change that. + +The list of commands lives in `git.c`. We can register a new command by adding +a `cmd_struct` to the `commands[]` array. `struct cmd_struct` takes a string +with the command name, a function pointer to the command implementation, and a +setup option flag. For now, let's keep mimicking `push`. Find the line where +`cmd_push` is registered, copy it, and modify it for `cmd_psuh`, placing the new +line in alphabetical order (immediately before `cmd_pull`). + +The options are documented in `builtin.h` under "Adding a new built-in." Since +we hope to print some data about the user's current workspace context later, +we need a Git directory, so choose `RUN_SETUP` as your only option. + +Go ahead and build again. You should see a clean build, so let's kick the tires +and see if it works. There's a binary you can use to test with in the +`bin-wrappers` directory. + +---- +$ ./bin-wrappers/git psuh +---- + +Check it out! You've got a command! Nice work! Let's commit this. + +`git status` reveals modified `Makefile`, `builtin.h`, and `git.c` as well as +untracked `builtin/psuh.c` and `git-psuh`. First, let's take care of the binary, +which should be ignored. Open `.gitignore` in your editor, find `/git-pull`, and +add an entry for your new command in alphabetical order: + +---- +... +/git-prune-packed +/git-psuh +/git-pull +/git-push +/git-quiltimport +/git-range-diff +... +---- + +Checking `git status` again should show that `git-psuh` has been removed from +the untracked list and `.gitignore` has been added to the modified list. Now we +can stage and commit: + +---- +$ git add Makefile builtin.h builtin/psuh.c git.c .gitignore +$ git commit -s +---- + +You will be presented with your editor in order to write a commit message. Start +the commit with a 50-column or less subject line, including the name of the +component you're working on, followed by a blank line (always required) and then +the body of your commit message, which should provide the bulk of the context. +Remember to be explicit and provide the "Why" of your change, especially if it +couldn't easily be understood from your diff. When editing your commit message, +don't remove the `Signed-off-by` trailer which was added by `-s` above. + +---- +psuh: add a built-in by popular demand + +Internal metrics indicate this is a command many users expect to be +present. So here's an implementation to help drive customer +satisfaction and engagement: a pony which doubtfully greets the user, +or, a Pony Saying "Um, Hello" (PSUH). + +This commit message is intentionally formatted to 72 columns per line, +starts with a single line as "commit message subject" that is written as +if to command the codebase to do something (add this, teach a command +that). The body of the message is designed to add information about the +commit that is not readily deduced from reading the associated diff, +such as answering the question "why?". + +Signed-off-by: A U Thor +---- + +Go ahead and inspect your new commit with `git show`. "psuh:" indicates you +have modified mainly the `psuh` command. The subject line gives readers an idea +of what you've changed. The sign-off line (`-s`) indicates that you agree to +the Developer's Certificate of Origin 1.1 (see the +`Documentation/SubmittingPatches` +++[[dco]]+++ header). + +For the remainder of the tutorial, the subject line only will be listed for the +sake of brevity. However, fully-fleshed example commit messages are available +on the reference implementation linked at the top of this document. + +[[implementation]] +=== Implementation + +It's probably useful to do at least something besides printing out a string. +Let's start by having a look at everything we get. + +Modify your `cmd_psuh` implementation to dump the args you're passed, +keeping existing `printf()` calls in place; because the args are now +used, remove the `UNUSED` macro from them: + +---- + int i; + + ... + + printf(Q_("Your args (there is %d):\n", + "Your args (there are %d):\n", + argc), + argc); + for (i = 0; i < argc; i++) + printf("%d: %s\n", i, argv[i]); + + printf(_("Your current working directory:\n%s%s\n"), + prefix ? "/" : "", prefix ? prefix : ""); + +---- + +Build and try it. As you may expect, there's pretty much just whatever we give +on the command line, including the name of our command. (If `prefix` is empty +for you, try `cd Documentation/ && ../bin-wrappers/git psuh`). That's not so +helpful. So what other context can we get? + +Add a line to `#include "config.h"` and `#include "repository.h"`. +Then, add the following bits to the function body: +function body: + +---- + const char *cfg_name; + +... + + repo_config(repo, git_default_config, NULL); + if (repo_config_get_string_tmp(repo, "user.name", &cfg_name)) + printf(_("No name is found in config\n")); + else + printf(_("Your name: %s\n"), cfg_name); +---- + +`repo_config()` will grab the configuration from config files known to Git and +apply standard precedence rules. `repo_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 `repo_config()`) in `Documentation/technical/api-config.adoc`. + +You should see that the name printed matches the one you see when you run: + +---- +$ git config --get user.name +---- + +Great! Now we know how to check for values in the Git config. Let's commit this +too, so we don't lose our progress. + +---- +$ git add builtin/psuh.c +$ git commit -sm "psuh: show parameters & config opts" +---- + +NOTE: Again, the above is for sake of brevity in this tutorial. In a real change +you should not use `-m` but instead use the editor to write a meaningful +message. + +Still, it'd be nice to know what the user's working context is like. Let's see +if we can print the name of the user's current branch. We can mimic the +`git status` implementation; the printer is located in `wt-status.c` and we can +see that the branch is held in a `struct wt_status`. + +`wt_status_print()` gets invoked by `cmd_status()` in `builtin/commit.c`. +Looking at that implementation we see the status config being populated like so: + +---- +status_init_config(&s, git_status_config); +---- + +But as we drill down, we can find that `status_init_config()` wraps a call +to `repo_config()`. Let's modify the code we wrote in the previous commit. + +Be sure to include the header to allow you to use `struct wt_status`: + +---- +#include "wt-status.h" +---- + +Then modify your `cmd_psuh` implementation to declare your `struct wt_status`, +prepare it, and print its contents: + +---- + struct wt_status status; + +... + + wt_status_prepare(repo, &status); + repo_config(repo, git_default_config, &status); + +... + + printf(_("Your current branch: %s\n"), status.branch); +---- + +Run it again. Check it out - here's the (verbose) name of your current branch! + +Let's commit this as well. + +---- +$ git add builtin/psuh.c +$ git commit -sm "psuh: print the current branch" +---- + +Now let's see if we can get some info about a specific commit. + +Luckily, there are some helpers for us here. `commit.h` has a function called +`lookup_commit_reference_by_name` to which we can simply provide a hardcoded +string; `pretty.h` has an extremely handy `pp_commit_easy()` call which doesn't +require a full format object to be passed. + +Add the following includes: + +---- +#include "commit.h" +#include "pretty.h" +---- + +Then, add the following lines within your implementation of `cmd_psuh()` near +the declarations and the logic, respectively. + +---- + struct commit *c = NULL; + struct strbuf commitline = STRBUF_INIT; + +... + + c = lookup_commit_reference_by_name("origin/master"); + + if (c != NULL) { + pp_commit_easy(CMIT_FMT_ONELINE, c, &commitline); + printf(_("Current commit: %s\n"), commitline.buf); + } +---- + +The `struct strbuf` provides some safety belts to your basic `char*`, one of +which is a length member to prevent buffer overruns. It needs to be initialized +nicely with `STRBUF_INIT`. Keep it in mind when you need to pass around `char*`. + +`lookup_commit_reference_by_name` resolves the name you pass it, so you can play +with the value there and see what kind of things you can come up with. + +`pp_commit_easy` is a convenience wrapper in `pretty.h` that takes a single +format enum shorthand, rather than an entire format struct. It then +pretty-prints the commit according to that shorthand. These are similar to the +formats available with `--pretty=FOO` in many Git commands. + +Build it and run, and if you're using the same name in the example, you should +see the subject line of the most recent commit in `origin/master` that you know +about. Neat! Let's commit that as well. + +---- +$ git add builtin/psuh.c +$ git commit -sm "psuh: display the top of origin/master" +---- + +[[add-documentation]] +=== Adding Documentation + +Awesome! You've got a fantastic new command that you're ready to share with the +community. But hang on just a minute - this isn't very user-friendly. Run the +following: + +---- +$ ./bin-wrappers/git help psuh +---- + +Your new command is undocumented! Let's fix that. + +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.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: + +// Surprisingly difficult to embed AsciiDoc source within AsciiDoc. +[listing] +.... +git-psuh(1) +=========== + +NAME +---- +git-psuh - Delight users' typo with a shy horse + + +SYNOPSIS +-------- +[verse] +'git-psuh [...]' + +DESCRIPTION +----------- +... + +OPTIONS[[OPTIONS]] +------------------ +... + +OUTPUT +------ +... + +GIT +--- +Part of the linkgit:git[1] suite +.... + +The most important pieces of this to note are the file header, underlined by =, +the NAME section, and the SYNOPSIS, which would normally contain the grammar if +your command took arguments. Try to use well-established manpage headers so your +documentation is consistent with other Git and UNIX manpages; this makes life +easier for your user, who can skip to the section they know contains the +information they need. + +NOTE: Before trying to build the docs, make sure you have the package `asciidoc` +installed. + +Now that you've written your manpage, you'll need to build it explicitly. We +convert your AsciiDoc to troff which is man-readable like so: + +---- +$ make all doc +$ man Documentation/git-psuh.1 +---- + +or + +---- +$ make -C Documentation/ git-psuh.1 +$ man Documentation/git-psuh.1 +---- + +While this isn't as satisfying as running through `git help`, you can at least +check that your help page looks right. + +You can also check that the documentation coverage is good (that is, the project +sees that your command has been implemented as well as documented) by running +`make check-docs` from the top-level. + +Go ahead and commit your new documentation change. + +[[add-usage]] +=== Adding Usage Text + +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.adoc`. This is a handy +tool for pulling out options you need to be able to handle, and it takes a +usage string. + +In order to use it, we'll need to prepare a NULL-terminated array of usage +strings and a `builtin_psuh_options` array. + +Add a line to `#include "parse-options.h"`. + +At global scope, add your array of usage strings: + +---- +static const char * const psuh_usage[] = { + N_("git psuh [...]"), + NULL, +}; +---- + +Then, within your `cmd_psuh()` implementation, we can declare and populate our +`option` struct. Ours is pretty boring but you can add more to it if you want to +explore `parse_options()` in more detail: + +---- + struct option options[] = { + OPT_END() + }; +---- + +Finally, before you print your args and prefix, add the call to +`parse-options()`: + +---- + argc = parse_options(argc, argv, prefix, options, psuh_usage, 0); +---- + +This call will modify your `argv` parameter. It will strip the options you +specified in `options` from `argv` and the locations pointed to from `options` +entries will be updated. Be sure to replace your `argc` with the result from +`parse_options()`, or you will be confused if you try to parse `argv` later. + +It's worth noting the special argument `--`. As you may be aware, many Unix +commands use `--` to indicate "end of named parameters" - all parameters after +the `--` are interpreted merely as positional arguments. (This can be handy if +you want to pass as a parameter something which would usually be interpreted as +a flag.) `parse_options()` will terminate parsing when it reaches `--` and give +you the rest of the options afterwards, untouched. + +Now that you have a usage hint, you can teach Git how to show it in the general +command list shown by `git help git` or `git help -a`, which is generated from +`command-list.txt`. Find the line for 'git-pull' so you can add your 'git-psuh' +line above it in alphabetical order. Now, we can add some attributes about the +command which impacts where it shows up in the aforementioned help commands. The +top of `command-list.txt` shares some information about what each attribute +means; in those help pages, the commands are sorted according to these +attributes. `git psuh` is user-facing, or porcelain - so we will mark it as +"mainporcelain". For "mainporcelain" commands, the comments at the top of +`command-list.txt` indicate we can also optionally add an attribute from another +list; since `git psuh` shows some information about the user's workspace but +doesn't modify anything, let's mark it as "info". Make sure to keep your +attributes in the same style as the rest of `command-list.txt` using spaces to +align and delineate them: + +---- +git-prune-packed plumbingmanipulators +git-psuh mainporcelain info +git-pull mainporcelain remote +git-push mainporcelain remote +---- + +Build again. Now, when you run with `-h`, you should see your usage printed and +your command terminated before anything else interesting happens. Great! + +Go ahead and commit this one, too. + +[[testing]] +== Testing + +It's important to test your code - even for a little toy command like this one. +Moreover, your patch won't be accepted into the Git tree without tests. Your +tests should: + +* Illustrate the current behavior of the feature +* Prove the current behavior matches the expected behavior +* Ensure the externally-visible behavior isn't broken in later changes + +So let's write some tests. + +Related reading: `t/README` + +[[overview-test-structure]] +=== Overview of Testing Structure + +The tests in Git live in `t/` and are named with a 4-digit decimal number using +the schema shown in the Naming Tests section of `t/README`. + +[[write-new-test]] +=== Writing Your Test + +Since this a toy command, let's go ahead and name the test with t9999. However, +as many of the family/subcmd combinations are full, best practice seems to be +to find a command close enough to the one you've added and share its naming +space. + +Create a new file `t/t9999-psuh-tutorial.sh`. Begin with the header as so (see +"Writing Tests" and "Source 'test-lib.sh'" in `t/README`): + +---- +#!/bin/sh + +test_description='git-psuh test + +This test runs git-psuh and makes sure it does not crash.' + +. ./test-lib.sh +---- + +Tests are framed inside of a `test_expect_success` in order to output TAP +formatted results. Let's make sure that `git psuh` doesn't exit poorly and does +mention the right animal somewhere: + +---- +test_expect_success 'runs correctly with no args and good output' ' + git psuh >actual && + grep Pony actual +' +---- + +Indicate that you've run everything you wanted by adding the following at the +bottom of your script: + +---- +test_done +---- + +Make sure you mark your test script executable: + +---- +$ chmod +x t/t9999-psuh-tutorial.sh +---- + +You can get an idea of whether you created your new test script successfully +by running `make -C t test-lint`, which will check for things like test number +uniqueness, executable bit, and so on. + +[[local-test]] +=== Running Locally + +Let's try and run locally: + +---- +$ make +$ cd t/ && prove t9999-psuh-tutorial.sh +---- + +You can run the full test suite and ensure `git-psuh` didn't break anything: + +---- +$ cd t/ +$ prove -j$(nproc) --shuffle t[0-9]*.sh +---- + +NOTE: You can also do this with `make test` or use any testing harness which can +speak TAP. `prove` can run concurrently. `shuffle` randomizes the order the +tests are run in, which makes them resilient against unwanted inter-test +dependencies. `prove` also makes the output nicer. + +Go ahead and commit this change, as well. + +[[ready-to-share]] +== Getting Ready to Share: Anatomy of a Patch Series + +You may have noticed already that the Git project performs its code reviews via +emailed patches, which are then applied by the maintainer when they are ready +and approved by the community. The Git project does not accept contributions from +pull requests, and the patches emailed for review need to be formatted a +specific way. + +:patch-series: https://lore.kernel.org/git/pull.1218.git.git.1645209647.gitgitgadget@gmail.com/ +:lore: https://lore.kernel.org/git/ + +Before taking a look at how to convert your commits into emailed patches, +let's analyze what the end result, a "patch series", looks like. Here is an +{patch-series}[example] of the summary view for a patch series on the web interface of +the {lore}[Git mailing list archive]: + +---- +2022-02-18 18:40 [PATCH 0/3] libify reflog John Cai via GitGitGadget +2022-02-18 18:40 ` [PATCH 1/3] reflog: libify delete reflog function and helpers John Cai via GitGitGadget +2022-02-18 19:10 ` Ævar Arnfjörð Bjarmason [this message] +2022-02-18 19:39 ` Taylor Blau +2022-02-18 19:48 ` Ævar Arnfjörð Bjarmason +2022-02-18 19:35 ` Taylor Blau +2022-02-21 1:43 ` John Cai +2022-02-21 1:50 ` Taylor Blau +2022-02-23 19:50 ` John Cai +2022-02-18 20:00 ` // other replies elided +2022-02-18 18:40 ` [PATCH 2/3] reflog: call reflog_delete from reflog.c John Cai via GitGitGadget +2022-02-18 19:15 ` Ævar Arnfjörð Bjarmason +2022-02-18 20:26 ` Junio C Hamano +2022-02-18 18:40 ` [PATCH 3/3] stash: call reflog_delete from reflog.c John Cai via GitGitGadget +2022-02-18 19:20 ` Ævar Arnfjörð Bjarmason +2022-02-19 0:21 ` Taylor Blau +2022-02-22 2:36 ` John Cai +2022-02-22 10:51 ` Ævar Arnfjörð Bjarmason +2022-02-18 19:29 ` [PATCH 0/3] libify reflog Ævar Arnfjörð Bjarmason +2022-02-22 18:30 ` [PATCH v2 0/3] libify reflog John Cai via GitGitGadget +2022-02-22 18:30 ` [PATCH v2 1/3] stash: add test to ensure reflog --rewrite --updatref behavior John Cai via GitGitGadget +2022-02-23 8:54 ` Ævar Arnfjörð Bjarmason +2022-02-23 21:27 ` Junio C Hamano +// continued +---- + +We can note a few things: + +- Each commit is sent as a separate email, with the commit message title as + subject, prefixed with "[PATCH _i_/_n_]" for the _i_-th commit of an + _n_-commit series. +- Each patch is sent as a reply to an introductory email called the _cover + letter_ of the series, prefixed "[PATCH 0/_n_]". +- Subsequent iterations of the patch series are labelled "PATCH v2", "PATCH + v3", etc. in place of "PATCH". For example, "[PATCH v2 1/3]" would be the first of + three patches in the second iteration. Each iteration is sent with a new cover + letter (like "[PATCH v2 0/3]" above), itself a reply to the cover letter of the + previous iteration (more on that below). + +NOTE: A single-patch topic is sent with "[PATCH]", "[PATCH v2]", etc. without +_i_/_n_ numbering (in the above thread overview, no single-patch topic appears, +though). + +[[cover-letter]] +=== The cover letter + +In addition to an email per patch, the Git community also expects your patches +to come with a cover letter. This is an important component of change +submission as it explains to the community from a high level what you're trying +to do, and why, in a way that's more apparent than just looking at your +patches. + +The title of your cover letter should be something which succinctly covers the +purpose of your entire topic branch. It's often in the imperative mood, just +like our commit message titles. Here is how we'll title our series: + +--- +Add the 'psuh' command +--- + +The body of the cover letter is used to give additional context to reviewers. +Be sure to explain anything your patches don't make clear on their own, but +remember that since the cover letter is not recorded in the commit history, +anything that might be useful to future readers of the repository's history +should also be in your commit messages. + +Here's an example body for `psuh`: + +---- +Our internal metrics indicate widespread interest in the command +git-psuh - that is, many users are trying to use it, but finding it is +unavailable, using some unknown workaround instead. + +The following handful of patches add the psuh command and implement some +handy features on top of it. + +This patchset is part of the MyFirstContribution tutorial and should not +be merged. +---- + +At this point the tutorial diverges, in order to demonstrate two +different methods of formatting your patchset and getting it reviewed. + +The first method to be covered is GitGitGadget, which is useful for those +already familiar with GitHub's common pull request workflow. This method +requires a GitHub account. + +The second method to be covered is `git send-email`, which can give slightly +more fine-grained control over the emails to be sent. This method requires some +setup which can change depending on your system and will not be covered in this +tutorial. + +Regardless of which method you choose, your engagement with reviewers will be +the same; the review process will be covered after the sections on GitGitGadget +and `git send-email`. + +[[howto-ggg]] +== Sending Patches via GitGitGadget + +One option for sending patches is to follow a typical pull request workflow and +send your patches out via GitGitGadget. GitGitGadget is a tool created by +Johannes Schindelin to make life as a Git contributor easier for those used to +the GitHub PR workflow. It allows contributors to open pull requests against its +mirror of the Git project, and does some magic to turn the PR into a set of +emails and send them out for you. It also runs the Git continuous integration +suite for you. It's documented at https://gitgitgadget.github.io/. + +[[create-fork]] +=== Forking `git/git` on GitHub + +Before you can send your patch off to be reviewed using GitGitGadget, you will +need to fork the Git project and upload your changes. First thing - make sure +you have a GitHub account. + +Head to the https://github.com/git/git[GitHub mirror] and look for the Fork +button. Place your fork wherever you deem appropriate and create it. + +[[upload-to-fork]] +=== Uploading to Your Own Fork + +To upload your branch to your own fork, you'll need to add the new fork as a +remote. You can use `git remote -v` to show the remotes you have added already. +From your new fork's page on GitHub, you can press "Clone or download" to get +the URL; then you need to run the following to add, replacing your own URL and +remote name for the examples provided: + +---- +$ git remote add remotename git@github.com:remotename/git.git +---- + +or to use the HTTPS URL: + +---- +$ git remote add remotename https://github.com/remotename/git/.git +---- + +Run `git remote -v` again and you should see the new remote showing up. +`git fetch remotename` (with the real name of your remote replaced) in order to +get ready to push. + +Next, double-check that you've been doing all your development in a new branch +by running `git branch`. If you didn't, now is a good time to move your new +commits to their own branch. + +As mentioned briefly at the beginning of this document, we are basing our work +on `master`, so go ahead and update as shown below, or using your preferred +workflow. + +---- +$ git checkout master +$ git pull -r +$ git rebase master psuh +---- + +Finally, you're ready to push your new topic branch! (Due to our branch and +command name choices, be careful when you type the command below.) + +---- +$ git push remotename psuh +---- + +Now you should be able to go and check out your newly created branch on GitHub. + +[[send-pr-ggg]] +=== Sending a PR to GitGitGadget + +In order to have your code tested and formatted for review, you need to start by +opening a Pull Request against either `gitgitgadget/git` or `git/git`. Head to +https://github.com/gitgitgadget/git or https://github.com/git/git and open a PR +either with the "New pull request" button or the convenient "Compare & pull +request" button that may appear with the name of your newly pushed branch. + +The differences between using `gitgitgadget/git` and `git/git` as your base can +be found [here](https://gitgitgadget.github.io/#should-i-use-gitgitgadget-on-gitgitgadgets-git-fork-or-on-gits-github-mirror) + +Review the PR's title and description, as they're used by GitGitGadget +respectively as the subject and body of the cover letter for your change. Refer +to <> above for advice on how to title your +submission and what content to include in the description. + +NOTE: For single-patch contributions, your commit message should already be +meaningful and explain at a high level the purpose (what is happening and why) +of your patch, so you usually do not need any additional context. In that case, +remove the PR description that GitHub automatically generates from your commit +message (your PR description should be empty). If you do need to supply even +more context, you can do so in that space and it will be appended to the email +that GitGitGadget will send, between the three-dash line and the diffstat +(see <> for how this looks once +submitted). + +When you're happy, submit your pull request. + +[[run-ci-ggg]] +=== Running CI and Getting Ready to Send + +If it's your first time using GitGitGadget (which is likely, as you're using +this tutorial) then someone will need to give you permission to use the tool. +As mentioned in the GitGitGadget documentation, you just need someone who +already uses it to comment on your PR with `/allow `. GitGitGadget +will automatically run your PRs through the CI even without the permission given +but you will not be able to `/submit` your changes until someone allows you to +use the tool. + +NOTE: You can typically find someone who can `/allow` you on GitGitGadget by +either examining recent pull requests where someone has been granted `/allow` +(https://github.com/gitgitgadget/git/pulls?utf8=%E2%9C%93&q=is%3Apr+is%3Aopen+%22%2Fallow%22[Search: +is:pr is:open "/allow"]), in which case both the author and the person who +granted the `/allow` can now `/allow` you, or by inquiring on the +https://web.libera.chat/#git-devel[#git-devel] IRC channel on Libera Chat +linking your pull request and asking for someone to `/allow` you. + +If the CI fails, you can update your changes with `git rebase -i` and push your +branch again: + +---- +$ git push -f remotename psuh +---- + +In fact, you should continue to make changes this way up until the point when +your patch is accepted into `next`. + +//// +TODO https://github.com/gitgitgadget/gitgitgadget/issues/83 +It'd be nice to be able to verify that the patch looks good before sending it +to everyone on Git mailing list. +[[check-work-ggg]] +=== Check Your Work +//// + +[[send-mail-ggg]] +=== Sending Your Patches + +Now that your CI is passing and someone has granted you permission to use +GitGitGadget with the `/allow` command, sending out for review is as simple as +commenting on your PR with `/submit`. + +[[responding-ggg]] +=== Updating With Comments + +Skip ahead to <> for information on how to +reply to review comments you will receive on the mailing list. + +Once you have your branch again in the shape you want following all review +comments, you can submit again: + +---- +$ git push -f remotename psuh +---- + +Next, go look at your pull request against GitGitGadget; you should see the CI +has been kicked off again. Now while the CI is running is a good time for you +to modify your description at the top of the pull request thread; it will be +used again as the cover letter. You should use this space to describe what +has changed since your previous version, so that your reviewers have some idea +of what they're looking at. When the CI is done running, you can comment once +more with `/submit` - GitGitGadget will automatically add a v2 mark to your +changes. + +[[howto-git-send-email]] +== Sending Patches with `git send-email` + +If you don't want to use GitGitGadget, you can also use Git itself to mail your +patches. Some benefits of using Git this way include finer grained control of +subject line (for example, being able to use the tag [RFC PATCH] in the subject) +and being able to send a ``dry run'' mail to yourself to ensure it all looks +good before going out to the list. + +[[setup-git-send-email]] +=== Prerequisite: Setting Up `git send-email` + +Configuration for `send-email` can vary based on your operating system and email +provider, and so will not be covered in this tutorial, beyond stating that in +many distributions of Linux, `git-send-email` is not packaged alongside the +typical `git` install. You may need to install this additional package; there +are a number of resources online to help you do so. You will also need to +determine the right way to configure it to use your SMTP server; again, as this +configuration can change significantly based on your system and email setup, it +is out of scope for the context of this tutorial. + +[[format-patch]] +=== Preparing Initial Patchset + +Sending emails with Git is a two-part process; before you can prepare the emails +themselves, you'll need to prepare the patches. Luckily, this is pretty simple: + +---- +$ git format-patch --cover-letter -o psuh/ --base=auto psuh@{u}..psuh +---- + + . The `--cover-letter` option tells `format-patch` to create a + cover letter template for you. You will need to fill in the + template before you're ready to send - but for now, the template + will be next to your other patches. + + . The `-o psuh/` option tells `format-patch` to place the patch + files into a directory. This is useful because `git send-email` + can take a directory and send out all the patches from there. + + . The `--base=auto` option tells the command to record the "base + commit", on which the recipient is expected to apply the patch + series. The `auto` value will cause `format-patch` to compute + the base commit automatically, which is the merge base of tip + commit of the remote-tracking branch and the specified revision + range. + + . The `psuh@{u}..psuh` option tells `format-patch` to generate + patches for the commits you created on the `psuh` branch since it + forked from its upstream (which is `origin/master` if you + followed the example in the "Set up your workspace" section). If + you are already on the `psuh` branch, you can just say `@{u}`, + which means "commits on the current branch since it forked from + its upstream", which is the same thing. + +The command will make one patch file per commit. After you +run, you can go have a look at each of the patches with your favorite text +editor and make sure everything looks alright; however, it's not recommended to +make code fixups via the patch file. It's a better idea to make the change the +normal way using `git rebase -i` or by adding a new commit than by modifying a +patch. + +NOTE: Optionally, you can also use the `--rfc` flag to prefix your patch subject +with ``[RFC PATCH]'' instead of ``[PATCH]''. RFC stands for ``request for +comments'' and indicates that while your code isn't quite ready for submission, +you'd like to begin the code review process. This can also be used when your +patch is a proposal, but you aren't sure whether the community wants to solve +the problem with that approach or not - to conduct a sort of design review. You +may also see on the list patches marked ``WIP'' - this means they are incomplete +but want reviewers to look at what they have so far. You can add this flag with +`--subject-prefix=WIP`. + +Check and make sure that your patches and cover letter template exist in the +directory you specified - you're nearly ready to send out your review! + +[[preparing-cover-letter]] +=== Preparing Email + +Since you invoked `format-patch` with `--cover-letter`, you've already got a +cover letter template ready. Open it up in your favorite editor. + +You should see a number of headers present already. Check that your `From:` +header is correct. Then modify your `Subject:` (see <> for +how to choose good title for your patch series): + +---- +Subject: [PATCH 0/7] Add the 'psuh' command +---- + +Make sure you retain the ``[PATCH 0/X]'' part; that's what indicates to the Git +community that this email is the beginning of a patch series, and many +reviewers filter their email for this type of flag. + +You'll need to add some extra parameters when you invoke `git send-email` to add +the cover letter. + +Next you'll have to fill out the body of your cover letter. Again, see +<> for what content to include. + +The template created by `git format-patch --cover-letter` includes a diffstat. +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.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.adoc + create mode 100644 builtin/psuh.c + create mode 100755 t/t9999-psuh-tutorial.sh +---- + +Finally, the letter will include the version of Git used to generate the +patches. You can leave that string alone. + +[[sending-git-send-email]] +=== Sending Email + +At this point you should have a directory `psuh/` which is filled with your +patches and a cover letter. Time to mail it out! You can send it like this: + +---- +$ git send-email --to=target@example.com psuh/*.patch +---- + +NOTE: Check `git help send-email` for some other options which you may find +valuable, such as changing the Reply-to address or adding more CC and BCC lines. + +:contrib-scripts: footnoteref:[contrib-scripts,Scripts under `contrib/` are + +not part of the core `git` binary and must be called directly. Clone the Git + +codebase and run `perl contrib/contacts/git-contacts`.] + +NOTE: If you're not sure whom to CC, running `contrib/contacts/git-contacts` can +list potential reviewers. In addition, you can do `git send-email +--cc-cmd='perl contrib/contacts/git-contacts' feature/*.patch`{contrib-scripts} to +automatically pass this list of emails to `send-email`. + +NOTE: When you are sending a real patch, it will go to git@vger.kernel.org - but +please don't send your patchset from the tutorial to the real mailing list! For +now, you can send it to yourself, to make sure you understand how it will look. + +NOTE: After sending your patches, you can confirm that they reached the mailing +list by visiting https://lore.kernel.org/git/. Use the search bar to find your +name or the subject of your patch. If it appears, your email was successfully +delivered. + +After you run the command above, you will be presented with an interactive +prompt for each patch that's about to go out. This gives you one last chance to +edit or quit sending something (but again, don't edit code this way). Once you +press `y` or `a` at these prompts your emails will be sent! Congratulations! + +Awesome, now the community will drop everything and review your changes. (Just +kidding - be patient!) + +[[v2-git-send-email]] +=== Sending v2 + +This section will focus on how to send a v2 of your patchset. To learn what +should go into v2, skip ahead to <> for +information on how to handle comments from reviewers. + +We'll reuse our `psuh` topic branch for v2. Before we make any changes, we'll +mark the tip of our v1 branch for easy reference: + +---- +$ git checkout psuh +$ git branch psuh-v1 +---- + +Refine your patch series by using `git rebase -i` to adjust commits based upon +reviewer comments. Once the patch series is ready for submission, generate your +patches again, but with some new flags: + +---- +$ git format-patch -v2 --cover-letter -o psuh/ --range-diff master..psuh-v1 master.. +---- + +The `--range-diff master..psuh-v1` parameter tells `format-patch` to include a +range-diff between `psuh-v1` and `psuh` in the cover letter (see +linkgit:git-range-diff[1]). This helps tell reviewers about the differences +between your v1 and v2 patches. + +The `-v2` parameter tells `format-patch` to output your patches +as version "2". For instance, you may notice that your v2 patches are +all named like `v2-000n-my-commit-subject.patch`. `-v2` will also format +your patches by prefixing them with "[PATCH v2]" instead of "[PATCH]", +and your range-diff will be prefaced with "Range-diff against v1". + +After you run this command, `format-patch` will output the patches to the `psuh/` +directory, alongside the v1 patches. Using a single directory makes it easy to +refer to the old v1 patches while proofreading the v2 patches, but you will need +to be careful to send out only the v2 patches. We will use a pattern like +`psuh/v2-*.patch` (not `psuh/*.patch`, which would match v1 and v2 patches). + +Edit your cover letter again. Now is a good time to mention what's different +between your last version and now, if it's something significant. You do not +need the exact same body in your second cover letter; focus on explaining to +reviewers the changes you've made that may not be as visible. + +You will also need to go and find the Message-ID of your previous cover letter. +You can either note it when you send the first series, from the output of `git +send-email`, or you can look it up on the +https://lore.kernel.org/git[mailing list]. Find your cover letter in the +archives, click on it, then click "permalink" or "raw" to reveal the Message-ID +header. It should match: + +---- +Message-ID: +---- + +Your Message-ID is ``. This example will be used +below as well; make sure to replace it with the correct Message-ID for your +**previous cover letter** - that is, if you're sending v2, use the Message-ID +from v1; if you're sending v3, use the Message-ID from v2. + +While you're looking at the email, you should also note who is CC'd, as it's +common practice in the mailing list to keep all CCs on a thread. You can add +these CC lines directly to your cover letter with a line like so in the header +(before the Subject line): + +---- +CC: author@example.com, Othe R +---- + +Now send the emails again, paying close attention to which messages you pass in +to the command: + +---- +$ git send-email --to=target@example.com + --in-reply-to="" + psuh/v2-*.patch +---- + +[[single-patch]] +=== Bonus Chapter: One-Patch Changes + +In some cases, your very small change may consist of only one patch. When that +happens, you only need to send one email. Your commit message should already be +meaningful and explain at a high level the purpose (what is happening and why) +of your patch, but if you need to supply even more context, you can do so below +the `---` in your patch. Take the example below, which was generated with `git +format-patch` on a single commit, and then edited to add the content between +the `---` and the diffstat. + +---- +From 1345bbb3f7ac74abde040c12e737204689a72723 Mon Sep 17 00:00:00 2001 +From: A U Thor +Date: Thu, 18 Apr 2019 15:11:02 -0700 +Subject: [PATCH] README: change the grammar + +I think it looks better this way. This part of the commit message will +end up in the commit-log. + +Signed-off-by: A U Thor +--- +Let's have a wild discussion about grammar on the mailing list. This +part of my email will never end up in the commit log. Here is where I +can add additional context to the mailing list about my intent, outside +of the context of the commit log. This section was added after `git +format-patch` was run, by editing the patch file in a text editor. + + README.md | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/README.md b/README.md +index 88f126184c..38da593a60 100644 +--- a/README.md ++++ b/README.md +@@ -3,7 +3,7 @@ + Git - fast, scalable, distributed revision control system + ========================================================= + +-Git is a fast, scalable, distributed revision control system with an ++Git is a fast, scalable, and distributed revision control system with an + unusually rich command set that provides both high-level operations + and full access to internals. + +-- +2.21.0.392.gf8f6787159e-goog +---- + +[[now-what]] +== My Patch Got Emailed - Now What? + +Please give reviewers enough time to process your initial patch before +sending an updated version. That is, resist the temptation to send a new +version immediately, because others may have already started reviewing +your initial version. + +While waiting for review comments, you may find mistakes in your initial +patch, or perhaps realize a different and better way to achieve the goal +of the patch. In this case you may communicate your findings to other +reviewers as follows: + + - If the mistakes you found are minor, send a reply to your patch as if + you were a reviewer and mention that you will fix them in an + updated version. + + - On the other hand, if you think you want to change the course so + drastically that reviews on the initial patch would be a waste of + time (for everyone involved), retract the patch immediately with + a reply like "I am working on a much better approach, so please + ignore this patch and wait for the updated version." + +Now, the above is a good practice if you sent your initial patch +prematurely without polish. But a better approach of course is to avoid +sending your patch prematurely in the first place. + +Please be considerate of the time needed by reviewers to examine each +new version of your patch. Rather than seeing the initial version right +now (followed by several "oops, I like this version better than the +previous one" patches over 2 days), reviewers would strongly prefer if a +single polished version came 2 days later instead, and that version with +fewer mistakes were the only one they would need to review. + + +[[reviewing]] +=== Responding to Reviews + +After a few days, you will hopefully receive a reply to your patchset with some +comments. Woohoo! Now you can get back to work. + +It's good manners to reply to each comment, notifying the reviewer that you have +made the change suggested, feel the original is better, or that the comment +inspired you to do something a new way which is superior to both the original +and the suggested change. This way reviewers don't need to inspect your v2 to +figure out whether you implemented their comment or not. + +Reviewers may ask you about what you wrote in the patchset, either in +the proposed commit log message or in the changes themselves. You +should answer these questions in your response messages, but often the +reason why reviewers asked these questions to understand what you meant +to write is because your patchset needed clarification to be understood. + +Do not be satisfied by just answering their questions in your response +and hear them say that they now understand what you wanted to say. +Update your patches to clarify the points reviewers had trouble with, +and prepare your v2; the words you used to explain your v1 to answer +reviewers' questions may be useful thing to use. Your goal is to make +your v2 clear enough so that it becomes unnecessary for you to give the +same explanation to the next person who reads it. + +If you are going to push back on a comment, be polite and explain why you feel +your original is better; be prepared that the reviewer may still disagree with +you, and the rest of the community may weigh in on one side or the other. As +with all code reviews, it's important to keep an open mind to doing something a +different way than you originally planned; other reviewers have a different +perspective on the project than you do, and may be thinking of a valid side +effect which had not occurred to you. It is always okay to ask for clarification +if you aren't sure why a change was suggested, or what the reviewer is asking +you to do. + +Make sure your email client has a plaintext email mode and it is turned on; the +Git list rejects HTML email. Please also follow the mailing list etiquette +outlined in the +https://kernel.googlesource.com/pub/scm/git/git/+/todo/MaintNotes[Maintainer's +Note], which are similar to etiquette rules in most open source communities +surrounding bottom-posting and inline replies. + +When you're making changes to your code, it is cleanest - that is, the resulting +commits are easiest to look at - if you use `git rebase -i` (interactive +rebase). Take a look at this +https://www.oreilly.com/library/view/git-pocket-guide/9781449327507/ch10.html[overview] +from O'Reilly. The general idea is to modify each commit which requires changes; +this way, instead of having a patch A with a mistake, a patch B which was fine +and required no upstream reviews in v1, and a patch C which fixes patch A for +v2, you can just ship a v2 with a correct patch A and correct patch B. This is +changing history, but since it's local history which you haven't shared with +anyone, that is okay for now! (Later, it may not make sense to do this; take a +look at the section below this one for some context.) + +[[after-approval]] +=== After Review Approval + +The Git project has four integration branches: `seen`, `next`, `master`, and +`maint`. Your change will be placed into `seen` fairly early on by the maintainer +while it is still in the review process; from there, when it is ready for wider +testing, it will be merged into `next`. Plenty of early testers use `next` and +may report issues. Eventually, changes in `next` will make it to `master`, +which is typically considered stable. Finally, when a new release is cut, +`maint` is used to base bugfixes onto. As mentioned at the beginning of this +document, you can read `Documents/SubmittingPatches` for some more info about +the use of the various integration branches. + +Back to now: your code has been lauded by the upstream reviewers. It is perfect. +It is ready to be accepted. You don't need to do anything else; the maintainer +will merge your topic branch to `next` and life is good. + +However, if you discover it isn't so perfect after this point, you may need to +take some special steps depending on where you are in the process. + +If the maintainer has announced in the "What's cooking in git.git" email that +your topic is marked for `next` - that is, that they plan to merge it to `next` +but have not yet done so - you should send an email asking the maintainer to +wait a little longer: "I've sent v4 of my series and you marked it for `next`, +but I need to change this and that - please wait for v5 before you merge it." + +If the topic has already been merged to `next`, rather than modifying your +patches with `git rebase -i`, you should make further changes incrementally - +that is, with another commit, based on top of the maintainer's topic branch as +detailed in https://github.com/gitster/git. Your work is still in the same topic +but is now incremental, rather than a wholesale rewrite of the topic branch. + +The topic branches in the maintainer's GitHub are mirrored in GitGitGadget, so +if you're sending your reviews out that way, you should be sure to open your PR +against the appropriate GitGitGadget/Git branch. + +If you're using `git send-email`, you can use it the same way as before, but you +should generate your diffs from `..` and base your work on +`` instead of `master`. diff --git a/Documentation/MyFirstContribution.txt b/Documentation/MyFirstContribution.txt deleted file mode 100644 index 63a2ef544939a3..00000000000000 --- a/Documentation/MyFirstContribution.txt +++ /dev/null @@ -1,1267 +0,0 @@ -My First Contribution to the Git Project -======================================== -:sectanchors: - -[[summary]] -== Summary - -This is a tutorial demonstrating the end-to-end workflow of creating a change to -the Git tree, sending it for review, and making changes based on comments. - -[[prerequisites]] -=== Prerequisites - -This tutorial assumes you're already fairly familiar with using Git to manage -source code. The Git workflow steps will largely remain unexplained. - -[[related-reading]] -=== Related Reading - -This tutorial aims to summarize the following documents, but the reader may find -useful additional context: - -- `Documentation/SubmittingPatches` -- `Documentation/howto/new-command.txt` - -[[getting-help]] -=== Getting Help - -If you get stuck, you can seek help in the following places. - -==== git@vger.kernel.org - -This is the main Git project mailing list where code reviews, version -announcements, design discussions, and more take place. Those interested in -contributing are welcome to post questions here. The Git list requires -plain-text-only emails and prefers inline and bottom-posting when replying to -mail; you will be CC'd in all replies to you. Optionally, you can subscribe to -the list by sending an email to majordomo@vger.kernel.org with "subscribe git" -in the body. The https://lore.kernel.org/git[archive] of this mailing list is -available to view in a browser. - -==== https://groups.google.com/forum/#!forum/git-mentoring[git-mentoring@googlegroups.com] - -This mailing list is targeted to new contributors and was created as a place to -post questions and receive answers outside of the public eye of the main list. -Veteran contributors who are especially interested in helping mentor newcomers -are present on the list. In order to avoid search indexers, group membership is -required to view messages; anyone can join and no approval is required. - -==== https://web.libera.chat/#git-devel[#git-devel] on Libera Chat - -This IRC channel is for conversations between Git contributors. If someone is -currently online and knows the answer to your question, you can receive help -in real time. Otherwise, you can read the -https://colabti.org/irclogger/irclogger_logs/git-devel[scrollback] to see -whether someone answered you. IRC does not allow offline private messaging, so -if you try to private message someone and then log out of IRC, they cannot -respond to you. It's better to ask your questions in the channel so that you -can be answered if you disconnect and so that others can learn from the -conversation. - -[[getting-started]] -== Getting Started - -[[cloning]] -=== Clone the Git Repository - -Git is mirrored in a number of locations. Clone the repository from one of them; -https://git-scm.com/downloads suggests one of the best places to clone from is -the mirror on GitHub. - ----- -$ git clone https://github.com/git/git git -$ cd git ----- - -[[dependencies]] -=== Installing Dependencies - -To build Git from source, you need to have a handful of dependencies installed -on your system. For a hint of what's needed, you can take a look at -`INSTALL`, paying close attention to the section about Git's dependencies on -external programs and libraries. That document mentions a way to "test-drive" -our freshly built Git without installing; that's the method we'll be using in -this tutorial. - -Make sure that your environment has everything you need by building your brand -new clone of Git from the above step: - ----- -$ make ----- - -NOTE: The Git build is parallelizable. `-j#` is not included above but you can -use it as you prefer, here and elsewhere. - -[[identify-problem]] -=== Identify Problem to Solve - -//// -Use + to indicate fixed-width here; couldn't get ` to work nicely with the -quotes around "Pony Saying 'Um, Hello'". -//// -In this tutorial, we will add a new command, +git psuh+, short for ``Pony Saying -`Um, Hello''' - a feature which has gone unimplemented despite a high frequency -of invocation during users' typical daily workflow. - -(We've seen some other effort in this space with the implementation of popular -commands such as `sl`.) - -[[setup-workspace]] -=== Set Up Your Workspace - -Let's start by making a development branch to work on our changes. Per -`Documentation/SubmittingPatches`, since a brand new command is a new feature, -it's fine to base your work on `master`. However, in the future for bugfixes, -etc., you should check that document and base it on the appropriate branch. - -For the purposes of this document, we will base all our work on the `master` -branch of the upstream project. Create the `psuh` branch you will use for -development like so: - ----- -$ git checkout -b psuh origin/master ----- - -We'll make a number of commits here in order to demonstrate how to send a topic -with multiple patches up for review simultaneously. - -[[code-it-up]] -== Code It Up! - -NOTE: A reference implementation can be found at -https://github.com/nasamuffin/git/tree/psuh. - -[[add-new-command]] -=== Adding a New Command - -Lots of the subcommands are written as builtins, which means they are -implemented in C and compiled into the main `git` executable. Implementing the -very simple `psuh` command as a built-in will demonstrate the structure of the -codebase, the internal API, and the process of working together as a contributor -with the reviewers and maintainer to integrate this change into the system. - -Built-in subcommands are typically implemented in a function named "cmd_" -followed by the name of the subcommand, in a source file named after the -subcommand and contained within `builtin/`. So it makes sense to implement your -command in `builtin/psuh.c`. Create that file, and within it, write the entry -point for your command in a function matching the style and signature: - ----- -int cmd_psuh(int argc, const char **argv, const char *prefix) ----- - -We'll also need to add the declaration of psuh; open up `builtin.h`, find the -declaration for `cmd_pull`, and add a new line for `psuh` immediately before it, -in order to keep the declarations alphabetically sorted: - ----- -int cmd_psuh(int argc, const char **argv, const char *prefix); ----- - -Be sure to `#include "builtin.h"` in your `psuh.c`. - -Go ahead and add some throwaway printf to that function. This is a decent -starting point as we can now add build rules and register the command. - -NOTE: Your throwaway text, as well as much of the text you will be adding over -the course of this tutorial, is user-facing. That means it needs to be -localizable. Take a look at `po/README` under "Marking strings for translation". -Throughout the tutorial, we will mark strings for translation as necessary; you -should also do so when writing your user-facing commands in the future. - ----- -int cmd_psuh(int argc, const char **argv, const char *prefix) -{ - printf(_("Pony saying hello goes here.\n")); - return 0; -} ----- - -Let's try to build it. Open `Makefile`, find where `builtin/pull.o` is added -to `BUILTIN_OBJS`, and add `builtin/psuh.o` in the same way next to it in -alphabetical order. Once you've done so, move to the top-level directory and -build simply with `make`. Also add the `DEVELOPER=1` variable to turn on -some additional warnings: - ----- -$ echo DEVELOPER=1 >config.mak -$ make ----- - -NOTE: When you are developing the Git project, it's preferred that you use the -`DEVELOPER` flag; if there's some reason it doesn't work for you, you can turn -it off, but it's a good idea to mention the problem to the mailing list. - -Great, now your new command builds happily on its own. But nobody invokes it. -Let's change that. - -The list of commands lives in `git.c`. We can register a new command by adding -a `cmd_struct` to the `commands[]` array. `struct cmd_struct` takes a string -with the command name, a function pointer to the command implementation, and a -setup option flag. For now, let's keep mimicking `push`. Find the line where -`cmd_push` is registered, copy it, and modify it for `cmd_psuh`, placing the new -line in alphabetical order (immediately before `cmd_pull`). - -The options are documented in `builtin.h` under "Adding a new built-in." Since -we hope to print some data about the user's current workspace context later, -we need a Git directory, so choose `RUN_SETUP` as your only option. - -Go ahead and build again. You should see a clean build, so let's kick the tires -and see if it works. There's a binary you can use to test with in the -`bin-wrappers` directory. - ----- -$ ./bin-wrappers/git psuh ----- - -Check it out! You've got a command! Nice work! Let's commit this. - -`git status` reveals modified `Makefile`, `builtin.h`, and `git.c` as well as -untracked `builtin/psuh.c` and `git-psuh`. First, let's take care of the binary, -which should be ignored. Open `.gitignore` in your editor, find `/git-pull`, and -add an entry for your new command in alphabetical order: - ----- -... -/git-prune-packed -/git-psuh -/git-pull -/git-push -/git-quiltimport -/git-range-diff -... ----- - -Checking `git status` again should show that `git-psuh` has been removed from -the untracked list and `.gitignore` has been added to the modified list. Now we -can stage and commit: - ----- -$ git add Makefile builtin.h builtin/psuh.c git.c .gitignore -$ git commit -s ----- - -You will be presented with your editor in order to write a commit message. Start -the commit with a 50-column or less subject line, including the name of the -component you're working on, followed by a blank line (always required) and then -the body of your commit message, which should provide the bulk of the context. -Remember to be explicit and provide the "Why" of your change, especially if it -couldn't easily be understood from your diff. When editing your commit message, -don't remove the `Signed-off-by` trailer which was added by `-s` above. - ----- -psuh: add a built-in by popular demand - -Internal metrics indicate this is a command many users expect to be -present. So here's an implementation to help drive customer -satisfaction and engagement: a pony which doubtfully greets the user, -or, a Pony Saying "Um, Hello" (PSUH). - -This commit message is intentionally formatted to 72 columns per line, -starts with a single line as "commit message subject" that is written as -if to command the codebase to do something (add this, teach a command -that). The body of the message is designed to add information about the -commit that is not readily deduced from reading the associated diff, -such as answering the question "why?". - -Signed-off-by: A U Thor ----- - -Go ahead and inspect your new commit with `git show`. "psuh:" indicates you -have modified mainly the `psuh` command. The subject line gives readers an idea -of what you've changed. The sign-off line (`-s`) indicates that you agree to -the Developer's Certificate of Origin 1.1 (see the -`Documentation/SubmittingPatches` +++[[dco]]+++ header). - -For the remainder of the tutorial, the subject line only will be listed for the -sake of brevity. However, fully-fleshed example commit messages are available -on the reference implementation linked at the top of this document. - -[[implementation]] -=== Implementation - -It's probably useful to do at least something besides printing out a string. -Let's start by having a look at everything we get. - -Modify your `cmd_psuh` implementation to dump the args you're passed, keeping -existing `printf()` calls in place: - ----- - int i; - - ... - - printf(Q_("Your args (there is %d):\n", - "Your args (there are %d):\n", - argc), - argc); - for (i = 0; i < argc; i++) - printf("%d: %s\n", i, argv[i]); - - printf(_("Your current working directory:\n%s%s\n"), - prefix ? "/" : "", prefix ? prefix : ""); - ----- - -Build and try it. As you may expect, there's pretty much just whatever we give -on the command line, including the name of our command. (If `prefix` is empty -for you, try `cd Documentation/ && ../bin-wrappers/git psuh`). That's not so -helpful. So what other context can we get? - -Add a line to `#include "config.h"`. Then, add the following bits to the -function body: - ----- - const char *cfg_name; - -... - - git_config(git_default_config, NULL); - if (git_config_get_string_tmp("user.name", &cfg_name) > 0) - printf(_("No name is found in config\n")); - else - printf(_("Your name: %s\n"), cfg_name); ----- - -`git_config()` will grab the configuration from config files known to Git and -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`. - -You should see that the name printed matches the one you see when you run: - ----- -$ git config --get user.name ----- - -Great! Now we know how to check for values in the Git config. Let's commit this -too, so we don't lose our progress. - ----- -$ git add builtin/psuh.c -$ git commit -sm "psuh: show parameters & config opts" ----- - -NOTE: Again, the above is for sake of brevity in this tutorial. In a real change -you should not use `-m` but instead use the editor to write a meaningful -message. - -Still, it'd be nice to know what the user's working context is like. Let's see -if we can print the name of the user's current branch. We can mimic the -`git status` implementation; the printer is located in `wt-status.c` and we can -see that the branch is held in a `struct wt_status`. - -`wt_status_print()` gets invoked by `cmd_status()` in `builtin/commit.c`. -Looking at that implementation we see the status config being populated like so: - ----- -status_init_config(&s, git_status_config); ----- - -But as we drill down, we can find that `status_init_config()` wraps a call -to `git_config()`. Let's modify the code we wrote in the previous commit. - -Be sure to include the header to allow you to use `struct wt_status`: ----- -#include "wt-status.h" ----- - -Then modify your `cmd_psuh` implementation to declare your `struct wt_status`, -prepare it, and print its contents: - ----- - struct wt_status status; - -... - - wt_status_prepare(the_repository, &status); - git_config(git_default_config, &status); - -... - - printf(_("Your current branch: %s\n"), status.branch); ----- - -Run it again. Check it out - here's the (verbose) name of your current branch! - -Let's commit this as well. - ----- -$ git add builtin/psuh.c -$ git commit -sm "psuh: print the current branch" ----- - -Now let's see if we can get some info about a specific commit. - -Luckily, there are some helpers for us here. `commit.h` has a function called -`lookup_commit_reference_by_name` to which we can simply provide a hardcoded -string; `pretty.h` has an extremely handy `pp_commit_easy()` call which doesn't -require a full format object to be passed. - -Add the following includes: - ----- -#include "commit.h" -#include "pretty.h" ----- - -Then, add the following lines within your implementation of `cmd_psuh()` near -the declarations and the logic, respectively. - ----- - struct commit *c = NULL; - struct strbuf commitline = STRBUF_INIT; - -... - - c = lookup_commit_reference_by_name("origin/master"); - - if (c != NULL) { - pp_commit_easy(CMIT_FMT_ONELINE, c, &commitline); - printf(_("Current commit: %s\n"), commitline.buf); - } ----- - -The `struct strbuf` provides some safety belts to your basic `char*`, one of -which is a length member to prevent buffer overruns. It needs to be initialized -nicely with `STRBUF_INIT`. Keep it in mind when you need to pass around `char*`. - -`lookup_commit_reference_by_name` resolves the name you pass it, so you can play -with the value there and see what kind of things you can come up with. - -`pp_commit_easy` is a convenience wrapper in `pretty.h` that takes a single -format enum shorthand, rather than an entire format struct. It then -pretty-prints the commit according to that shorthand. These are similar to the -formats available with `--pretty=FOO` in many Git commands. - -Build it and run, and if you're using the same name in the example, you should -see the subject line of the most recent commit in `origin/master` that you know -about. Neat! Let's commit that as well. - ----- -$ git add builtin/psuh.c -$ git commit -sm "psuh: display the top of origin/master" ----- - -[[add-documentation]] -=== Adding Documentation - -Awesome! You've got a fantastic new command that you're ready to share with the -community. But hang on just a minute - this isn't very user-friendly. Run the -following: - ----- -$ ./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 -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 -project, help pages are written with AsciiDoc (see CodingGuidelines, "Writing -Documentation" section). Use the following template to fill out your own -manpage: - -// Surprisingly difficult to embed AsciiDoc source within AsciiDoc. -[listing] -.... -git-psuh(1) -=========== - -NAME ----- -git-psuh - Delight users' typo with a shy horse - - -SYNOPSIS --------- -[verse] -'git-psuh [...]' - -DESCRIPTION ------------ -... - -OPTIONS[[OPTIONS]] ------------------- -... - -OUTPUT ------- -... - -GIT ---- -Part of the linkgit:git[1] suite -.... - -The most important pieces of this to note are the file header, underlined by =, -the NAME section, and the SYNOPSIS, which would normally contain the grammar if -your command took arguments. Try to use well-established manpage headers so your -documentation is consistent with other Git and UNIX manpages; this makes life -easier for your user, who can skip to the section they know contains the -information they need. - -NOTE: Before trying to build the docs, make sure you have the package `asciidoc` -installed. - -Now that you've written your manpage, you'll need to build it explicitly. We -convert your AsciiDoc to troff which is man-readable like so: - ----- -$ make all doc -$ man Documentation/git-psuh.1 ----- - -or - ----- -$ make -C Documentation/ git-psuh.1 -$ man Documentation/git-psuh.1 ----- - -While this isn't as satisfying as running through `git help`, you can at least -check that your help page looks right. - -You can also check that the documentation coverage is good (that is, the project -sees that your command has been implemented as well as documented) by running -`make check-docs` from the top-level. - -Go ahead and commit your new documentation change. - -[[add-usage]] -=== Adding Usage Text - -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 -tool for pulling out options you need to be able to handle, and it takes a -usage string. - -In order to use it, we'll need to prepare a NULL-terminated array of usage -strings and a `builtin_psuh_options` array. - -Add a line to `#include "parse-options.h"`. - -At global scope, add your array of usage strings: - ----- -static const char * const psuh_usage[] = { - N_("git psuh [...]"), - NULL, -}; ----- - -Then, within your `cmd_psuh()` implementation, we can declare and populate our -`option` struct. Ours is pretty boring but you can add more to it if you want to -explore `parse_options()` in more detail: - ----- - struct option options[] = { - OPT_END() - }; ----- - -Finally, before you print your args and prefix, add the call to -`parse-options()`: - ----- - argc = parse_options(argc, argv, prefix, options, psuh_usage, 0); ----- - -This call will modify your `argv` parameter. It will strip the options you -specified in `options` from `argv` and the locations pointed to from `options` -entries will be updated. Be sure to replace your `argc` with the result from -`parse_options()`, or you will be confused if you try to parse `argv` later. - -It's worth noting the special argument `--`. As you may be aware, many Unix -commands use `--` to indicate "end of named parameters" - all parameters after -the `--` are interpreted merely as positional arguments. (This can be handy if -you want to pass as a parameter something which would usually be interpreted as -a flag.) `parse_options()` will terminate parsing when it reaches `--` and give -you the rest of the options afterwards, untouched. - -Now that you have a usage hint, you can teach Git how to show it in the general -command list shown by `git help git` or `git help -a`, which is generated from -`command-list.txt`. Find the line for 'git-pull' so you can add your 'git-psuh' -line above it in alphabetical order. Now, we can add some attributes about the -command which impacts where it shows up in the aforementioned help commands. The -top of `command-list.txt` shares some information about what each attribute -means; in those help pages, the commands are sorted according to these -attributes. `git psuh` is user-facing, or porcelain - so we will mark it as -"mainporcelain". For "mainporcelain" commands, the comments at the top of -`command-list.txt` indicate we can also optionally add an attribute from another -list; since `git psuh` shows some information about the user's workspace but -doesn't modify anything, let's mark it as "info". Make sure to keep your -attributes in the same style as the rest of `command-list.txt` using spaces to -align and delineate them: - ----- -git-prune-packed plumbingmanipulators -git-psuh mainporcelain info -git-pull mainporcelain remote -git-push mainporcelain remote ----- - -Build again. Now, when you run with `-h`, you should see your usage printed and -your command terminated before anything else interesting happens. Great! - -Go ahead and commit this one, too. - -[[testing]] -== Testing - -It's important to test your code - even for a little toy command like this one. -Moreover, your patch won't be accepted into the Git tree without tests. Your -tests should: - -* Illustrate the current behavior of the feature -* Prove the current behavior matches the expected behavior -* Ensure the externally-visible behavior isn't broken in later changes - -So let's write some tests. - -Related reading: `t/README` - -[[overview-test-structure]] -=== Overview of Testing Structure - -The tests in Git live in `t/` and are named with a 4-digit decimal number using -the schema shown in the Naming Tests section of `t/README`. - -[[write-new-test]] -=== Writing Your Test - -Since this a toy command, let's go ahead and name the test with t9999. However, -as many of the family/subcmd combinations are full, best practice seems to be -to find a command close enough to the one you've added and share its naming -space. - -Create a new file `t/t9999-psuh-tutorial.sh`. Begin with the header as so (see -"Writing Tests" and "Source 'test-lib.sh'" in `t/README`): - ----- -#!/bin/sh - -test_description='git-psuh test - -This test runs git-psuh and makes sure it does not crash.' - -. ./test-lib.sh ----- - -Tests are framed inside of a `test_expect_success` in order to output TAP -formatted results. Let's make sure that `git psuh` doesn't exit poorly and does -mention the right animal somewhere: - ----- -test_expect_success 'runs correctly with no args and good output' ' - git psuh >actual && - grep Pony actual -' ----- - -Indicate that you've run everything you wanted by adding the following at the -bottom of your script: - ----- -test_done ----- - -Make sure you mark your test script executable: - ----- -$ chmod +x t/t9999-psuh-tutorial.sh ----- - -You can get an idea of whether you created your new test script successfully -by running `make -C t test-lint`, which will check for things like test number -uniqueness, executable bit, and so on. - -[[local-test]] -=== Running Locally - -Let's try and run locally: - ----- -$ make -$ cd t/ && prove t9999-psuh-tutorial.sh ----- - -You can run the full test suite and ensure `git-psuh` didn't break anything: - ----- -$ cd t/ -$ prove -j$(nproc) --shuffle t[0-9]*.sh ----- - -NOTE: You can also do this with `make test` or use any testing harness which can -speak TAP. `prove` can run concurrently. `shuffle` randomizes the order the -tests are run in, which makes them resilient against unwanted inter-test -dependencies. `prove` also makes the output nicer. - -Go ahead and commit this change, as well. - -[[ready-to-share]] -== Getting Ready to Share - -You may have noticed already that the Git project performs its code reviews via -emailed patches, which are then applied by the maintainer when they are ready -and approved by the community. The Git project does not accept patches from -pull requests, and the patches emailed for review need to be formatted a -specific way. At this point the tutorial diverges, in order to demonstrate two -different methods of formatting your patchset and getting it reviewed. - -The first method to be covered is GitGitGadget, which is useful for those -already familiar with GitHub's common pull request workflow. This method -requires a GitHub account. - -The second method to be covered is `git send-email`, which can give slightly -more fine-grained control over the emails to be sent. This method requires some -setup which can change depending on your system and will not be covered in this -tutorial. - -Regardless of which method you choose, your engagement with reviewers will be -the same; the review process will be covered after the sections on GitGitGadget -and `git send-email`. - -[[howto-ggg]] -== Sending Patches via GitGitGadget - -One option for sending patches is to follow a typical pull request workflow and -send your patches out via GitGitGadget. GitGitGadget is a tool created by -Johannes Schindelin to make life as a Git contributor easier for those used to -the GitHub PR workflow. It allows contributors to open pull requests against its -mirror of the Git project, and does some magic to turn the PR into a set of -emails and send them out for you. It also runs the Git continuous integration -suite for you. It's documented at http://gitgitgadget.github.io. - -[[create-fork]] -=== Forking `git/git` on GitHub - -Before you can send your patch off to be reviewed using GitGitGadget, you will -need to fork the Git project and upload your changes. First thing - make sure -you have a GitHub account. - -Head to the https://github.com/git/git[GitHub mirror] and look for the Fork -button. Place your fork wherever you deem appropriate and create it. - -[[upload-to-fork]] -=== Uploading to Your Own Fork - -To upload your branch to your own fork, you'll need to add the new fork as a -remote. You can use `git remote -v` to show the remotes you have added already. -From your new fork's page on GitHub, you can press "Clone or download" to get -the URL; then you need to run the following to add, replacing your own URL and -remote name for the examples provided: - ----- -$ git remote add remotename git@github.com:remotename/git.git ----- - -or to use the HTTPS URL: - ----- -$ git remote add remotename https://github.com/remotename/git/.git ----- - -Run `git remote -v` again and you should see the new remote showing up. -`git fetch remotename` (with the real name of your remote replaced) in order to -get ready to push. - -Next, double-check that you've been doing all your development in a new branch -by running `git branch`. If you didn't, now is a good time to move your new -commits to their own branch. - -As mentioned briefly at the beginning of this document, we are basing our work -on `master`, so go ahead and update as shown below, or using your preferred -workflow. - ----- -$ git checkout master -$ git pull -r -$ git rebase master psuh ----- - -Finally, you're ready to push your new topic branch! (Due to our branch and -command name choices, be careful when you type the command below.) - ----- -$ git push remotename psuh ----- - -Now you should be able to go and check out your newly created branch on GitHub. - -[[send-pr-ggg]] -=== Sending a PR to GitGitGadget - -In order to have your code tested and formatted for review, you need to start by -opening a Pull Request against `gitgitgadget/git`. Head to -https://github.com/gitgitgadget/git and open a PR either with the "New pull -request" button or the convenient "Compare & pull request" button that may -appear with the name of your newly pushed branch. - -Review the PR's title and description, as it's used by GitGitGadget as the cover -letter for your change. When you're happy, submit your pull request. - -[[run-ci-ggg]] -=== Running CI and Getting Ready to Send - -If it's your first time using GitGitGadget (which is likely, as you're using -this tutorial) then someone will need to give you permission to use the tool. -As mentioned in the GitGitGadget documentation, you just need someone who -already uses it to comment on your PR with `/allow `. GitGitGadget -will automatically run your PRs through the CI even without the permission given -but you will not be able to `/submit` your changes until someone allows you to -use the tool. - -NOTE: You can typically find someone who can `/allow` you on GitGitGadget by -either examining recent pull requests where someone has been granted `/allow` -(https://github.com/gitgitgadget/git/pulls?utf8=%E2%9C%93&q=is%3Apr+is%3Aopen+%22%2Fallow%22[Search: -is:pr is:open "/allow"]), in which case both the author and the person who -granted the `/allow` can now `/allow` you, or by inquiring on the -https://web.libera.chat/#git-devel[#git-devel] IRC channel on Libera Chat -linking your pull request and asking for someone to `/allow` you. - -If the CI fails, you can update your changes with `git rebase -i` and push your -branch again: - ----- -$ git push -f remotename psuh ----- - -In fact, you should continue to make changes this way up until the point when -your patch is accepted into `next`. - -//// -TODO https://github.com/gitgitgadget/gitgitgadget/issues/83 -It'd be nice to be able to verify that the patch looks good before sending it -to everyone on Git mailing list. -[[check-work-ggg]] -=== Check Your Work -//// - -[[send-mail-ggg]] -=== Sending Your Patches - -Now that your CI is passing and someone has granted you permission to use -GitGitGadget with the `/allow` command, sending out for review is as simple as -commenting on your PR with `/submit`. - -[[responding-ggg]] -=== Updating With Comments - -Skip ahead to <> for information on how to -reply to review comments you will receive on the mailing list. - -Once you have your branch again in the shape you want following all review -comments, you can submit again: - ----- -$ git push -f remotename psuh ----- - -Next, go look at your pull request against GitGitGadget; you should see the CI -has been kicked off again. Now while the CI is running is a good time for you -to modify your description at the top of the pull request thread; it will be -used again as the cover letter. You should use this space to describe what -has changed since your previous version, so that your reviewers have some idea -of what they're looking at. When the CI is done running, you can comment once -more with `/submit` - GitGitGadget will automatically add a v2 mark to your -changes. - -[[howto-git-send-email]] -== Sending Patches with `git send-email` - -If you don't want to use GitGitGadget, you can also use Git itself to mail your -patches. Some benefits of using Git this way include finer grained control of -subject line (for example, being able to use the tag [RFC PATCH] in the subject) -and being able to send a ``dry run'' mail to yourself to ensure it all looks -good before going out to the list. - -[[setup-git-send-email]] -=== Prerequisite: Setting Up `git send-email` - -Configuration for `send-email` can vary based on your operating system and email -provider, and so will not be covered in this tutorial, beyond stating that in -many distributions of Linux, `git-send-email` is not packaged alongside the -typical `git` install. You may need to install this additional package; there -are a number of resources online to help you do so. You will also need to -determine the right way to configure it to use your SMTP server; again, as this -configuration can change significantly based on your system and email setup, it -is out of scope for the context of this tutorial. - -[[format-patch]] -=== Preparing Initial Patchset - -Sending emails with Git is a two-part process; before you can prepare the emails -themselves, you'll need to prepare the patches. Luckily, this is pretty simple: - ----- -$ git format-patch --cover-letter -o psuh/ --base=auto psuh@{u}..psuh ----- - - . The `--cover-letter` option tells `format-patch` to create a - cover letter template for you. You will need to fill in the - template before you're ready to send - but for now, the template - will be next to your other patches. - - . The `-o psuh/` option tells `format-patch` to place the patch - files into a directory. This is useful because `git send-email` - can take a directory and send out all the patches from there. - - . The `--base=auto` option tells the command to record the "base - commit", on which the recipient is expected to apply the patch - series. The `auto` value will cause `format-patch` to compute - the base commit automatically, which is the merge base of tip - commit of the remote-tracking branch and the specified revision - range. - - . The `psuh@{u}..psuh` option tells `format-patch` to generate - patches for the commits you created on the `psuh` branch since it - forked from its upstream (which is `origin/master` if you - followed the example in the "Set up your workspace" section). If - you are already on the `psuh` branch, you can just say `@{u}`, - which means "commits on the current branch since it forked from - its upstream", which is the same thing. - -The command will make one patch file per commit. After you -run, you can go have a look at each of the patches with your favorite text -editor and make sure everything looks alright; however, it's not recommended to -make code fixups via the patch file. It's a better idea to make the change the -normal way using `git rebase -i` or by adding a new commit than by modifying a -patch. - -NOTE: Optionally, you can also use the `--rfc` flag to prefix your patch subject -with ``[RFC PATCH]'' instead of ``[PATCH]''. RFC stands for ``request for -comments'' and indicates that while your code isn't quite ready for submission, -you'd like to begin the code review process. This can also be used when your -patch is a proposal, but you aren't sure whether the community wants to solve -the problem with that approach or not - to conduct a sort of design review. You -may also see on the list patches marked ``WIP'' - this means they are incomplete -but want reviewers to look at what they have so far. You can add this flag with -`--subject-prefix=WIP`. - -Check and make sure that your patches and cover letter template exist in the -directory you specified - you're nearly ready to send out your review! - -[[cover-letter]] -=== Preparing Email - -In addition to an email per patch, the Git community also expects your patches -to come with a cover letter, typically with a subject line [PATCH 0/x] (where -x is the number of patches you're sending). Since you invoked `format-patch` -with `--cover-letter`, you've already got a template ready. Open it up in your -favorite editor. - -You should see a number of headers present already. Check that your `From:` -header is correct. Then modify your `Subject:` to something which succinctly -covers the purpose of your entire topic branch, for example: - ----- -Subject: [PATCH 0/7] adding the 'psuh' command ----- - -Make sure you retain the ``[PATCH 0/X]'' part; that's what indicates to the Git -community that this email is the beginning of a review, and many reviewers -filter their email for this type of flag. - -You'll need to add some extra parameters when you invoke `git send-email` to add -the cover letter. - -Next you'll have to fill out the body of your cover letter. This is an important -component of change submission as it explains to the community from a high level -what you're trying to do, and why, in a way that's more apparent than just -looking at your diff. Be sure to explain anything your diff doesn't make clear -on its own. - -Here's an example body for `psuh`: - ----- -Our internal metrics indicate widespread interest in the command -git-psuh - that is, many users are trying to use it, but finding it is -unavailable, using some unknown workaround instead. - -The following handful of patches add the psuh command and implement some -handy features on top of it. - -This patchset is part of the MyFirstContribution tutorial and should not -be merged. ----- - -The template created by `git format-patch --cover-letter` includes a diffstat. -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 +++++++ - 6 files changed, 128 insertions(+) - create mode 100644 Documentation/git-psuh.txt - create mode 100644 builtin/psuh.c - create mode 100755 t/t9999-psuh-tutorial.sh ----- - -Finally, the letter will include the version of Git used to generate the -patches. You can leave that string alone. - -[[sending-git-send-email]] -=== Sending Email - -At this point you should have a directory `psuh/` which is filled with your -patches and a cover letter. Time to mail it out! You can send it like this: - ----- -$ git send-email --to=target@example.com psuh/*.patch ----- - -NOTE: Check `git help send-email` for some other options which you may find -valuable, such as changing the Reply-to address or adding more CC and BCC lines. - -NOTE: When you are sending a real patch, it will go to git@vger.kernel.org - but -please don't send your patchset from the tutorial to the real mailing list! For -now, you can send it to yourself, to make sure you understand how it will look. - -After you run the command above, you will be presented with an interactive -prompt for each patch that's about to go out. This gives you one last chance to -edit or quit sending something (but again, don't edit code this way). Once you -press `y` or `a` at these prompts your emails will be sent! Congratulations! - -Awesome, now the community will drop everything and review your changes. (Just -kidding - be patient!) - -[[v2-git-send-email]] -=== Sending v2 - -This section will focus on how to send a v2 of your patchset. To learn what -should go into v2, skip ahead to <> for -information on how to handle comments from reviewers. - -We'll reuse our `psuh` topic branch for v2. Before we make any changes, we'll -mark the tip of our v1 branch for easy reference: - ----- -$ git checkout psuh -$ git branch psuh-v1 ----- - -Refine your patch series by using `git rebase -i` to adjust commits based upon -reviewer comments. Once the patch series is ready for submission, generate your -patches again, but with some new flags: - ----- -$ git format-patch -v2 --cover-letter -o psuh/ --range-diff master..psuh-v1 master.. ----- - -The `--range-diff master..psuh-v1` parameter tells `format-patch` to include a -range-diff between `psuh-v1` and `psuh` in the cover letter (see -linkgit:git-range-diff[1]). This helps tell reviewers about the differences -between your v1 and v2 patches. - -The `-v2` parameter tells `format-patch` to output your patches -as version "2". For instance, you may notice that your v2 patches are -all named like `v2-000n-my-commit-subject.patch`. `-v2` will also format -your patches by prefixing them with "[PATCH v2]" instead of "[PATCH]", -and your range-diff will be prefaced with "Range-diff against v1". - -Afer you run this command, `format-patch` will output the patches to the `psuh/` -directory, alongside the v1 patches. Using a single directory makes it easy to -refer to the old v1 patches while proofreading the v2 patches, but you will need -to be careful to send out only the v2 patches. We will use a pattern like -"psuh/v2-*.patch" (not "psuh/*.patch", which would match v1 and v2 patches). - -Edit your cover letter again. Now is a good time to mention what's different -between your last version and now, if it's something significant. You do not -need the exact same body in your second cover letter; focus on explaining to -reviewers the changes you've made that may not be as visible. - -You will also need to go and find the Message-Id of your previous cover letter. -You can either note it when you send the first series, from the output of `git -send-email`, or you can look it up on the -https://lore.kernel.org/git[mailing list]. Find your cover letter in the -archives, click on it, then click "permalink" or "raw" to reveal the Message-Id -header. It should match: - ----- -Message-Id: ----- - -Your Message-Id is ``. This example will be used -below as well; make sure to replace it with the correct Message-Id for your -**previous cover letter** - that is, if you're sending v2, use the Message-Id -from v1; if you're sending v3, use the Message-Id from v2. - -While you're looking at the email, you should also note who is CC'd, as it's -common practice in the mailing list to keep all CCs on a thread. You can add -these CC lines directly to your cover letter with a line like so in the header -(before the Subject line): - ----- -CC: author@example.com, Othe R ----- - -Now send the emails again, paying close attention to which messages you pass in -to the command: - ----- -$ git send-email --to=target@example.com - --in-reply-to="" - psuh/v2-*.patch ----- - -[[single-patch]] -=== Bonus Chapter: One-Patch Changes - -In some cases, your very small change may consist of only one patch. When that -happens, you only need to send one email. Your commit message should already be -meaningful and explain at a high level the purpose (what is happening and why) -of your patch, but if you need to supply even more context, you can do so below -the `---` in your patch. Take the example below, which was generated with `git -format-patch` on a single commit, and then edited to add the content between -the `---` and the diffstat. - ----- -From 1345bbb3f7ac74abde040c12e737204689a72723 Mon Sep 17 00:00:00 2001 -From: A U Thor -Date: Thu, 18 Apr 2019 15:11:02 -0700 -Subject: [PATCH] README: change the grammar - -I think it looks better this way. This part of the commit message will -end up in the commit-log. - -Signed-off-by: A U Thor ---- -Let's have a wild discussion about grammar on the mailing list. This -part of my email will never end up in the commit log. Here is where I -can add additional context to the mailing list about my intent, outside -of the context of the commit log. This section was added after `git -format-patch` was run, by editing the patch file in a text editor. - - README.md | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/README.md b/README.md -index 88f126184c..38da593a60 100644 ---- a/README.md -+++ b/README.md -@@ -3,7 +3,7 @@ - Git - fast, scalable, distributed revision control system - ========================================================= - --Git is a fast, scalable, distributed revision control system with an -+Git is a fast, scalable, and distributed revision control system with an - unusually rich command set that provides both high-level operations - and full access to internals. - --- -2.21.0.392.gf8f6787159e-goog ----- - -[[now-what]] -== My Patch Got Emailed - Now What? - -[[reviewing]] -=== Responding to Reviews - -After a few days, you will hopefully receive a reply to your patchset with some -comments. Woohoo! Now you can get back to work. - -It's good manners to reply to each comment, notifying the reviewer that you have -made the change suggested, feel the original is better, or that the comment -inspired you to do something a new way which is superior to both the original -and the suggested change. This way reviewers don't need to inspect your v2 to -figure out whether you implemented their comment or not. - -Reviewers may ask you about what you wrote in the patchset, either in -the proposed commit log message or in the changes themselves. You -should answer these questions in your response messages, but often the -reason why reviewers asked these questions to understand what you meant -to write is because your patchset needed clarification to be understood. - -Do not be satisfied by just answering their questions in your response -and hear them say that they now understand what you wanted to say. -Update your patches to clarify the points reviewers had trouble with, -and prepare your v2; the words you used to explain your v1 to answer -reviewers' questions may be useful thing to use. Your goal is to make -your v2 clear enough so that it becomes unnecessary for you to give the -same explanation to the next person who reads it. - -If you are going to push back on a comment, be polite and explain why you feel -your original is better; be prepared that the reviewer may still disagree with -you, and the rest of the community may weigh in on one side or the other. As -with all code reviews, it's important to keep an open mind to doing something a -different way than you originally planned; other reviewers have a different -perspective on the project than you do, and may be thinking of a valid side -effect which had not occurred to you. It is always okay to ask for clarification -if you aren't sure why a change was suggested, or what the reviewer is asking -you to do. - -Make sure your email client has a plaintext email mode and it is turned on; the -Git list rejects HTML email. Please also follow the mailing list etiquette -outlined in the -https://kernel.googlesource.com/pub/scm/git/git/+/todo/MaintNotes[Maintainer's -Note], which are similar to etiquette rules in most open source communities -surrounding bottom-posting and inline replies. - -When you're making changes to your code, it is cleanest - that is, the resulting -commits are easiest to look at - if you use `git rebase -i` (interactive -rebase). Take a look at this -https://www.oreilly.com/library/view/git-pocket-guide/9781449327507/ch10.html[overview] -from O'Reilly. The general idea is to modify each commit which requires changes; -this way, instead of having a patch A with a mistake, a patch B which was fine -and required no upstream reviews in v1, and a patch C which fixes patch A for -v2, you can just ship a v2 with a correct patch A and correct patch B. This is -changing history, but since it's local history which you haven't shared with -anyone, that is okay for now! (Later, it may not make sense to do this; take a -look at the section below this one for some context.) - -[[after-approval]] -=== After Review Approval - -The Git project has four integration branches: `seen`, `next`, `master`, and -`maint`. Your change will be placed into `seen` fairly early on by the maintainer -while it is still in the review process; from there, when it is ready for wider -testing, it will be merged into `next`. Plenty of early testers use `next` and -may report issues. Eventually, changes in `next` will make it to `master`, -which is typically considered stable. Finally, when a new release is cut, -`maint` is used to base bugfixes onto. As mentioned at the beginning of this -document, you can read `Documents/SubmittingPatches` for some more info about -the use of the various integration branches. - -Back to now: your code has been lauded by the upstream reviewers. It is perfect. -It is ready to be accepted. You don't need to do anything else; the maintainer -will merge your topic branch to `next` and life is good. - -However, if you discover it isn't so perfect after this point, you may need to -take some special steps depending on where you are in the process. - -If the maintainer has announced in the "What's cooking in git.git" email that -your topic is marked for `next` - that is, that they plan to merge it to `next` -but have not yet done so - you should send an email asking the maintainer to -wait a little longer: "I've sent v4 of my series and you marked it for `next`, -but I need to change this and that - please wait for v5 before you merge it." - -If the topic has already been merged to `next`, rather than modifying your -patches with `git rebase -i`, you should make further changes incrementally - -that is, with another commit, based on top of the maintainer's topic branch as -detailed in https://github.com/gitster/git. Your work is still in the same topic -but is now incremental, rather than a wholesale rewrite of the topic branch. - -The topic branches in the maintainer's GitHub are mirrored in GitGitGadget, so -if you're sending your reviews out that way, you should be sure to open your PR -against the appropriate GitGitGadget/Git branch. - -If you're using `git send-email`, you can use it the same way as before, but you -should generate your diffs from `..` and base your work on -`` instead of `master`. diff --git a/Documentation/MyFirstObjectWalk.adoc b/Documentation/MyFirstObjectWalk.adoc new file mode 100644 index 00000000000000..413a9fdb05c56e --- /dev/null +++ b/Documentation/MyFirstObjectWalk.adoc @@ -0,0 +1,913 @@ += My First Object Walk + +== What's an Object Walk? + +The object walk is a key concept in Git - this is the process that underpins +operations like object transfer and fsck. Beginning from a given commit, the +list of objects is found by walking parent relationships between commits (commit +X based on commit W) and containment relationships between objects (tree Y is +contained within commit X, and blob Z is located within tree Y, giving our +working tree for commit X something like `y/z.txt`). + +A related concept is the revision walk, which is focused on commit objects and +their parent relationships and does not delve into other object types. The +revision walk is used for operations like `git log`. + +=== Related Reading + +- `Documentation/user-manual.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] + gives a good overview of the types of objects in Git and what your object + walk is really describing. + +== Setting Up + +Create a new branch from `master`. + +---- +git checkout -b revwalk origin/master +---- + +We'll put our fiddling into a new command. For fun, let's name it `git walken`. +Open up a new file `builtin/walken.c` and set up the command handler: + +---- +/* + * "git walken" + * + * Part of the "My First Object Walk" tutorial. + */ + +#include "builtin.h" +#include "trace.h" + +int cmd_walken(int argc, const char **argv, const char *prefix, struct repository *repo) +{ + trace_printf(_("cmd_walken incoming...\n")); + return 0; +} +---- + +NOTE: `trace_printf()`, defined in `trace.h`, differs from `printf()` in +that it can be turned on or off at runtime. For the purposes of this +tutorial, we will write `walken` as though it is intended for use as +a "plumbing" command: that is, a command which is used primarily in +scripts, rather than interactively by humans (a "porcelain" command). +So we will send our debug output to `trace_printf()` instead. +When running, enable trace output by setting the environment variable `GIT_TRACE`. + +Add usage text and `-h` handling, like all subcommands should consistently do +(our test suite will notice and complain if you fail to do so). +We'll need to include the `parse-options.h` header. + +---- +#include "parse-options.h" + +... + +int cmd_walken(int argc, const char **argv, const char *prefix) +{ + const char * const walken_usage[] = { + N_("git walken"), + NULL, + }; + struct option options[] = { + OPT_END() + }; + + argc = parse_options(argc, argv, prefix, options, walken_usage, 0); + + ... +} +---- + +Also add the relevant line in `builtin.h` near `cmd_version()`: + +---- +int cmd_walken(int argc, const char **argv, const char *prefix, struct repository *repo); +---- + +Include the command in `git.c` in `commands[]` near the entry for `version`, +maintaining alphabetical ordering: + +---- +{ "walken", cmd_walken, RUN_SETUP }, +---- + +Add an entry for the new command in the both the Make and Meson build system, +before the entry for `worktree`: + +- In the `Makefile`: +---- +... +BUILTIN_OBJS += builtin/walken.o +... +---- + +- In the `meson.build` file: +---- +builtin_sources = [ + ... + 'builtin/walken.c', + ... +] +---- + +Build and test out your command, without forgetting to ensure the `DEVELOPER` +flag is set, and with `GIT_TRACE` enabled so the debug output can be seen: + +---- +$ echo DEVELOPER=1 >>config.mak +$ make +$ GIT_TRACE=1 ./bin-wrappers/git walken +---- + +NOTE: For a more exhaustive overview of the new command process, take a look at +`Documentation/MyFirstContribution.adoc`. + +NOTE: A reference implementation can be found at +https://github.com/nasamuffin/git/tree/revwalk. + +=== `struct rev_cmdline_info` + +The definition of `struct rev_cmdline_info` can be found in `revision.h`. + +This struct is contained within the `rev_info` struct and is used to reflect +parameters provided by the user over the CLI. + +`nr` represents the number of `rev_cmdline_entry` present in the array. + +`alloc` is used by the `ALLOC_GROW` macro. Check `alloc.h` - this variable is +used to track the allocated size of the list. + +Per entry, we find: + +`item` is the object provided upon which to base the object walk. Items in Git +can be blobs, trees, commits, or tags. (See `Documentation/gittutorial-2.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 +mentioned above towards the top for a discussion of where the OID can come +from. + +`whence` indicates some information about what to do with the parents of the +specified object. We'll explore this flag more later on; take a look at +`Documentation/revisions.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 +block under the `#include`s in `revision.h`. The most likely ones to be set in +the `rev_cmdline_info` are `UNINTERESTING` and `BOTTOM`, but these same flags +can be used during the walk, as well. + +=== `struct rev_info` + +This one is quite a bit longer, and many fields are only used during the walk +by `revision.c` - not configuration options. Most of the configurable flags in +`struct rev_info` have a mirror in `Documentation/rev-list-options.adoc`. It's a +good idea to take some time and read through that document. + +== Basic Commit Walk + +First, let's see if we can replicate the output of `git log --oneline`. We'll +refer back to the implementation frequently to discover norms when performing +an object walk of our own. + +To do so, we'll first find all the commits, in order, which preceded the current +commit. We'll extract the name and subject of the commit from each. + +Ideally, we will also be able to find out which ones are currently at the tip of +various branches. + +=== Setting Up + +Preparing for your object walk has some distinct stages. + +1. Perform default setup for this mode, and others which may be invoked. +2. Check configuration files for relevant settings. +3. Set up the `rev_info` struct. +4. Tweak the initialized `rev_info` to suit the current walk. +5. Prepare the `rev_info` for the walk. +6. Iterate over the objects, processing each one. + +==== Default Setups + +Before examining configuration files which may modify command behavior, set up +default state for switches or options your command may have. If your command +utilizes other Git components, ask them to set up their default states as well. +For instance, `git log` takes advantage of `grep` and `diff` functionality, so +its `init_log_defaults()` sets its own state (`decoration_style`) and asks +`grep` and `diff` to initialize themselves by calling each of their +initialization functions. + +==== Configuring From `.gitconfig` + +Next, we should have a look at any relevant configuration settings (i.e., +settings readable and settable from `git config`). This is done by providing a +callback to `repo_config()`; within that callback, you can also invoke methods +from other components you may need that need to intercept these options. Your +callback will be invoked once per each configuration value which Git knows about +(global, local, worktree, etc.). + +Similarly to the default values, we don't have anything to do here yet +ourselves; however, we should call `git_default_config()` if we aren't calling +any other existing config callbacks. + +Add a new function to `builtin/walken.c`. +We'll also need to include the `config.h` header: + +---- +#include "config.h" + +... + +static int git_walken_config(const char *var, const char *value, + const struct config_context *ctx, void *cb) +{ + /* + * For now, we don't have any custom configuration, so fall back to + * the default config. + */ + return git_default_config(var, value, ctx, cb); +} +---- + +Make sure to invoke `repo_config()` with it in your `cmd_walken()`: + +---- +int cmd_walken(int argc, const char **argv, const char *prefix, struct repository *repo) +{ + ... + + repo_config(repo, git_walken_config, NULL); + + ... +} +---- + +==== Setting Up `rev_info` + +Now that we've gathered external configuration and options, it's time to +initialize the `rev_info` object which we will use to perform the walk. This is +typically done by calling `repo_init_revisions()` with the repository you intend +to target, as well as the `prefix` argument of `cmd_walken` and your `rev_info` +struct. + +Add the `struct rev_info` and the `repo_init_revisions()` call. +We'll also need to include the `revision.h` header: + +---- +#include "revision.h" + +... + +int cmd_walken(int argc, const char **argv, const char *prefix, struct repository *repo) +{ + /* This can go wherever you like in your declarations.*/ + struct rev_info rev; + ... + + /* This should go after the repo_config() call. */ + repo_init_revisions(repo, &rev, prefix); + + ... +} +---- + +==== Tweaking `rev_info` For the Walk + +We're getting close, but we're still not quite ready to go. Now that `rev` is +initialized, we can modify it to fit our needs. This is usually done within a +helper for clarity, so let's add one: + +---- +static void final_rev_info_setup(struct rev_info *rev) +{ + /* + * We want to mimic the appearance of `git log --oneline`, so let's + * force oneline format. + */ + get_commit_format("oneline", rev); + + /* Start our object walk at HEAD. */ + add_head_to_pending(rev); +} +---- + +[NOTE] +==== +Instead of using the shorthand `add_head_to_pending()`, you could do +something like this: + +---- + struct setup_revision_opt opt; + + memset(&opt, 0, sizeof(opt)); + opt.def = "HEAD"; + opt.revarg_opt = REVARG_COMMITTISH; + setup_revisions(argc, argv, rev, &opt); +---- + +Using a `setup_revision_opt` gives you finer control over your walk's starting +point. +==== + +Then let's invoke `final_rev_info_setup()` after the call to +`repo_init_revisions()`: + +---- +int cmd_walken(int argc, const char **argv, const char *prefix, struct repository *repo) +{ + ... + + final_rev_info_setup(&rev); + + ... +} +---- + +Later, we may wish to add more arguments to `final_rev_info_setup()`. But for +now, this is all we need. + +==== Preparing `rev_info` For the Walk + +Now that `rev` is all initialized and configured, we've got one more setup step +before we get rolling. We can do this in a helper, which will both prepare the +`rev_info` for the walk, and perform the walk itself. Let's start the helper +with the call to `prepare_revision_walk()`, which can return an error without +dying on its own: + +---- +static void walken_commit_walk(struct rev_info *rev) +{ + if (prepare_revision_walk(rev)) + die(_("revision walk setup failed")); +} +---- + +NOTE: `die()` prints to `stderr` and exits the program. Since it will print to +`stderr` it's likely to be seen by a human, so we will localize it. + +==== Performing the Walk! + +Finally! We are ready to begin the walk itself. Now we can see that `rev_info` +can also be used as an iterator; we move to the next item in the walk by using +`get_revision()` repeatedly. Add the listed variable declarations at the top and +the walk loop below the `prepare_revision_walk()` call within your +`walken_commit_walk()`: + +---- +#include "pretty.h" + +... + +static void walken_commit_walk(struct rev_info *rev) +{ + struct commit *commit; + struct strbuf prettybuf = STRBUF_INIT; + + ... + + while ((commit = get_revision(rev))) { + strbuf_reset(&prettybuf); + pp_commit_easy(CMIT_FMT_ONELINE, commit, &prettybuf); + puts(prettybuf.buf); + } + strbuf_release(&prettybuf); +} +---- + +NOTE: `puts()` prints a `char*` to `stdout`. Since this is the part of the +command we expect to be machine-parsed, we're sending it directly to stdout. + +Give it a shot. + +---- +$ make +$ ./bin-wrappers/git walken +---- + +You should see all of the subject lines of all the commits in +your tree's history, in order, ending with the initial commit, "Initial revision +of "git", the information manager from hell". Congratulations! You've written +your first revision walk. You can play with printing some additional fields +from each commit if you're curious; have a look at the functions available in +`commit.h`. + +=== Adding a Filter + +Next, let's try to filter the commits we see based on their author. This is +equivalent to running `git log --author=`. We can add a filter by +modifying `rev_info.grep_filter`, which is a `struct grep_opt`. + +First some setup. Add `grep_config()` to `git_walken_config()`: + +---- +static int git_walken_config(const char *var, const char *value, + const struct config_context *ctx, void *cb) +{ + grep_config(var, value, ctx, cb); + return git_default_config(var, value, ctx, cb); +} +---- + +Next, we can modify the `grep_filter`. This is done with convenience functions +found in `grep.h`. For fun, we're filtering to only commits from folks using a +`gmail.com` email address - a not-very-precise guess at who may be working on +Git as a hobby. Since we're checking the author, which is a specific line in the +header, we'll use the `append_header_grep_pattern()` helper. We can use +the `enum grep_header_field` to indicate which part of the commit header we want +to search. + +In `final_rev_info_setup()`, add your filter line: + +---- +static void final_rev_info_setup(int argc, const char **argv, + const char *prefix, struct rev_info *rev) +{ + ... + + append_header_grep_pattern(&rev->grep_filter, GREP_HEADER_AUTHOR, + "gmail"); + compile_grep_patterns(&rev->grep_filter); + + ... +} +---- + +`append_header_grep_pattern()` adds your new "gmail" pattern to `rev_info`, but +it won't work unless we compile it with `compile_grep_patterns()`. + +NOTE: If you are using `setup_revisions()` (for example, if you are passing a +`setup_revision_opt` instead of using `add_head_to_pending()`), you don't need +to call `compile_grep_patterns()` because `setup_revisions()` calls it for you. + +NOTE: We could add the same filter via the `append_grep_pattern()` helper if we +wanted to, but `append_header_grep_pattern()` adds the `enum grep_context` and +`enum grep_pat_token` for us. + +=== Changing the Order + +There are a few ways that we can change the order of the commits during a +revision walk. Firstly, we can use the `enum rev_sort_order` to choose from some +typical orderings. + +`topo_order` is the same as `git log --topo-order`: we avoid showing a parent +before all of its children have been shown, and we avoid mixing commits which +are in different lines of history. (`git help log`'s section on `--topo-order` +has a very nice diagram to illustrate this.) + +Let's see what happens when we run with `REV_SORT_BY_COMMIT_DATE` as opposed to +`REV_SORT_BY_AUTHOR_DATE`. Add the following: + +---- +static void final_rev_info_setup(int argc, const char **argv, + const char *prefix, struct rev_info *rev) +{ + ... + + rev->topo_order = 1; + rev->sort_order = REV_SORT_BY_COMMIT_DATE; + + ... +} +---- + +Let's output this into a file so we can easily diff it with the walk sorted by +author date. + +---- +$ make +$ ./bin-wrappers/git walken > commit-date.txt +---- + +Then, let's sort by author date and run it again. + +---- +static void final_rev_info_setup(int argc, const char **argv, + const char *prefix, struct rev_info *rev) +{ + ... + + rev->topo_order = 1; + rev->sort_order = REV_SORT_BY_AUTHOR_DATE; + + ... +} +---- + +---- +$ make +$ ./bin-wrappers/git walken > author-date.txt +---- + +Finally, compare the two. This is a little less helpful without object names or +dates, but hopefully we get the idea. + +---- +$ diff -u commit-date.txt author-date.txt +---- + +This display indicates that commits can be reordered after they're written, for +example with `git rebase`. + +Let's try one more reordering of commits. `rev_info` exposes a `reverse` flag. +Set that flag somewhere inside of `final_rev_info_setup()`: + +---- +static void final_rev_info_setup(int argc, const char **argv, const char *prefix, + struct rev_info *rev) +{ + ... + + rev->reverse = 1; + + ... +} +---- + +Run your walk again and note the difference in order. (If you remove the grep +pattern, you should see the last commit this call gives you as your current +HEAD.) + +== Basic Object Walk + +So far we've been walking only commits. But Git has more types of objects than +that! Let's see if we can walk _all_ objects, and find out some information +about each one. + +We can base our work on an example. `git pack-objects` prepares all kinds of +objects for packing into a bitmap or packfile. The work we are interested in +resides in `builtin/pack-objects.c:get_object_list()`; examination of that +function shows that the all-object walk is being performed by +`traverse_commit_list()` or `traverse_commit_list_filtered()`. Those two +functions reside in `list-objects.c`; examining the source shows that, despite +the name, these functions traverse all kinds of objects. Let's have a look at +the arguments to `traverse_commit_list()`. + +- `struct rev_info *revs`: This is the `rev_info` used for the walk. If + its `filter` member is not `NULL`, then `filter` contains information for + how to filter the object list. +- `show_commit_fn show_commit`: A callback which will be used to handle each + individual commit object. +- `show_object_fn show_object`: A callback which will be used to handle each + non-commit object (so each blob, tree, or tag). +- `void *show_data`: A context buffer which is passed in turn to `show_commit` + and `show_object`. + +In addition, `traverse_commit_list_filtered()` has an additional parameter: + +- `struct oidset *omitted`: A linked-list of object IDs which the provided + filter caused to be omitted. + +It looks like these methods use callbacks we provide instead of needing us +to call it repeatedly ourselves. Cool! Let's add the callbacks first. + +For the sake of this tutorial, we'll simply keep track of how many of each kind +of object we find. At file scope in `builtin/walken.c` add the following +tracking variables: + +---- +static int commit_count; +static int tag_count; +static int blob_count; +static int tree_count; +---- + +Commits are handled by a different callback than other objects; let's do that +one first: + +---- +static void walken_show_commit(struct commit *cmt, void *buf) +{ + commit_count++; +} +---- + +The `cmt` argument is fairly self-explanatory. But it's worth mentioning that +the `buf` argument is actually the context buffer that we can provide to the +traversal calls - `show_data`, which we mentioned a moment ago. + +Since we have the `struct commit` object, we can look at all the same parts that +we looked at in our earlier commit-only walk. For the sake of this tutorial, +though, we'll just increment the commit counter and move on. + +The callback for non-commits is a little different, as we'll need to check +which kind of object we're dealing with: + +---- +static void walken_show_object(struct object *obj, const char *str, void *buf) +{ + switch (obj->type) { + case OBJ_TREE: + tree_count++; + break; + case OBJ_BLOB: + blob_count++; + break; + case OBJ_TAG: + tag_count++; + break; + case OBJ_COMMIT: + BUG("unexpected commit object in walken_show_object\n"); + default: + BUG("unexpected object type %s in walken_show_object\n", + type_name(obj->type)); + } +} +---- + +Again, `obj` is fairly self-explanatory, and we can guess that `buf` is the same +context pointer that `walken_show_commit()` receives: the `show_data` argument +to `traverse_commit_list()` and `traverse_commit_list_filtered()`. Finally, +`str` contains the name of the object, which ends up being something like +`foo.txt` (blob), `bar/baz` (tree), or `v1.2.3` (tag). + +To help assure us that we aren't double-counting commits, we'll include some +complaining if a commit object is routed through our non-commit callback; we'll +also complain if we see an invalid object type. Since those two cases should be +unreachable, and would only change in the event of a semantic change to the Git +codebase, we complain by using `BUG()` - which is a signal to a developer that +the change they made caused unintended consequences, and the rest of the +codebase needs to be updated to understand that change. `BUG()` is not intended +to be seen by the public, so it is not localized. + +Our main object walk implementation is substantially different from our commit +walk implementation, so let's make a new function to perform the object walk. We +can perform setup which is applicable to all objects here, too, to keep separate +from setup which is applicable to commit-only walks. + +We'll start by enabling all types of objects in the `struct rev_info`. We'll +also turn on `tree_blobs_in_commit_order`, which means that we will walk a +commit's tree and everything it points to immediately after we find each commit, +as opposed to waiting for the end and walking through all trees after the commit +history has been discovered. With the appropriate settings configured, we are +ready to call `prepare_revision_walk()`. + +---- +static void walken_object_walk(struct rev_info *rev) +{ + rev->tree_objects = 1; + rev->blob_objects = 1; + rev->tag_objects = 1; + rev->tree_blobs_in_commit_order = 1; + + if (prepare_revision_walk(rev)) + die(_("revision walk setup failed")); + + commit_count = 0; + tag_count = 0; + blob_count = 0; + tree_count = 0; +---- + +Let's start by calling just the unfiltered walk and reporting our counts. +Complete your implementation of `walken_object_walk()`. +We'll also need to include the `list-objects.h` header. + +---- +#include "list-objects.h" + +... + + traverse_commit_list(rev, walken_show_commit, walken_show_object, NULL); + + printf("commits %d\nblobs %d\ntags %d\ntrees %d\n", commit_count, + blob_count, tag_count, tree_count); +} +---- + +NOTE: This output is intended to be machine-parsed. Therefore, we are not +sending it to `trace_printf()`, and we are not localizing it - we need scripts +to be able to count on the formatting to be exactly the way it is shown here. +If we were intending this output to be read by humans, we would need to localize +it with `_()`. + +Finally, we'll ask `cmd_walken()` to use the object walk instead. Discussing +command line options is out of scope for this tutorial, so we'll just hardcode +a branch we can change at compile time. Where you call `final_rev_info_setup()` +and `walken_commit_walk()`, instead branch like so: + +---- + if (1) { + add_head_to_pending(&rev); + walken_object_walk(&rev); + } else { + final_rev_info_setup(argc, argv, prefix, &rev); + walken_commit_walk(&rev); + } +---- + +NOTE: For simplicity, we've avoided all the filters and sorts we applied in +`final_rev_info_setup()` and simply added `HEAD` to our pending queue. If you +want, you can certainly use the filters we added before by moving +`final_rev_info_setup()` out of the conditional and removing the call to +`add_head_to_pending()`. + +Now we can try to run our command! It should take noticeably longer than the +commit walk, but an examination of the output will give you an idea why. Your +output should look similar to this example, but with different counts: + +---- +Object walk completed. Found 55733 commits, 100274 blobs, 0 tags, and 104210 trees. +---- + +This makes sense. We have more trees than commits because the Git project has +lots of subdirectories which can change, plus at least one tree per commit. We +have no tags because we started on a commit (`HEAD`) and while tags can point to +commits, commits can't point to tags. + +NOTE: You will have different counts when you run this yourself! The number of +objects grows along with the Git project. + +=== Adding a Filter + +There are a handful of filters that we can apply to the object walk laid out in +`Documentation/rev-list-options.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 +which are not directly referenced by commits reachable from the commit in +`pending` when the walk begins. (`pending` is the list of objects which need to +be traversed during a walk; you can imagine a breadth-first tree traversal to +help understand. In our case, that means we omit trees and blobs not directly +referenced by `HEAD` or `HEAD`'s history, because we begin the walk with only +`HEAD` in the `pending` list.) + +For now, we are not going to track the omitted objects, so we'll replace those +parameters with `NULL`. For the sake of simplicity, we'll add a simple +build-time branch to use our filter or not. Preface the line calling +`traverse_commit_list()` with the following, which will remind us which kind of +walk we've just performed: + +---- + if (0) { + /* Unfiltered: */ + trace_printf(_("Unfiltered object walk.\n")); + } else { + trace_printf( + _("Filtered object walk with filterspec 'tree:1'.\n")); + + parse_list_objects_filter(&rev->filter, "tree:1"); + } + traverse_commit_list(rev, walken_show_commit, + walken_show_object, NULL); +---- + +The `rev->filter` member is usually built directly from a command +line argument, so the module provides an easy way to build one from a string. +Even though we aren't taking user input right now, we can still build one with +a hardcoded string using `parse_list_objects_filter()`. + +With the filter spec "tree:1", we are expecting to see _only_ the root tree for +each commit; therefore, the tree object count should be less than or equal to +the number of commits. (For an example of why that's true: `git commit --revert` +points to the same tree object as its grandparent.) + +=== Counting Omitted Objects + +We also have the capability to enumerate all objects which were omitted by a +filter, like with `git log --filter= --filter-print-omitted`. To do this, +change `traverse_commit_list()` to `traverse_commit_list_filtered()`, which is +able to populate an `omitted` list. Asking for this list of filtered objects +may cause performance degradations, however, because in this case, despite +filtering objects, the possibly much larger set of all reachable objects must +be processed in order to populate that list. + +First, add the `struct oidset` and related items we will use to iterate it: + +---- +#include "oidset.h" + +... + +static void walken_object_walk( + ... + + struct oidset omitted; + struct oidset_iter oit; + struct object_id *oid = NULL; + int omitted_count = 0; + oidset_init(&omitted, 0); + + ... +---- + +Replace the call to `traverse_commit_list()` with +`traverse_commit_list_filtered()` and pass a pointer to the `omitted` oidset +defined and initialized above: + +---- + ... + + traverse_commit_list_filtered(rev, + walken_show_commit, walken_show_object, NULL, &omitted); + + ... +---- + +Then, after your traversal, the `oidset` traversal is pretty straightforward. +Count all the objects within and modify the print statement: + +---- + /* Count the omitted objects. */ + oidset_iter_init(&omitted, &oit); + + while ((oid = oidset_iter_next(&oit))) + omitted_count++; + + printf("commits %d\nblobs %d\ntags %d\ntrees %d\nomitted %d\n", + commit_count, blob_count, tag_count, tree_count, omitted_count); +---- + +By running your walk with and without the filter, you should find that the total +object count in each case is identical. You can also time each invocation of +the `walken` subcommand, with and without `omitted` being passed in, to confirm +to yourself the runtime impact of tracking all omitted objects. + +=== Changing the Order + +Finally, let's demonstrate that you can also reorder walks of all objects, not +just walks of commits. First, we'll make our handlers chattier - modify +`walken_show_commit()` and `walken_show_object()` to print the object as they +go: + +---- +#include "hex.h" + +... + +static void walken_show_commit(struct commit *cmt, void *buf) +{ + trace_printf("commit: %s\n", oid_to_hex(&cmt->object.oid)); + commit_count++; +} + +static void walken_show_object(struct object *obj, const char *str, void *buf) +{ + trace_printf("%s: %s\n", type_name(obj->type), oid_to_hex(&obj->oid)); + + ... +} +---- + +NOTE: Since we will be examining this output directly as humans, we'll use +`trace_printf()` here. Additionally, since this change introduces a significant +number of printed lines, using `trace_printf()` will allow us to easily silence +those lines without having to recompile. + +(Leave the counter increment logic in place.) + +With only that change, run again (but save yourself some scrollback): + +---- +$ GIT_TRACE=1 ./bin-wrappers/git walken 2>&1 | head -n 10 +---- + +Take a look at the top commit with `git show` and the object ID you printed; it +should be the same as the output of `git show HEAD`. + +Next, let's change a setting on our `struct rev_info` within +`walken_object_walk()`. Find where you're changing the other settings on `rev`, +such as `rev->tree_objects` and `rev->tree_blobs_in_commit_order`, and add the +`reverse` setting at the bottom: + +---- + ... + + rev->tree_objects = 1; + rev->blob_objects = 1; + rev->tag_objects = 1; + rev->tree_blobs_in_commit_order = 1; + rev->reverse = 1; + + ... +---- + +Now, run again, but this time, let's grab the last handful of objects instead +of the first handful: + +---- +$ make +$ GIT_TRACE=1 ./bin-wrappers/git walken 2>&1 | tail -n 10 +---- + +The last commit object given should have the same OID as the one we saw at the +top before, and running `git show ` with that OID should give you again +the same results as `git show HEAD`. Furthermore, if you run and examine the +first ten lines again (with `head` instead of `tail` like we did before applying +the `reverse` setting), you should see that now the first commit printed is the +initial commit, `e83c5163`. + +== Wrapping Up + +Let's review. In this tutorial, we: + +- Built a commit walk from the ground up +- Enabled a grep filter for that commit walk +- Changed the sort order of that filtered commit walk +- Built an object walk (tags, commits, trees, and blobs) from the ground up +- Learned how to add a filter-spec to an object walk +- Changed the display order of the filtered object walk diff --git a/Documentation/MyFirstObjectWalk.txt b/Documentation/MyFirstObjectWalk.txt deleted file mode 100644 index 8d9e85566e642e..00000000000000 --- a/Documentation/MyFirstObjectWalk.txt +++ /dev/null @@ -1,879 +0,0 @@ -= My First Object Walk - -== What's an Object Walk? - -The object walk is a key concept in Git - this is the process that underpins -operations like object transfer and fsck. Beginning from a given commit, the -list of objects is found by walking parent relationships between commits (commit -X based on commit W) and containment relationships between objects (tree Y is -contained within commit X, and blob Z is located within tree Y, giving our -working tree for commit X something like `y/z.txt`). - -A related concept is the revision walk, which is focused on commit objects and -their parent relationships and does not delve into other object types. The -revision walk is used for operations like `git log`. - -=== Related Reading - -- `Documentation/user-manual.txt` under "Hacking Git" contains some coverage of - the revision walker in its various incarnations. -- `revision.h` -- https://eagain.net/articles/git-for-computer-scientists/[Git for Computer Scientists] - gives a good overview of the types of objects in Git and what your object - walk is really describing. - -== Setting Up - -Create a new branch from `master`. - ----- -git checkout -b revwalk origin/master ----- - -We'll put our fiddling into a new command. For fun, let's name it `git walken`. -Open up a new file `builtin/walken.c` and set up the command handler: - ----- -/* - * "git walken" - * - * Part of the "My First Object Walk" tutorial. - */ - -#include "builtin.h" - -int cmd_walken(int argc, const char **argv, const char *prefix) -{ - trace_printf(_("cmd_walken incoming...\n")); - return 0; -} ----- - -NOTE: `trace_printf()` differs from `printf()` in that it can be turned on or -off at runtime. For the purposes of this tutorial, we will write `walken` as -though it is intended for use as a "plumbing" command: that is, a command which -is used primarily in scripts, rather than interactively by humans (a "porcelain" -command). So we will send our debug output to `trace_printf()` instead. When -running, enable trace output by setting the environment variable `GIT_TRACE`. - -Add usage text and `-h` handling, like all subcommands should consistently do -(our test suite will notice and complain if you fail to do so). -We'll need to include the `parse-options.h` header. - ----- -#include "parse-options.h" - -... - -int cmd_walken(int argc, const char **argv, const char *prefix) -{ - const char * const walken_usage[] = { - N_("git walken"), - NULL, - }; - struct option options[] = { - OPT_END() - }; - - argc = parse_options(argc, argv, prefix, options, walken_usage, 0); - - ... -} ----- - -Also add the relevant line in `builtin.h` near `cmd_whatchanged()`: - ----- -int cmd_walken(int argc, const char **argv, const char *prefix); ----- - -Include the command in `git.c` in `commands[]` near the entry for `whatchanged`, -maintaining alphabetical ordering: - ----- -{ "walken", cmd_walken, RUN_SETUP }, ----- - -Add it to the `Makefile` near the line for `builtin/worktree.o`: - ----- -BUILTIN_OBJS += builtin/walken.o ----- - -Build and test out your command, without forgetting to ensure the `DEVELOPER` -flag is set, and with `GIT_TRACE` enabled so the debug output can be seen: - ----- -$ echo DEVELOPER=1 >>config.mak -$ make -$ GIT_TRACE=1 ./bin-wrappers/git walken ----- - -NOTE: For a more exhaustive overview of the new command process, take a look at -`Documentation/MyFirstContribution.txt`. - -NOTE: A reference implementation can be found at -https://github.com/nasamuffin/git/tree/revwalk. - -=== `struct rev_cmdline_info` - -The definition of `struct rev_cmdline_info` can be found in `revision.h`. - -This struct is contained within the `rev_info` struct and is used to reflect -parameters provided by the user over the CLI. - -`nr` represents the number of `rev_cmdline_entry` present in the array. - -`alloc` is used by the `ALLOC_GROW` macro. Check `cache.h` - this variable is -used to track the allocated size of the list. - -Per entry, we find: - -`item` is the object provided upon which to base the object walk. Items in Git -can be blobs, trees, commits, or tags. (See `Documentation/gittutorial-2.txt`.) - -`name` is the object ID (OID) of the object - a hex string you may be familiar -with from using Git to organize your source in the past. Check the tutorial -mentioned above towards the top for a discussion of where the OID can come -from. - -`whence` indicates some information about what to do with the parents of the -specified object. We'll explore this flag more later on; take a look at -`Documentation/revisions.txt` to get an idea of what could set the `whence` -value. - -`flags` are used to hint the beginning of the revision walk and are the first -block under the `#include`s in `revision.h`. The most likely ones to be set in -the `rev_cmdline_info` are `UNINTERESTING` and `BOTTOM`, but these same flags -can be used during the walk, as well. - -=== `struct rev_info` - -This one is quite a bit longer, and many fields are only used during the walk -by `revision.c` - not configuration options. Most of the configurable flags in -`struct rev_info` have a mirror in `Documentation/rev-list-options.txt`. It's a -good idea to take some time and read through that document. - -== Basic Commit Walk - -First, let's see if we can replicate the output of `git log --oneline`. We'll -refer back to the implementation frequently to discover norms when performing -an object walk of our own. - -To do so, we'll first find all the commits, in order, which preceded the current -commit. We'll extract the name and subject of the commit from each. - -Ideally, we will also be able to find out which ones are currently at the tip of -various branches. - -=== Setting Up - -Preparing for your object walk has some distinct stages. - -1. Perform default setup for this mode, and others which may be invoked. -2. Check configuration files for relevant settings. -3. Set up the `rev_info` struct. -4. Tweak the initialized `rev_info` to suit the current walk. -5. Prepare the `rev_info` for the walk. -6. Iterate over the objects, processing each one. - -==== Default Setups - -Before examining configuration files which may modify command behavior, set up -default state for switches or options your command may have. If your command -utilizes other Git components, ask them to set up their default states as well. -For instance, `git log` takes advantage of `grep` and `diff` functionality, so -its `init_log_defaults()` sets its own state (`decoration_style`) and asks -`grep` and `diff` to initialize themselves by calling each of their -initialization functions. - -==== Configuring From `.gitconfig` - -Next, we should have a look at any relevant configuration settings (i.e., -settings readable and settable from `git config`). This is done by providing a -callback to `git_config()`; within that callback, you can also invoke methods -from other components you may need that need to intercept these options. Your -callback will be invoked once per each configuration value which Git knows about -(global, local, worktree, etc.). - -Similarly to the default values, we don't have anything to do here yet -ourselves; however, we should call `git_default_config()` if we aren't calling -any other existing config callbacks. - -Add a new function to `builtin/walken.c`. -We'll also need to include the `config.h` header: - ----- -#include "config.h" - -... - -static int git_walken_config(const char *var, const char *value, void *cb) -{ - /* - * For now, we don't have any custom configuration, so fall back to - * the default config. - */ - return git_default_config(var, value, cb); -} ----- - -Make sure to invoke `git_config()` with it in your `cmd_walken()`: - ----- -int cmd_walken(int argc, const char **argv, const char *prefix) -{ - ... - - git_config(git_walken_config, NULL); - - ... -} ----- - -==== Setting Up `rev_info` - -Now that we've gathered external configuration and options, it's time to -initialize the `rev_info` object which we will use to perform the walk. This is -typically done by calling `repo_init_revisions()` with the repository you intend -to target, as well as the `prefix` argument of `cmd_walken` and your `rev_info` -struct. - -Add the `struct rev_info` and the `repo_init_revisions()` call. -We'll also need to include the `revision.h` header: - ----- -#include "revision.h" - -... - -int cmd_walken(int argc, const char **argv, const char *prefix) -{ - /* This can go wherever you like in your declarations.*/ - struct rev_info rev; - ... - - /* This should go after the git_config() call. */ - repo_init_revisions(the_repository, &rev, prefix); - - ... -} ----- - -==== Tweaking `rev_info` For the Walk - -We're getting close, but we're still not quite ready to go. Now that `rev` is -initialized, we can modify it to fit our needs. This is usually done within a -helper for clarity, so let's add one: - ----- -static void final_rev_info_setup(struct rev_info *rev) -{ - /* - * We want to mimic the appearance of `git log --oneline`, so let's - * force oneline format. - */ - get_commit_format("oneline", rev); - - /* Start our object walk at HEAD. */ - add_head_to_pending(rev); -} ----- - -[NOTE] -==== -Instead of using the shorthand `add_head_to_pending()`, you could do -something like this: ----- - struct setup_revision_opt opt; - - memset(&opt, 0, sizeof(opt)); - opt.def = "HEAD"; - opt.revarg_opt = REVARG_COMMITTISH; - setup_revisions(argc, argv, rev, &opt); ----- -Using a `setup_revision_opt` gives you finer control over your walk's starting -point. -==== - -Then let's invoke `final_rev_info_setup()` after the call to -`repo_init_revisions()`: - ----- -int cmd_walken(int argc, const char **argv, const char *prefix) -{ - ... - - final_rev_info_setup(&rev); - - ... -} ----- - -Later, we may wish to add more arguments to `final_rev_info_setup()`. But for -now, this is all we need. - -==== Preparing `rev_info` For the Walk - -Now that `rev` is all initialized and configured, we've got one more setup step -before we get rolling. We can do this in a helper, which will both prepare the -`rev_info` for the walk, and perform the walk itself. Let's start the helper -with the call to `prepare_revision_walk()`, which can return an error without -dying on its own: - ----- -static void walken_commit_walk(struct rev_info *rev) -{ - if (prepare_revision_walk(rev)) - die(_("revision walk setup failed")); -} ----- - -NOTE: `die()` prints to `stderr` and exits the program. Since it will print to -`stderr` it's likely to be seen by a human, so we will localize it. - -==== Performing the Walk! - -Finally! We are ready to begin the walk itself. Now we can see that `rev_info` -can also be used as an iterator; we move to the next item in the walk by using -`get_revision()` repeatedly. Add the listed variable declarations at the top and -the walk loop below the `prepare_revision_walk()` call within your -`walken_commit_walk()`: - ----- -static void walken_commit_walk(struct rev_info *rev) -{ - struct commit *commit; - struct strbuf prettybuf = STRBUF_INIT; - - ... - - while ((commit = get_revision(rev))) { - strbuf_reset(&prettybuf); - pp_commit_easy(CMIT_FMT_ONELINE, commit, &prettybuf); - puts(prettybuf.buf); - } - strbuf_release(&prettybuf); -} ----- - -NOTE: `puts()` prints a `char*` to `stdout`. Since this is the part of the -command we expect to be machine-parsed, we're sending it directly to stdout. - -Give it a shot. - ----- -$ make -$ ./bin-wrappers/git walken ----- - -You should see all of the subject lines of all the commits in -your tree's history, in order, ending with the initial commit, "Initial revision -of "git", the information manager from hell". Congratulations! You've written -your first revision walk. You can play with printing some additional fields -from each commit if you're curious; have a look at the functions available in -`commit.h`. - -=== Adding a Filter - -Next, let's try to filter the commits we see based on their author. This is -equivalent to running `git log --author=`. We can add a filter by -modifying `rev_info.grep_filter`, which is a `struct grep_opt`. - -First some setup. Add `grep_config()` to `git_walken_config()`: - ----- -static int git_walken_config(const char *var, const char *value, void *cb) -{ - grep_config(var, value, cb); - return git_default_config(var, value, cb); -} ----- - -Next, we can modify the `grep_filter`. This is done with convenience functions -found in `grep.h`. For fun, we're filtering to only commits from folks using a -`gmail.com` email address - a not-very-precise guess at who may be working on -Git as a hobby. Since we're checking the author, which is a specific line in the -header, we'll use the `append_header_grep_pattern()` helper. We can use -the `enum grep_header_field` to indicate which part of the commit header we want -to search. - -In `final_rev_info_setup()`, add your filter line: - ----- -static void final_rev_info_setup(int argc, const char **argv, - const char *prefix, struct rev_info *rev) -{ - ... - - append_header_grep_pattern(&rev->grep_filter, GREP_HEADER_AUTHOR, - "gmail"); - compile_grep_patterns(&rev->grep_filter); - - ... -} ----- - -`append_header_grep_pattern()` adds your new "gmail" pattern to `rev_info`, but -it won't work unless we compile it with `compile_grep_patterns()`. - -NOTE: If you are using `setup_revisions()` (for example, if you are passing a -`setup_revision_opt` instead of using `add_head_to_pending()`), you don't need -to call `compile_grep_patterns()` because `setup_revisions()` calls it for you. - -NOTE: We could add the same filter via the `append_grep_pattern()` helper if we -wanted to, but `append_header_grep_pattern()` adds the `enum grep_context` and -`enum grep_pat_token` for us. - -=== Changing the Order - -There are a few ways that we can change the order of the commits during a -revision walk. Firstly, we can use the `enum rev_sort_order` to choose from some -typical orderings. - -`topo_order` is the same as `git log --topo-order`: we avoid showing a parent -before all of its children have been shown, and we avoid mixing commits which -are in different lines of history. (`git help log`'s section on `--topo-order` -has a very nice diagram to illustrate this.) - -Let's see what happens when we run with `REV_SORT_BY_COMMIT_DATE` as opposed to -`REV_SORT_BY_AUTHOR_DATE`. Add the following: - ----- -static void final_rev_info_setup(int argc, const char **argv, - const char *prefix, struct rev_info *rev) -{ - ... - - rev->topo_order = 1; - rev->sort_order = REV_SORT_BY_COMMIT_DATE; - - ... -} ----- - -Let's output this into a file so we can easily diff it with the walk sorted by -author date. - ----- -$ make -$ ./bin-wrappers/git walken > commit-date.txt ----- - -Then, let's sort by author date and run it again. - ----- -static void final_rev_info_setup(int argc, const char **argv, - const char *prefix, struct rev_info *rev) -{ - ... - - rev->topo_order = 1; - rev->sort_order = REV_SORT_BY_AUTHOR_DATE; - - ... -} ----- - ----- -$ make -$ ./bin-wrappers/git walken > author-date.txt ----- - -Finally, compare the two. This is a little less helpful without object names or -dates, but hopefully we get the idea. - ----- -$ diff -u commit-date.txt author-date.txt ----- - -This display indicates that commits can be reordered after they're written, for -example with `git rebase`. - -Let's try one more reordering of commits. `rev_info` exposes a `reverse` flag. -Set that flag somewhere inside of `final_rev_info_setup()`: - ----- -static void final_rev_info_setup(int argc, const char **argv, const char *prefix, - struct rev_info *rev) -{ - ... - - rev->reverse = 1; - - ... -} ----- - -Run your walk again and note the difference in order. (If you remove the grep -pattern, you should see the last commit this call gives you as your current -HEAD.) - -== Basic Object Walk - -So far we've been walking only commits. But Git has more types of objects than -that! Let's see if we can walk _all_ objects, and find out some information -about each one. - -We can base our work on an example. `git pack-objects` prepares all kinds of -objects for packing into a bitmap or packfile. The work we are interested in -resides in `builtins/pack-objects.c:get_object_list()`; examination of that -function shows that the all-object walk is being performed by -`traverse_commit_list()` or `traverse_commit_list_filtered()`. Those two -functions reside in `list-objects.c`; examining the source shows that, despite -the name, these functions traverse all kinds of objects. Let's have a look at -the arguments to `traverse_commit_list()`. - -- `struct rev_info *revs`: This is the `rev_info` used for the walk. If - its `filter` member is not `NULL`, then `filter` contains information for - how to filter the object list. -- `show_commit_fn show_commit`: A callback which will be used to handle each - individual commit object. -- `show_object_fn show_object`: A callback which will be used to handle each - non-commit object (so each blob, tree, or tag). -- `void *show_data`: A context buffer which is passed in turn to `show_commit` - and `show_object`. - -In addition, `traverse_commit_list_filtered()` has an additional paramter: - -- `struct oidset *omitted`: A linked-list of object IDs which the provided - filter caused to be omitted. - -It looks like these methods use callbacks we provide instead of needing us -to call it repeatedly ourselves. Cool! Let's add the callbacks first. - -For the sake of this tutorial, we'll simply keep track of how many of each kind -of object we find. At file scope in `builtin/walken.c` add the following -tracking variables: - ----- -static int commit_count; -static int tag_count; -static int blob_count; -static int tree_count; ----- - -Commits are handled by a different callback than other objects; let's do that -one first: - ----- -static void walken_show_commit(struct commit *cmt, void *buf) -{ - commit_count++; -} ----- - -The `cmt` argument is fairly self-explanatory. But it's worth mentioning that -the `buf` argument is actually the context buffer that we can provide to the -traversal calls - `show_data`, which we mentioned a moment ago. - -Since we have the `struct commit` object, we can look at all the same parts that -we looked at in our earlier commit-only walk. For the sake of this tutorial, -though, we'll just increment the commit counter and move on. - -The callback for non-commits is a little different, as we'll need to check -which kind of object we're dealing with: - ----- -static void walken_show_object(struct object *obj, const char *str, void *buf) -{ - switch (obj->type) { - case OBJ_TREE: - tree_count++; - break; - case OBJ_BLOB: - blob_count++; - break; - case OBJ_TAG: - tag_count++; - break; - case OBJ_COMMIT: - BUG("unexpected commit object in walken_show_object\n"); - default: - BUG("unexpected object type %s in walken_show_object\n", - type_name(obj->type)); - } -} ----- - -Again, `obj` is fairly self-explanatory, and we can guess that `buf` is the same -context pointer that `walken_show_commit()` receives: the `show_data` argument -to `traverse_commit_list()` and `traverse_commit_list_filtered()`. Finally, -`str` contains the name of the object, which ends up being something like -`foo.txt` (blob), `bar/baz` (tree), or `v1.2.3` (tag). - -To help assure us that we aren't double-counting commits, we'll include some -complaining if a commit object is routed through our non-commit callback; we'll -also complain if we see an invalid object type. Since those two cases should be -unreachable, and would only change in the event of a semantic change to the Git -codebase, we complain by using `BUG()` - which is a signal to a developer that -the change they made caused unintended consequences, and the rest of the -codebase needs to be updated to understand that change. `BUG()` is not intended -to be seen by the public, so it is not localized. - -Our main object walk implementation is substantially different from our commit -walk implementation, so let's make a new function to perform the object walk. We -can perform setup which is applicable to all objects here, too, to keep separate -from setup which is applicable to commit-only walks. - -We'll start by enabling all types of objects in the `struct rev_info`. We'll -also turn on `tree_blobs_in_commit_order`, which means that we will walk a -commit's tree and everything it points to immediately after we find each commit, -as opposed to waiting for the end and walking through all trees after the commit -history has been discovered. With the appropriate settings configured, we are -ready to call `prepare_revision_walk()`. - ----- -static void walken_object_walk(struct rev_info *rev) -{ - rev->tree_objects = 1; - rev->blob_objects = 1; - rev->tag_objects = 1; - rev->tree_blobs_in_commit_order = 1; - - if (prepare_revision_walk(rev)) - die(_("revision walk setup failed")); - - commit_count = 0; - tag_count = 0; - blob_count = 0; - tree_count = 0; ----- - -Let's start by calling just the unfiltered walk and reporting our counts. -Complete your implementation of `walken_object_walk()`. -We'll also need to include the `list-objects.h` header. - ----- -#include "list-objects.h" - -... - - traverse_commit_list(rev, walken_show_commit, walken_show_object, NULL); - - printf("commits %d\nblobs %d\ntags %d\ntrees %d\n", commit_count, - blob_count, tag_count, tree_count); -} ----- - -NOTE: This output is intended to be machine-parsed. Therefore, we are not -sending it to `trace_printf()`, and we are not localizing it - we need scripts -to be able to count on the formatting to be exactly the way it is shown here. -If we were intending this output to be read by humans, we would need to localize -it with `_()`. - -Finally, we'll ask `cmd_walken()` to use the object walk instead. Discussing -command line options is out of scope for this tutorial, so we'll just hardcode -a branch we can change at compile time. Where you call `final_rev_info_setup()` -and `walken_commit_walk()`, instead branch like so: - ----- - if (1) { - add_head_to_pending(&rev); - walken_object_walk(&rev); - } else { - final_rev_info_setup(argc, argv, prefix, &rev); - walken_commit_walk(&rev); - } ----- - -NOTE: For simplicity, we've avoided all the filters and sorts we applied in -`final_rev_info_setup()` and simply added `HEAD` to our pending queue. If you -want, you can certainly use the filters we added before by moving -`final_rev_info_setup()` out of the conditional and removing the call to -`add_head_to_pending()`. - -Now we can try to run our command! It should take noticeably longer than the -commit walk, but an examination of the output will give you an idea why. Your -output should look similar to this example, but with different counts: - ----- -Object walk completed. Found 55733 commits, 100274 blobs, 0 tags, and 104210 trees. ----- - -This makes sense. We have more trees than commits because the Git project has -lots of subdirectories which can change, plus at least one tree per commit. We -have no tags because we started on a commit (`HEAD`) and while tags can point to -commits, commits can't point to tags. - -NOTE: You will have different counts when you run this yourself! The number of -objects grows along with the Git project. - -=== Adding a Filter - -There are a handful of filters that we can apply to the object walk laid out in -`Documentation/rev-list-options.txt`. These filters are typically useful for -operations such as creating packfiles or performing a partial clone. They are -defined in `list-objects-filter-options.h`. For the purposes of this tutorial we -will use the "tree:1" filter, which causes the walk to omit all trees and blobs -which are not directly referenced by commits reachable from the commit in -`pending` when the walk begins. (`pending` is the list of objects which need to -be traversed during a walk; you can imagine a breadth-first tree traversal to -help understand. In our case, that means we omit trees and blobs not directly -referenced by `HEAD` or `HEAD`'s history, because we begin the walk with only -`HEAD` in the `pending` list.) - -For now, we are not going to track the omitted objects, so we'll replace those -parameters with `NULL`. For the sake of simplicity, we'll add a simple -build-time branch to use our filter or not. Preface the line calling -`traverse_commit_list()` with the following, which will remind us which kind of -walk we've just performed: - ----- - if (0) { - /* Unfiltered: */ - trace_printf(_("Unfiltered object walk.\n")); - } else { - trace_printf( - _("Filtered object walk with filterspec 'tree:1'.\n")); - CALLOC_ARRAY(rev->filter, 1); - parse_list_objects_filter(rev->filter, "tree:1"); - } - traverse_commit_list(rev, walken_show_commit, - walken_show_object, NULL); ----- - -The `rev->filter` member is usually built directly from a command -line argument, so the module provides an easy way to build one from a string. -Even though we aren't taking user input right now, we can still build one with -a hardcoded string using `parse_list_objects_filter()`. - -With the filter spec "tree:1", we are expecting to see _only_ the root tree for -each commit; therefore, the tree object count should be less than or equal to -the number of commits. (For an example of why that's true: `git commit --revert` -points to the same tree object as its grandparent.) - -=== Counting Omitted Objects - -We also have the capability to enumerate all objects which were omitted by a -filter, like with `git log --filter= --filter-print-omitted`. Asking -`traverse_commit_list_filtered()` to populate the `omitted` list means that our -object walk does not perform any better than an unfiltered object walk; all -reachable objects are walked in order to populate the list. - -First, add the `struct oidset` and related items we will use to iterate it: - ----- -static void walken_object_walk( - ... - - struct oidset omitted; - struct oidset_iter oit; - struct object_id *oid = NULL; - int omitted_count = 0; - oidset_init(&omitted, 0); - - ... ----- - -Modify the call to `traverse_commit_list_filtered()` to include your `omitted` -object: - ----- - ... - - traverse_commit_list_filtered(rev, - walken_show_commit, walken_show_object, NULL, &omitted); - - ... ----- - -Then, after your traversal, the `oidset` traversal is pretty straightforward. -Count all the objects within and modify the print statement: - ----- - /* Count the omitted objects. */ - oidset_iter_init(&omitted, &oit); - - while ((oid = oidset_iter_next(&oit))) - omitted_count++; - - printf("commits %d\nblobs %d\ntags %d\ntrees %d\nomitted %d\n", - commit_count, blob_count, tag_count, tree_count, omitted_count); ----- - -By running your walk with and without the filter, you should find that the total -object count in each case is identical. You can also time each invocation of -the `walken` subcommand, with and without `omitted` being passed in, to confirm -to yourself the runtime impact of tracking all omitted objects. - -=== Changing the Order - -Finally, let's demonstrate that you can also reorder walks of all objects, not -just walks of commits. First, we'll make our handlers chattier - modify -`walken_show_commit()` and `walken_show_object()` to print the object as they -go: - ----- -static void walken_show_commit(struct commit *cmt, void *buf) -{ - trace_printf("commit: %s\n", oid_to_hex(&cmt->object.oid)); - commit_count++; -} - -static void walken_show_object(struct object *obj, const char *str, void *buf) -{ - trace_printf("%s: %s\n", type_name(obj->type), oid_to_hex(&obj->oid)); - - ... -} ----- - -NOTE: Since we will be examining this output directly as humans, we'll use -`trace_printf()` here. Additionally, since this change introduces a significant -number of printed lines, using `trace_printf()` will allow us to easily silence -those lines without having to recompile. - -(Leave the counter increment logic in place.) - -With only that change, run again (but save yourself some scrollback): - ----- -$ GIT_TRACE=1 ./bin-wrappers/git walken | head -n 10 ----- - -Take a look at the top commit with `git show` and the object ID you printed; it -should be the same as the output of `git show HEAD`. - -Next, let's change a setting on our `struct rev_info` within -`walken_object_walk()`. Find where you're changing the other settings on `rev`, -such as `rev->tree_objects` and `rev->tree_blobs_in_commit_order`, and add the -`reverse` setting at the bottom: - ----- - ... - - rev->tree_objects = 1; - rev->blob_objects = 1; - rev->tag_objects = 1; - rev->tree_blobs_in_commit_order = 1; - rev->reverse = 1; - - ... ----- - -Now, run again, but this time, let's grab the last handful of objects instead -of the first handful: - ----- -$ make -$ GIT_TRACE=1 ./bin-wrappers git walken | tail -n 10 ----- - -The last commit object given should have the same OID as the one we saw at the -top before, and running `git show ` with that OID should give you again -the same results as `git show HEAD`. Furthermore, if you run and examine the -first ten lines again (with `head` instead of `tail` like we did before applying -the `reverse` setting), you should see that now the first commit printed is the -initial commit, `e83c5163`. - -== Wrapping Up - -Let's review. In this tutorial, we: - -- Built a commit walk from the ground up -- Enabled a grep filter for that commit walk -- Changed the sort order of that filtered commit walk -- Built an object walk (tags, commits, trees, and blobs) from the ground up -- Learned how to add a filter-spec to an object walk -- Changed the display order of the filtered object walk diff --git a/Documentation/RelNotes/1.5.0.1.txt b/Documentation/RelNotes/1.5.0.1.adoc similarity index 100% rename from Documentation/RelNotes/1.5.0.1.txt rename to Documentation/RelNotes/1.5.0.1.adoc diff --git a/Documentation/RelNotes/1.5.0.2.txt b/Documentation/RelNotes/1.5.0.2.adoc similarity index 100% rename from Documentation/RelNotes/1.5.0.2.txt rename to Documentation/RelNotes/1.5.0.2.adoc diff --git a/Documentation/RelNotes/1.5.0.3.txt b/Documentation/RelNotes/1.5.0.3.adoc similarity index 100% rename from Documentation/RelNotes/1.5.0.3.txt rename to Documentation/RelNotes/1.5.0.3.adoc diff --git a/Documentation/RelNotes/1.5.0.4.txt b/Documentation/RelNotes/1.5.0.4.adoc similarity index 100% rename from Documentation/RelNotes/1.5.0.4.txt rename to Documentation/RelNotes/1.5.0.4.adoc diff --git a/Documentation/RelNotes/1.5.0.5.txt b/Documentation/RelNotes/1.5.0.5.adoc similarity index 100% rename from Documentation/RelNotes/1.5.0.5.txt rename to Documentation/RelNotes/1.5.0.5.adoc diff --git a/Documentation/RelNotes/1.5.0.6.txt b/Documentation/RelNotes/1.5.0.6.adoc similarity index 100% rename from Documentation/RelNotes/1.5.0.6.txt rename to Documentation/RelNotes/1.5.0.6.adoc diff --git a/Documentation/RelNotes/1.5.0.7.txt b/Documentation/RelNotes/1.5.0.7.adoc similarity index 100% rename from Documentation/RelNotes/1.5.0.7.txt rename to Documentation/RelNotes/1.5.0.7.adoc diff --git a/Documentation/RelNotes/1.5.0.txt b/Documentation/RelNotes/1.5.0.adoc similarity index 100% rename from Documentation/RelNotes/1.5.0.txt rename to Documentation/RelNotes/1.5.0.adoc diff --git a/Documentation/RelNotes/1.5.1.1.txt b/Documentation/RelNotes/1.5.1.1.adoc similarity index 100% rename from Documentation/RelNotes/1.5.1.1.txt rename to Documentation/RelNotes/1.5.1.1.adoc diff --git a/Documentation/RelNotes/1.5.1.2.txt b/Documentation/RelNotes/1.5.1.2.adoc similarity index 100% rename from Documentation/RelNotes/1.5.1.2.txt rename to Documentation/RelNotes/1.5.1.2.adoc diff --git a/Documentation/RelNotes/1.5.1.3.txt b/Documentation/RelNotes/1.5.1.3.adoc similarity index 100% rename from Documentation/RelNotes/1.5.1.3.txt rename to Documentation/RelNotes/1.5.1.3.adoc diff --git a/Documentation/RelNotes/1.5.1.4.txt b/Documentation/RelNotes/1.5.1.4.adoc similarity index 100% rename from Documentation/RelNotes/1.5.1.4.txt rename to Documentation/RelNotes/1.5.1.4.adoc diff --git a/Documentation/RelNotes/1.5.1.5.txt b/Documentation/RelNotes/1.5.1.5.adoc similarity index 100% rename from Documentation/RelNotes/1.5.1.5.txt rename to Documentation/RelNotes/1.5.1.5.adoc diff --git a/Documentation/RelNotes/1.5.1.6.txt b/Documentation/RelNotes/1.5.1.6.adoc similarity index 100% rename from Documentation/RelNotes/1.5.1.6.txt rename to Documentation/RelNotes/1.5.1.6.adoc diff --git a/Documentation/RelNotes/1.5.1.txt b/Documentation/RelNotes/1.5.1.adoc similarity index 100% rename from Documentation/RelNotes/1.5.1.txt rename to Documentation/RelNotes/1.5.1.adoc diff --git a/Documentation/RelNotes/1.5.2.1.txt b/Documentation/RelNotes/1.5.2.1.adoc similarity index 100% rename from Documentation/RelNotes/1.5.2.1.txt rename to Documentation/RelNotes/1.5.2.1.adoc diff --git a/Documentation/RelNotes/1.5.2.2.txt b/Documentation/RelNotes/1.5.2.2.adoc similarity index 100% rename from Documentation/RelNotes/1.5.2.2.txt rename to Documentation/RelNotes/1.5.2.2.adoc diff --git a/Documentation/RelNotes/1.5.2.3.txt b/Documentation/RelNotes/1.5.2.3.adoc similarity index 100% rename from Documentation/RelNotes/1.5.2.3.txt rename to Documentation/RelNotes/1.5.2.3.adoc diff --git a/Documentation/RelNotes/1.5.2.4.txt b/Documentation/RelNotes/1.5.2.4.adoc similarity index 100% rename from Documentation/RelNotes/1.5.2.4.txt rename to Documentation/RelNotes/1.5.2.4.adoc diff --git a/Documentation/RelNotes/1.5.2.5.txt b/Documentation/RelNotes/1.5.2.5.adoc similarity index 100% rename from Documentation/RelNotes/1.5.2.5.txt rename to Documentation/RelNotes/1.5.2.5.adoc diff --git a/Documentation/RelNotes/1.5.2.txt b/Documentation/RelNotes/1.5.2.adoc similarity index 100% rename from Documentation/RelNotes/1.5.2.txt rename to Documentation/RelNotes/1.5.2.adoc diff --git a/Documentation/RelNotes/1.5.3.1.txt b/Documentation/RelNotes/1.5.3.1.adoc similarity index 100% rename from Documentation/RelNotes/1.5.3.1.txt rename to Documentation/RelNotes/1.5.3.1.adoc diff --git a/Documentation/RelNotes/1.5.3.2.txt b/Documentation/RelNotes/1.5.3.2.adoc similarity index 100% rename from Documentation/RelNotes/1.5.3.2.txt rename to Documentation/RelNotes/1.5.3.2.adoc diff --git a/Documentation/RelNotes/1.5.3.3.txt b/Documentation/RelNotes/1.5.3.3.adoc similarity index 100% rename from Documentation/RelNotes/1.5.3.3.txt rename to Documentation/RelNotes/1.5.3.3.adoc diff --git a/Documentation/RelNotes/1.5.3.4.txt b/Documentation/RelNotes/1.5.3.4.adoc similarity index 100% rename from Documentation/RelNotes/1.5.3.4.txt rename to Documentation/RelNotes/1.5.3.4.adoc diff --git a/Documentation/RelNotes/1.5.3.5.txt b/Documentation/RelNotes/1.5.3.5.adoc similarity index 100% rename from Documentation/RelNotes/1.5.3.5.txt rename to Documentation/RelNotes/1.5.3.5.adoc diff --git a/Documentation/RelNotes/1.5.3.6.txt b/Documentation/RelNotes/1.5.3.6.adoc similarity index 100% rename from Documentation/RelNotes/1.5.3.6.txt rename to Documentation/RelNotes/1.5.3.6.adoc diff --git a/Documentation/RelNotes/1.5.3.7.txt b/Documentation/RelNotes/1.5.3.7.adoc similarity index 100% rename from Documentation/RelNotes/1.5.3.7.txt rename to Documentation/RelNotes/1.5.3.7.adoc diff --git a/Documentation/RelNotes/1.5.3.8.txt b/Documentation/RelNotes/1.5.3.8.adoc similarity index 100% rename from Documentation/RelNotes/1.5.3.8.txt rename to Documentation/RelNotes/1.5.3.8.adoc diff --git a/Documentation/RelNotes/1.5.3.txt b/Documentation/RelNotes/1.5.3.adoc similarity index 100% rename from Documentation/RelNotes/1.5.3.txt rename to Documentation/RelNotes/1.5.3.adoc diff --git a/Documentation/RelNotes/1.5.4.1.txt b/Documentation/RelNotes/1.5.4.1.adoc similarity index 100% rename from Documentation/RelNotes/1.5.4.1.txt rename to Documentation/RelNotes/1.5.4.1.adoc diff --git a/Documentation/RelNotes/1.5.4.2.txt b/Documentation/RelNotes/1.5.4.2.adoc similarity index 100% rename from Documentation/RelNotes/1.5.4.2.txt rename to Documentation/RelNotes/1.5.4.2.adoc diff --git a/Documentation/RelNotes/1.5.4.3.txt b/Documentation/RelNotes/1.5.4.3.adoc similarity index 100% rename from Documentation/RelNotes/1.5.4.3.txt rename to Documentation/RelNotes/1.5.4.3.adoc diff --git a/Documentation/RelNotes/1.5.4.4.txt b/Documentation/RelNotes/1.5.4.4.adoc similarity index 100% rename from Documentation/RelNotes/1.5.4.4.txt rename to Documentation/RelNotes/1.5.4.4.adoc diff --git a/Documentation/RelNotes/1.5.4.5.txt b/Documentation/RelNotes/1.5.4.5.adoc similarity index 100% rename from Documentation/RelNotes/1.5.4.5.txt rename to Documentation/RelNotes/1.5.4.5.adoc diff --git a/Documentation/RelNotes/1.5.4.6.txt b/Documentation/RelNotes/1.5.4.6.adoc similarity index 100% rename from Documentation/RelNotes/1.5.4.6.txt rename to Documentation/RelNotes/1.5.4.6.adoc diff --git a/Documentation/RelNotes/1.5.4.7.txt b/Documentation/RelNotes/1.5.4.7.adoc similarity index 100% rename from Documentation/RelNotes/1.5.4.7.txt rename to Documentation/RelNotes/1.5.4.7.adoc diff --git a/Documentation/RelNotes/1.5.4.txt b/Documentation/RelNotes/1.5.4.adoc similarity index 100% rename from Documentation/RelNotes/1.5.4.txt rename to Documentation/RelNotes/1.5.4.adoc diff --git a/Documentation/RelNotes/1.5.5.1.txt b/Documentation/RelNotes/1.5.5.1.adoc similarity index 100% rename from Documentation/RelNotes/1.5.5.1.txt rename to Documentation/RelNotes/1.5.5.1.adoc diff --git a/Documentation/RelNotes/1.5.5.2.txt b/Documentation/RelNotes/1.5.5.2.adoc similarity index 100% rename from Documentation/RelNotes/1.5.5.2.txt rename to Documentation/RelNotes/1.5.5.2.adoc diff --git a/Documentation/RelNotes/1.5.5.3.txt b/Documentation/RelNotes/1.5.5.3.adoc similarity index 100% rename from Documentation/RelNotes/1.5.5.3.txt rename to Documentation/RelNotes/1.5.5.3.adoc diff --git a/Documentation/RelNotes/1.5.5.4.txt b/Documentation/RelNotes/1.5.5.4.adoc similarity index 100% rename from Documentation/RelNotes/1.5.5.4.txt rename to Documentation/RelNotes/1.5.5.4.adoc diff --git a/Documentation/RelNotes/1.5.5.5.txt b/Documentation/RelNotes/1.5.5.5.adoc similarity index 100% rename from Documentation/RelNotes/1.5.5.5.txt rename to Documentation/RelNotes/1.5.5.5.adoc diff --git a/Documentation/RelNotes/1.5.5.6.txt b/Documentation/RelNotes/1.5.5.6.adoc similarity index 100% rename from Documentation/RelNotes/1.5.5.6.txt rename to Documentation/RelNotes/1.5.5.6.adoc diff --git a/Documentation/RelNotes/1.5.5.txt b/Documentation/RelNotes/1.5.5.adoc similarity index 100% rename from Documentation/RelNotes/1.5.5.txt rename to Documentation/RelNotes/1.5.5.adoc diff --git a/Documentation/RelNotes/1.5.6.1.txt b/Documentation/RelNotes/1.5.6.1.adoc similarity index 100% rename from Documentation/RelNotes/1.5.6.1.txt rename to Documentation/RelNotes/1.5.6.1.adoc diff --git a/Documentation/RelNotes/1.5.6.2.txt b/Documentation/RelNotes/1.5.6.2.adoc similarity index 100% rename from Documentation/RelNotes/1.5.6.2.txt rename to Documentation/RelNotes/1.5.6.2.adoc diff --git a/Documentation/RelNotes/1.5.6.3.txt b/Documentation/RelNotes/1.5.6.3.adoc similarity index 100% rename from Documentation/RelNotes/1.5.6.3.txt rename to Documentation/RelNotes/1.5.6.3.adoc diff --git a/Documentation/RelNotes/1.5.6.4.txt b/Documentation/RelNotes/1.5.6.4.adoc similarity index 100% rename from Documentation/RelNotes/1.5.6.4.txt rename to Documentation/RelNotes/1.5.6.4.adoc diff --git a/Documentation/RelNotes/1.5.6.5.txt b/Documentation/RelNotes/1.5.6.5.adoc similarity index 100% rename from Documentation/RelNotes/1.5.6.5.txt rename to Documentation/RelNotes/1.5.6.5.adoc diff --git a/Documentation/RelNotes/1.5.6.6.txt b/Documentation/RelNotes/1.5.6.6.adoc similarity index 100% rename from Documentation/RelNotes/1.5.6.6.txt rename to Documentation/RelNotes/1.5.6.6.adoc diff --git a/Documentation/RelNotes/1.5.6.txt b/Documentation/RelNotes/1.5.6.adoc similarity index 100% rename from Documentation/RelNotes/1.5.6.txt rename to Documentation/RelNotes/1.5.6.adoc diff --git a/Documentation/RelNotes/1.6.0.1.txt b/Documentation/RelNotes/1.6.0.1.adoc similarity index 100% rename from Documentation/RelNotes/1.6.0.1.txt rename to Documentation/RelNotes/1.6.0.1.adoc diff --git a/Documentation/RelNotes/1.6.0.2.txt b/Documentation/RelNotes/1.6.0.2.adoc similarity index 100% rename from Documentation/RelNotes/1.6.0.2.txt rename to Documentation/RelNotes/1.6.0.2.adoc diff --git a/Documentation/RelNotes/1.6.0.3.txt b/Documentation/RelNotes/1.6.0.3.adoc similarity index 100% rename from Documentation/RelNotes/1.6.0.3.txt rename to Documentation/RelNotes/1.6.0.3.adoc diff --git a/Documentation/RelNotes/1.6.0.4.txt b/Documentation/RelNotes/1.6.0.4.adoc similarity index 100% rename from Documentation/RelNotes/1.6.0.4.txt rename to Documentation/RelNotes/1.6.0.4.adoc diff --git a/Documentation/RelNotes/1.6.0.5.txt b/Documentation/RelNotes/1.6.0.5.adoc similarity index 100% rename from Documentation/RelNotes/1.6.0.5.txt rename to Documentation/RelNotes/1.6.0.5.adoc diff --git a/Documentation/RelNotes/1.6.0.6.txt b/Documentation/RelNotes/1.6.0.6.adoc similarity index 100% rename from Documentation/RelNotes/1.6.0.6.txt rename to Documentation/RelNotes/1.6.0.6.adoc diff --git a/Documentation/RelNotes/1.6.0.txt b/Documentation/RelNotes/1.6.0.adoc similarity index 100% rename from Documentation/RelNotes/1.6.0.txt rename to Documentation/RelNotes/1.6.0.adoc diff --git a/Documentation/RelNotes/1.6.1.1.txt b/Documentation/RelNotes/1.6.1.1.adoc similarity index 100% rename from Documentation/RelNotes/1.6.1.1.txt rename to Documentation/RelNotes/1.6.1.1.adoc diff --git a/Documentation/RelNotes/1.6.1.2.txt b/Documentation/RelNotes/1.6.1.2.adoc similarity index 100% rename from Documentation/RelNotes/1.6.1.2.txt rename to Documentation/RelNotes/1.6.1.2.adoc diff --git a/Documentation/RelNotes/1.6.1.3.txt b/Documentation/RelNotes/1.6.1.3.adoc similarity index 100% rename from Documentation/RelNotes/1.6.1.3.txt rename to Documentation/RelNotes/1.6.1.3.adoc diff --git a/Documentation/RelNotes/1.6.1.4.txt b/Documentation/RelNotes/1.6.1.4.adoc similarity index 100% rename from Documentation/RelNotes/1.6.1.4.txt rename to Documentation/RelNotes/1.6.1.4.adoc diff --git a/Documentation/RelNotes/1.6.1.txt b/Documentation/RelNotes/1.6.1.adoc similarity index 100% rename from Documentation/RelNotes/1.6.1.txt rename to Documentation/RelNotes/1.6.1.adoc diff --git a/Documentation/RelNotes/1.6.2.1.txt b/Documentation/RelNotes/1.6.2.1.adoc similarity index 100% rename from Documentation/RelNotes/1.6.2.1.txt rename to Documentation/RelNotes/1.6.2.1.adoc diff --git a/Documentation/RelNotes/1.6.2.2.txt b/Documentation/RelNotes/1.6.2.2.adoc similarity index 100% rename from Documentation/RelNotes/1.6.2.2.txt rename to Documentation/RelNotes/1.6.2.2.adoc diff --git a/Documentation/RelNotes/1.6.2.3.txt b/Documentation/RelNotes/1.6.2.3.adoc similarity index 100% rename from Documentation/RelNotes/1.6.2.3.txt rename to Documentation/RelNotes/1.6.2.3.adoc diff --git a/Documentation/RelNotes/1.6.2.4.adoc b/Documentation/RelNotes/1.6.2.4.adoc new file mode 100644 index 00000000000000..053dbb604de6c4 --- /dev/null +++ b/Documentation/RelNotes/1.6.2.4.adoc @@ -0,0 +1,40 @@ +GIT v1.6.2.4 Release Notes +========================== + +Fixes since v1.6.2.3 +-------------------- + +* The configuration parser had a buffer overflow while parsing an overlong + value. + +* pruning reflog entries that are unreachable from the tip of the ref + during "git reflog prune" (hence "git gc") was very inefficient. + +* "git-add -p" lacked a way to say "q"uit to refuse staging any hunks for + the remaining paths. You had to say "d" and then ^C. + +* "git-checkout " did not update the index entry at + the named path; it now does. + +* "git-fast-export" choked when seeing a tag that does not point at commit. + +* "git init" segfaulted when given an overlong template location via + the --template= option. + +* "git-ls-tree" and "git-diff-tree" used a pathspec correctly when + deciding to descend into a subdirectory but they did not match the + individual paths correctly. This caused pathspecs "abc/d ab" to match + "abc/0" ("abc/d" made them decide to descend into the directory "abc/", + and then "ab" incorrectly matched "abc/0" when it shouldn't). + +* "git-merge-recursive" was broken when a submodule entry was involved in + a criss-cross merge situation. + +Many small documentation updates are included as well. + +--- +exec >/var/tmp/1 +echo O=$(git describe maint) +O=v1.6.2.3-38-g318b847 +git shortlog --no-merges $O..maint +--- diff --git a/Documentation/RelNotes/1.6.2.4.txt b/Documentation/RelNotes/1.6.2.4.txt deleted file mode 100644 index f4bf1d09863c71..00000000000000 --- a/Documentation/RelNotes/1.6.2.4.txt +++ /dev/null @@ -1,39 +0,0 @@ -GIT v1.6.2.4 Release Notes -========================== - -Fixes since v1.6.2.3 --------------------- - -* The configuration parser had a buffer overflow while parsing an overlong - value. - -* pruning reflog entries that are unreachable from the tip of the ref - during "git reflog prune" (hence "git gc") was very inefficient. - -* "git-add -p" lacked a way to say "q"uit to refuse staging any hunks for - the remaining paths. You had to say "d" and then ^C. - -* "git-checkout " did not update the index entry at - the named path; it now does. - -* "git-fast-export" choked when seeing a tag that does not point at commit. - -* "git init" segfaulted when given an overlong template location via - the --template= option. - -* "git-ls-tree" and "git-diff-tree" used a pathspec correctly when - deciding to descend into a subdirectory but they did not match the - individual paths correctly. This caused pathspecs "abc/d ab" to match - "abc/0" ("abc/d" made them decide to descend into the directory "abc/", - and then "ab" incorrectly matched "abc/0" when it shouldn't). - -* "git-merge-recursive" was broken when a submodule entry was involved in - a criss-cross merge situation. - -Many small documentation updates are included as well. - ---- -exec >/var/tmp/1 -echo O=$(git describe maint) -O=v1.6.2.3-38-g318b847 -git shortlog --no-merges $O..maint diff --git a/Documentation/RelNotes/1.6.2.5.txt b/Documentation/RelNotes/1.6.2.5.adoc similarity index 100% rename from Documentation/RelNotes/1.6.2.5.txt rename to Documentation/RelNotes/1.6.2.5.adoc diff --git a/Documentation/RelNotes/1.6.2.adoc b/Documentation/RelNotes/1.6.2.adoc new file mode 100644 index 00000000000000..166d73c60fb11e --- /dev/null +++ b/Documentation/RelNotes/1.6.2.adoc @@ -0,0 +1,164 @@ +GIT v1.6.2 Release Notes +======================== + +With the next major release, "git push" into a branch that is +currently checked out will be refused by default. You can choose +what should happen upon such a push by setting the configuration +variable receive.denyCurrentBranch in the receiving repository. + +To ease the transition plan, the receiving repository of such a +push running this release will issue a big warning when the +configuration variable is missing. Please refer to: + + https://archive.kernel.org/oldwiki/git.wiki.kernel.org/index.php/GitFaq.html#non-bare + https://lore.kernel.org/git/7vbptlsuyv.fsf@gitster.siamese.dyndns.org/ + +for more details on the reason why this change is needed and the +transition plan. + +For a similar reason, "git push $there :$killed" to delete the branch +$killed in a remote repository $there, if $killed branch is the current +branch pointed at by its HEAD, gets a large warning. You can choose what +should happen upon such a push by setting the configuration variable +receive.denyDeleteCurrent in the receiving repository. + + +Updates since v1.6.1 +-------------------- + +(subsystems) + +* git-svn updates. + +* gitweb updates, including a new patch view and RSS/Atom feed + improvements. + +* (contrib/emacs) git.el now has commands for checking out a branch, + creating a branch, cherry-picking and reverting commits; vc-git.el + is not shipped with git anymore (it is part of official Emacs). + +(performance) + +* pack-objects autodetects the number of CPUs available and uses threaded + version. + +(usability, bells and whistles) + +* automatic typo correction works on aliases as well + +* @{-1} is a way to refer to the last branch you were on. This is + accepted not only where an object name is expected, but anywhere + a branch name is expected and acts as if you typed the branch name. + E.g. "git branch --track mybranch @{-1}", "git merge @{-1}", and + "git rev-parse --symbolic-full-name @{-1}" would work as expected. + +* When refs/remotes/origin/HEAD points at a remote tracking branch that + has been pruned away, many git operations issued warning when they + internally enumerated the refs. We now warn only when you say "origin" + to refer to that pruned branch. + +* The location of .mailmap file can be configured, and its file format was + enhanced to allow mapping an incorrect e-mail field as well. + +* "git add -p" learned 'g'oto action to jump directly to a hunk. + +* "git add -p" learned to find a hunk with given text with '/'. + +* "git add -p" optionally can be told to work with just the command letter + without Enter. + +* when "git am" stops upon a patch that does not apply, it shows the + title of the offending patch. + +* "git am --directory=" and "git am --reject" passes these options + to underlying "git apply". + +* "git am" learned --ignore-date option. + +* "git blame" aligns author names better when they are spelled in + non US-ASCII encoding. + +* "git clone" now makes its best effort when cloning from an empty + repository to set up configuration variables to refer to the remote + repository. + +* "git checkout -" is a shorthand for "git checkout @{-1}". + +* "git cherry" defaults to whatever the current branch is tracking (if + exists) when the argument is not given. + +* "git cvsserver" can be told not to add extra "via git-CVS emulator" to + the commit log message it serves via gitcvs.commitmsgannotation + configuration. + +* "git cvsserver" learned to handle 'noop' command some CVS clients seem + to expect to work. + +* "git diff" learned a new option --inter-hunk-context to coalesce close + hunks together and show context between them. + +* The definition of what constitutes a word for "git diff --color-words" + can be customized via gitattributes, command line or a configuration. + +* "git diff" learned --patience to run "patience diff" algorithm. + +* "git filter-branch" learned --prune-empty option that discards commits + that do not change the contents. + +* "git fsck" now checks loose objects in alternate object stores, instead + of misreporting them as missing. + +* "git gc --prune" was resurrected to allow "git gc --no-prune" and + giving non-default expiration period e.g. "git gc --prune=now". + +* "git grep -w" and "git grep" for fixed strings have been optimized. + +* "git mergetool" learned -y(--no-prompt) option to disable prompting. + +* "git rebase -i" can transplant a history down to root to elsewhere + with --root option. + +* "git reset --merge" is a new mode that works similar to the way + "git checkout" switches branches, taking the local changes while + switching to another commit. + +* "git submodule update" learned --no-fetch option. + +* "git tag" learned --contains that works the same way as the same option + from "git branch". + + +Fixes since v1.6.1 +------------------ + +All of the fixes in v1.6.1.X maintenance series are included in this +release, unless otherwise noted. + +Here are fixes that this release has, but have not been backported to +v1.6.1.X series. + +* "git-add sub/file" when sub is a submodule incorrectly added the path to + the superproject. + +* "git bundle" did not exclude annotated tags even when a range given + from the command line wanted to. + +* "git filter-branch" unnecessarily refused to work when you had + checked out a different commit from what is recorded in the superproject + index in a submodule. + +* "git filter-branch" incorrectly tried to update a nonexistent work tree + at the end when it is run in a bare repository. + +* "git gc" did not work if your repository was created with an ancient git + and never had any pack files in it before. + +* "git mergetool" used to ignore autocrlf and other attributes + based content rewriting. + +* branch switching and merges had a silly bug that did not validate + the correct directory when making sure an existing subdirectory is + clean. + +* "git -p cmd" when cmd is not a built-in one left the display in funny state + when killed in the middle. diff --git a/Documentation/RelNotes/1.6.2.txt b/Documentation/RelNotes/1.6.2.txt deleted file mode 100644 index 980adfb3154697..00000000000000 --- a/Documentation/RelNotes/1.6.2.txt +++ /dev/null @@ -1,164 +0,0 @@ -GIT v1.6.2 Release Notes -======================== - -With the next major release, "git push" into a branch that is -currently checked out will be refused by default. You can choose -what should happen upon such a push by setting the configuration -variable receive.denyCurrentBranch in the receiving repository. - -To ease the transition plan, the receiving repository of such a -push running this release will issue a big warning when the -configuration variable is missing. Please refer to: - - http://git.or.cz/gitwiki/GitFaq#non-bare - https://lore.kernel.org/git/7vbptlsuyv.fsf@gitster.siamese.dyndns.org/ - -for more details on the reason why this change is needed and the -transition plan. - -For a similar reason, "git push $there :$killed" to delete the branch -$killed in a remote repository $there, if $killed branch is the current -branch pointed at by its HEAD, gets a large warning. You can choose what -should happen upon such a push by setting the configuration variable -receive.denyDeleteCurrent in the receiving repository. - - -Updates since v1.6.1 --------------------- - -(subsystems) - -* git-svn updates. - -* gitweb updates, including a new patch view and RSS/Atom feed - improvements. - -* (contrib/emacs) git.el now has commands for checking out a branch, - creating a branch, cherry-picking and reverting commits; vc-git.el - is not shipped with git anymore (it is part of official Emacs). - -(performance) - -* pack-objects autodetects the number of CPUs available and uses threaded - version. - -(usability, bells and whistles) - -* automatic typo correction works on aliases as well - -* @{-1} is a way to refer to the last branch you were on. This is - accepted not only where an object name is expected, but anywhere - a branch name is expected and acts as if you typed the branch name. - E.g. "git branch --track mybranch @{-1}", "git merge @{-1}", and - "git rev-parse --symbolic-full-name @{-1}" would work as expected. - -* When refs/remotes/origin/HEAD points at a remote tracking branch that - has been pruned away, many git operations issued warning when they - internally enumerated the refs. We now warn only when you say "origin" - to refer to that pruned branch. - -* The location of .mailmap file can be configured, and its file format was - enhanced to allow mapping an incorrect e-mail field as well. - -* "git add -p" learned 'g'oto action to jump directly to a hunk. - -* "git add -p" learned to find a hunk with given text with '/'. - -* "git add -p" optionally can be told to work with just the command letter - without Enter. - -* when "git am" stops upon a patch that does not apply, it shows the - title of the offending patch. - -* "git am --directory=" and "git am --reject" passes these options - to underlying "git apply". - -* "git am" learned --ignore-date option. - -* "git blame" aligns author names better when they are spelled in - non US-ASCII encoding. - -* "git clone" now makes its best effort when cloning from an empty - repository to set up configuration variables to refer to the remote - repository. - -* "git checkout -" is a shorthand for "git checkout @{-1}". - -* "git cherry" defaults to whatever the current branch is tracking (if - exists) when the argument is not given. - -* "git cvsserver" can be told not to add extra "via git-CVS emulator" to - the commit log message it serves via gitcvs.commitmsgannotation - configuration. - -* "git cvsserver" learned to handle 'noop' command some CVS clients seem - to expect to work. - -* "git diff" learned a new option --inter-hunk-context to coalesce close - hunks together and show context between them. - -* The definition of what constitutes a word for "git diff --color-words" - can be customized via gitattributes, command line or a configuration. - -* "git diff" learned --patience to run "patience diff" algorithm. - -* "git filter-branch" learned --prune-empty option that discards commits - that do not change the contents. - -* "git fsck" now checks loose objects in alternate object stores, instead - of misreporting them as missing. - -* "git gc --prune" was resurrected to allow "git gc --no-prune" and - giving non-default expiration period e.g. "git gc --prune=now". - -* "git grep -w" and "git grep" for fixed strings have been optimized. - -* "git mergetool" learned -y(--no-prompt) option to disable prompting. - -* "git rebase -i" can transplant a history down to root to elsewhere - with --root option. - -* "git reset --merge" is a new mode that works similar to the way - "git checkout" switches branches, taking the local changes while - switching to another commit. - -* "git submodule update" learned --no-fetch option. - -* "git tag" learned --contains that works the same way as the same option - from "git branch". - - -Fixes since v1.6.1 ------------------- - -All of the fixes in v1.6.1.X maintenance series are included in this -release, unless otherwise noted. - -Here are fixes that this release has, but have not been backported to -v1.6.1.X series. - -* "git-add sub/file" when sub is a submodule incorrectly added the path to - the superproject. - -* "git bundle" did not exclude annotated tags even when a range given - from the command line wanted to. - -* "git filter-branch" unnecessarily refused to work when you had - checked out a different commit from what is recorded in the superproject - index in a submodule. - -* "git filter-branch" incorrectly tried to update a nonexistent work tree - at the end when it is run in a bare repository. - -* "git gc" did not work if your repository was created with an ancient git - and never had any pack files in it before. - -* "git mergetool" used to ignore autocrlf and other attributes - based content rewriting. - -* branch switching and merges had a silly bug that did not validate - the correct directory when making sure an existing subdirectory is - clean. - -* "git -p cmd" when cmd is not a built-in one left the display in funny state - when killed in the middle. diff --git a/Documentation/RelNotes/1.6.3.1.txt b/Documentation/RelNotes/1.6.3.1.adoc similarity index 100% rename from Documentation/RelNotes/1.6.3.1.txt rename to Documentation/RelNotes/1.6.3.1.adoc diff --git a/Documentation/RelNotes/1.6.3.2.txt b/Documentation/RelNotes/1.6.3.2.adoc similarity index 100% rename from Documentation/RelNotes/1.6.3.2.txt rename to Documentation/RelNotes/1.6.3.2.adoc diff --git a/Documentation/RelNotes/1.6.3.3.txt b/Documentation/RelNotes/1.6.3.3.adoc similarity index 100% rename from Documentation/RelNotes/1.6.3.3.txt rename to Documentation/RelNotes/1.6.3.3.adoc diff --git a/Documentation/RelNotes/1.6.3.4.txt b/Documentation/RelNotes/1.6.3.4.adoc similarity index 100% rename from Documentation/RelNotes/1.6.3.4.txt rename to Documentation/RelNotes/1.6.3.4.adoc diff --git a/Documentation/RelNotes/1.6.3.adoc b/Documentation/RelNotes/1.6.3.adoc new file mode 100644 index 00000000000000..bbf177fc3c5ba4 --- /dev/null +++ b/Documentation/RelNotes/1.6.3.adoc @@ -0,0 +1,182 @@ +GIT v1.6.3 Release Notes +======================== + +With the next major release, "git push" into a branch that is +currently checked out will be refused by default. You can choose +what should happen upon such a push by setting the configuration +variable receive.denyCurrentBranch in the receiving repository. + +To ease the transition plan, the receiving repository of such a +push running this release will issue a big warning when the +configuration variable is missing. Please refer to: + + https://archive.kernel.org/oldwiki/git.wiki.kernel.org/index.php/GitFaq.html#non-bare + https://lore.kernel.org/git/7vbptlsuyv.fsf@gitster.siamese.dyndns.org/ + +for more details on the reason why this change is needed and the +transition plan. + +For a similar reason, "git push $there :$killed" to delete the branch +$killed in a remote repository $there, if $killed branch is the current +branch pointed at by its HEAD, gets a large warning. You can choose what +should happen upon such a push by setting the configuration variable +receive.denyDeleteCurrent in the receiving repository. + +When the user does not tell "git push" what to push, it has always +pushed matching refs. For some people it is unexpected, and a new +configuration variable push.default has been introduced to allow +changing a different default behaviour. To advertise the new feature, +a big warning is issued if this is not configured and a git push without +arguments is attempted. + + +Updates since v1.6.2 +-------------------- + +(subsystems) + +* various git-svn updates. + +* git-gui updates, including an update to Russian translation, and a + fix to an infinite loop when showing an empty diff. + +* gitk updates, including an update to Russian translation and improved Windows + support. + +(performance) + +* many uses of lstat(2) in the codepath for "git checkout" have been + optimized out. + +(usability, bells and whistles) + +* Boolean configuration variable yes/no can be written as on/off. + +* rsync:/path/to/repo can be used to run git over rsync for local + repositories. It may not be useful in practice; meant primarily for + testing. + +* http transport learned to prompt and use password when fetching from or + pushing to http://user@host.xz/ URL. + +* (msysgit) progress output that is sent over the sideband protocol can + be handled appropriately in Windows console. + +* "--pretty= diff --git a/Documentation/everyday.txto b/Documentation/everyday.adoco similarity index 100% rename from Documentation/everyday.txto rename to Documentation/everyday.adoco diff --git a/Documentation/fetch-options.adoc b/Documentation/fetch-options.adoc new file mode 100644 index 00000000000000..fcba46ee9e5d61 --- /dev/null +++ b/Documentation/fetch-options.adoc @@ -0,0 +1,337 @@ +`--all`:: +`--no-all`:: + Fetch all remotes, except for the ones that has the + `remote..skipFetchAll` configuration variable set. + This overrides the configuration variable `fetch.all`. + +`-a`:: +`--append`:: + Append ref names and object names of fetched refs to the + existing contents of `.git/FETCH_HEAD`. Without this + option old data in `.git/FETCH_HEAD` will be overwritten. + +`--atomic`:: + Use an atomic transaction to update local refs. Either all refs are + updated, or on error, no refs are updated. + +`--depth=`:: + Limit fetching to the specified number of commits from the tip of + each remote branch history. If fetching to a 'shallow' repository + created by `git clone` with `--depth=` option (see + linkgit:git-clone[1]), deepen or shorten the history to the specified + number of commits. Tags for the deepened commits are not fetched. + +`--deepen=`:: + Similar to `--depth`, except it specifies the number of commits + from the current shallow boundary instead of from the tip of + each remote branch history. + +`--shallow-since=`:: + Deepen or shorten the history of a shallow repository to + include all reachable commits after __. + +`--shallow-exclude=`:: + Deepen or shorten the history of a shallow repository to + exclude commits reachable from a specified remote branch or tag. + This option can be specified multiple times. + +`--unshallow`:: + If the source repository is complete, convert a shallow + repository to a complete one, removing all the limitations + imposed by shallow repositories. ++ +If the source repository is shallow, fetch as much as possible so that +the current repository has the same history as the source repository. + +`--update-shallow`:: + By default when fetching from a shallow repository, + `git fetch` refuses refs that require updating + `.git/shallow`. This option updates `.git/shallow` and accepts such + refs. + +`--negotiation-tip=(|)`:: + By default, Git will report, to the server, commits reachable + from all local refs to find common commits in an attempt to + reduce the size of the to-be-received packfile. If specified, + Git will only report commits reachable from the given tips. + This is useful to speed up fetches when the user knows which + local ref is likely to have commits in common with the + upstream ref being fetched. ++ +This option may be specified more than once; if so, Git will report +commits reachable from any of the given commits. ++ +The argument to this option may be a glob on ref names, a ref, or the (possibly +abbreviated) SHA-1 of a commit. Specifying a glob is equivalent to specifying +this option multiple times, one for each matching ref name. ++ +See also the `fetch.negotiationAlgorithm` and `push.negotiate` +configuration variables documented in linkgit:git-config[1], and the +`--negotiate-only` option below. + +`--negotiate-only`:: + Do not fetch anything from the server, and instead print the + ancestors of the provided `--negotiation-tip=` arguments, + which we have in common with the server. ++ +This is incompatible with `--recurse-submodules=(yes|on-demand)`. +Internally this is used to implement the `push.negotiate` option, see +linkgit:git-config[1]. + +`--dry-run`:: + Show what would be done, without making any changes. + +`--porcelain`:: + Print the output to standard output in an easy-to-parse format for + scripts. See section OUTPUT in linkgit:git-fetch[1] for details. ++ +This is incompatible with `--recurse-submodules=(yes|on-demand)` and takes +precedence over the `fetch.output` config option. + +ifndef::git-pull[] +`--write-fetch-head`:: +`--no-write-fetch-head`:: + Write the list of remote refs fetched in the `FETCH_HEAD` + file directly under `$GIT_DIR`. This is the default. + Passing `--no-write-fetch-head` from the command line tells + Git not to write the file. Under `--dry-run` option, the + file is never written. +endif::git-pull[] + +`-f`:: +`--force`:: +ifdef::git-pull[] +When `git fetch` is used with `:` refspec, it may +refuse to update the local branch as discussed +in the __ part of the linkgit:git-fetch[1] +documentation. +endif::git-pull[] +ifndef::git-pull[] +When `git fetch` is used with `:` refspec, it may +refuse to update the local branch as discussed in the __ part below. +endif::git-pull[] +This option overrides that check. + +`-k`:: +`--keep`:: + Keep downloaded pack. + +ifndef::git-pull[] +`--multiple`:: + Allow several __ and __ arguments to be + specified. No ____s may be specified. + +`--auto-maintenance`:: +`--no-auto-maintenance`:: +`--auto-gc`:: +`--no-auto-gc`:: + Run `git maintenance run --auto` at the end to perform automatic + repository maintenance if needed. + This is enabled by default. + +`--write-commit-graph`:: +`--no-write-commit-graph`:: + Write a commit-graph after fetching. This overrides the config + setting `fetch.writeCommitGraph`. +endif::git-pull[] + +`--prefetch`:: + Modify the configured refspec to place all refs into the + `refs/prefetch/` namespace. See the `prefetch` task in + linkgit:git-maintenance[1]. + +`-p`:: +`--prune`:: + Before fetching, remove any remote-tracking references that no + longer exist on the remote. Tags are not subject to pruning + if they are fetched only because of the default tag + auto-following or due to a `--tags` option. However, if tags + are fetched due to an explicit refspec (either on the command + line or in the remote configuration, for example if the remote + was cloned with the `--mirror` option), then they are also + subject to pruning. Supplying `--prune-tags` is a shorthand for + providing the tag refspec. +ifndef::git-pull[] ++ +See the PRUNING section below for more details. + +`-P`:: +`--prune-tags`:: + Before fetching, remove any local tags that no longer exist on + the remote if `--prune` is enabled. This option should be used + more carefully, unlike `--prune` it will remove any local + references (local tags) that have been created. This option is + a shorthand for providing the explicit tag refspec along with + `--prune`, see the discussion about that in its documentation. ++ +See the PRUNING section below for more details. + +endif::git-pull[] + +ifndef::git-pull[] +`-n`:: +endif::git-pull[] +`--no-tags`:: + By default, tags that point at objects that are downloaded + from the remote repository are fetched and stored locally. + This option disables this automatic tag following. The default + behavior for a remote may be specified with the `remote..tagOpt` + setting. See linkgit:git-config[1]. + +ifndef::git-pull[] +`--refetch`:: + Instead of negotiating with the server to avoid transferring commits and + associated objects that are already present locally, this option fetches + all objects as a fresh clone would. Use this to reapply a partial clone + filter from configuration or using `--filter=` when the filter + definition has changed. Automatic post-fetch maintenance will perform + object database pack consolidation to remove any duplicate objects. +endif::git-pull[] + +`--refmap=`:: + When fetching refs listed on the command line, use the + specified refspec (can be given more than once) to map the + refs to remote-tracking branches, instead of the values of + `remote..fetch` configuration variables for the remote + repository. Providing an empty __ to the + `--refmap` option causes Git to ignore the configured + refspecs and rely entirely on the refspecs supplied as + command-line arguments. See section on "Configured Remote-tracking + Branches" for details. + +`-t`:: +`--tags`:: + Fetch all tags from the remote (i.e., fetch remote tags + `refs/tags/*` into local tags with the same name), in addition + to whatever else would otherwise be fetched. Using this + option alone does not subject tags to pruning, even if `--prune` + is used (though tags may be pruned anyway if they are also the + destination of an explicit refspec; see `--prune`). + +ifndef::git-pull[] +`--recurse-submodules[=(yes|on-demand|no)]`:: + Control if and under what conditions new commits of + submodules should be fetched too. When recursing through submodules, + `git fetch` always attempts to fetch "changed" submodules, that is, a + submodule that has commits that are referenced by a newly fetched + superproject commit but are missing in the local submodule clone. A + changed submodule can be fetched as long as it is present locally e.g. + in `$GIT_DIR/modules/` (see linkgit:gitsubmodules[7]); if the upstream + adds a new submodule, that submodule cannot be fetched until it is + cloned e.g. by `git submodule update`. ++ +When set to `on-demand`, only changed submodules are fetched. When set +to `yes`, all populated submodules are fetched and submodules that are +both unpopulated and changed are fetched. When set to `no`, submodules +are never fetched. ++ +When unspecified, this uses the value of `fetch.recurseSubmodules` if it +is set (see linkgit:git-config[1]), defaulting to `on-demand` if unset. +When this option is used without any value, it defaults to `yes`. +endif::git-pull[] + +`-j `:: +`--jobs=`:: + Parallelize all forms of fetching up to __ jobs at a time. ++ +If the `--multiple` option was specified, the different remotes will be fetched +in parallel. If multiple submodules are fetched, they will be fetched in +parallel. To control them independently, use the config settings +`fetch.parallel` and `submodule.fetchJobs` (see linkgit:git-config[1]). ++ +Typically, parallel recursive and multi-remote fetches will be faster. By +default fetches are performed sequentially, not in parallel. + +ifndef::git-pull[] +`--no-recurse-submodules`:: + Disable recursive fetching of submodules (this has the same effect as + using the `--recurse-submodules=no` option). +endif::git-pull[] + +`--set-upstream`:: + If the remote is fetched successfully, add upstream + (tracking) reference, used by argument-less + linkgit:git-pull[1] and other commands. For more information, + see `branch..merge` and `branch..remote` in + linkgit:git-config[1]. + +ifndef::git-pull[] +`--submodule-prefix=`:: + Prepend __ to paths printed in informative messages + such as "Fetching submodule foo". This option is used + internally when recursing over submodules. + +`--recurse-submodules-default=(yes|on-demand)`:: + This option is used internally to temporarily provide a + non-negative default value for the `--recurse-submodules` + option. All other methods of configuring fetch's submodule + recursion (such as settings in linkgit:gitmodules[5] and + linkgit:git-config[1]) override this option, as does + specifying `--[no-]recurse-submodules` directly. + +`-u`:: +`--update-head-ok`:: + By default `git fetch` refuses to update the head which + corresponds to the current branch. This flag disables the + check. This is purely for the internal use for `git pull` + to communicate with `git fetch`, and unless you are + implementing your own Porcelain you are not supposed to + use it. +endif::git-pull[] + +`--upload-pack `:: + When given, and the repository to fetch from is handled + by `git fetch-pack`, `--exec=` is passed to + the command to specify non-default path for the command + run on the other end. + +ifndef::git-pull[] +`-q`:: +`--quiet`:: + Pass `--quiet` to `git-fetch-pack` and silence any other internally + used git commands. Progress is not reported to the standard error + stream. + +`-v`:: +`--verbose`:: + Be verbose. +endif::git-pull[] + +`--progress`:: + Progress status is reported on the standard error stream + by default when it is attached to a terminal, unless `-q` + is specified. This flag forces progress status even if the + standard error stream is not directed to a terminal. + +`-o