This project is mirrored from https://github.com/git/git. Updated .
  1. 13 Jun, 2014 2 commits
    • Jeff King's avatar
      commit: record buffer length in cache · 8597ea3a
      Jeff King authored
      Most callsites which use the commit buffer try to use the
      cached version attached to the commit, rather than
      re-reading from disk. Unfortunately, that interface provides
      only a pointer to the NUL-terminated buffer, with no
      indication of the original length.
      
      For the most part, this doesn't matter. People do not put
      NULs in their commit messages, and the log code is happy to
      treat it all as a NUL-terminated string. However, some code
      paths do care. For example, when checking signatures, we
      want to be very careful that we verify all the bytes to
      avoid malicious trickery.
      
      This patch just adds an optional "size" out-pointer to
      get_commit_buffer and friends. The existing callers all pass
      NULL (there did not seem to be any obvious sites where we
      could avoid an immediate strlen() call, though perhaps with
      some further refactoring we could).
      Signed-off-by: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      8597ea3a
    • Jeff King's avatar
      use get_commit_buffer everywhere · bc6b8fc1
      Jeff King authored
      Each of these sites assumes that commit->buffer is valid.
      Since they would segfault if this was not the case, they are
      likely to be correct in practice. However, we can
      future-proof them by using get_commit_buffer.
      
      And as a side effect, we abstract away the final bare uses
      of commit->buffer.
      Signed-off-by: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      bc6b8fc1
  2. 12 Jun, 2014 2 commits
    • Jeff King's avatar
      replace dangerous uses of strbuf_attach · e6dfcd67
      Jeff King authored
      It is not a good idea to strbuf_attach an arbitrary pointer
      just because a function you are calling wants a strbuf.
      Attaching implies a transfer of memory ownership; if anyone
      were to modify or release the resulting strbuf, we would
      free() the pointer, leading to possible problems:
      
        1. Other users of the original pointer might access freed
           memory.
      
        2. The pointer might not be the start of a malloc'd
           area, so calling free() on it in the first place would
           be wrong.
      
      In the two cases modified here, we are fortunate that nobody
      touches the strbuf once it is attached, but it is an
      accident waiting to happen.  Since the previous commit,
      commit_tree and friends take a pointer/buf pair, so we can
      just do away with the strbufs entirely.
      Signed-off-by: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      e6dfcd67
    • Jeff King's avatar
      commit_tree: take a pointer/len pair rather than a const strbuf · 3ffefb54
      Jeff King authored
      While strbufs are pretty common throughout our code, it is
      more flexible for functions to take a pointer/len pair than
      a strbuf. It's easy to turn a strbuf into such a pair (by
      dereferencing its members), but less easy to go the other
      way (you can strbuf_attach, but that has implications about
      memory ownership).
      
      This patch teaches commit_tree (and its associated callers
      and sub-functions) to take such a pair for the commit
      message rather than a strbuf.  This makes passing the buffer
      around slightly more verbose, but means we can get rid of
      some dangerous strbuf_attach calls in the next patch.
      Signed-off-by: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      3ffefb54
  3. 15 Jul, 2013 1 commit
  4. 12 Jun, 2013 1 commit
  5. 03 Aug, 2012 1 commit
    • Thomas Rast's avatar
      diff_setup_done(): return void · 28452655
      Thomas Rast authored
      diff_setup_done() has historically returned an error code, but lost
      the last nonzero return in 943d5b73 (allow diff.renamelimit to be set
      regardless of -M/-C, 2006-08-09).  The callers were in a pretty
      confused state: some actually checked for the return code, and some
      did not.
      
      Let it return void, and patch all callers to take this into account.
      This conveniently also gets rid of a handful of different(!) error
      messages that could never be triggered anyway.
      
      Note that the function can still die().
      Signed-off-by: default avatarThomas Rast <trast@student.ethz.ch>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      28452655
  6. 07 Jun, 2012 1 commit
  7. 15 Mar, 2012 2 commits
    • Johan Herland's avatar
      notes-merge: Don't remove .git/NOTES_MERGE_WORKTREE; it may be the user's cwd · dabba590
      Johan Herland authored
      When a manual notes merge is committed or aborted, we need to remove the
      temporary worktree at .git/NOTES_MERGE_WORKTREE. However, removing the
      entire directory is not good if the user ran the 'git notes merge
      --commit/--abort' from within that directory. On Windows, the directory
      removal would simply fail, while on POSIX systems, users would suddenly
      find themselves in an invalid current directory.
      
      Therefore, instead of deleting the entire directory, we delete everything
      _within_ the directory, and leave the (empty) directory in place.
      
      This would cause a subsequent notes merge to abort, complaining about a
      previous - unfinished - notes merge (due to the presence of
      .git/NOTES_MERGE_WORKTREE), so we also need to adjust this check to only
      trigger when .git/NOTES_MERGE_WORKTREE is non-empty.
      
      Finally, adjust the t3310 manual notes merge testcases to correctly handle
      the existence of an empty .git/NOTES_MERGE_WORKTREE directory.
      Inspired-by: default avatarJunio C Hamano <gitster@pobox.com>
      Signed-off-by: default avatarJohan Herland <johan@herland.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      dabba590
    • Johan Herland's avatar
      notes-merge: use opendir/readdir instead of using read_directory() · a0be62c1
      Johan Herland authored
      notes_merge_commit() only needs to list all entries (non-recursively)
      under a directory, which can be easily accomplished with
      opendir/readdir and would be more lightweight than read_directory().
      
      read_directory() is designed to list paths inside a working
      directory. Using it outside of its scope may lead to undesired effects.
      
      Apparently, one of the undesired effects of read_directory() is that it
      doesn't deal with being given absolute paths. This creates problems for
      notes_merge_commit() when git_path() returns an absolute path, which
      happens when the current working directory is in a subdirectory of the
      .git directory.
      Originally-by: Duy Nguyen's avatarNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Updated-by: default avatarJohan Herland <johan@herland.net>
      Signed-off-by: default avatarJohan Herland <johan@herland.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      a0be62c1
  8. 15 Dec, 2011 1 commit
  9. 18 Nov, 2011 1 commit
  10. 13 Nov, 2011 2 commits
    • Duy Nguyen's avatar
      Convert many resolve_ref() calls to read_ref*() and ref_exists() · c6893323
      Duy Nguyen authored
      resolve_ref() may return a pointer to a static buffer, which is not
      safe for long-term use because if another resolve_ref() call happens,
      the buffer may be changed.  Many call sites though do not care about
      this buffer. They simply check if the return value is NULL or not.
      
      Convert all these call sites to new wrappers to reduce resolve_ref()
      calls from 57 to 34. If we change resolve_ref() prototype later on
      to avoid passing static buffer out, this helps reduce changes.
      Signed-off-by: Duy Nguyen's avatarNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      c6893323
    • Junio C Hamano's avatar
      commit: teach --gpg-sign option · ba3c69a9
      Junio C Hamano authored
      This uses the gpg-interface.[ch] to allow signing the commit, i.e.
      
          $ git commit --gpg-sign -m foo
          You need a passphrase to unlock the secret key for
          user: "Junio C Hamano <gitster@pobox.com>"
          4096-bit RSA key, ID 96AFE6CB, created 2011-10-03 (main key ID 713660A7)
      
          [master 8457d13] foo
           1 files changed, 1 insertions(+), 0 deletions(-)
      
      The lines of GPG detached signature are placed in a new multi-line header
      field, instead of tucking the signature block at the end of the commit log
      message text (similar to how signed tag is done), for multiple reasons:
      
       - The signature won't clutter output from "git log" and friends if it is
         in the extra header. If we place it at the end of the log message, we
         would need to teach "git log" and friends to strip the signature block
         with an option.
      
       - Teaching new versions of "git log" and "gitk" to optionally verify and
         show signatures is cleaner if we structurally know where the signature
         block is (instead of scanning in the commit log message).
      
       - The signature needs to be stripped upon various commit rewriting
         operations, e.g. rebase, filter-branch, etc. They all already ignore
         unknown headers, but if we place signature in the log message, all of
         these tools (and third-party tools) also need to learn how a signature
         block would look like.
      
       - When we added the optional encoding header, all the tools (both in tree
         and third-party) that acts on the raw commit object should have been
         fixed to ignore headers they do not understand, so it is not like that
         new header would be more likely to break than extra text in the commit.
      
      A commit made with the above sample sequence would look like this:
      
          $ git cat-file commit HEAD
          tree 3cd71d90e3db4136e5260ab54599791c4f883b9d
          parent b87755351a47b09cb27d6913e6e0e17e6254a4d4
          author Junio C Hamano <gitster@pobox.com> 1317862251 -0700
          committer Junio C Hamano <gitster@pobox.com> 1317862251 -0700
          gpgsig -----BEGIN PGP SIGNATURE-----
           Version: GnuPG v1.4.10 (GNU/Linux)
      
           iQIcBAABAgAGBQJOjPtrAAoJELC16IaWr+bL4TMP/RSe2Y/jYnCkds9unO5JEnfG
           ...
           =dt98
           -----END PGP SIGNATURE-----
      
          foo
      
      but "git log" (unless you ask for it with --pretty=raw) output is not
      cluttered with the signature information.
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      ba3c69a9
  11. 05 Oct, 2011 1 commit
    • Michael Haggerty's avatar
      Change check_ref_format() to take a flags argument · 8d9c5010
      Michael Haggerty authored
      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: default avatarMichael Haggerty <mhagger@alum.mit.edu>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      8d9c5010
  12. 27 Sep, 2011 1 commit
  13. 09 May, 2011 1 commit
  14. 22 Mar, 2011 1 commit
    • Stephen Boyd's avatar
      Fix sparse warnings · c2e86add
      Stephen Boyd authored
      Fix warnings from 'make check'.
      
       - These files don't include 'builtin.h' causing sparse to complain that
         cmd_* isn't declared:
      
         builtin/clone.c:364, builtin/fetch-pack.c:797,
         builtin/fmt-merge-msg.c:34, builtin/hash-object.c:78,
         builtin/merge-index.c:69, builtin/merge-recursive.c:22
         builtin/merge-tree.c:341, builtin/mktag.c:156, builtin/notes.c:426
         builtin/notes.c:822, builtin/pack-redundant.c:596,
         builtin/pack-refs.c:10, builtin/patch-id.c:60, builtin/patch-id.c:149,
         builtin/remote.c:1512, builtin/remote-ext.c:240,
         builtin/remote-fd.c:53, builtin/reset.c:236, builtin/send-pack.c:384,
         builtin/unpack-file.c:25, builtin/var.c:75
      
       - These files have symbols which should be marked static since they're
         only file scope:
      
         submodule.c:12, diff.c:631, replace_object.c:92, submodule.c:13,
         submodule.c:14, trace.c:78, transport.c:195, transport-helper.c:79,
         unpack-trees.c:19, url.c:3, url.c:18, url.c:104, url.c:117, url.c:123,
         url.c:129, url.c:136, thread-utils.c:21, thread-utils.c:48
      
       - These files redeclare symbols to be different types:
      
         builtin/index-pack.c:210, parse-options.c:564, parse-options.c:571,
         usage.c:49, usage.c:58, usage.c:63, usage.c:72
      
       - These files use a literal integer 0 when they really should use a NULL
         pointer:
      
         daemon.c:663, fast-import.c:2942, imap-send.c:1072, notes-merge.c:362
      
      While we're in the area, clean up some unused #includes in builtin files
      (mostly exec_cmd.h).
      Signed-off-by: default avatarStephen Boyd <bebarino@gmail.com>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      c2e86add
  15. 14 Feb, 2011 1 commit
    • Jonathan Nieder's avatar
      correct type of EMPTY_TREE_SHA1_BIN · dab0d410
      Jonathan Nieder authored
      Functions such as hashcmp that expect a binary SHA-1 value take
      parameters of type "unsigned char *" to avoid accepting a textual
      SHA-1 passed by mistake.  Unfortunately, this means passing the string
      literal EMPTY_TREE_SHA1_BIN requires an ugly cast.  Tweak the
      definition of EMPTY_TREE_SHA1_BIN to produce a value of more
      convenient type.
      
      In the future the definition might change to
      
      	extern const unsigned char empty_tree_sha1_bin[20];
      	#define EMPTY_TREE_SHA1_BIN empty_tree_sha1_bin
      Signed-off-by: default avatarJonathan Nieder <jrnieder@gmail.com>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      dab0d410
  16. 17 Nov, 2010 8 commits
    • Johan Herland's avatar
      git notes merge: Add another auto-resolving strategy: "cat_sort_uniq" · a6a09095
      Johan Herland authored
      This new strategy is similar to "concatenate", but in addition to
      concatenating the two note candidates, this strategy sorts the resulting
      lines, and removes duplicate lines from the result. This is equivalent to
      applying the "cat | sort | uniq" shell pipeline to the two note candidates.
      
      This strategy is useful if the notes follow a line-based format where one
      wants to avoid duplicate lines in the merge result.
      
      Note that if either of the note candidates contain duplicate lines _prior_
      to the merge, these will also be removed by this merge strategy.
      
      The patch also contains tests and documentation for the new strategy.
      Signed-off-by: default avatarJohan Herland <johan@herland.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      a6a09095
    • Johan Herland's avatar
      git notes merge: List conflicting notes in notes merge commit message · 443259cf
      Johan Herland authored
      This brings notes merge in line with regular merge's behaviour.
      
      This patch has been improved by the following contributions:
      - Ævar Arnfjörð Bjarmason: Don't use C99 comments.
      
      Thanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
      Signed-off-by: default avatarJohan Herland <johan@herland.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      443259cf
    • Johan Herland's avatar
      git notes merge: Manual conflict resolution, part 2/2 · 6abb3655
      Johan Herland authored
      When the notes merge conflicts in .git/NOTES_MERGE_WORKTREE have been
      resolved, we need to record a new notes commit on the appropriate notes
      ref with the resolved notes.
      
      This patch implements 'git notes merge --commit' which the user should
      run after resolving conflicts in the notes merge worktree. This command
      finalizes the notes merge by recombining the partial notes tree from
      part 1 with the now-resolved conflicts in the notes merge worktree in a
      merge commit, and updating the appropriate ref to this merge commit.
      
      In order to correctly finalize the merge, we need to keep track of three
      things:
      
      - The partial merge result from part 1, containing the auto-merged notes.
        This is now stored into a ref called .git/NOTES_MERGE_PARTIAL.
      - The unmerged notes. These are already stored in
        .git/NOTES_MERGE_WORKTREE, thanks to part 1.
      - The notes ref to be updated by the finalized merge result. This is now
        stored in a symref called .git/NOTES_MERGE_REF.
      
      In addition to "git notes merge --commit", which uses the above details
      to create the finalized notes merge commit, this patch also implements
      "git notes merge --reset", which aborts the ongoing notes merge by simply
      removing the files/directory described above.
      
      FTR, "git notes merge --commit" reuses "git notes merge --reset" to remove
      the information described above (.git/NOTES_MERGE_*) after the notes merge
      have been successfully finalized.
      
      The patch also contains documentation and testcases for the two new options.
      
      This patch has been improved by the following contributions:
      - Ævar Arnfjörð Bjarmason: Fix nonsense sentence in --commit description
      - Sverre Rabbelier: Rename --reset to --abort
      
      Thanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
      Thanks-to: Sverre Rabbelier <srabbelier@gmail.com>
      Signed-off-by: default avatarJohan Herland <johan@herland.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      6abb3655
    • Johan Herland's avatar
      git notes merge: Manual conflict resolution, part 1/2 · 809f38c8
      Johan Herland authored
      Conflicts (that are to be resolved manually) are written into a special-
      purpose working tree, located at .git/NOTES_MERGE_WORKTREE. Within this
      directory, conflicting notes entries are stored (with conflict markers
      produced by ll_merge()) using the SHA1 of the annotated object. The
      .git/NOTES_MERGE_WORKTREE directory will only contain the _conflicting_
      note entries. The non-conflicting note entries (aka. the partial merge
      result) are stored in 'local_tree', and the SHA1 of the resulting commit
      is written to 'result_sha1'. The return value from notes_merge() is -1.
      
      The user is told to edit the files within the .git/NOTES_MERGE_WORKTREE
      directory in order to resolve the conflicts.
      
      The patch also contains documentation and testcases for the correct setup
      of .git/NOTES_MERGE_WORKTREE.
      
      The next part will recombine the partial notes merge result with the
      resolved conflicts in .git/NOTES_MERGE_WORKTREE to produce the complete
      merge result.
      
      This patch has been improved by the following contributions:
      - Jonathan Nieder: Use trace_printf(...) instead of OUTPUT(o, 5, ...)
      
      Thanks-to: Jonathan Nieder <jrnieder@gmail.com>
      Signed-off-by: default avatarJohan Herland <johan@herland.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      809f38c8
    • Johan Herland's avatar
      git notes merge: Add automatic conflict resolvers (ours, theirs, union) · 3228e671
      Johan Herland authored
      The new -s/--strategy command-line option to 'git notes merge' allow the user
      to choose how notes merge conflicts should be resolved. There are four valid
      strategies to choose from:
      
      1. "manual" (the default): This will let the user manually resolve conflicts.
         This option currently fails with an error message. It will be implemented
         properly in future patches.
      
      2. "ours": This automatically chooses the local version of a conflict, and
         discards the remote version.
      
      3. "theirs": This automatically chooses the remote version of a conflict, and
         discards the local version.
      
      4. "union": This automatically resolves the conflict by appending the remote
         version to the local version.
      
      The strategies are implemented using the combine_notes_* functions from the
      notes.h API.
      
      The patch also includes testcases verifying the correct implementation of
      these strategies.
      
      This patch has been improved by the following contributions:
      - Jonathan Nieder: Future-proof by always checking add_note() return value
      - Stephen Boyd: Use test_commit
      - Stephen Boyd: Use correct option name
      
      Thanks-to: Jonathan Nieder <jrnieder@gmail.com>
      Thanks-to: Stephen Boyd <bebarino@gmail.com>
      Signed-off-by: default avatarJohan Herland <johan@herland.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      3228e671
    • Johan Herland's avatar
      git notes merge: Handle real, non-conflicting notes merges · 2085b16a
      Johan Herland authored
      This continuation of the 'git notes merge' implementation teaches notes-merge
      to properly do real merges between notes trees: Two diffs are performed, one
      from $base to $remote, and another from $base to $local. The paths in each
      diff are normalized to SHA1 object names. The two diffs are then consolidated
      into a single list of change pairs to be evaluated. Each change pair consist
      of:
      
        - The annotated object's SHA1
        - The $base SHA1 (i.e. the common ancestor notes for this object)
        - The $local SHA1 (i.e. the current notes for this object)
        - The $remote SHA1 (i.e. the to-be-merged notes for this object)
      
      From the pair ($base -> $local, $base -> $remote), we can determine the merge
      result using regular 3-way rules. If conflicts are encountered in this
      process, we fail loudly and exit (conflict handling to be added in a future
      patch), If we can complete the merge without conflicts, the resulting
      notes tree is committed, and the current notes ref updated.
      
      The patch includes added testcases verifying that we can successfully do real
      conflict-less merges.
      
      This patch has been improved by the following contributions:
      - Jonathan Nieder: Future-proof by always checking add_note() return value
      - Stephen Boyd: Use test_commit
      - Jonathan Nieder: Use trace_printf(...) instead of OUTPUT(o, 5, ...)
      - Junio C Hamano: fixup minor style issues
      
      Thanks-to: Jonathan Nieder <jrnieder@gmail.com>
      Thanks-to: Stephen Boyd <bebarino@gmail.com>
      Thanks-to: Junio C Hamano <gitster@pobox.com>
      Signed-off-by: default avatarJohan Herland <johan@herland.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      2085b16a
    • Johan Herland's avatar
      builtin/notes.c: Refactor creation of notes commits. · 56881843
      Johan Herland authored
      Create new function create_notes_commit() which is slightly more general than
      commit_notes() (accepts multiple commit parents and does not auto-update the
      notes ref). This function will be used by the notes-merge functionality in
      future patches.
      
      Also rewrite builtin/notes.c:commit_notes() to reuse this new function.
      Signed-off-by: default avatarJohan Herland <johan@herland.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      56881843
    • Johan Herland's avatar
      git notes merge: Initial implementation handling trivial merges only · 75ef3f4a
      Johan Herland authored
      This initial implementation of 'git notes merge' only handles the trivial
      merge cases (i.e. where the merge is either a no-op, or a fast-forward).
      
      The patch includes testcases for these trivial merge cases.
      
      Future patches will extend the functionality of 'git notes merge'.
      
      This patch has been improved by the following contributions:
      - Stephen Boyd: Simplify argc logic
      - Stephen Boyd: Use test_commit
      - Ævar Arnfjörð Bjarmason: Don't use C99 comments.
      - Jonathan Nieder: Add constants for common verbosity values
      - Jonathan Nieder: Use trace_printf(...) instead of OUTPUT(o, 5, ...)
      - Jonathan Nieder: Remove extraneous show() function
      - Jonathan Nieder: Clarify handling of empty/missing notes ref in notes_merge()
      - Junio C Hamano: fixup minor style issues
      
      Thanks-to: Stephen Boyd <bebarino@gmail.com>
      Thanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
      Thanks-to: Jonathan Nieder <jrnieder@gmail.com>
      Thanks-to: Junio C Hamano <gitster@pobox.com>
      Signed-off-by: default avatarJohan Herland <johan@herland.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      75ef3f4a