Merge branch 'jc/hidden-refs'
authorJunio C Hamano <gitster@pobox.com>
Sun, 17 Feb 2013 23:25:57 +0000 (15:25 -0800)
committerJunio C Hamano <gitster@pobox.com>
Sun, 17 Feb 2013 23:25:57 +0000 (15:25 -0800)
Allow the server side to redact the refs/ namespace it shows to the
client.

Will merge to 'master'.

* jc/hidden-refs:
  upload/receive-pack: allow hiding ref hierarchies
  upload-pack: simplify request validation
  upload-pack: share more code

1  2 
Documentation/config.txt
builtin/receive-pack.c
refs.c
t/t5516-fetch-push.sh
upload-pack.c

diff --combined Documentation/config.txt
index 9b115973870d164b13334726ef9dad37802f0616,10be9ed90ea617c25d090abcd29cd3d611376a75..481736a471d67d11f9bda3429b342132236b12f9
@@@ -1,14 -1,14 +1,14 @@@
  CONFIGURATION FILE
  ------------------
  
 -The git configuration file contains a number of variables that affect
 -the git command's behavior. The `.git/config` file in each repository
 +The Git configuration file contains a number of variables that affect
 +the Git commands' behavior. The `.git/config` file in each repository
  is used to store the configuration for that repository, and
  `$HOME/.gitconfig` is used to store a per-user configuration as
  fallback values for the `.git/config` file. The file `/etc/gitconfig`
  can be used to store a system-wide default configuration.
  
 -The configuration variables are used by both the git plumbing
 +The configuration variables are used by both the Git plumbing
  and the porcelains. The variables are divided into sections, wherein
  the fully qualified variable name of the variable itself is the last
  dot-separated segment and the section name is everything before the last
@@@ -143,8 -143,7 +143,8 @@@ advice.*:
        pushUpdateRejected::
                Set this variable to 'false' if you want to disable
                'pushNonFFCurrent', 'pushNonFFDefault',
 -              'pushNonFFMatching', and 'pushAlreadyExists'
 +              'pushNonFFMatching', 'pushAlreadyExists',
 +              'pushFetchFirst', and 'pushNeedsForce'
                simultaneously.
        pushNonFFCurrent::
                Advice shown when linkgit:git-push[1] fails due to a
        pushAlreadyExists::
                Shown when linkgit:git-push[1] rejects an update that
                does not qualify for fast-forwarding (e.g., a tag.)
 +      pushFetchFirst::
 +              Shown when linkgit:git-push[1] rejects an update that
 +              tries to overwrite a remote ref that points at an
 +              object we do not have.
 +      pushNeedsForce::
 +              Shown when linkgit:git-push[1] rejects an update that
 +              tries to overwrite a remote ref that points at an
 +              object that is not a committish, or make the remote
 +              ref point at an object that is not a committish.
        statusHints::
                Show directions on how to proceed from the current
                state in the output of linkgit:git-status[1], in
@@@ -219,9 -209,9 +219,9 @@@ core.ignoreCygwinFSTricks:
  
  core.ignorecase::
        If true, this option enables various workarounds to enable
 -      git to work better on filesystems that are not case sensitive,
 +      Git to work better on filesystems that are not case sensitive,
        like FAT. For example, if a directory listing finds
 -      "makefile" when git expects "Makefile", git will assume
 +      "makefile" when Git expects "Makefile", Git will assume
        it is really the same file, and continue to remember it as
        "Makefile".
  +
@@@ -230,13 -220,13 +230,13 @@@ will probe and set core.ignorecase tru
  is created.
  
  core.precomposeunicode::
 -      This option is only used by Mac OS implementation of git.
 -      When core.precomposeunicode=true, git reverts the unicode decomposition
 +      This option is only used by Mac OS implementation of Git.
 +      When core.precomposeunicode=true, Git reverts the unicode decomposition
        of filenames done by Mac OS. This is useful when sharing a repository
        between Mac OS and Linux or Windows.
 -      (Git for Windows 1.7.10 or higher is needed, or git under cygwin 1.7).
 -      When false, file names are handled fully transparent by git,
 -      which is backward compatible with older versions of git.
 +      (Git for Windows 1.7.10 or higher is needed, or Git under cygwin 1.7).
 +      When false, file names are handled fully transparent by Git,
 +      which is backward compatible with older versions of Git.
  
  core.trustctime::
        If false, the ctime differences between the index and the
        crawlers and some backup systems).
        See linkgit:git-update-index[1]. True by default.
  
 +core.checkstat::
 +      Determines which stat fields to match between the index
 +      and work tree. The user can set this to 'default' or
 +      'minimal'. Default (or explicitly 'default'), is to check
 +      all fields, including the sub-second part of mtime and ctime.
 +
  core.quotepath::
        The commands that output paths (e.g. 'ls-files',
        'diff'), when not given the `-z` option, will quote
