1. 14 Mar, 2018 2 commits
    • brian m. carlson's avatar
      sha1_file: convert read_sha1_file to struct object_id · b4f5aca4
      brian m. carlson authored
      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: brian m. carlson's avatarbrian m. carlson <sandals@crustytoothpaste.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      b4f5aca4
    • brian m. carlson's avatar
      Convert find_unique_abbrev* to struct object_id · aab9583f
      brian m. carlson authored
      Convert find_unique_abbrev and find_unique_abbrev_r to each take a
      pointer to struct object_id.
      Signed-off-by: brian m. carlson's avatarbrian m. carlson <sandals@crustytoothpaste.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      aab9583f
  2. 22 Feb, 2018 1 commit
  3. 16 Jan, 2018 1 commit
    • Torsten Bögershausen's avatar
      convert_to_git(): safe_crlf/checksafe becomes int conv_flags · 8462ff43
      Torsten Bögershausen authored
      When calling convert_to_git(), the checksafe parameter defined what
      should happen if the EOL conversion (CRLF --> LF --> CRLF) does not
      roundtrip cleanly. In addition, it also defined if line endings should
      be renormalized (CRLF --> LF) or kept as they are.
      
      checksafe was an safe_crlf enum with these values:
      SAFE_CRLF_FALSE:       do nothing in case of EOL roundtrip errors
      SAFE_CRLF_FAIL:        die in case of EOL roundtrip errors
      SAFE_CRLF_WARN:        print a warning in case of EOL roundtrip errors
      SAFE_CRLF_RENORMALIZE: change CRLF to LF
      SAFE_CRLF_KEEP_CRLF:   keep all line endings as they are
      
      In some cases the integer value 0 was passed as checksafe parameter
      instead of the correct enum value SAFE_CRLF_FALSE. That was no problem
      because SAFE_CRLF_FALSE is defined as 0.
      
      FALSE/FAIL/WARN are different from RENORMALIZE and KEEP_CRLF. Therefore,
      an enum is not ideal. Let's use a integer bit pattern instead and rename
      the parameter to conv_flags to make it more generically usable. This
      allows us to extend the bit pattern in a subsequent commit.
      Reported-By: default avatarRandall S. Becker <rsbecker@nexbridge.com>
      Helped-By: default avatarLars Schneider <larsxschneider@gmail.com>
      Signed-off-by: default avatarTorsten Bögershausen <tboegi@web.de>
      Signed-off-by: default avatarLars Schneider <larsxschneider@gmail.com>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      8462ff43
  4. 04 Jan, 2018 1 commit
    • Stefan Beller's avatar
      diff: introduce DIFF_PICKAXE_KINDS_MASK · cf63051a
      Stefan Beller authored
      Currently the check whether to perform pickaxing is done via checking
      `diffopt->pickaxe`, which contains the command line argument that we
      want to pickaxe for. Soon we'll introduce a new type of pickaxing, that
      will not store anything in the `.pickaxe` field, so let's migrate the
      check to be dependent on pickaxe_opts.
      
      It is not enough to just replace the check for pickaxe by pickaxe_opts,
      because flags might be set, but pickaxing was not requested ('-i').
      To cope with that, introduce a mask to check only for the bits indicating
      the modes of operation.
      Signed-off-by: Stefan Beller's avatarStefan Beller <sbeller@google.com>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      cf63051a
  5. 01 Nov, 2017 4 commits
    • Brandon Williams's avatar
      diff: make struct diff_flags members lowercase · 0d1e0e78
      Brandon Williams authored
      Now that the flags stored in struct diff_flags are being accessed
      directly and not through macros, change all struct members from being
      uppercase to lowercase.
      This conversion is done using the following semantic patch:
      
      	@@
      	expression E;
      	@@
      	- E.RECURSIVE
      	+ E.recursive
      
      	@@
      	expression E;
      	@@
      	- E.TREE_IN_RECURSIVE
      	+ E.tree_in_recursive
      
      	@@
      	expression E;
      	@@
      	- E.BINARY
      	+ E.binary
      
      	@@
      	expression E;
      	@@
      	- E.TEXT
      	+ E.text
      
      	@@
      	expression E;
      	@@
      	- E.FULL_INDEX
      	+ E.full_index
      
      	@@
      	expression E;
      	@@
      	- E.SILENT_ON_REMOVE
      	+ E.silent_on_remove
      
      	@@
      	expression E;
      	@@
      	- E.FIND_COPIES_HARDER
      	+ E.find_copies_harder
      
      	@@
      	expression E;
      	@@
      	- E.FOLLOW_RENAMES
      	+ E.follow_renames
      
      	@@
      	expression E;
      	@@
      	- E.RENAME_EMPTY
      	+ E.rename_empty
      
      	@@
      	expression E;
      	@@
      	- E.HAS_CHANGES
      	+ E.has_changes
      
      	@@
      	expression E;
      	@@
      	- E.QUICK
      	+ E.quick
      
      	@@
      	expression E;
      	@@
      	- E.NO_INDEX
      	+ E.no_index
      
      	@@
      	expression E;
      	@@
      	- E.ALLOW_EXTERNAL
      	+ E.allow_external
      
      	@@
      	expression E;
      	@@
      	- E.EXIT_WITH_STATUS
      	+ E.exit_with_status
      
      	@@
      	expression E;
      	@@
      	- E.REVERSE_DIFF
      	+ E.reverse_diff
      
      	@@
      	expression E;
      	@@
      	- E.CHECK_FAILED
      	+ E.check_failed
      
      	@@
      	expression E;
      	@@
      	- E.RELATIVE_NAME
      	+ E.relative_name
      
      	@@
      	expression E;
      	@@
      	- E.IGNORE_SUBMODULES
      	+ E.ignore_submodules
      
      	@@
      	expression E;
      	@@
      	- E.DIRSTAT_CUMULATIVE
      	+ E.dirstat_cumulative
      
      	@@
      	expression E;
      	@@
      	- E.DIRSTAT_BY_FILE
      	+ E.dirstat_by_file
      
      	@@
      	expression E;
      	@@
      	- E.ALLOW_TEXTCONV
      	+ E.allow_textconv
      
      	@@
      	expression E;
      	@@
      	- E.TEXTCONV_SET_VIA_CMDLINE
      	+ E.textconv_set_via_cmdline
      
      	@@
      	expression E;
      	@@
      	- E.DIFF_FROM_CONTENTS
      	+ E.diff_from_contents
      
      	@@
      	expression E;
      	@@
      	- E.DIRTY_SUBMODULES
      	+ E.dirty_submodules
      
      	@@
      	expression E;
      	@@
      	- E.IGNORE_UNTRACKED_IN_SUBMODULES
      	+ E.ignore_untracked_in_submodules
      
      	@@
      	expression E;
      	@@
      	- E.IGNORE_DIRTY_SUBMODULES
      	+ E.ignore_dirty_submodules
      
      	@@
      	expression E;
      	@@
      	- E.OVERRIDE_SUBMODULE_CONFIG
      	+ E.override_submodule_config
      
      	@@
      	expression E;
      	@@
      	- E.DIRSTAT_BY_LINE
      	+ E.dirstat_by_line
      
      	@@
      	expression E;
      	@@
      	- E.FUNCCONTEXT
      	+ E.funccontext
      
      	@@
      	expression E;
      	@@
      	- E.PICKAXE_IGNORE_CASE
      	+ E.pickaxe_ignore_case
      
      	@@
      	expression E;
      	@@
      	- E.DEFAULT_FOLLOW_RENAMES
      	+ E.default_follow_renames
      Signed-off-by: default avatarBrandon Williams <bmwill@google.com>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      0d1e0e78
    • Brandon Williams's avatar
      diff: remove DIFF_OPT_CLR macro · b2100e52
      Brandon Williams authored
      Remove the `DIFF_OPT_CLR` macro and instead set the flags directly.
      This conversion is done using the following semantic patch:
      
      	@@
      	expression E;
      	identifier fld;
      	@@
      	- DIFF_OPT_CLR(&E, fld)
      	+ E.flags.fld = 0
      
      	@@
      	type T;
      	T *ptr;
      	identifier fld;
      	@@
      	- DIFF_OPT_CLR(ptr, fld)
      	+ ptr->flags.fld = 0
      Signed-off-by: default avatarBrandon Williams <bmwill@google.com>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      b2100e52
    • Brandon Williams's avatar
      diff: remove DIFF_OPT_SET macro · 23dcf77f
      Brandon Williams authored
      Remove the `DIFF_OPT_SET` macro and instead set the flags directly.
      This conversion is done using the following semantic patch:
      
      	@@
      	expression E;
      	identifier fld;
      	@@
      	- DIFF_OPT_SET(&E, fld)
      	+ E.flags.fld = 1
      
      	@@
      	type T;
      	T *ptr;
      	identifier fld;
      	@@
      	- DIFF_OPT_SET(ptr, fld)
      	+ ptr->flags.fld = 1
      Signed-off-by: default avatarBrandon Williams <bmwill@google.com>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      23dcf77f
    • Brandon Williams's avatar
      diff: remove DIFF_OPT_TST macro · 3b69daed
      Brandon Williams authored
      Remove the `DIFF_OPT_TST` macro and instead access the flags directly.
      This conversion is done using the following semantic patch:
      
      	@@
      	expression E;
      	identifier fld;
      	@@
      	- DIFF_OPT_TST(&E, fld)
      	+ E.flags.fld
      
      	@@
      	type T;
      	T *ptr;
      	identifier fld;
      	@@
      	- DIFF_OPT_TST(ptr, fld)
      	+ ptr->flags.fld
      Signed-off-by: default avatarBrandon Williams <bmwill@google.com>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      3b69daed
  6. 16 Oct, 2017 1 commit
  7. 13 Jun, 2017 1 commit
  8. 05 Jun, 2017 2 commits
  9. 02 Jun, 2017 3 commits
  10. 31 Mar, 2017 2 commits
  11. 30 Mar, 2017 1 commit
  12. 28 Mar, 2017 1 commit
  13. 26 Oct, 2016 2 commits
  14. 28 Jun, 2016 2 commits
  15. 02 Jun, 2016 1 commit
  16. 09 May, 2016 1 commit
  17. 22 Feb, 2016 4 commits
    • Jeff King's avatar
      use st_add and st_mult for allocation size computation · 50a6c8ef
      Jeff King authored
      If our size computation overflows size_t, we may allocate a
      much smaller buffer than we expected and overflow it. It's
      probably impossible to trigger an overflow in most of these
      sites in practice, but it is easy enough convert their
      additions and multiplications into overflow-checking
      variants. This may be fixing real bugs, and it makes
      auditing the code easier.
      Signed-off-by: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      50a6c8ef
    • Jeff King's avatar
      convert trivial cases to FLEX_ARRAY macros · 96ffc06f
      Jeff King authored
      Using FLEX_ARRAY macros reduces the amount of manual
      computation size we have to do. It also ensures we don't
      overflow size_t, and it makes sure we write the same number
      of bytes that we allocated.
      Signed-off-by: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      96ffc06f
    • Jeff King's avatar
      use xmallocz to avoid size arithmetic · 3733e694
      Jeff King authored
      We frequently allocate strings as xmalloc(len + 1), where
      the extra 1 is for the NUL terminator. This can be done more
      simply with xmallocz, which also checks for integer
      overflow.
      
      There's no case where switching xmalloc(n+1) to xmallocz(n)
      is wrong; the result is the same length, and malloc made no
      guarantees about what was in the buffer anyway. But in some
      cases, we can stop manually placing NUL at the end of the
      allocated buffer. But that's only safe if it's clear that
      the contents will always fill the buffer.
      
      In each case where this patch does so, I manually examined
      the control flow, and I tried to err on the side of caution.
      Signed-off-by: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      3733e694
    • Jeff King's avatar
      convert trivial cases to ALLOC_ARRAY · b32fa95f
      Jeff King authored
      Each of these cases can be converted to use ALLOC_ARRAY or
      REALLOC_ARRAY, which has two advantages:
      
        1. It automatically checks the array-size multiplication
           for overflow.
      
        2. It always uses sizeof(*array) for the element-size,
           so that it can never go out of sync with the declared
           type of the array.
      Signed-off-by: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      b32fa95f
  18. 20 Nov, 2015 2 commits
  19. 28 Sep, 2015 1 commit
    • Jeff King's avatar
      react to errors in xdi_diff · 3efb9880
      Jeff King authored
      When we call into xdiff to perform a diff, we generally lose
      the return code completely. Typically by ignoring the return
      of our xdi_diff wrapper, but sometimes we even propagate
      that return value up and then ignore it later.  This can
      lead to us silently producing incorrect diffs (e.g., "git
      log" might produce no output at all, not even a diff header,
      for a content-level diff).
      
      In practice this does not happen very often, because the
      typical reason for xdiff to report failure is that it
      malloc() failed (it uses straight malloc, and not our
      xmalloc wrapper).  But it could also happen when xdiff
      triggers one our callbacks, which returns an error (e.g.,
      outf() in builtin/rerere.c tries to report a write failure
      in this way). And the next patch also plans to add more
      failure modes.
      
      Let's notice an error return from xdiff and react
      appropriately. In most of the diff.c code, we can simply
      die(), which matches the surrounding code (e.g., that is
      what we do if we fail to load a file for diffing in the
      first place). This is not that elegant, but we are probably
      better off dying to let the user know there was a problem,
      rather than simply generating bogus output.
      
      We could also just die() directly in xdi_diff, but the
      callers typically have a bit more context, and can provide a
      better message (and if we do later decide to pass errors up,
      we're one step closer to doing so).
      
      There is one interesting case, which is in diff_grep(). Here
      if we cannot generate the diff, there is nothing to match,
      and we silently return "no hits". This is actually what the
      existing code does already, but we make it a little more
      explicit.
      Signed-off-by: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      3efb9880
  20. 27 May, 2015 1 commit
  21. 14 Mar, 2015 1 commit
  22. 20 Aug, 2014 1 commit
    • Jeff King's avatar
      intersect_paths: respect mode in git's tree-sort · e09867f0
      Jeff King authored
      When we do a combined diff, we individually diff against
      each parent, and then use intersect_paths to do a parallel
      walk through the sorted results and come up with a final
      list of interesting paths.
      
      The sort order here is that returned by the diffs, which
      means it is in git's tree-order which sorts sub-trees as if
      their paths have "/" at the end. When we do our parallel
      walk, we need to use a comparison function which provides
      the same order.
      
      Since 8518ff8f (combine-diff: optimize combine_diff_path sets
      intersection, 2014-01-20), we use a simple strcmp to
      compare the pathnames, and get this wrong. It's somewhat
      hard to trigger because normally a diff does not produce
      tree entries at all, and therefore the sort order is the
      same as a strcmp. However, if the "-t" option is used with
      the diff, then we will produce diff_filepairs for both trees
      and files.
      
      We can use base_name_compare to do the comparison, just as
      the tree-diff code does. Even though what we have are not
      technically base names (they are full paths within the
      tree), the end result is the same (we do not care about
      interior slashes at all, only about the final character).
      
      However, since we do not have the length of each path
      stored, we take a slight shortcut: if neither of the entries
      is a sub-tree then the comparison is equivalent to a strcmp.
      This lets us skip the extra strlen calls in the common case
      without having to reimplement base_name_compare from
      scratch.
      Signed-off-by: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      e09867f0
  23. 30 Jul, 2014 1 commit
    • Jeff King's avatar
      pretty: make empty userformats truly empty · b9c7d6e4
      Jeff King authored
      If the user provides an empty format with "--format=", we
      end up putting in extra whitespace that the user cannot
      prevent. This comes from two places:
      
        1. If the format is missing a terminating newline, we add
           one automatically. This makes sense for --format=%h, but
           not for a truly empty format.
      
        2. We add an extra newline between the pretty-printed
           format and a diff or diffstat. If the format is empty,
           there's no point in doing so if there's nothing to
           separate.
      
      With this patch, one can get a diff with no other cruft out
      of "diff-tree --format= $commit".
      Signed-off-by: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      b9c7d6e4
  24. 15 May, 2014 1 commit
    • Max A.K.'s avatar
      git-show: fix 'git show -s' to not add extra terminator after merge commit · ad2f7255
      Max A.K. authored
      When git show -s is called for merge commit it prints extra newline
      after any merge commit. This differs from output for commits with one
      parent. Fix it by more thorough checking that diff output is disabled.
      
      The code in question exists since commit 3969cf7d. The additional
      newline is really needed for cases when patch is requested, test
      t4013-diff-various.sh contains cases which can demonstrate behavior when
      the condition is restricted further.
      
      Tests:
      
      Added merge commit to 'set up a bit of history' case in t7007-show.sh to
      cover the fix.
      
      Existing tests are updated to demonstrate the new behaviour.  Earlier,
      the tests that used "git show -s --pretty=format:%s", even though
      "--pretty=format:%s" calls for item separator semantics and does not ask
      for the terminating newline after the last item, expected the output to
      end with such a newline.  They were relying on the buggy behaviour.  Use
      of "--format=%s", which is equivalent to "--pretty=tformat:%s" that asks
      for a terminating newline after each item, is a more realistic way to
      use the command.
      
      In the test 'merge log messages' the expected data is changed, because
      it was explicitly listing the extra newline. Also the msg.nologff and
      msg.nolognoff expected files are replaced by one msg.nolog, because they
      were diffing because of the bug, and now there should be no difference.
      Signed-off-by: Max A.K.'s avatarMax Kirillov <max@max630.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      ad2f7255
  25. 07 Apr, 2014 1 commit
    • Kirill Smelkov's avatar
      combine-diff: speed it up, by using multiparent diff tree-walker directly · 7195fbfa
      Kirill Smelkov authored
      As was recently shown in "combine-diff: optimize
      combine_diff_path sets intersection", combine-diff runs very slowly. In
      that commit we optimized paths sets intersection, but that accounted
      only for ~ 25% of the slowness, and as my tracing showed, for linux.git
      v3.10..v3.11, for merges a lot of time is spent computing
      diff(commit,commit^2) just to only then intersect that huge diff to
      almost small set of files from diff(commit,commit^1).
      
      In previous commit, we described the problem in more details, and
      reworked the diff tree-walker to be general one - i.e. to work in
      multiple parent case too. Now is the time to take advantage of it for
      finding paths for combine diff.
      
      The implementation is straightforward - if we know, we can get generated
      diff paths directly, and at present that means no diff filtering or
      rename/copy detection was requested(*), we can call multiparent tree-walker
      directly and get ready paths.
      
      (*) because e.g. at present, all diffcore transformations work on
          diff_filepair queues, but in the future, that limitation can be
          lifted, if filters would operate directly on combine_diff_paths.
      
      Timings for `git log --raw --no-abbrev --no-renames` without `-c` ("git log")
      and with `-c` ("git log -c") and with `-c --merges` ("git log -c --merges")
      before and after the patch are as follows:
      
                      linux.git v3.10..v3.11
      
                  log     log -c     log -c --merges
      
          before  1.9s    16.4s      15.2s
          after   1.9s     2.4s       1.1s
      
      The result stayed the same.
      Signed-off-by: default avatarKirill Smelkov <kirr@mns.spb.ru>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      7195fbfa
  26. 24 Feb, 2014 1 commit