1. 21 Sep, 2018 1 commit
  2. 01 Nov, 2017 3 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_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
  3. 02 Jun, 2017 1 commit
  4. 21 Mar, 2017 2 commits
    • Jeff King's avatar
      prefix_filename: return newly allocated string · e4da43b1
      Jeff King authored
      The prefix_filename() function returns a pointer to static
      storage, which makes it easy to use dangerously. We already
      fixed one buggy caller in hash-object recently, and the
      calls in apply.c are suspicious (I didn't dig in enough to
      confirm that there is a bug, but we call the function once
      in apply_all_patches() and then again indirectly from
      parse_chunk()).
      
      Let's make it harder to get wrong by allocating the return
      value. For simplicity, we'll do this even when the prefix is
      empty (and we could just return the original file pointer).
      That will cause us to allocate sometimes when we wouldn't
      otherwise need to, but this function isn't called in
      performance critical code-paths (and it already _might_
      allocate on any given call, so a caller that cares about
      performance is questionable anyway).
      
      The downside is that the callers need to remember to free()
      the result to avoid leaking. Most of them already used
      xstrdup() on the result, so we know they are OK. The
      remainder have been converted to use free() as appropriate.
      
      I considered retaining a prefix_filename_unsafe() for cases
      where we know the static lifetime is OK (and handling the
      cleanup is awkward). This is only a handful of cases,
      though, and it's not worth the mental energy in worrying
      about whether the "unsafe" variant is OK to use in any
      situation.
      Signed-off-by: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      e4da43b1
    • Jeff King's avatar
      prefix_filename: drop length parameter · 116fb64e
      Jeff King authored
      This function takes the prefix as a ptr/len pair, but in
      every caller the length is exactly strlen(ptr). Let's
      simplify the interface and just take the string. This saves
      callers specifying it (and in some cases handling a NULL
      prefix).
      
      In a handful of cases we had the length already without
      calling strlen, so this is technically slower. But it's not
      likely to matter (after all, if the prefix is non-empty
      we'll allocate and copy it into a buffer anyway).
      Signed-off-by: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      116fb64e
  5. 30 Jan, 2017 2 commits
    • René Scharfe's avatar
      diff: use SWAP macro · 402bf8e1
      René Scharfe authored
      Use the macro SWAP to exchange the value of pairs of variables instead
      of swapping them manually with the help of a temporary variable.  The
      resulting code is shorter and easier to read.
      
      The two cases were not transformed by the semantic patch swap.cocci
      because it's extra careful and handles only cases where the types of all
      variables are the same -- and here we swap two ints and use an unsigned
      temporary variable for that.  Nevertheless the conversion is safe, as
      the value range is preserved with and without the patch.
      Signed-off-by: default avatarRene Scharfe <l.s.r@web.de>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      402bf8e1
    • René Scharfe's avatar
      use SWAP macro · 35d803bc
      René Scharfe authored
      Apply the semantic patch swap.cocci to convert hand-rolled swaps to use
      the macro SWAP.  The resulting code is shorter and easier to read, the
      object code is effectively unchanged.
      
      The patch for object.c had to be hand-edited in order to preserve the
      comment before the change; Coccinelle tried to eat it for some reason.
      Signed-off-by: default avatarRene Scharfe <l.s.r@web.de>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      35d803bc
  6. 13 Sep, 2016 1 commit
    • Jeff King's avatar
      diff: handle --no-index prefixes consistently · 7d8930d9
      Jeff King authored
      If we see an explicit "git diff --no-index ../foo ../bar",
      then we do not set up the git repository at all (we already
      know we are in --no-index mode, so do not have to check "are
      we in a repository?"), and hence have no "prefix" within the
      repository. A patch generated by this command will have the
      filenames "a/../foo" and "b/../bar", no matter which
      directory we are in with respect to any repository.
      
      However, in the implicit case, where we notice that the
      files are outside the repository, we will have chdir()'d to
      the top-level of the repository. We then feed the prefix
      back to the diff machinery. As a result, running the same
      diff from a subdirectory will result in paths that look like
      "a/subdir/../../foo".
      
      Besides being unnecessarily long, this may also be confusing
      to the user: they don't care about the subdir or the
      repository at all; it's just where they happened to be when
      running the command. We should treat this the same as the
      explicit --no-index case.
      
      One way to address this would be to chdir() back to the
      original path before running our diff. However, that's a bit
      hacky, as we would also need to adjust $GIT_DIR, which could
      be a relative path from our top-level.
      
      Instead, we can reuse the diff machinery's RELATIVE_NAME
      option, which automatically strips off the prefix. Note that
      this _also_ restricts the diff to this relative prefix, but
      that's OK for our purposes: we queue our own diff pairs
      manually, and do not rely on that part of the diff code.
      Signed-off-by: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      7d8930d9
  7. 09 May, 2016 1 commit
  8. 21 Jan, 2016 2 commits
  9. 05 Oct, 2015 1 commit
    • Jeff King's avatar
      use strbuf_complete to conditionally append slash · 00b6c178
      Jeff King authored
      When working with paths in strbufs, we frequently want to
      ensure that a directory contains a trailing slash before
      appending to it. We can shorten this code (and make the
      intent more obvious) by calling strbuf_complete.
      
      Most of these cases are trivially identical conversions, but
      there are two things to note:
      
        - in a few cases we did not check that the strbuf is
          non-empty (which would lead to an out-of-bounds memory
          access). These were generally not triggerable in
          practice, either from earlier assertions, or typically
          because we would have just fed the strbuf to opendir(),
          which would choke on an empty path.
      
        - in a few cases we indexed the buffer with "original_len"
          or similar, rather than the current sb->len, and it is
          not immediately obvious from the diff that they are the
          same. In all of these cases, I manually verified that
          the strbuf does not change between the assignment and
          the strbuf_complete call.
      
      This does not convert cases which look like:
      
        if (sb->len && !is_dir_sep(sb->buf[sb->len - 1]))
      	  strbuf_addch(sb, '/');
      
      as those are obviously semantically different. Some of these
      cases arguably should be doing that, but that is out of
      scope for this change, which aims purely for cleanup with no
      behavior change (and at least it will make such sites easier
      to find and examine in the future, as we can grep for
      strbuf_complete).
      Signed-off-by: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      00b6c178
  10. 26 Mar, 2015 2 commits
    • Junio C Hamano's avatar
      diff-no-index: align D/F handling with that of normal Git · 06151739
      Junio C Hamano authored
      When a commit changes a path P that used to be a file to a directory
      and creates a new path P/X in it, "git show" would say that file P
      was removed and file P/X was created for such a commit.
      
      However, if we compare two directories, D1 and D2, where D1 has a
      file D1/P in it and D2 has a directory D2/P under which there is a
      file D2/P/X, and ask "git diff --no-index D1 D2" to show their
      differences, we simply get a refusal "file/directory conflict".
      
      Surely, that may be what GNU diff does, but we can do better and it
      is easy to do so.
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      06151739
    • Junio C Hamano's avatar
      diff-no-index: DWIM "diff D F" into "diff D/F F" · c9e1f2c7
      Junio C Hamano authored
      "git diff --no-index" was supposed to be a poor-man's approach to
      allow using Git diff goodies outside of a Git repository, without
      having to patch mainstream diff implementations.
      
      Unlike a POSIX diff that treats "diff D F" (or "diff F D") as a
      request to compare D/F and F (or F and D/F) when D is a directory
      and F is a file, however, we did not accept such a command line and
      instead barfed with "file/directory conflict".
      
      Imitate what POSIX diff does and append the basename of the file
      after the name of the directory before comparing.
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      c9e1f2c7
  11. 31 Mar, 2014 1 commit
    • Junio C Hamano's avatar
      diff-no-index: correctly diagnose error return from diff_opt_parse() · ad1c3fbd
      Junio C Hamano authored
      diff_opt_parse() returns the number of options parsed, or often
      returns error() which is defined to return -1.  Yes, return value of
      0 is "I did not process that option at all", which should cause the
      caller to say that, but negative return should not be forgotten.
      
      This bug caused "diff --no-index" to infinitely show the same error
      message because the returned value was used to decrement the loop
      control variable, e.g.
      
              $ git diff --no-index --color=words a b
              error: option `color' expects "always", "auto", or "never"
              error: option `color' expects "always", "auto", or "never"
              ...
      
      Instead, make it act like so:
      
              $ git diff --no-index --color=words a b
              error: option `color' expects "always", "auto", or "never"
              fatal: invalid diff option/value: --color=words
      Reported-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      ad1c3fbd
  12. 19 Mar, 2014 2 commits
  13. 12 Dec, 2013 1 commit
  14. 22 Aug, 2013 1 commit
  15. 19 Jul, 2013 2 commits
  16. 08 May, 2013 1 commit
    • Jonathan Nieder's avatar
      mingw: rename WIN32 cpp macro to GIT_WINDOWS_NATIVE · 380395d0
      Jonathan Nieder authored
      Throughout git, it is assumed that the WIN32 preprocessor symbol is
      defined on native Windows setups (mingw and msvc) and not on Cygwin.
      On Cygwin, most of the time git can pretend this is just another Unix
      machine, and Windows-specific magic is generally counterproductive.
      
      Unfortunately Cygwin *does* define the WIN32 symbol in some headers.
      Best to rely on a new git-specific symbol GIT_WINDOWS_NATIVE instead,
      defined as follows:
      
      	#if defined(WIN32) && !defined(__CYGWIN__)
      	# define GIT_WINDOWS_NATIVE
      	#endif
      
      After this change, it should be possible to drop the
      CYGWIN_V15_WIN32API setting without any negative effect.
      
      [rj: %s/WINDOWS_NATIVE/GIT_WINDOWS_NATIVE/g ]
      Signed-off-by: default avatarJonathan Nieder <jrnieder@gmail.com>
      Signed-off-by: default avatarRamsay Jones <ramsay@ramsay1.demon.co.uk>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      380395d0
  17. 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
  18. 29 Jul, 2012 1 commit
    • Jeff King's avatar
      diff: do not use null sha1 as a sentinel value · e5450100
      Jeff King authored
      The diff code represents paths using the diff_filespec
      struct. This struct has a sha1 to represent the sha1 of the
      content at that path, as well as a sha1_valid member which
      indicates whether its sha1 field is actually useful. If
      sha1_valid is not true, then the filespec represents a
      working tree file (e.g., for the no-index case, or for when
      the index is not up-to-date).
      
      The diff_filespec is only used internally, though. At the
      interfaces to the diff subsystem, callers feed the sha1
      directly, and we create a diff_filespec from it. It's at
      that point that we look at the sha1 and decide whether it is
      valid or not; callers may pass the null sha1 as a sentinel
      value to indicate that it is not.
      
      We should not typically see the null sha1 coming from any
      other source (e.g., in the index itself, or from a tree).
      However, a corrupt tree might have a null sha1, which would
      cause "diff --patch" to accidentally diff the working tree
      version of a file instead of treating it as a blob.
      
      This patch extends the edges of the diff interface to accept
      a "sha1_valid" flag whenever we accept a sha1, and to use
      that flag when creating a filespec. In some cases, this
      means passing the flag through several layers, making the
      code change larger than would be desirable.
      
      One alternative would be to simply die() upon seeing
      corrupted trees with null sha1s. However, this fix more
      directly addresses the problem (while bogus sha1s in a tree
      are probably a bad thing, it is really the sentinel
      confusion sending us down the wrong code path that is what
      makes it devastating). And it means that git is more capable
      of examining and debugging these corrupted trees. For
      example, you can still "diff --raw" such a tree to find out
      when the bogus entry was introduced; you just cannot do a
      "--patch" diff (just as you could not with any other
      corrupted tree, as we do not have any content to diff).
      Signed-off-by: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      e5450100
  19. 28 Jun, 2012 3 commits
    • Junio C Hamano's avatar
      diff-index.c: "git diff" has no need to read blob from the standard input · 4682d852
      Junio C Hamano authored
      Only "diff --no-index -" does.  Bolting the logic into the low-level
      function diff_populate_filespec() was a layering violation from day
      one.  Move populate_from_stdin() function out of the generic diff.c
      to its only user, diff-index.c.
      
      Also make sure "-" from the command line stays a special token "read
      from the standard input", even if we later decide to sanitize the
      result from prefix_filename() function in a few obvious ways,
      e.g. removing unnecessary "./" prefix, duplicated slashes "//" in
      the middle, etc.
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      4682d852
    • Junio C Hamano's avatar
      diff-index.c: unify handling of command line paths · 3b069b1b
      Junio C Hamano authored
      Regardless of where in the directory hierarchy you are, "-" on the
      command line means the standard input.  The old code knew too much
      about how the low level machinery uses paths to read from the
      working tree and did not bother to have the same check for "-" when
      the command is run from the top-level.
      
      Unify the codepaths for subdirectory case and toplevel case into one
      and make it clearer.
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      3b069b1b
    • Junio C Hamano's avatar
      diff-index.c: do not pretend paths are pathspecs · c20f5926
      Junio C Hamano authored
      "git diff --no-index" takes exactly two paths, not pathspecs, and
      has its own way queue_diff() to populate the diff_queue.  Do not
      call diff_tree_setup_paths(), pretending as it takes pathspecs.
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      c20f5926
  20. 22 Jun, 2012 2 commits
  21. 15 Jun, 2012 2 commits
    • Jeff King's avatar
      do not run pager with diff --no-index --quiet · af63b543
      Jeff King authored
      There is no point in running a pager when --quiet is given,
      since we are producing no output. The regular diff code path
      handles this already, because --quiet implies --exit-code,
      and we check for --exit-code when deciding not to run the
      pager.
      
      However, the "quiet implies exit-code" logic is done in
      diff_setup_done, and the no-index code path sets up its
      pager before running diff_setup_done, and misses this case.
      
      We can fix this by reordering our initialization.
      Currently we do:
      
        1. read command line arguments into diff_options
      
        2. Set pager if EXIT_CODE not requested
      
        3. always set EXIT_CODE, since we are emulating
           traditional diff
      
        4. call diff_setup_done
      
      We can fix the problem by moving pager initialization (step
      2) after step 4. But step 3 must come after step 2 (since we
      want to know whether the _user_ requested --exit-code, not
      whether we turned it on unconditionally). So we must move
      both.
      Signed-off-by: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      af63b543
    • Jeff King's avatar
      fix pager.diff with diff --no-index · 1af3d977
      Jeff King authored
      git-diff does not rely on the git wrapper to setup its
      pager; instead, it sets it up on its own after seeing
      whether --quiet or --exit-code has been specified.  After
      diff_no_index was split off from cmd_diff, commit b3fde6cc
      (git diff --no-index: default to page like other diff
      frontends, 2008-05-26) duplicated the one-liner from
      cmd_diff to turn on the pager.
      
      Later, commit 8f0359f0 (Allow pager of diff command be
      enabled/disabled, 2008-07-21) taught the the version in
      cmd_diff to respect the pager.diff config, but the version
      in diff_no_index was left behind. This meant that
      
        git -c pager.diff=0 diff a b
      
      would not use a pager, but
      
        git -c pager.diff=0 diff --no-index a b
      
      would.  Let's fix it by factoring out a common function.
      
      While we're there, let's update the antiquated comment,
      which claims that the pager interferes with propagating the
      exit code; this has not been the case since ea27a18c (spawn
      pager via run_command interface, 2008-07-22).
      Signed-off-by: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      1af3d977
  22. 16 May, 2012 2 commits
  23. 26 Apr, 2012 1 commit
  24. 16 Apr, 2012 1 commit
  25. 03 Feb, 2011 2 commits
  26. 05 Jul, 2010 1 commit