@@@ -272,20 -256,20 +272,20 @@@ core.eol:
        conversion.
  
  core.safecrlf::
 -      If true, makes git check if converting `CRLF` is reversible when
 +      If true, makes Git check if converting `CRLF` is reversible when
        end-of-line conversion is active.  Git will verify if a command
        modifies a file in the work tree either directly or indirectly.
        For example, committing a file followed by checking out the
        same file should yield the original file in the work tree.  If
        this is not the case for the current setting of
 -      `core.autocrlf`, git will reject the file.  The variable can
 -      be set to "warn", in which case git will only warn about an
 +      `core.autocrlf`, Git will reject the file.  The variable can
 +      be set to "warn", in which case Git will only warn about an
        irreversible conversion but continue the operation.
  +
  CRLF conversion bears a slight chance of corrupting data.
 -When it is enabled, git will convert CRLF to LF during commit and LF to
 +When it is enabled, Git will convert CRLF to LF during commit and LF to
  CRLF during checkout.  A file that contains a mixture of LF and
 -CRLF before the commit cannot be recreated by git.  For text
 +CRLF before the commit cannot be recreated by Git.  For text
  files this is the right thing to do: it corrects line endings
  such that we have only LF line endings in the repository.
  But for binary files that are accidentally classified as text the
@@@ -295,7 -279,7 +295,7 @@@ If you recognize such corruption early 
  setting the conversion type explicitly in .gitattributes.  Right
  after committing you still have the original file in your work
  tree and this file is not yet corrupted.  You can explicitly tell
 -git that this file is binary and git will handle the file
 +Git that this file is binary and Git will handle the file
  appropriately.
  +
  Unfortunately, the desired effect of cleaning up text files with
@@@ -340,7 -324,7 +340,7 @@@ is created
  core.gitProxy::
        A "proxy command" to execute (as 'command host port') instead
        of establishing direct connection to the remote server when
 -      using the git protocol for fetching. If the variable value is
 +      using the Git protocol for fetching. If the variable value is
        in the "COMMAND for DOMAIN" format, the command is applied only
        on hostnames ending with the specified domain string. This variable
        may be set multiple times and is matched in the given order;
