1. 08 5月, 2017 7 次提交
  2. 02 5月, 2017 1 次提交
  3. 03 3月, 2017 1 次提交
    • J
      interpret_branch_name: allow callers to restrict expansions · 0e9f62da
      Jeff King 提交于
      The interpret_branch_name() function converts names like
      @{-1} and @{upstream} into branch names. The expanded ref
      names are not fully qualified, and may be outside of the
      refs/heads/ namespace (e.g., "@" expands to "HEAD", and
      "@{upstream}" is likely to be in "refs/remotes/").
      
      This is OK for callers like dwim_ref() which are primarily
      interested in resolving the resulting name, no matter where
      it is. But callers like "git branch" treat the result as a
      branch name in refs/heads/.  When we expand to a ref outside
      that namespace, the results are very confusing (e.g., "git
      branch @" tries to create refs/heads/HEAD, which is
      nonsense).
      
      Callers can't know from the returned string how the
      expansion happened (e.g., did the user really ask for a
      branch named "HEAD", or did we do a bogus expansion?). One
      fix would be to return some out-parameters describing the
      types of expansion that occurred. This has the benefit that
      the caller can generate precise error messages ("I
      understood @{upstream} to mean origin/master, but that is a
      remote tracking branch, so you cannot create it as a local
      name").
      
      However, out-parameters make the function interface somewhat
      cumbersome. Instead, let's do the opposite: let the caller
      tell us which elements to expand. That's easier to pass in,
      and none of the callers give more precise error messages
      than "@{upstream} isn't a valid branch name" anyway (which
      should be sufficient).
      
      The strbuf_branchname() function needs a similar parameter,
      as most of the callers access interpret_branch_name()
      through it.
      
      We can break the callers down into two groups:
      
        1. Callers that are happy with any kind of ref in the
           result. We pass "0" here, so they continue to work
           without restrictions. This includes merge_name(),
           the reflog handling in add_pending_object_with_path(),
           and substitute_branch_name(). This last is what powers
           dwim_ref().
      
        2. Callers that have funny corner cases (mostly in
           git-branch and git-checkout). These need to make use of
           the new parameter, but I've left them as "0" in this
           patch, and will address them individually in follow-on
           patches.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      0e9f62da
  4. 23 2月, 2017 1 次提交
  5. 28 9月, 2016 1 次提交
  6. 08 9月, 2016 1 次提交
  7. 30 7月, 2016 1 次提交
  8. 26 7月, 2016 1 次提交
    • J
      grep: further simplify setting the pattern type · 8465541e
      Junio C Hamano 提交于
      When c5c31d33 (grep: move pattern-type bits support to top-level
      grep.[ch], 2012-10-03) introduced grep_commit_pattern_type() helper
      function, the intention was to allow the users of grep API to having
      to fiddle only with .pattern_type_option (which can be set to "fixed",
      "basic", "extended", and "pcre"), and then immediately before compiling
      the pattern strings for use, call grep_commit_pattern_type() to have
      it prepare various bits in the grep_opt structure (like .fixed,
      .regflags, etc.).
      
      However, grep_set_pattern_type_option() helper function the grep API
      internally uses were left as an external function by mistake.  This
      function shouldn't have been made callable by the users of the API.
      
      Later when the grep API was used in revision traversal machinery,
      the caller then mistakenly started calling the function around
      34a4ae55 (log --grep: use the same helper to set -E/-F options as
      "git grep", 2012-10-03), instead of setting the .pattern_type_option
      field and letting the grep_commit_pattern_type() to take care of the
      details.
      
      This caused an unnecessary bug that made a configured
      grep.patternType take precedence over the command line options
      (e.g. --basic-regexp, --fixed-strings) in "git log" family of
      commands.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      8465541e
  9. 25 6月, 2016 1 次提交
  10. 03 6月, 2016 1 次提交
  11. 26 4月, 2016 1 次提交
  12. 31 3月, 2016 3 次提交
    • J
      pretty: allow tweaking tabwidth in --expand-tabs · fe37a9c5
      Junio C Hamano 提交于
      When the local convention of the project is to use tab width that is
      not 8, it may make sense to allow "git log --expand-tabs=<n>" to
      tweak the output to match it.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      fe37a9c5
    • J
      pretty: enable --expand-tabs by default for selected pretty formats · 0893eec8
      Junio C Hamano 提交于
      "git log --pretty={medium,full,fuller}" and "git log" by default
      prepend 4 spaces to the log message, so it makes sense to enable
      the new "expand-tabs" facility by default for these formats.
      Add --no-expand-tabs option to override the new default.
      
      The change alone breaks a test in t4201 that runs "git shortlog"
      on the output from "git log", and expects that the output from
      "git log" does not do such a tab expansion.  Adjust the test to
      explicitly disable expand-tabs with --no-expand-tabs.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      0893eec8
    • L
      pretty: expand tabs in indented logs to make things line up properly · 7cc13c71
      Linus Torvalds 提交于
      A commit log message sometimes tries to line things up using tabs,
      assuming fixed-width font with the standard 8-place tab settings.
      Viewing such a commit however does not work well in "git log", as
      we indent the lines by prefixing 4 spaces in front of them.
      
      This should all line up:
      
        Column 1	Column 2
        --------	--------
        A		B
        ABCD		EFGH
        SPACES        Instead of Tabs
      
      Even with multi-byte UTF8 characters:
      
        Column 1	Column 2
        --------	--------
        Ä		B
        åäö		100
        A Møøse	once bit my sister..
      
      Tab-expand the lines in "git log --expand-tabs" output before
      prefixing 4 spaces.
      
      This is based on the patch by Linus Torvalds, but at this step, we
      require an explicit command line option to enable the behaviour.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      7cc13c71
  13. 17 3月, 2016 4 次提交
    • J
      list-objects: pass full pathname to callbacks · 2824e184
      Jeff King 提交于
      When we find a blob at "a/b/c", we currently pass this to
      our show_object_fn callbacks as two components: "a/b/" and
      "c". Callbacks which want the full value then call
      path_name(), which concatenates the two. But this is an
      inefficient interface; the path is a strbuf, and we could
      simply append "c" to it temporarily, then roll back the
      length, without creating a new copy.
      
      So we could improve this by teaching the callsites of
      path_name() this trick (and there are only 3). But we can
      also notice that no callback actually cares about the
      broken-down representation, and simply pass each callback
      the full path "a/b/c" as a string. The callback code becomes
      even simpler, then, as we do not have to worry about freeing
      an allocated buffer, nor rolling back our modification to
      the strbuf.
      
      This is theoretically less efficient, as some callbacks
      would not bother to format the final path component. But in
      practice this is not measurable. Since we use the same
      strbuf over and over, our work to grow it is amortized, and
      we really only pay to memcpy a few bytes.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      2824e184
    • J
      list-objects: drop name_path entirely · dc06dc88
      Jeff King 提交于
      In the previous commit, we left name_path as a thin wrapper
      around a strbuf. This patch drops it entirely. As a result,
      every show_object_fn callback needs to be adjusted. However,
      none of their code needs to be changed at all, because the
      only use was to pass it to path_name(), which now handles
      the bare strbuf.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      dc06dc88
    • J
      list-objects: convert name_path to a strbuf · f3badaed
      Jeff King 提交于
      The "struct name_path" data is examined in only two places:
      we generate it in process_tree(), and we convert it to a
      single string in path_name(). Everyone else just passes it
      through to those functions.
      
      We can further note that process_tree() already keeps a
      single strbuf with the leading tree path, for use with
      tree_entry_interesting().
      
      Instead of building a separate name_path linked list, let's
      just use the one we already build in "base". This reduces
      the amount of code (especially tricky code in path_name()
      which did not check for integer overflows caused by deep
      or large pathnames).
      
      It is also more efficient in some instances.  Any time we
      were using tree_entry_interesting, we were building up the
      strbuf anyway, so this is an immediate and obvious win
      there. In cases where we were not, we trade off storing
      "pathname/" in a strbuf on the heap for each level of the
      path, instead of two pointers and an int on the stack (with
      one pointer into the tree object). On a 64-bit system, the
      latter is 20 bytes; so if path components are less than that
      on average, this has lower peak memory usage.  In practice
      it probably doesn't matter either way; we are already
      holding in memory all of the tree objects leading up to each
      pathname, and for normal-depth pathnames, we are only
      talking about hundreds of bytes.
      
      This patch leaves "struct name_path" as a thin wrapper
      around the strbuf, to avoid disrupting callbacks. We should
      fix them, but leaving it out makes this diff easier to view.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      f3badaed
    • J
      show_object_with_name: simplify by using path_name() · 8eee9f92
      Jeff King 提交于
      When "git rev-list" shows an object with its associated path
      name, it does so by walking the name_path linked list and
      printing each component (stopping at any embedded NULs or
      newlines).
      
      We'd like to eventually get rid of name_path entirely in
      favor of a single buffer, and dropping this custom printing
      code is part of that. As a first step, let's use path_name()
      to format the list into a single buffer, and print that.
      This is strictly less efficient than the original, but it's
      a temporary step in the refactoring; our end game will be to
      get the fully formatted name in the first place.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      8eee9f92
  14. 23 2月, 2016 1 次提交
  15. 13 2月, 2016 4 次提交
    • J
      list-objects: pass full pathname to callbacks · de1e67d0
      Jeff King 提交于
      When we find a blob at "a/b/c", we currently pass this to
      our show_object_fn callbacks as two components: "a/b/" and
      "c". Callbacks which want the full value then call
      path_name(), which concatenates the two. But this is an
      inefficient interface; the path is a strbuf, and we could
      simply append "c" to it temporarily, then roll back the
      length, without creating a new copy.
      
      So we could improve this by teaching the callsites of
      path_name() this trick (and there are only 3). But we can
      also notice that no callback actually cares about the
      broken-down representation, and simply pass each callback
      the full path "a/b/c" as a string. The callback code becomes
      even simpler, then, as we do not have to worry about freeing
      an allocated buffer, nor rolling back our modification to
      the strbuf.
      
      This is theoretically less efficient, as some callbacks
      would not bother to format the final path component. But in
      practice this is not measurable. Since we use the same
      strbuf over and over, our work to grow it is amortized, and
      we really only pay to memcpy a few bytes.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      de1e67d0
    • J
      list-objects: drop name_path entirely · bd64516a
      Jeff King 提交于
      In the previous commit, we left name_path as a thin wrapper
      around a strbuf. This patch drops it entirely. As a result,
      every show_object_fn callback needs to be adjusted. However,
      none of their code needs to be changed at all, because the
      only use was to pass it to path_name(), which now handles
      the bare strbuf.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      bd64516a
    • J
      list-objects: convert name_path to a strbuf · 13528ab3
      Jeff King 提交于
      The "struct name_path" data is examined in only two places:
      we generate it in process_tree(), and we convert it to a
      single string in path_name(). Everyone else just passes it
      through to those functions.
      
      We can further note that process_tree() already keeps a
      single strbuf with the leading tree path, for use with
      tree_entry_interesting().
      
      Instead of building a separate name_path linked list, let's
      just use the one we already build in "base". This reduces
      the amount of code (especially tricky code in path_name()
      which did not check for integer overflows caused by deep
      or large pathnames).
      
      It is also more efficient in some instances.  Any time we
      were using tree_entry_interesting, we were building up the
      strbuf anyway, so this is an immediate and obvious win
      there. In cases where we were not, we trade off storing
      "pathname/" in a strbuf on the heap for each level of the
      path, instead of two pointers and an int on the stack (with
      one pointer into the tree object). On a 64-bit system, the
      latter is 20 bytes; so if path components are less than that
      on average, this has lower peak memory usage.  In practice
      it probably doesn't matter either way; we are already
      holding in memory all of the tree objects leading up to each
      pathname, and for normal-depth pathnames, we are only
      talking about hundreds of bytes.
      
      This patch leaves "struct name_path" as a thin wrapper
      around the strbuf, to avoid disrupting callbacks. We should
      fix them, but leaving it out makes this diff easier to view.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      13528ab3
    • J
      show_object_with_name: simplify by using path_name() · f9fb9d0e
      Jeff King 提交于
      When "git rev-list" shows an object with its associated path
      name, it does so by walking the name_path linked list and
      printing each component (stopping at any embedded NULs or
      newlines).
      
      We'd like to eventually get rid of name_path entirely in
      favor of a single buffer, and dropping this custom printing
      code is part of that. As a first step, let's use path_name()
      to format the list into a single buffer, and print that.
      This is strictly less efficient than the original, but it's
      a temporary step in the refactoring; our end game will be to
      get the fully formatted name in the first place.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      f9fb9d0e
  16. 22 1月, 2016 1 次提交
  17. 16 1月, 2016 1 次提交
    • J
      revision: read --stdin with strbuf_getline() · 6e8d46f9
      Junio C Hamano 提交于
      Reading with getwholeline() and manually stripping the terminating
      '\n' would leave CR at the end of the line if the input comes from
      a DOS editor.
      
      Constrasting this with the other changes around "--stdin" in this
      series, one may realize that the way "log" family of commands read
      the paths with "--stdin" looks inconsistent and sloppy.  It does not
      allow us to C-quote a textual input, neither does it accept records
      that are NUL-terminated.  These are unfortunately way too late to
      fix X-<.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      6e8d46f9
  18. 18 12月, 2015 1 次提交
    • J
      revision.c: propagate tag names from pending array · 728350b7
      Jeff King 提交于
      When we unwrap a tag to find its commit for a traversal, we
      do not propagate the "name" field of the tag in the pending
      array (i.e., the ref name the user gave us in the first
      place) to the commit (instead, we use an empty string). This
      means that "git log --source" will never show the tag-name
      for commits we reach through it.
      
      This was broken in 20739490 (traverse_commit_list: support
      pending blobs/trees with paths, 2014-10-15). That commit
      tried to be careful and avoid propagating the path
      information for a tag (which would be nonsensical) to trees
      and blobs. But it should not have cut off the "name" field,
      which should carry forward to children.
      
      Note that this does mean that the "name" field will carry
      forward to blobs and trees, too. Whereas prior to 20739490,
      we always gave them an empty string. This is the right thing
      to do, but in practice no callers probably use it (since now
      we have an explicit separate "path" field, which was the
      point of 20739490).
      
      We add tests here not only for the broken case, but also a
      basic sanity test of "log --source" in general, which did
      not have any coverage in the test suite.
      Reported-by: NRaymundo <gypark@gmail.com>
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      728350b7
  19. 08 12月, 2015 1 次提交
  20. 20 11月, 2015 3 次提交
  21. 27 10月, 2015 1 次提交
  22. 06 10月, 2015 1 次提交
    • J
      prefer memcpy to strcpy · 34fa79a6
      Jeff King 提交于
      When we already know the length of a string (e.g., because
      we just malloc'd to fit it), it's nicer to use memcpy than
      strcpy, as it makes it more obvious that we are not going to
      overflow the buffer (because the size we pass matches the
      size in the allocation).
      
      This also eliminates calls to strcpy, which make auditing
      the code base harder.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      34fa79a6
  23. 01 9月, 2015 1 次提交
    • J
      log: diagnose empty HEAD more clearly · ce113604
      Jeff King 提交于
      If you init or clone an empty repository, the initial
      message from running "git log" is not very friendly:
      
        $ git init
        Initialized empty Git repository in /home/peff/foo/.git/
        $ git log
        fatal: bad default revision 'HEAD'
      
      Let's detect this situation and write a more friendly
      message:
      
        $ git log
        fatal: your current branch 'master' does not have any commits yet
      
      We also detect the case that 'HEAD' points to a broken ref;
      this should be even less common, but is easy to see. Note
      that we do not diagnose all possible cases. We rely on
      resolve_ref, which means we do not get information about
      complex cases. E.g., "--default master" would use dwim_ref
      to find "refs/heads/master", but we notice only that
      "master" does not exist. Similarly, a complex sha1
      expression like "--default HEAD^2" will not resolve as a
      ref.
      
      But that's OK. We fall back to a generic error message in
      those cases, and they are unlikely to be used anyway.
      Catching an empty or broken "HEAD" improves the common case,
      and the other cases are not regressed.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      ce113604
  24. 04 8月, 2015 1 次提交