1. 17 11月, 2018 1 次提交
    • J
      bundle: dup() output descriptor closer to point-of-use · 2c8ee1f5
      Jeff King 提交于
      When writing a bundle to a file, the bundle code actually creates
      "your.bundle.lock" using our lockfile interface. We feed that output
      descriptor to a child git-pack-objects via run-command, which has the
      quirk that it closes the output descriptor in the parent.
      
      To avoid confusing the lockfile code (which still thinks the descriptor
      is valid), we dup() it, and operate on the duplicate.
      
      However, this has a confusing side effect: after the dup() but before we
      call pack-objects, we have _two_ descriptors open to the lockfile. If we
      call die() during that time, the lockfile code will try to clean up the
      partially-written file. It knows to close() the file before unlinking,
      since on some platforms (i.e., Windows) the open file would block the
      deletion. But it doesn't know about the duplicate descriptor. On
      Windows, triggering an error at the right part of the code will result
      in the cleanup failing and the lockfile being left in the filesystem.
      
      We can solve this by moving the dup() much closer to start_command(),
      shrinking the window in which we have the second descriptor open. It's
      easy to place this in such a way that no die() is possible. We could
      still die due to a signal in the exact wrong moment, but we already
      tolerate races there (e.g., a signal could come before we manage to put
      the file on the cleanup list in the first place).
      
      As a bonus, this shields create_bundle() itself from the duplicate-fd
      trick, and we can simplify its error handling (note that the lock
      rollback now happens unconditionally, but that's OK; it's a noop if we
      didn't open the lock in the first place).
      
      The included test uses an empty bundle to cause a failure at the right
      spot in the code, because that's easy to trigger (the other likely
      errors are write() problems like ENOSPC).  Note that it would already
      pass on non-Windows systems (because they are happy to unlink an
      already-open file).
      Based-on-a-patch-by: NGaël Lhez <gael.lhez@gmail.com>
      Signed-off-by: NJeff King <peff@peff.net>
      Tested-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      2c8ee1f5
  2. 22 9月, 2018 1 次提交
  3. 30 8月, 2018 1 次提交
    • J
      convert "oidcmp() != 0" to "!oideq()" · 9001dc2a
      Jeff King 提交于
      This is the flip side of the previous two patches: checking
      for a non-zero oidcmp() can be more strictly expressed as
      inequality. Like those patches, we write "!= 0" in the
      coccinelle transformation, which covers by isomorphism the
      more common:
      
        if (oidcmp(E1, E2))
      
      As with the previous two patches, this patch can be achieved
      almost entirely by running "make coccicheck"; the only
      differences are manual line-wrap fixes to match the original
      code.
      
      There is one thing to note for anybody replicating this,
      though: coccinelle 1.0.4 seems to miss the case in
      builtin/tag.c, even though it's basically the same as all
      the others. Running with 1.0.7 does catch this, so
      presumably it's just a coccinelle bug that was fixed in the
      interim.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      9001dc2a
  4. 30 6月, 2018 3 次提交
  5. 16 5月, 2018 1 次提交
    • S
      object-store: move object access functions to object-store.h · cbd53a21
      Stefan Beller 提交于
      This should make these functions easier to find and cache.h less
      overwhelming to read.
      
      In particular, this moves:
      - read_object_file
      - oid_object_info
      - write_object_file
      
      As a result, most of the codebase needs to #include object-store.h.
      In this patch the #include is only added to files that would fail to
      compile otherwise.  It would be better to #include wherever
      identifiers from the header are used.  That can happen later
      when we have better tooling for it.
      Signed-off-by: NStefan Beller <sbeller@google.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      cbd53a21
  6. 10 5月, 2018 1 次提交
    • M
      lock_file: make function-local locks non-static · b2275868
      Martin Ågren 提交于
      Placing `struct lock_file`s on the stack used to be a bad idea, because
      the temp- and lockfile-machinery would keep a pointer into the struct.
      But after 076aa2cb (tempfile: auto-allocate tempfiles on heap,
      2017-09-05), we can safely have lockfiles on the stack. (This applies
      even if a user returns early, leaving a locked lock behind.)
      
      These `struct lock_file`s are local to their respective functions and we
      can drop their staticness.
      
      For good measure, I have inspected these sites and come to believe that
      they always release the lock, with the possible exception of bailing out
      using `die()` or `exit()` or by returning from a `cmd_foo()`.
      
      As pointed out by Jeff King, it would be bad if someone held on to a
      `struct lock_file *` for some reason. After some grepping, I agree with
      his findings: no-one appears to be doing that.
      Signed-off-by: NMartin Ågren <martin.agren@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      b2275868
  7. 15 3月, 2018 1 次提交
    • B
      sha1_file: convert read_sha1_file to struct object_id · b4f5aca4
      brian m. carlson 提交于
      Convert read_sha1_file to take a pointer to struct object_id and rename
      it read_object_file.  Do the same for read_sha1_file_extended.
      
      Convert one use in grep.c to use the new function without any other code
      change, since the pointer being passed is a void pointer that is already
      initialized with a pointer to struct object_id.  Update the declaration
      and definitions of the modified functions, and apply the following
      semantic patch to convert the remaining callers:
      
      @@
      expression E1, E2, E3;
      @@
      - read_sha1_file(E1.hash, E2, E3)
      + read_object_file(&E1, E2, E3)
      
      @@
      expression E1, E2, E3;
      @@
      - read_sha1_file(E1->hash, E2, E3)
      + read_object_file(E1, E2, E3)
      
      @@
      expression E1, E2, E3, E4;
      @@
      - read_sha1_file_extended(E1.hash, E2, E3, E4)
      + read_object_file_extended(&E1, E2, E3, E4)
      
      @@
      expression E1, E2, E3, E4;
      @@
      - read_sha1_file_extended(E1->hash, E2, E3, E4)
      + read_object_file_extended(E1, E2, E3, E4)
      Signed-off-by: Nbrian m. carlson <sandals@crustytoothpaste.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      b4f5aca4
  8. 29 12月, 2017 1 次提交
    • R
      bundle: avoid using the rev_info flag leak_pending · 63647391
      René Scharfe 提交于
      The leak_pending flag is so awkward to use that multiple comments had to
      be added around each occurrence.  We use it for remembering the
      prerequisites for the bundle.  That is easy, though: We have the
      ref_list named "prerequisites" in the header for just that purpose.
      
      Use this original list of prerequisites to check if all of them are
      present and to clear their commit marks afterward.  The two new loops
      are intentionally kept similar to the first one in the function.
      Calling parse_object() a second time is expected be quick and successful
      in each case -- any errors should have been handled in the first round.
      Signed-off-by: NRene Scharfe <l.s.r@web.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      63647391
  9. 16 10月, 2017 2 次提交
  10. 24 9月, 2017 1 次提交
    • M
      leak_pending: use `object_array_clear()`, not `free()` · b2ccdf7f
      Martin Ågren 提交于
      Setting `leak_pending = 1` tells `prepare_revision_walk()` not to
      release the `pending` array, and makes that the caller's responsibility.
      See 4a43d374 (revision: add leak_pending flag, 2011-10-01) and
      353f5657 (bisect: use leak_pending flag, 2011-10-01).
      
      Commit 1da1e07c (clean up name allocation in prepare_revision_walk,
      2014-10-15) fixed a memory leak in `prepare_revision_walk()` by
      switching from `free()` to `object_array_clear()`. However, where we use
      the `leak_pending`-mechanism, we're still only calling `free()`.
      
      Use `object_array_clear()` instead. Copy some helpful comments from
      353f5657 to the other callers that we update to clarify the memory
      responsibilities, and to highlight that the commits are not affected
      when we clear the array -- it is indeed correct to both tidy up the
      commit flags and clear the object array.
      
      Document `leak_pending` in revision.h to help future users get this
      right.
      Signed-off-by: NMartin Ågren <martin.agren@gmail.com>
      Reviewed-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      b2ccdf7f
  11. 08 5月, 2017 2 次提交
    • B
      object: convert parse_object* to take struct object_id · c251c83d
      brian m. carlson 提交于
      Make parse_object, parse_object_or_die, and parse_object_buffer take a
      pointer to struct object_id.  Remove the temporary variables inserted
      earlier, since they are no longer necessary.  Transform all of the
      callers using the following semantic patch:
      
      @@
      expression E1;
      @@
      - parse_object(E1.hash)
      + parse_object(&E1)
      
      @@
      expression E1;
      @@
      - parse_object(E1->hash)
      + parse_object(E1)
      
      @@
      expression E1, E2;
      @@
      - parse_object_or_die(E1.hash, E2)
      + parse_object_or_die(&E1, E2)
      
      @@
      expression E1, E2;
      @@
      - parse_object_or_die(E1->hash, E2)
      + parse_object_or_die(E1, E2)
      
      @@
      expression E1, E2, E3, E4, E5;
      @@
      - parse_object_buffer(E1.hash, E2, E3, E4, E5)
      + parse_object_buffer(&E1, E2, E3, E4, E5)
      
      @@
      expression E1, E2, E3, E4, E5;
      @@
      - parse_object_buffer(E1->hash, E2, E3, E4, E5)
      + parse_object_buffer(E1, E2, E3, E4, E5)
      Signed-off-by: Nbrian m. carlson <sandals@crustytoothpaste.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      c251c83d
    • B
      Convert lookup_commit* to struct object_id · bc83266a
      brian m. carlson 提交于
      Convert lookup_commit, lookup_commit_or_die,
      lookup_commit_reference, and lookup_commit_reference_gently to take
      struct object_id arguments.
      
      Introduce a temporary in parse_object buffer in order to convert this
      function.  This is required since in order to convert parse_object and
      parse_object_buffer, lookup_commit_reference_gently and
      lookup_commit_or_die would need to be converted.  Not introducing a
      temporary would therefore require that lookup_commit_or_die take a
      struct object_id *, but lookup_commit would take unsigned char *,
      leaving a confusing and hard-to-use interface.
      
      parse_object_buffer will lose this temporary in a later patch.
      
      This commit was created with manual changes to commit.c, commit.h, and
      object.c, plus the following semantic patch:
      
      @@
      expression E1, E2;
      @@
      - lookup_commit_reference_gently(E1.hash, E2)
      + lookup_commit_reference_gently(&E1, E2)
      
      @@
      expression E1, E2;
      @@
      - lookup_commit_reference_gently(E1->hash, E2)
      + lookup_commit_reference_gently(E1, E2)
      
      @@
      expression E1;
      @@
      - lookup_commit_reference(E1.hash)
      + lookup_commit_reference(&E1)
      
      @@
      expression E1;
      @@
      - lookup_commit_reference(E1->hash)
      + lookup_commit_reference(E1)
      
      @@
      expression E1;
      @@
      - lookup_commit(E1.hash)
      + lookup_commit(&E1)
      
      @@
      expression E1;
      @@
      - lookup_commit(E1->hash)
      + lookup_commit(E1)
      
      @@
      expression E1, E2;
      @@
      - lookup_commit_or_die(E1.hash, E2)
      + lookup_commit_or_die(&E1, E2)
      
      @@
      expression E1, E2;
      @@
      - lookup_commit_or_die(E1->hash, E2)
      + lookup_commit_or_die(E1, E2)
      Signed-off-by: Nbrian m. carlson <sandals@crustytoothpaste.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      bc83266a
  12. 02 5月, 2017 1 次提交
  13. 27 4月, 2017 1 次提交
    • J
      timestamp_t: a new data type for timestamps · dddbad72
      Johannes Schindelin 提交于
      Git's source code assumes that unsigned long is at least as precise as
      time_t. Which is incorrect, and causes a lot of problems, in particular
      where unsigned long is only 32-bit (notably on Windows, even in 64-bit
      versions).
      
      So let's just use a more appropriate data type instead. In preparation
      for this, we introduce the new `timestamp_t` data type.
      
      By necessity, this is a very, very large patch, as it has to replace all
      timestamps' data type in one go.
      
      As we will use a data type that is not necessarily identical to `time_t`,
      we need to be very careful to use `time_t` whenever we interact with the
      system functions, and `timestamp_t` everywhere else.
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      dddbad72
  14. 24 4月, 2017 1 次提交
  15. 02 4月, 2016 1 次提交
  16. 20 11月, 2015 3 次提交
  17. 11 8月, 2015 1 次提交
    • M
      create_bundle(): duplicate file descriptor to avoid closing it twice · e54c347c
      Michael Haggerty 提交于
      write_pack_data() passes bundle_fd to start_command() to be used as
      the stdout of pack-objects. But start_command() closes its stdout if
      it is > 1. This is a problem if bundle_fd is the fd of a lock_file,
      because commit_lock_file() will also try to close the fd.
      
      So the old code suppressed commit_lock_file()'s usual behavior of
      closing the file descriptor by setting the lock_file object's fd field
      to -1.
      
      But this is not really kosher. Code here shouldn't be mutating fields
      within the lock_file object.
      
      Instead, duplicate the file descriptor before passing it to
      write_pack_data(). Then that function can close its copy without
      closing the copy held in the lock_file object.
      Signed-off-by: NMichael Haggerty <mhagger@alum.mit.edu>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      e54c347c
  18. 11 3月, 2015 1 次提交
  19. 31 10月, 2014 3 次提交
    • J
      bundle: split out ref writing from bundle_create · d9362ef9
      Jeff King 提交于
      The bundle_create() function has a number of logical steps:
      process the input, write the refs, and write the packfile.
      Recent commits split the first and third into separate
      sub-functions. It's worth splitting the middle step out,
      too, if only because it makes the progression of the steps
      more obvious.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      d9362ef9
    • J
      bundle: split out a helper function to compute and write prerequisites · e8eb2512
      Junio C Hamano 提交于
      The new helper compute_and_write_prerequistes() is ugly, but it
      cannot be avoided.  Ideally we should avoid a function that computes
      and does I/O at the same time, but the prerequisites lines in the
      output needs the human readable title only to help the recipient of
      the bundle.  The code copies them straight from the rev-list output
      and immediately discards as no other internal computation needs that
      information.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      e8eb2512
    • J
      bundle: split out a helper function to create pack data · 5e626b91
      Junio C Hamano 提交于
      The create_bundle() function, while it does one single logical
      thing, takes a rather large implementation to do so.
      
      Let's start separating what it does into smaller steps to make it
      easier to see what is going on.  This is a first step to separate
      out the actual pack-data generation, after the earlier part of the
      function figures out which part of the history to place in the
      bundle.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      5e626b91
  20. 29 10月, 2014 1 次提交
  21. 16 10月, 2014 1 次提交
  22. 08 10月, 2014 1 次提交
  23. 02 10月, 2014 1 次提交
  24. 21 8月, 2014 1 次提交
  25. 08 8月, 2014 1 次提交
  26. 19 7月, 2014 1 次提交
  27. 26 3月, 2014 1 次提交
  28. 07 3月, 2014 1 次提交
  29. 04 3月, 2014 1 次提交
  30. 13 11月, 2013 1 次提交
  31. 03 6月, 2013 1 次提交
    • M
      object_array_entry: fix memory handling of the name field · 31faeb20
      Michael Haggerty 提交于
      Previously, the memory management of the object_array_entry::name
      field was inconsistent and undocumented.  object_array_entries are
      ultimately created by a single function, add_object_array_with_mode(),
      which has an argument "const char *name".  This function used to
      simply set the name field to reference the string pointed to by the
      name parameter, and nobody on the object_array side ever freed the
      memory.  Thus, it assumed that the memory for the name field would be
      managed by the caller, and that the lifetime of that string would be
      at least as long as the lifetime of the object_array_entry.  But
      callers were inconsistent:
      
      * Some passed pointers to constant strings or argv entries, which was
        OK.
      
      * Some passed pointers to newly-allocated memory, but didn't arrange
        for the memory ever to be freed.
      
      * Some passed the return value of sha1_to_hex(), which is a pointer to
        a statically-allocated buffer that can be overwritten at any time.
      
      * Some passed pointers to refnames that they received from a
        for_each_ref()-type iteration, but the lifetimes of such refnames is
        not guaranteed by the refs API.
      
      Bring consistency to this mess by changing object_array to make its
      own copy for the object_array_entry::name field and free this memory
      when an object_array_entry is deleted from the array.
      
      Many callers were passing the empty string as the name parameter, so
      as a performance optimization, treat the empty string specially.
      Instead of making a copy, store a pointer to a statically-allocated
      empty string to object_array_entry::name.  When deleting such an
      entry, skip the free().
      
      Change the callers that were already passing copies to
      add_object_array_with_mode() to either skip the copy, or (if the
      memory needed to be allocated anyway) freeing the memory itself.
      
      A part of this commit effectively reverts
      
          70d26c6e read_revisions_from_stdin: make copies for handle_revision_arg
      
      because the copying introduced by that commit (which is still
      necessary) is now done at a deeper level.
      Signed-off-by: NMichael Haggerty <mhagger@alum.mit.edu>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      31faeb20
  32. 08 4月, 2013 1 次提交
    • L
      bundle: Accept prerequisites without commit messages · 5446e33f
      Lukas Fleischer 提交于
      While explicitly stating that the commit message in a prerequisite
      line is optional, we required all lines with 40 or more characters
      to contain a space after the object name, bailing out if a line
      consisted of an object name only. This was to allow bundling a
      history to a commit without an message, but the code forgot that it
      already called rtrim() to remove that whitespace.
      
      As a workaround, only check for SP when the line has more than 40
      characters.
      Signed-off-by: NLukas Fleischer <git@cryptocrack.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      5446e33f