@@@ -399,7 -383,7 +399,7 @@@ Note that this variable is honored eve
  file in a ".git" subdirectory of a directory and its value differs
  from the latter directory (e.g. "/path/to/.git/config" has
  core.worktree set to "/different/path"), which is most likely a
 -misconfiguration.  Running git commands in the "/path/to" directory will
 +misconfiguration.  Running Git commands in the "/path/to" directory will
  still use "/different/path" as the root of the work tree and can cause
  confusion unless you know what you are doing (e.g. you are creating a
  read-only snapshot of the same index to a location different from the
@@@ -431,7 -415,7 +431,7 @@@ core.sharedRepository:
        several users in a group (making sure all the files and objects are
        group-writable). When 'all' (or 'world' or 'everybody'), the
        repository will be readable by all users, additionally to being
 -      group-shareable. When 'umask' (or 'false'), git will use permissions
 +      group-shareable. When 'umask' (or 'false'), Git will use permissions
        reported by umask(2). When '0xxx', where '0xxx' is an octal number,
        files in the repository will have this mode value. '0xxx' will override
        user's umask value (whereas the other options will only override
        See linkgit:git-init[1]. False by default.
  
  core.warnAmbiguousRefs::
 -      If true, git will warn you if the ref name you passed it is ambiguous
 +      If true, Git will warn you if the ref name you passed it is ambiguous
        and might match multiple refs in the .git/refs/ tree. True by default.
  
  core.compression::
@@@ -514,7 -498,7 +514,7 @@@ Common unit suffixes of 'k', 'm', or 'g
  
  core.excludesfile::
        In addition to '.gitignore' (per-directory) and
 -      '.git/info/exclude', git looks into this file for patterns
 +      '.git/info/exclude', Git looks into this file for patterns
        of files which are not meant to be tracked.  "`~/`" is expanded
        to the value of `$HOME` and "`~user/`" to the specified user's
        home directory. Its default value is $XDG_CONFIG_HOME/git/ignore.
@@@ -532,7 -516,7 +532,7 @@@ core.askpass:
  
  core.attributesfile::
        In addition to '.gitattributes' (per-directory) and
 -      '.git/info/attributes', git looks into this file for attributes
 +      '.git/info/attributes', Git looks into this file for attributes
        (see linkgit:gitattributes[5]). Path expansions are made the same
        way as for `core.excludesfile`. Its default value is
        $XDG_CONFIG_HOME/git/attributes. If $XDG_CONFIG_HOME is either not
@@@ -544,12 -528,6 +544,12 @@@ core.editor:
        variable when it is set, and the environment variable
        `GIT_EDITOR` is not set.  See linkgit:git-var[1].
  
 +core.commentchar::
 +      Commands such as `commit` and `tag` that lets you edit
 +      messages consider a line that begins with this character
 +      commented, and removes them after the editor returns
 +      (default '#').
 +
  sequence.editor::
        Text editor used by `git rebase -i` for editing the rebase insn file.
        The value is meant to be interpreted by the shell when it is used.
        When not configured the default commit message editor is used instead.
  
  core.pager::
 -      The command that git will use to paginate output.  Can
 +      The command that Git will use to paginate output.  Can
        be overridden with the `GIT_PAGER` environment
 -      variable.  Note that git sets the `LESS` environment
 +      variable.  Note that Git sets the `LESS` environment
        variable to `FRSX` if it is unset when it runs the
        pager.  One can change these settings by setting the
        `LESS` variable to some other value.  Alternately,
        global basis by setting the `core.pager` option.
        Setting `core.pager` has no effect on the `LESS`
        environment variable behaviour above, so if you want
 -      to override git's default settings this way, you need
 +      to override Git's default settings this way, you need
        to be explicit.  For example, to disable the S option
        in a backward compatible manner, set `core.pager`
        to `less -+S`.  This will be passed to the shell by
 -      git, which will translate the final command to
 +      Git, which will translate the final command to
        `LESS=FRSX less -+S`.
  
  core.whitespace::
    does not trigger if the character before such a carriage-return
    is not a whitespace (not enabled by default).
  * `tabwidth=<n>` tells how many character positions a tab occupies; this
 -  is relevant for `indent-with-non-tab` and when git fixes `tab-in-indent`
 +  is relevant for `indent-with-non-tab` and when Git fixes `tab-in-indent`
    errors. The default tab width is 8. Allowed values are 1 to 63.
  
  core.fsyncobjectfiles::
@@@ -616,7 -594,7 +616,7 @@@ core.preloadindex:
  +
  This can speed up operations like 'git diff' and 'git status' especially
  on filesystems like NFS that have weak caching semantics and thus
 -relatively high IO latencies.  With this set to 'true', git will do the
 +relatively high IO latencies.  With this set to 'true', Git will do the
  index comparison to the filesystem data in parallel, allowing
  overlapping IO's.
  
@@@ -652,9 -630,9 +652,9 @@@ add.ignore-errors:
  add.ignoreErrors::
        Tells 'git add' to continue adding files when some files cannot be
        added due to indexing errors. Equivalent to the '--ignore-errors'
 -      option of linkgit:git-add[1].  Older versions of git accept only
 +      option of linkgit:git-add[1].  Older versions of Git accept only
        `add.ignore-errors`, which does not follow the usual naming
 -      convention for configuration variables.  Newer versions of git
 +      convention for configuration variables.  Newer versions of Git
        honor `add.ignoreErrors` as well.
  
  alias.*::
        after defining "alias.last = cat-file commit HEAD", the invocation
        "git last" is equivalent to "git cat-file commit HEAD". To avoid
        confusion and troubles with script usage, aliases that
 -      hide existing git commands are ignored. Arguments are split by
 +      hide existing Git commands are ignored. Arguments are split by
        spaces, the usual shell quoting and escaping is supported.
        quote pair and a backslash can be used to quote them.
  +
@@@ -709,7 -687,7 +709,7 @@@ branch.autosetupmerge:
  
  branch.autosetuprebase::
        When a new branch is created with 'git branch' or 'git checkout'
 -      that tracks another branch, this variable tells git to set
 +      that tracks another branch, this variable tells Git to set
        up pull to rebase instead of merge (see "branch.<name>.rebase").
        When `never`, rebase is never automatically set to true.
        When `local`, rebase is set to true for tracked branches of
@@@ -890,7 -868,7 +890,7 @@@ color.status.<slot>:
        one of `header` (the header text of the status message),
        `added` or `updated` (files which are added but not committed),
        `changed` (files which are changed but not added in the index),
 -      `untracked` (files which are not tracked by git),
 +      `untracked` (files which are not tracked by Git),
        `branch` (the current branch), or
        `nobranch` (the color the 'no branch' warning is shown in, defaulting
        to red). The values of these variables may be specified as in
@@@ -904,7 -882,7 +904,7 @@@ color.ui:
        to `always` if you want all output not intended for machine
        consumption to use color, to `true` or `auto` if you want such
        output to use color when written to the terminal, or to `false` or
 -      `never` if you prefer git commands not to use color unless enabled
 +      `never` if you prefer Git commands not to use color unless enabled
        explicitly with some other configuration or the `--color` option.
  
  column.ui::
@@@ -945,15 -923,6 +945,15 @@@ column.tag:
        Specify whether to output tag listing in `git tag` in columns.
        See `column.ui` for details.
  
 +commit.cleanup::
 +      This setting overrides the default of the `--cleanup` option in
 +      `git commit`. See linkgit:git-commit[1] for details. Changing the
 +      default can be useful when you always want to keep lines that begin
 +      with comment character `#` in your log message, in which case you
 +      would do `git config commit.cleanup whitespace` (note that you will
 +      have to remove the help lines that begin with `#` in the commit log
 +      template yourself, if you do this).
 +
  commit.status::
        A boolean to enable/disable inclusion of status information in the
        commit message template when using an editor to prepare the commit
@@@ -1021,7 -990,7 +1021,7 @@@ fetch.fsckObjects:
        is used instead.
  
  fetch.unpackLimit::
 -      If the number of objects fetched over the git native
 +      If the number of objects fetched over the Git native
        transfer is below this
        limit, then the objects will be unpacked into loose object
        files. However if the number of received objects equals or
@@@ -1061,7 -1030,7 +1061,7 @@@ format.subjectprefix:
  
  format.signature::
        The default for format-patch is to output a signature containing
 -      the git version number. Use this variable to change that default.
 +      the Git version number. Use this variable to change that default.
        Set this variable to the empty string ("") to suppress
        signature generation.
  
@@@ -1174,7 -1143,7 +1174,7 @@@ gitcvs.logfile:
  gitcvs.usecrlfattr::
        If true, the server will look up the end-of-line conversion
        attributes for files to determine the '-k' modes to use. If
 -      the attributes force git to treat a file as text,
 +      the attributes force Git to treat a file as text,
        the '-k' mode will be left blank so CVS clients will
        treat it as text. If they suppress text conversion, the file
        will be set with '-kb' mode, which suppresses any newline munging
@@@ -1194,7 -1163,7 +1194,7 @@@ gitcvs.allbinary:
  
  gitcvs.dbname::
        Database used by git-cvsserver to cache revision information
 -      derived from the git repository. The exact meaning depends on the
 +      derived from the Git repository. The exact meaning depends on the
        used database driver, for SQLite (which is the default driver) this
        is a filename. Supports variable substitution (see
        linkgit:git-cvsserver[1] for details). May not contain semicolons (`;`).
@@@ -1406,7 -1375,7 +1406,7 @@@ http.proxy:
  
  http.cookiefile::
        File containing previously stored cookie lines which should be used
 -      in the git http session, if they match the server. The file format
 +      in the Git http session, if they match the server. The file format
        of the file to read cookies from should be plain HTTP headers or
        the Netscape/Mozilla cookie file format (see linkgit:curl[1]).
        NOTE that the file specified with http.cookiefile is only used as
@@@ -1428,7 -1397,7 +1428,7 @@@ http.sslKey:
        variable.
  
  http.sslCertPasswordProtected::
 -      Enable git's password prompt for the SSL certificate.  Otherwise
 +      Enable Git's password prompt for the SSL certificate.  Otherwise
        OpenSSL will prompt the user, possibly many times, if the
        certificate or private key is encrypted.  Can be overridden by the
        'GIT_SSL_CERT_PASSWORD_PROTECTED' environment variable.
@@@ -1475,7 -1444,7 +1475,7 @@@ http.noEPSV:
  
  http.useragent::
        The HTTP USER_AGENT string presented to an HTTP server.  The default
 -      value represents the version of the client git such as git/1.7.1.
 +      value represents the version of the client Git such as git/1.7.1.
        This option allows you to override this value to a more common value
        such as Mozilla/4.0.  This may be necessary, for instance, if
        connecting through a firewall that restricts HTTP connections to a set
        Can be overridden by the 'GIT_HTTP_USER_AGENT' environment variable.
  
  i18n.commitEncoding::
 -      Character encoding the commit messages are stored in; git itself
 +      Character encoding the commit messages are stored in; Git itself
        does not care per se, but this information is necessary e.g. when
        importing commits from emails or in the gitk graphical history
        browser (and possibly at other places in the future or in other
@@@ -1556,10 -1525,6 +1556,10 @@@ log.showroot:
        Tools like linkgit:git-log[1] or linkgit:git-whatchanged[1], which
        normally hide the root commit will now show it. True by default.
  
 +log.mailmap::
 +      If true, makes linkgit:git-log[1], linkgit:git-show[1], and
 +      linkgit:git-whatchanged[1] assume `--use-mailmap`.
 +
  mailmap.file::
        The location of an augmenting mailmap file. The default
        mailmap, located in the root of the repository, is loaded
@@@ -1621,7 -1586,7 +1621,7 @@@ mergetool.keepBackup:
        `true` (i.e. keep the backup files).
  
  mergetool.keepTemporaries::
 -      When invoking a custom merge tool, git uses a set of temporary
 +      When invoking a custom merge tool, Git uses a set of temporary
        files to pass to the tool. If the tool returns an error and this
        variable is set to `true`, then these temporary files will be
        preserved, otherwise they will be removed after the tool has
@@@ -1649,7 -1614,7 +1649,7 @@@ displayed
  
  notes.rewrite.<command>::
        When rewriting commits with <command> (currently `amend` or
 -      `rebase`) and this variable is set to `true`, git
 +      `rebase`) and this variable is set to `true`, Git
        automatically copies your notes from the original to the
        rewritten commit.  Defaults to `true`, but see
        "notes.rewriteRef" below.
@@@ -1729,7 -1694,7 +1729,7 @@@ pack.threads:
        warning. This is meant to reduce packing time on multiprocessor
        machines. The required amount of memory for the delta search window
        is however multiplied by the number of threads.
 -      Specifying 0 will cause git to auto-detect the number of CPU's
 +      Specifying 0 will cause Git to auto-detect the number of CPU's
        and set the number of threads accordingly.
  
  pack.indexVersion::
        and this config option ignored whenever the corresponding pack is
        larger than 2 GB.
  +
 -If you have an old git that does not understand the version 2 `*.idx` file,
 +If you have an old Git that does not understand the version 2 `*.idx` file,
  cloning or fetching over a non native protocol (e.g. "http" and "rsync")
  that will copy both `*.pack` file and corresponding `*.idx` file from the
  other side may give you a repository that cannot be accessed with your
 -older version of git. If the `*.pack` file is smaller than 2 GB, however,
 +older version of Git. If the `*.pack` file is smaller than 2 GB, however,
  you can use linkgit:git-index-pack[1] on the *.pack file to regenerate
  the `*.idx` file.
  
@@@ -1760,7 -1725,7 +1760,7 @@@ pack.packSizeLimit:
  
  pager.<cmd>::
        If the value is boolean, turns on or off pagination of the
 -      output of a particular git subcommand when writing to a tty.
 +      output of a particular Git subcommand when writing to a tty.
        Otherwise, turns on pagination for the subcommand using the
        pager specified by the value of `pager.<cmd>`.  If `--paginate`
        or `--no-pager` is specified on the command line, it takes
@@@ -1795,7 -1760,7 +1795,7 @@@ pull.twohead:
        The default merge strategy to use when pulling a single branch.
  
  push.default::
 -      Defines the action git push should take if no refspec is given
 +      Defines the action `git push` should take if no refspec is given
        on the command line, no refspec is configured in the remote, and
        no refspec is implied by any of the options given on the command
        line. Possible values are:
@@@ -1880,6 -1845,15 +1880,15 @@@ receive.denyNonFastForwards:
        even if that push is forced. This configuration variable is
        set when initializing a shared repository.
  
+ receive.hiderefs::
+       String(s) `receive-pack` uses to decide which refs to omit
+       from its initial advertisement.  Use more than one
+       definitions to specify multiple prefix strings. A ref that
+       are under the hierarchies listed on the value of this
+       variable is excluded, and is hidden when responding to `git
+       push`, and an attempt to update or delete a hidden ref by
+       `git push` is rejected.
  receive.updateserverinfo::
        If set to true, git-receive-pack will run git-update-server-info
        after receiving data from git-push and updating refs.
@@@ -1935,7 -1909,7 +1944,7 @@@ remote.<name>.tagopt:
        linkgit:git-fetch[1].
  
  remote.<name>.vcs::
 -      Setting this to a value <vcs> will cause git to interact with
 +      Setting this to a value <vcs> will cause Git to interact with
        the remote with the git-remote-<vcs> helper.
  
  remotes.<group>::
  repack.usedeltabaseoffset::
        By default, linkgit:git-repack[1] creates packs that use
        delta-base offset. If you need to share your repository with
 -      git older than version 1.4.4, either directly or via a dumb
 +      Git older than version 1.4.4, either directly or via a dumb
        protocol such as http, then you need to set this option to
 -      "false" and repack. Access from old git versions over the
 +      "false" and repack. Access from old Git versions over the
        native protocol are unaffected by this option.
  
  rerere.autoupdate::
@@@ -2016,7 -1990,7 +2025,7 @@@ showbranch.default:
  status.relativePaths::
        By default, linkgit:git-status[1] shows paths relative to the
        current directory. Setting this variable to `false` shows paths
 -      relative to the repository root (this was the default for git
 +      relative to the repository root (this was the default for Git
        prior to v1.5.4).
  
  status.showUntrackedFiles::
@@@ -2092,18 -2066,32 +2101,32 @@@ transfer.fsckObjects:
        not set, the value of this variable is used instead.
        Defaults to false.
  
+ transfer.hiderefs::
+       This variable can be used to set both `receive.hiderefs`
+       and `uploadpack.hiderefs` at the same time to the same
+       values.  See entries for these other variables.
  transfer.unpackLimit::
        When `fetch.unpackLimit` or `receive.unpackLimit` are
        not set, the value of this variable is used instead.
        The default value is 100.
  
+ uploadpack.hiderefs::
+       String(s) `upload-pack` uses to decide which refs to omit
+       from its initial advertisement.  Use more than one
+       definitions to specify multiple prefix strings. A ref that
+       are under the hierarchies listed on the value of this
+       variable is excluded, and is hidden from `git ls-remote`,
+       `git fetch`, etc.  An attempt to fetch a hidden ref by `git
+       fetch` will fail.
  url.<base>.insteadOf::
        Any URL that starts with this value will be rewritten to
        start, instead, with <base>. In cases where some site serves a
        large number of repositories, and serves them with multiple
        access methods, and some users need to use different access
        methods, this feature allows people to specify any of the
 -      equivalent URLs and have git automatically rewrite the URL to
 +      equivalent URLs and have Git automatically rewrite the URL to
        the best alternative for the particular user, even for a
        never-before-seen repository on the site.  When more than one
        insteadOf strings match a given URL, the longest match is used.
@@@ -2114,11 -2102,11 +2137,11 @@@ url.<base>.pushInsteadOf:
        resulting URL will be pushed to. In cases where some site serves
        a large number of repositories, and serves them with multiple
        access methods, some of which do not allow push, this feature
 -      allows people to specify a pull-only URL and have git
 +      allows people to specify a pull-only URL and have Git
        automatically use an appropriate URL to push, even for a
        never-before-seen repository on the site.  When more than one
        pushInsteadOf strings match a given URL, the longest match is
 -      used.  If a remote has an explicit pushurl, git will ignore this
 +      used.  If a remote has an explicit pushurl, Git will ignore this
        setting for that remote.
  
  user.email::
diff --combined builtin/receive-pack.c
index e8878de45c9474cddd5c713cd7a712bed15a515a,131c1635cb80d4bcf3541f3cb3120a8843dbf8d0..62ba6e7a3d014be01fe01ed497c083f7e44e9d34
@@@ -59,6 -59,11 +59,11 @@@ static enum deny_action parse_deny_acti
  
  static int receive_pack_config(const char *var, const char *value, void *cb)
  {
+       int status = parse_hide_refs_config(var, value, "receive");
+       if (status)
+               return status;
        if (strcmp(var, "receive.denydeletes") == 0) {
                deny_deletes = git_config_bool(var, value);
                return 0;
  
  static void show_ref(const char *path, const unsigned char *sha1)
  {
+       if (ref_is_hidden(path))
+               return;
        if (sent_capabilities)
                packet_write(1, "%s %s\n", sha1_to_hex(sha1), path);
        else
@@@ -182,6 -190,9 +190,6 @@@ struct command 
        char ref_name[FLEX_ARRAY]; /* more */
  };
  
 -static const char pre_receive_hook[] = "hooks/pre-receive";
 -static const char post_receive_hook[] = "hooks/post-receive";
 -
  static void rp_error(const char *err, ...) __attribute__((format (printf, 1, 2)));
  static void rp_warning(const char *err, ...) __attribute__((format (printf, 1, 2)));
  
@@@ -239,10 -250,10 +247,10 @@@ static int run_and_feed_hook(const cha
        const char *argv[2];
        int code;
  
 -      if (access(hook_name, X_OK) < 0)
 +      argv[0] = find_hook(hook_name);
 +      if (!argv[0])
                return 0;
  
 -      argv[0] = hook_name;
        argv[1] = NULL;
  
        memset(&proc, 0, sizeof(proc));
@@@ -328,14 -339,15 +336,14 @@@ static int run_receive_hook(struct comm
  
  static int run_update_hook(struct command *cmd)
  {
 -      static const char update_hook[] = "hooks/update";
        const char *argv[5];
        struct child_process proc;
        int code;
  
 -      if (access(update_hook, X_OK) < 0)
 +      argv[0] = find_hook("update");
 +      if (!argv[0])
                return 0;
  
 -      argv[0] = update_hook;
        argv[1] = cmd->ref_name;
        argv[2] = sha1_to_hex(cmd->old_sha1);
        argv[3] = sha1_to_hex(cmd->new_sha1);
@@@ -528,25 -540,24 +536,25 @@@ static const char *update(struct comman
        }
  }
  
 -static char update_post_hook[] = "hooks/post-update";
 -
  static void run_update_post_hook(struct command *commands)
  {
        struct command *cmd;
        int argc;
        const char **argv;
        struct child_process proc;
 +      char *hook;
  
 +      hook = find_hook("post-update");
        for (argc = 0, cmd = commands; cmd; cmd = cmd->next) {
                if (cmd->error_string || cmd->did_not_exist)
                        continue;
                argc++;
        }
 -      if (!argc || access(update_post_hook, X_OK) < 0)
 +      if (!argc || !hook)
                return;
 +
        argv = xmalloc(sizeof(*argv) * (2 + argc));
 -      argv[0] = update_post_hook;
 +      argv[0] = hook;
  
        for (argc = 1, cmd = commands; cmd; cmd = cmd->next) {
                char *p;
@@@ -685,6 -696,20 +693,20 @@@ static int iterate_receive_command_list
        return -1; /* end of list */
  }
  
+ static void reject_updates_to_hidden(struct command *commands)
+ {
+       struct command *cmd;
+       for (cmd = commands; cmd; cmd = cmd->next) {
+               if (cmd->error_string || !ref_is_hidden(cmd->ref_name))
+                       continue;
+               if (is_null_sha1(cmd->new_sha1))
+                       cmd->error_string = "deny deleting a hidden ref";
+               else
+                       cmd->error_string = "deny updating a hidden ref";
+       }
+ }
  static void execute_commands(struct command *commands, const char *unpacker_error)
  {
        struct command *cmd;
                                       0, &cmd))
                set_connectivity_errors(commands);
  
 -      if (run_receive_hook(commands, pre_receive_hook, 0)) {
+       reject_updates_to_hidden(commands);
 +      if (run_receive_hook(commands, "pre-receive", 0)) {
                for (cmd = commands; cmd; cmd = cmd->next) {
                        if (!cmd->error_string)
                                cmd->error_string = "pre-receive hook declined";
@@@ -991,7 -1018,7 +1015,7 @@@ int cmd_receive_pack(int argc, const ch
                        unlink_or_warn(pack_lockfile);
                if (report_status)
                        report(commands, unpack_status);
 -              run_receive_hook(commands, post_receive_hook, 1);
 +              run_receive_hook(commands, "post-receive", 1);
                run_update_post_hook(commands);
                if (auto_gc) {
                        const char *argv_gc_auto[] = {
diff --combined refs.c
index 29628253087fb0d54a8f7a45938624527f35d4a8,ec41eeeabe6026f6fd60e54cb860203e01a6c4a9..175b9fcaa25eba2ad02564b32eba04c3351978c5
--- 1/refs.c
--- 2/refs.c
+++ b/refs.c
@@@ -3,6 -3,7 +3,7 @@@
  #include "object.h"
  #include "tag.h"
  #include "dir.h"
+ #include "string-list.h"
  
  /*
   * Make sure "ref" is something reasonable to have under ".git/refs/";
@@@ -333,12 -334,14 +334,12 @@@ struct string_slice 
  
  static int ref_entry_cmp_sslice(const void *key_, const void *ent_)
  {
 -      struct string_slice *key = (struct string_slice *)key_;
 -      struct ref_entry *ent = *(struct ref_entry **)ent_;
 -      int entlen = strlen(ent->name);
 -      int cmplen = key->len < entlen ? key->len : entlen;
 -      int cmp = memcmp(key->str, ent->name, cmplen);
 +      const struct string_slice *key = key_;
 +      const struct ref_entry *ent = *(const struct ref_entry * const *)ent_;
 +      int cmp = strncmp(key->str, ent->name, key->len);
        if (cmp)
                return cmp;
 -      return key->len - entlen;
 +      return '\0' - (unsigned char)ent->name[key->len];
  }
  
  /*
@@@ -2554,3 -2557,46 +2555,46 @@@ char *shorten_unambiguous_ref(const cha
        free(short_name);
        return xstrdup(refname);
  }
+ static struct string_list *hide_refs;
+ int parse_hide_refs_config(const char *var, const char *value, const char *section)
+ {
+       if (!strcmp("transfer.hiderefs", var) ||
+           /* NEEDSWORK: use parse_config_key() once both are merged */
+           (!prefixcmp(var, section) && var[strlen(section)] == '.' &&
+            !strcmp(var + strlen(section), ".hiderefs"))) {
+               char *ref;
+               int len;
+               if (!value)
+                       return config_error_nonbool(var);
+               ref = xstrdup(value);
+               len = strlen(ref);
+               while (len && ref[len - 1] == '/')
+                       ref[--len] = '\0';
+               if (!hide_refs) {
+                       hide_refs = xcalloc(1, sizeof(*hide_refs));
+                       hide_refs->strdup_strings = 1;
+               }
+               string_list_append(hide_refs, ref);
+       }
+       return 0;
+ }
+ int ref_is_hidden(const char *refname)
+ {
+       struct string_list_item *item;
+       if (!hide_refs)
+               return 0;
+       for_each_string_list_item(item, hide_refs) {
+               int len;
+               if (prefixcmp(refname, item->string))
+                       continue;
+               len = strlen(item->string);
+               if (!refname[len] || refname[len] == '/')
+                       return 1;
+       }
+       return 0;
+ }
diff --combined t/t5516-fetch-push.sh
index 8f024a08f0b175c12747c33ac0a07cacb73937d9,2b26ecebf7d46e47c79856b0046d045c883527eb..c31e5c1c525eea5a9f4677b03c5d7314d70c6136
@@@ -950,6 -950,27 +950,6 @@@ test_expect_success 'push requires --fo
        )
  '
  
 -test_expect_success 'push requires --force to update annotated tag' '
 -      mk_test heads/master &&
 -      mk_child child1 &&
 -      mk_child child2 &&
 -      (
 -              cd child1 &&
 -              git tag -a -m "message 1" Tag &&
 -              git push ../child2 Tag:refs/tmp/Tag &&
 -              git push ../child2 Tag:refs/tmp/Tag &&
 -              >file1 &&
 -              git add file1 &&
 -              git commit -m "file1" &&
 -              git tag -f -a -m "message 2" Tag &&
 -              test_must_fail git push ../child2 Tag:refs/tmp/Tag &&
 -              git push --force ../child2 Tag:refs/tmp/Tag &&
 -              git tag -f -a -m "message 3" Tag HEAD~ &&
 -              test_must_fail git push ../child2 Tag:refs/tmp/Tag &&
 -              git push --force ../child2 Tag:refs/tmp/Tag
 -      )
 -'
 -
  test_expect_success 'push --porcelain' '
        mk_empty &&
        echo >.git/foo  "To testrepo" &&
@@@ -1016,4 -1037,31 +1016,31 @@@ test_expect_success 'push --prune refsp
        ! check_push_result $the_first_commit tmp/foo tmp/bar
  '
  
+ for configsection in transfer receive
+ do
+       test_expect_success "push to update a ref hidden by $configsection.hiderefs" '
+               mk_test heads/master hidden/one hidden/two hidden/three &&
+               (
+                       cd testrepo &&
+                       git config $configsection.hiderefs refs/hidden
+               ) &&
+               # push to unhidden ref succeeds normally
+               git push testrepo master:refs/heads/master &&
+               check_push_result $the_commit heads/master &&
+               # push to update a hidden ref should fail
+               test_must_fail git push testrepo master:refs/hidden/one &&
+               check_push_result $the_first_commit hidden/one &&
+               # push to delete a hidden ref should fail
+               test_must_fail git push testrepo :refs/hidden/two &&
+               check_push_result $the_first_commit hidden/two &&
+               # idempotent push to update a hidden ref should fail
+               test_must_fail git push testrepo $the_first_commit:refs/hidden/three &&
+               check_push_result $the_first_commit hidden/three
+       '
+ done
  test_done
diff --combined upload-pack.c
index 7c05b15e68d6deed45a172df397e814fcf2032b0,dec02377936557dc4558c295d5bb9302ab3b58cf..30146a04f7a271ffaa033c0c6567ad1036f4bc49
@@@ -12,6 -12,7 +12,7 @@@
  #include "run-command.h"
  #include "sigchain.h"
  #include "version.h"
+ #include "string-list.h"
  
  static const char upload_pack_usage[] = "git upload-pack [--strict] [--timeout=<n>] <dir>";
  
@@@ -28,7 -29,7 +29,7 @@@
  
  static unsigned long oldest_have;
  
- static int multi_ack, nr_our_refs;
+ static int multi_ack;
  static int no_done;
  static int use_thin_pack, use_ofs_delta, use_include_tag;
  static int no_progress, daemon_mode;
@@@ -139,7 -140,6 +140,6 @@@ static void create_pack_file(void
  {
        struct async rev_list;
        struct child_process pack_objects;
-       int create_full_pack = (nr_our_refs == want_obj.nr && !have_obj.nr);
        char data[8193], progress[128];
        char abort_msg[] = "aborting due to possible repository "
                "corruption on the remote side.";
        argv[arg++] = "pack-objects";
        if (!shallow_nr) {
                argv[arg++] = "--revs";
-               if (create_full_pack)
-                       argv[arg++] = "--all";
-               else if (use_thin_pack)
+               if (use_thin_pack)
                        argv[arg++] = "--thin";
        }
  
        }
        else {
                FILE *pipe_fd = xfdopen(pack_objects.in, "w");
-               if (!create_full_pack) {
-                       int i;
-                       for (i = 0; i < want_obj.nr; i++)
-                               fprintf(pipe_fd, "%s\n", sha1_to_hex(want_obj.objects[i].item->sha1));
-                       fprintf(pipe_fd, "--not\n");
-                       for (i = 0; i < have_obj.nr; i++)
-                               fprintf(pipe_fd, "%s\n", sha1_to_hex(have_obj.objects[i].item->sha1));
-               }
+               int i;
  
+               for (i = 0; i < want_obj.nr; i++)
+                       fprintf(pipe_fd, "%s\n",
+                               sha1_to_hex(want_obj.objects[i].item->sha1));
+               fprintf(pipe_fd, "--not\n");
+               for (i = 0; i < have_obj.nr; i++)
+                       fprintf(pipe_fd, "%s\n",
+                               sha1_to_hex(have_obj.objects[i].item->sha1));
                fprintf(pipe_fd, "\n");
                fflush(pipe_fd);
                fclose(pipe_fd);
@@@ -672,17 -670,10 +670,17 @@@ static void receive_needs(void
        if (depth == 0 && shallows.nr == 0)
                return;
        if (depth > 0) {
 -              struct commit_list *result, *backup;
 +              struct commit_list *result = NULL, *backup = NULL;
                int i;
 -              backup = result = get_shallow_commits(&want_obj, depth,
 -                      SHALLOW, NOT_SHALLOW);
 +              if (depth == INFINITE_DEPTH)
 +                      for (i = 0; i < shallows.nr; i++) {
 +                              struct object *object = shallows.objects[i].item;
 +                              object->flags |= NOT_SHALLOW;
 +                      }
 +              else
 +                      backup = result =
 +                              get_shallow_commits(&want_obj, depth,
 +                                                  SHALLOW, NOT_SHALLOW);
                while (result) {
                        struct object *object = &result->item->object;
                        if (!(object->flags & (CLIENT_SHALLOW|NOT_SHALLOW))) {
        free(shallows.objects);
  }
  
+ /* return non-zero if the ref is hidden, otherwise 0 */
+ static int mark_our_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
+ {
+       struct object *o = lookup_unknown_object(sha1);
+       if (ref_is_hidden(refname))
+               return 1;
+       if (!o)
+               die("git upload-pack: cannot find object %s:", sha1_to_hex(sha1));
+       o->flags |= OUR_REF;
+       return 0;
+ }
  static int send_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
  {
        static const char *capabilities = "multi_ack thin-pack side-band"
                " side-band-64k ofs-delta shallow no-progress"
                " include-tag multi_ack_detailed";
-       struct object *o = lookup_unknown_object(sha1);
        const char *refname_nons = strip_namespace(refname);
        unsigned char peeled[20];
  
+       if (mark_our_ref(refname, sha1, flag, cb_data))
+               return 0;
        if (capabilities)
                packet_write(1, "%s %s%c%s%s agent=%s\n",
                             sha1_to_hex(sha1), refname_nons,
        else
                packet_write(1, "%s %s\n", sha1_to_hex(sha1), refname_nons);
        capabilities = NULL;
-       if (!(o->flags & OUR_REF)) {
-               o->flags |= OUR_REF;
-               nr_our_refs++;
-       }
        if (!peel_ref(refname, peeled))
                packet_write(1, "%s %s^{}\n", sha1_to_hex(peeled), refname_nons);
        return 0;
  }
  
- static int mark_our_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
- {
-       struct object *o = parse_object(sha1);
-       if (!o)
-               die("git upload-pack: cannot find object %s:", sha1_to_hex(sha1));
-       if (!(o->flags & OUR_REF)) {
-               o->flags |= OUR_REF;
-               nr_our_refs++;
-       }
-       return 0;
- }
  static void upload_pack(void)
  {
        if (advertise_refs || !stateless_rpc) {
        }
  }
  
+ static int upload_pack_config(const char *var, const char *value, void *unused)
+ {
+       return parse_hide_refs_config(var, value, "uploadpack");
+ }
  int main(int argc, char **argv)
  {
        char *dir;
                die("'%s' does not appear to be a git repository", dir);
        if (is_repository_shallow())
                die("attempt to fetch/clone from a shallow repository");
+       git_config(upload_pack_config, NULL);
        if (getenv("GIT_DEBUG_SEND_PACK"))
                debug_fd = atoi(getenv("GIT_DEBUG_SEND_PACK"));
        upload_pack();