1. 30 Jun, 2014 2 commits
    • Jeff King's avatar
      use strip_suffix instead of ends_with in simple cases · 26936bfd
      Jeff King authored
      When stripping a suffix like:
      
        if (ends_with(str, "foo"))
      	buf = xmemdupz(str, strlen(str) - 3);
      
      we can instead use strip_suffix to avoid the constant 3,
      which must match the literal "foo" (we sometimes use
      strlen("foo") instead, but that means we are repeating
      ourselves). The example above becomes:
      
        if (strip_suffix(str, "foo", &len))
      	buf = xmemdupz(str, len);
      
      This also saves a strlen(), since we calculate the string
      length when detecting the suffix.
      
      Note that in some cases we also switch from xstrndup to
      xmemdupz, which saves a further strlen call.
      Signed-off-by: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      26936bfd
    • Jeff King's avatar
      replace has_extension with ends_with · 2975c770
      Jeff King authored
      These two are almost the same function, with the exception
      that has_extension only matches if there is content before
      the suffix. So ends_with(".exe", ".exe") is true, but
      has_extension would not be.
      
      This distinction does not matter to any of the callers,
      though, and we can just replace uses of has_extension with
      ends_with. We prefer the "ends_with" name because it is more
      generic, and there is nothing about the function that
      requires it to be used for file extensions.
      Signed-off-by: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      2975c770
  2. 20 Jun, 2014 3 commits
    • Jeff King's avatar
      use skip_prefix to avoid repeated calculations · de8118e1
      Jeff King authored
      In some cases, we use starts_with to check for a prefix, and
      then use an already-calculated prefix length to advance a
      pointer past the prefix. There are no magic numbers or
      duplicated strings here, but we can still make the code
      simpler and more obvious by using skip_prefix.
      Signed-off-by: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      de8118e1
    • Jeff King's avatar
      use skip_prefix to avoid repeating strings · 95b567c7
      Jeff King authored
      It's a common idiom to match a prefix and then skip past it
      with strlen, like:
      
        if (starts_with(foo, "bar"))
      	  foo += strlen("bar");
      
      This avoids magic numbers, but means we have to repeat the
      string (and there is no compiler check that we didn't make a
      typo in one of the strings).
      
      We can use skip_prefix to handle this case without repeating
      ourselves.
      Signed-off-by: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      95b567c7
    • Jeff King's avatar
      use skip_prefix to avoid magic numbers · ae021d87
      Jeff King authored
      It's a common idiom to match a prefix and then skip past it
      with a magic number, like:
      
        if (starts_with(foo, "bar"))
      	  foo += 3;
      
      This is easy to get wrong, since you have to count the
      prefix string yourself, and there's no compiler check if the
      string changes.  We can use skip_prefix to avoid the magic
      numbers here.
      
      Note that some of these conversions could be much shorter.
      For example:
      
        if (starts_with(arg, "--foo=")) {
      	  bar = arg + 6;
      	  continue;
        }
      
      could become:
      
        if (skip_prefix(arg, "--foo=", &bar))
      	  continue;
      
      However, I have left it as:
      
        if (skip_prefix(arg, "--foo=", &v)) {
      	  bar = v;
      	  continue;
        }
      
      to visually match nearby cases which need to actually
      process the string. Like:
      
        if (skip_prefix(arg, "--foo=", &v)) {
      	  bar = atoi(v);
      	  continue;
        }
      Signed-off-by: default avatarJeff King <peff@peff.net>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      ae021d87
  3. 28 Feb, 2014 1 commit
  4. 05 Dec, 2013 1 commit
    • Christian Couder's avatar
      replace {pre,suf}fixcmp() with {starts,ends}_with() · 59556548
      Christian Couder authored
      Leaving only the function definitions and declarations so that any
      new topic in flight can still make use of the old functions, replace
      existing uses of the prefixcmp() and suffixcmp() with new API
      functions.
      
      The change can be recreated by mechanically applying this:
      
          $ git grep -l -e prefixcmp -e suffixcmp -- \*.c |
            grep -v strbuf\\.c |
            xargs perl -pi -e '
              s|!prefixcmp\(|starts_with\(|g;
              s|prefixcmp\(|!starts_with\(|g;
              s|!suffixcmp\(|ends_with\(|g;
              s|suffixcmp\(|!ends_with\(|g;
            '
      
      on the result of preparatory changes in this series.
      Signed-off-by: Christian Couder's avatarChristian Couder <chriscool@tuxfamily.org>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      59556548
  5. 18 Jul, 2013 1 commit
  6. 08 May, 2013 2 commits
    • Vikrant Varma's avatar
      help: add help_unknown_ref() · e5618106
      Vikrant Varma authored
      When the user gives an unknown string to a command that expects to
      get a ref, we could be more helpful than just saying "that's not a
      ref" and die.
      
      Add helper function help_unknown_ref() to take care of displaying an
      error message along with a list of suggested refs the user might
      have meant.  An interaction with "git merge" might go like this:
      
      	$ git merge foo
      	merge: foo - not something we can merge
      
      	Did you mean one of these?
      	    origin/foo
      	    upstream/foo
      Signed-off-by: default avatarVikrant Varma <vikrant.varma94@gmail.com>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      e5618106
    • 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
  7. 16 Apr, 2013 1 commit
  8. 19 Jan, 2013 1 commit
  9. 25 Jul, 2012 2 commits
  10. 03 Jun, 2012 1 commit
  11. 29 May, 2012 1 commit
  12. 27 Apr, 2012 1 commit
  13. 25 Apr, 2012 1 commit
  14. 24 Apr, 2012 1 commit
  15. 13 Feb, 2012 1 commit
  16. 08 Jul, 2011 1 commit
  17. 16 Jun, 2011 1 commit
    • Ramsay Jones's avatar
      help.c: Fix detection of custom merge strategy on cygwin · b8a97333
      Ramsay Jones authored
      Test t7606-merge-custom.sh fails on cygwin when git-merge fails
      with an "Could not find merge strategy 'theirs'" error, despite
      the test correctly preparing an (executable) git-merge-theirs
      script.
      
      The cause of the failure is the mis-detection of the executable
      status of the script, by the is_executable() function, while the
      load_command_list() function is searching the path for additional
      merge strategy programs.
      
      Note that the l/stat() "functions" on cygwin are somewhat
      schizophrenic (see commits adbc0b6b, 7faee6b8 and 79748439), and
      their behaviour depends on the timing of various git setup and
      config function calls. In particular, until the "git_dir" has
      been set (have_git_dir() returns true), the real cygwin (POSIX
      emulating) l/stat() functions are called. Once "git_dir" has
      been set, the "native Win32 API" implementations of l/stat()
      may, or may not, be called depending on the setting of the
      core.filemode and core.ignorecygwinfstricks config variables.
      
      We also note that, since commit c869753e, core.filemode is forced
      to false, even on NTFS, by git-init and git-clone. A user (or a
      test) can, of course, reset core.filemode to true explicitly if
      the filesystem supports it (and he doesn't use any problematic
      windows software). The test-suite currently runs all tests on
      cygwin with core.filemode set to false.
      
      Given the above, we see that the built-in merge strategies are
      correctly detected as executable, since they are checked for
      before "git_dir" is set, whereas all custom merge strategies are
      not, since they are checked for after "git_dir" is set.
      
      In order to fix the mis-detection problem, we change the code in
      is_executable() to re-use the conditional WIN32 code section,
      which actually looks at the content of the file to determine if
      the file is executable. On cygwin we also make the additional
      code conditional on the executable bit of the file mode returned
      by the initial stat() call. (only the real cygwin function would
      set the executable bit in the file mode.)
      Signed-off-by: default avatarRamsay Jones <ramsay@ramsay1.demon.co.uk>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      b8a97333
  18. 05 Dec, 2010 1 commit
  19. 16 Feb, 2010 1 commit
  20. 16 Dec, 2009 1 commit
    • Johannes Sixt's avatar
      help.autocorrect: do not run a command if the command given is junk · 06500a02
      Johannes Sixt authored
      If a given command is not found, then help.c tries to guess which one the
      user could have meant. If help.autocorrect is 0 or unset, then a list of
      suggestions is given as long as the dissimilarity between the given command
      and the candidates is not excessively high. But if help.autocorrect was
      non-zero (i.e., a delay after which the command is run automatically), the
      latter restriction on dissimilarity was not obeyed.
      
      In my case, this happened:
      
       $ git ..daab02
       WARNING: You called a Git command named '..daab02', which does not exist.
       Continuing under the assumption that you meant 'read-tree'
       in 4.0 seconds automatically...
      
      The patch reuses the similarity limit that is also applied when the list of
      suggested commands is printed.
      Signed-off-by: default avatarJohannes Sixt <j6t@kdbg.org>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      06500a02
  21. 19 Sep, 2009 2 commits
  22. 12 Aug, 2009 2 commits
  23. 23 Jul, 2009 1 commit
  24. 12 Sep, 2008 1 commit
  25. 31 Aug, 2008 2 commits
    • Alex Riesen's avatar
      Add help.autocorrect to enable/disable autocorrecting · f0e90716
      Alex Riesen authored
      It is off(0) by default, to avoid scaring people unless they asked to.
      If set to a non-0 value, wait for that amount of deciseconds before
      running the corrected command.
      
      Suggested by Junio, so he has a chance to hit Ctrl-C.
      Signed-off-by: default avatarAlex Riesen <raa.lkml@gmail.com>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      f0e90716
    • Johannes Schindelin's avatar
      git wrapper: DWIM mistyped commands · 8af84dad
      Johannes Schindelin authored
      This patch introduces a modified Damerau-Levenshtein algorithm into
      Git's code base, and uses it with the following penalties to show some
      similar commands when an unknown command was encountered:
      
      	swap = 0, insertion = 1, substitution = 2, deletion = 4
      
      A typical output would now look like this:
      
      	$ git sm
      	git: 'sm' is not a git-command. See 'git --help'.
      
      	Did you mean one of these?
      		am
      		rm
      
      The cut-off is at similarity rating 6, which was empirically determined
      to give sensible results.
      
      As a convenience, if there is only one candidate, Git continues under
      the assumption that the user mistyped it.  Example:
      
      	$ git reabse
      	WARNING: You called a Git program named 'reabse', which does
      	not exist.
      	Continuing under the assumption that you meant 'rebase'
      	[...]
      Signed-off-by: Johannes Schindelin's avatarJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: default avatarAlex Riesen <raa.lkml@gmail.com>
      Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
      8af84dad
  26. 29 Aug, 2008 3 commits
  27. 22 Aug, 2008 1 commit
  28. 03 Aug, 2008 1 commit
  29. 31 Jul, 2008 1 commit
  30. 30 Jul, 2008 1 commit