1. 11 12月, 2013 4 次提交
    • N
      receive-pack: allow pushes that update .git/shallow · 0a1bc12b
      Nguyễn Thái Ngọc Duy 提交于
      The basic 8 steps to update .git/shallow does not fully apply here
      because the user may choose to accept just a few refs (while fetch
      always accepts all refs). The steps are modified a bit.
      
      1-6. same as before. After calling assign_shallow_commits_to_refs at
         step 6, each shallow commit has a bitmap that marks all refs that
         require it.
      
      7. mark all "ours" shallow commits that are reachable from any
         refs. We will need to do the original step 7 on them later.
      
      8. go over all shallow commit bitmaps, mark refs that require new
         shallow commits.
      
      9. setup a strict temporary shallow file to plug all the holes, even
         if it may cut some of our history short. This file is used by all
         hooks. The hooks could use --shallow-file=$GIT_DIR/shallow to
         overcome this and reach everything in current repo.
      
      10. go over the new refs one by one. For each ref, do the reachability
         test if it needs a shallow commit on the list from step 7. Remove
         it if it's reachable from our refs. Gather all required shallow
         commits, run check_everything_connected() with the new ref, then
         install them to .git/shallow.
      
      This mode is disabled by default and can be turned on with
      receive.shallowupdate
      Signed-off-by: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      0a1bc12b
    • N
    • N
      receive-pack: reorder some code in unpack() · 31c42bff
      Nguyễn Thái Ngọc Duy 提交于
      This is the preparation for adding --shallow-file to both
      unpack-objects and index-pack. To sum up:
      
       - struct argv_array used instead of const char **
      
       - status/code, ip/child, unpacker/keeper are moved out to function
         top level
      
       - successful flow now ends at the end of the function
      Signed-off-by: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      31c42bff
    • N
      make the sender advertise shallow commits to the receiver · ad491366
      Nguyễn Thái Ngọc Duy 提交于
      If either receive-pack or upload-pack is called on a shallow
      repository, shallow commits (*) will be sent after the ref
      advertisement (but before the packet flush), so that the receiver has
      the full "shape" of the sender's commit graph. This will be needed for
      the receiver to update its .git/shallow if necessary.
      
      This breaks the protocol for all clients trying to push to a shallow
      repo, or fetch from one. Which is basically the same end result as
      today's "is_repository_shallow() && die()" in receive-pack and
      upload-pack. New clients will be made aware of shallow upstream and
      can make use of this information.
      
      The sender must send all shallow commits that are sent in the
      following pack. It may send more shallow commits than necessary.
      
      upload-pack for example may choose to advertise no shallow commits if
      it knows in advance that the pack it's going to send contains no
      shallow commits. But upload-pack is the server, so we choose the
      cheaper way, send full .git/shallow and let the client deal with it.
      
      Smart HTTP is not affected by this patch. Shallow support on
      smart-http comes later separately.
      
      (*) A shallow commit is a commit that terminates the revision
          walker. It is usually put in .git/shallow in order to keep the
          revision walker from going out of bound because there is no
          guarantee that objects behind this commit is available.
      Signed-off-by: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      ad491366
  2. 31 8月, 2013 1 次提交
  3. 14 8月, 2013 1 次提交
    • N
      push: respect --no-thin · f7c815c3
      Nguyễn Thái Ngọc Duy 提交于
      - From the beginning of push.c in 755225de, 2006-04-29, "thin" option
        was enabled by default but could be turned off with --no-thin.
      
      - Then Shawn changed the default to 0 in favor of saving server
        resources in a4503a15, 2007-09-09. --no-thin worked great.
      
      - One day later, in 9b288516 Daniel extracted some code from push.c to
        create transport.c. He (probably accidentally) flipped the default
        value from 0 to 1 in transport_get().
      
      From then on --no-thin is effectively no-op because git-push still
      expects the default value to be false and only calls
      transport_set_option() when "thin" variable in push.c is true (which
      is unnecessary). Correct the code to respect --no-thin by calling
      transport_set_option() in both cases.
      
      receive-pack learns about --reject-thin-pack-for-testing option,
      which only is for testing purposes, hence no document update.
      Signed-off-by: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      f7c815c3
  4. 09 7月, 2013 1 次提交
    • J
      cache.h: move remote/connect API out of it · 47a59185
      Junio C Hamano 提交于
      The definition of "struct ref" in "cache.h", a header file so
      central to the system, always confused me.  This structure is not
      about the local ref used by sha1-name API to name local objects.
      
      It is what refspecs are expanded into, after finding out what refs
      the other side has, to define what refs are updated after object
      transfer succeeds to what values.  It belongs to "remote.h" together
      with "struct refspec".
      
      While we are at it, also move the types and functions related to the
      Git transport connection to a new header file connect.h
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      47a59185
  5. 20 4月, 2013 1 次提交
    • J
      receive-pack: close sideband fd on early pack errors · 49ecfa13
      Jeff King 提交于
      Since commit a22e6f85 (receive-pack: send pack-processing
      stderr over sideband, 2012-09-21), receive-pack will start
      an async sideband thread to copy the stderr from our
      index-pack or unpack-objects child to the client. We hand
      the thread's input descriptor to unpack(), which puts it in
      the "err" member of the "struct child_process".
      
      After unpack() returns, we use finish_async() to reap the
      sideband thread. The thread is only ready to die when it
      gets EOF on its pipe, which is connected to the err
      descriptor. So we expect all of the write ends of that pipe
      to be closed as part of unpack().
      
      Normally, this works fine. After start_command forks, it
      closes the parent copy of the descriptor. Then once the
      child exits (whether it was successful or not), that closes
      the only remaining writer.
      
      However, there is one code-path in unpack() that does not
      handle this. Before we decide which of unpack-objects or
      index-pack to use, we read the pack header ourselves to see
      how many objects it contains. If there is an error here, we
      exit without running either sub-command, the pipe descriptor
      remains open, and we are in a deadlock, waiting for the
      sideband thread to die (which is in turn waiting for us to
      close the pipe).
      
      We can fix this by making sure that unpack() always closes
      the pipe before returning.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      49ecfa13
  6. 21 2月, 2013 3 次提交
    • J
      pkt-line: provide a LARGE_PACKET_MAX static buffer · 74543a04
      Jeff King 提交于
      Most of the callers of packet_read_line just read into a
      static 1000-byte buffer (callers which handle arbitrary
      binary data already use LARGE_PACKET_MAX). This works fine
      in practice, because:
      
        1. The only variable-sized data in these lines is a ref
           name, and refs tend to be a lot shorter than 1000
           characters.
      
        2. When sending ref lines, git-core always limits itself
           to 1000 byte packets.
      
      However, the only limit given in the protocol specification
      in Documentation/technical/protocol-common.txt is
      LARGE_PACKET_MAX; the 1000 byte limit is mentioned only in
      pack-protocol.txt, and then only describing what we write,
      not as a specific limit for readers.
      
      This patch lets us bump the 1000-byte limit to
      LARGE_PACKET_MAX. Even though git-core will never write a
      packet where this makes a difference, there are two good
      reasons to do this:
      
        1. Other git implementations may have followed
           protocol-common.txt and used a larger maximum size. We
           don't bump into it in practice because it would involve
           very long ref names.
      
        2. We may want to increase the 1000-byte limit one day.
           Since packets are transferred before any capabilities,
           it's difficult to do this in a backwards-compatible
           way. But if we bump the size of buffer the readers can
           handle, eventually older versions of git will be
           obsolete enough that we can justify bumping the
           writers, as well. We don't have plans to do this
           anytime soon, but there is no reason not to start the
           clock ticking now.
      
      Just bumping all of the reading bufs to LARGE_PACKET_MAX
      would waste memory. Instead, since most readers just read
      into a temporary buffer anyway, let's provide a single
      static buffer that all callers can use. We can further wrap
      this detail away by having the packet_read_line wrapper just
      use the buffer transparently and return a pointer to the
      static storage.  That covers most of the cases, and the
      remaining ones already read into their own LARGE_PACKET_MAX
      buffers.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      74543a04
    • J
      pkt-line: teach packet_read_line to chomp newlines · 819b929d
      Jeff King 提交于
      The packets sent during ref negotiation are all terminated
      by newline; even though the code to chomp these newlines is
      short, we end up doing it in a lot of places.
      
      This patch teaches packet_read_line to auto-chomp the
      trailing newline; this lets us get rid of a lot of inline
      chomping code.
      
      As a result, some call-sites which are not reading
      line-oriented data (e.g., when reading chunks of packfiles
      alongside sideband) transition away from packet_read_line to
      the generic packet_read interface. This patch converts all
      of the existing callsites.
      
      Since the function signature of packet_read_line does not
      change (but its behavior does), there is a possibility of
      new callsites being introduced in later commits, silently
      introducing an incompatibility.  However, since a later
      patch in this series will change the signature, such a
      commit would have to be merged directly into this commit,
      not to the tip of the series; we can therefore ignore the
      issue.
      
      This is an internal cleanup and should produce no change of
      behavior in the normal case. However, there is one corner
      case to note. Callers of packet_read_line have never been
      able to tell the difference between a flush packet ("0000")
      and an empty packet ("0004"), as both cause packet_read_line
      to return a length of 0. Readers treat them identically,
      even though Documentation/technical/protocol-common.txt says
      we must not; it also says that implementations should not
      send an empty pkt-line.
      
      By stripping out the newline before the result gets to the
      caller, we will now treat the newline-only packet ("0005\n")
      the same as an empty packet, which in turn gets treated like
      a flush packet. In practice this doesn't matter, as neither
      empty nor newline-only packets are part of git's protocols
      (at least not for the line-oriented bits, and readers who
      are not expecting line-oriented packets will be calling
      packet_read directly, anyway). But even if we do decide to
      care about the distinction later, it is orthogonal to this
      patch.  The right place to tighten would be to stop treating
      empty packets as flush packets, and this change does not
      make doing so any harder.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      819b929d
    • J
      pkt-line: drop safe_write function · cdf4fb8e
      Jeff King 提交于
      This is just write_or_die by another name. The one
      distinction is that write_or_die will treat EPIPE specially
      by suppressing error messages. That's fine, as we die by
      SIGPIPE anyway (and in the off chance that it is disabled,
      write_or_die will simulate it).
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      cdf4fb8e
  7. 08 2月, 2013 1 次提交
    • J
      upload/receive-pack: allow hiding ref hierarchies · daebaa78
      Junio C Hamano 提交于
      A repository may have refs that are only used for its internal
      bookkeeping purposes that should not be exposed to the others that
      come over the network.
      
      Teach upload-pack to omit some refs from its initial advertisement
      by paying attention to the uploadpack.hiderefs multi-valued
      configuration variable.  Do the same to receive-pack via the
      receive.hiderefs variable.  As a convenient short-hand, allow using
      transfer.hiderefs to set the value to both of these variables.
      
      Any ref that is under the hierarchies listed on the value of these
      variable is excluded from responses to requests made by "ls-remote",
      "fetch", etc. (for upload-pack) and "push" (for receive-pack).
      
      Because these hidden refs do not count as OUR_REF, an attempt to
      fetch objects at the tip of them will be rejected, and because these
      refs do not get advertised, "git push :" will not see local branches
      that have the same name as them as "matching" ones to be sent.
      
      An attempt to update/delete these hidden refs with an explicit
      refspec, e.g. "git push origin :refs/hidden/22", is rejected.  This
      is not a new restriction.  To the pusher, it would appear that there
      is no such ref, so its push request will conclude with "Now that I
      sent you all the data, it is time for you to update the refs.  I saw
      that the ref did not exist when I started pushing, and I want the
      result to point at this commit".  The receiving end will apply the
      compare-and-swap rule to this request and rejects the push with
      "Well, your update request conflicts with somebody else; I see there
      is such a ref.", which is the right thing to do. Otherwise a push to
      a hidden ref will always be "the last one wins", which is not a good
      default.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      daebaa78
  8. 15 1月, 2013 1 次提交
    • A
      hooks: Add function to check if a hook exists · 5a7da2dc
      Aaron Schrab 提交于
      Create find_hook() function to determine if a given hook exists and is
      executable.  If it is, the path to the script will be returned,
      otherwise NULL is returned.
      
      This encapsulates the tests that are used to check for the existence of
      a hook in one place, making it easier to modify those checks if that is
      found to be necessary.  This also makes it simple for places that can
      use a hook to check if a hook exists before doing, possibly lengthy,
      setup work which would be pointless if no such hook is present.
      
      The returned value is left as a static value from get_pathname() rather
      than a duplicate because it is anticipated that the return value will
      either be used as a boolean, immediately added to an argv_array list
      which would result in it being duplicated at that point, or used to
      actually run the command without much intervening work.  Callers which
      need to hold onto the returned value for a longer time are expected to
      duplicate the return value themselves.
      Signed-off-by: NAaron Schrab <aaron@schrab.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      5a7da2dc
  9. 22 9月, 2012 3 次提交
    • J
      receive-pack: drop "n/a" on unpacker errors · 74eb32d3
      Jeff King 提交于
      The output from git push currently looks like this:
      
        $ git push dest HEAD
        fatal: [some message from index-pack]
        error: unpack failed: index-pack abnormal exit
        To dest
         ! [remote rejected] HEAD -> master (n/a (unpacker error))
      
      That n/a is meant to be "the per-ref status is not
      available" but the nested parentheses just make it look
      ugly. Let's turn the final line into just:
      
         ! [remote rejected] HEAD -> master (unpacker error)
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      74eb32d3
    • J
      receive-pack: send pack-processing stderr over sideband · a22e6f85
      Jeff King 提交于
      Receive-pack invokes either unpack-objects or index-pack to
      handle the incoming pack. However, we do not redirect the
      stderr of the sub-processes at all, so it is never seen by
      the client. From the initial thread adding sideband support,
      which is here:
      
        http://thread.gmane.org/gmane.comp.version-control.git/139471
      
      it is clear that some messages are specifically kept off the
      sideband (with the assumption that they are of interest only
      to an administrator, not the client). The stderr of the
      subprocesses is mentioned in the thread, but it's unclear if
      they are included in that group, or were simply forgotten.
      
      However, there are a few good reasons to show them to the
      client:
      
        1. In many cases, they are directly about the incoming
           packfile (e.g., fsck warnings with --strict, corruption
           in the packfile, etc). Without these messages, the
           client just gets "unpacker error" with no extra useful
           diagnosis.
      
        2. No matter what the cause, we are probably better off
           showing the errors to the client. If the client and the
           server admin are not the same entity, it is probably
           much easier for the client to cut-and-paste the errors
           they see than for the admin to try to dig them out of a
           log and correlate them with a particular session.
      
        3. Users of the ssh transport typically already see these
           stderr messages, as the remote's stderr is copied
           literally by ssh. This brings other transports (http,
           and push-over-git if you are crazy enough to enable it)
           more in line with ssh. As a bonus for ssh users,
           because the messages are now fed through the sideband
           and printed by the local git, they will have "remote:"
           prepended and be properly interleaved with any local
           output to stderr.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      a22e6f85
    • J
      receive-pack: redirect unpack-objects stdout to /dev/null · 59bfdfb8
      Jeff King 提交于
      The unpack-objects command should not generally produce any
      output on stdout. However, if it's given extra input after
      the packfile, it will spew the remainder to stdout. When
      called by receive-pack, this means we will break protocol,
      since our stdout is connected to the remote send-pack.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      59bfdfb8
  10. 28 8月, 2012 1 次提交
  11. 07 8月, 2012 1 次提交
  12. 04 8月, 2012 1 次提交
    • J
      include agent identifier in capability string · ff5effdf
      Jeff King 提交于
      Instead of having the client advertise a particular version
      number in the git protocol, we have managed extensions and
      backwards compatibility by having clients and servers
      advertise capabilities that they support. This is far more
      robust than having each side consult a table of
      known versions, and provides sufficient information for the
      protocol interaction to complete.
      
      However, it does not allow servers to keep statistics on
      which client versions are being used. This information is
      not necessary to complete the network request (the
      capabilities provide enough information for that), but it
      may be helpful to conduct a general survey of client
      versions in use.
      
      We already send the client version in the user-agent header
      for http requests; adding it here allows us to gather
      similar statistics for non-http requests.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      ff5effdf
  13. 14 2月, 2012 1 次提交
    • C
      do not override receive-pack errors · ef7e93d9
      Clemens Buchacher 提交于
      Receive runs rev-list --verify-objects in order to detect missing
      objects. However, such errors are ignored and overridden later.
      Instead, consequently ignore all update commands for which an error has
      already been detected.
      
      Some tests in t5504 are obsoleted by this change, because invalid
      objects are detected even if fsck is not enabled. Instead, they now test
      for different error messages depending on whether or not fsck is turned
      on. A better fix would be to force a corruption that will be detected by
      fsck but not by rev-list.
      Signed-off-by: NClemens Buchacher <drizzd@aon.at>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      ef7e93d9
  14. 09 1月, 2012 2 次提交
  15. 07 1月, 2012 3 次提交
  16. 14 12月, 2011 2 次提交
  17. 06 12月, 2011 1 次提交
    • N
      Copy resolve_ref() return value for longer use · d5a35c11
      Nguyễn Thái Ngọc Duy 提交于
      resolve_ref() may return a pointer to a static buffer. Callers that
      use this value longer than a couple of statements should copy the
      value to avoid some hidden resolve_ref() call that may change the
      static buffer's value.
      
      The bug found by Tony Wang <wwwjfy@gmail.com> in builtin/merge.c
      demonstrates this. The first call is in cmd_merge()
      
      branch = resolve_ref("HEAD", head_sha1, 0, &flag);
      
      Then deep in lookup_commit_or_die() a few lines after, resolve_ref()
      may be called again and destroy "branch".
      
      lookup_commit_or_die
       lookup_commit_reference
        lookup_commit_reference_gently
         parse_object
          lookup_replace_object
           do_lookup_replace_object
            prepare_replace_object
             for_each_replace_ref
              do_for_each_ref
               get_loose_refs
                get_ref_dir
                 get_ref_dir
                  resolve_ref
      
      All call sites are checked and made sure that xstrdup() is called if
      the value should be saved.
      Signed-off-by: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      d5a35c11
  18. 04 11月, 2011 1 次提交
  19. 06 10月, 2011 1 次提交
    • M
      Change check_ref_format() to take a flags argument · 8d9c5010
      Michael Haggerty 提交于
      Change check_ref_format() to take a flags argument that indicates what
      is acceptable in the reference name (analogous to "git
      check-ref-format"'s "--allow-onelevel" and "--refspec-pattern").  This
      is more convenient for callers and also fixes a failure in the test
      suite (and likely elsewhere in the code) by enabling "onelevel" and
      "refspec-pattern" to be allowed independently of each other.
      
      Also rename check_ref_format() to check_refname_format() to make it
      obvious that it deals with refnames rather than references themselves.
      Signed-off-by: NMichael Haggerty <mhagger@alum.mit.edu>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      8d9c5010
  20. 01 10月, 2011 1 次提交
    • P
      receive-pack: don't pass non-existent refs to post-{receive,update} hooks · 160b81ed
      Pang Yan Han 提交于
      When a push specifies deletion of non-existent refs, the post post-receive and
      post-update hooks receive them as input/arguments.
      
      For instance, for the following push, where refs/heads/nonexistent is a ref
      which does not exist on the remote side:
      
      	git push origin :refs/heads/nonexistent
      
      the post-receive hook receives from standard input:
      
      	<null-sha1> SP <null-sha1> SP refs/heads/nonexistent
      
      and the post-update hook receives as arguments:
      
      	refs/heads/nonexistent
      
      which does not make sense since it is a no-op.
      
      Teach receive-pack not to pass non-existent refs to the post-receive and
      post-update hooks. If the push only attempts to delete non-existent refs,
      these hooks are not even called.
      
      The update and pre-receive hooks are still notified about attempted
      deletion of non-existent refs to give them a chance to inspect the
      situation and act on it.
      
      [jc: mild fix-ups to avoid introducing an extra list; also added fixes to
      some tests]
      Signed-off-by: NPang Yan Han <pangyanhan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      160b81ed
  21. 13 9月, 2011 1 次提交
    • J
      refactor run_receive_hook() · 9684e44a
      Junio C Hamano 提交于
      Running a hook has to make complex set-up to establish web of
      communication between child process and multiplexer, which is common
      regardless of what kind of data is fed to the hook. Refactor the parts
      that is specific to the data fed to the particular set of hooks from the
      part that runs the hook, so that the code can be reused to drive hooks
      that take different kind of data.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      9684e44a
  22. 10 9月, 2011 1 次提交
  23. 07 9月, 2011 1 次提交
  24. 05 9月, 2011 1 次提交
  25. 09 8月, 2011 1 次提交
  26. 01 8月, 2011 1 次提交
  27. 12 7月, 2011 1 次提交
    • J
      ref namespaces: Support remote repositories via upload-pack and receive-pack · 6b01ecfe
      Josh Triplett 提交于
      Change upload-pack and receive-pack to use the namespace-prefixed refs
      when working with the repository, and use the unprefixed refs when
      talking to the client, maintaining the masquerade.  This allows
      clone, pull, fetch, and push to work with a suitably configured
      GIT_NAMESPACE.
      
      receive-pack advertises refs outside the current namespace as .have refs
      (as it currently does for refs in alternates), so that the client can
      use them to minimize data transfer but will otherwise ignore them.
      
      With appropriate configuration, this also allows http-backend to expose
      namespaces as multiple repositories with different paths.  This only
      requires setting GIT_NAMESPACE, which http-backend passes through to
      upload-pack and receive-pack.
      Signed-off-by: NJosh Triplett <josh@joshtriplett.org>
      Signed-off-by: NJamey Sharp <jamey@minilop.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      6b01ecfe
  28. 20 5月, 2011 2 次提交
    • J
      receive-pack: eliminate duplicate .have refs · cff38a5e
      Jeff King 提交于
      When receiving a push, we advertise ref tips from any
      alternate repositories, in case that helps the client send a
      smaller pack. Since these refs don't actually exist in the
      destination repository, we don't transmit the real ref
      names, but instead use the pseudo-ref ".have".
      
      If your alternate has a large number of duplicate refs (for
      example, because it is aggregating objects from many related
      repositories, some of which will have the same tags and
      branch tips), then we will send each ".have $sha1" line
      multiple times. This is a pointless waste of bandwidth, as
      we are simply repeating the same fact to the client over and
      over.
      
      This patch eliminates duplicate .have refs early on. It does
      so efficiently by sorting the complete list and skipping
      duplicates. This has the side effect of re-ordering the
      .have lines by ascending sha1; this isn't a problem, though,
      as the original order was meaningless.
      
      There is a similar .have system in fetch-pack, but it
      does not suffer from the same problem. For each alternate
      ref we consider in fetch-pack, we actually open the object
      and mark it with the SEEN flag, so duplicates are
      automatically culled.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      cff38a5e
    • J
      refactor refs_from_alternate_cb to allow passing extra data · 114a6a88
      Jeff King 提交于
      The foreach_alt_odb function triggers a callback for each
      alternate object db we have, with room for a single void
      pointer as data. Currently, we always call refs_from_alternate_cb
      as the callback function, and then pass another callback (to
      receive each ref individually) as the void pointer.
      
      This has two problems:
      
        1. C technically forbids stuffing a function pointer into
           a "void *". In practice, this probably doesn't matter
           on any architectures git runs on, but it never hurts to
           follow the letter of the law.
      
        2. There is no room for an extra data pointer. Indeed, the
           alternate_ref_fn that refs_from_alternate_cb calls
           takes a void* for data, but we always pass it NULL.
      
      Instead, let's properly stuff our function pointer into a
      data struct, which also leaves room for an extra
      caller-supplied data pointer. And to keep things simple for
      existing callers, let's make a for_each_alternate_ref
      function that takes care of creating the extra struct.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      114a6a88