1. 17 10月, 2015 1 次提交
  2. 31 8月, 2015 1 次提交
    • D
      commit: don't rewrite shared index unnecessarily · 475a3445
      David Turner 提交于
      Remove a cache invalidation which would cause the shared index to be
      rewritten on as-is commits.
      
      When the cache-tree has changed, we need to update it.  But we don't
      necessarily need to update the shared index.  So setting
      active_cache_changed to SOMETHING_CHANGED is unnecessary.  Instead, we
      let update_main_cache_tree just update the CACHE_TREE_CHANGED bit.
      
      In order to test this, make test-dump-split-index not segfault on
      missing replace_bitmap/delete_bitmap.  This new codepath is not called
      now that the test passes, but is necessary to avoid a segfault when the
      new test is run with the old builtin/commit.c code.
      Signed-off-by: NDavid Turner <dturner@twopensource.com>
      Acked-by: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      475a3445
  3. 11 8月, 2015 2 次提交
    • J
      memoize common git-path "constant" files · f932729c
      Jeff King 提交于
      One of the most common uses of git_path() is to pass a
      constant, like git_path("MERGE_MSG"). This has two
      drawbacks:
      
        1. The return value is a static buffer, and the lifetime
           is dependent on other calls to git_path, etc.
      
        2. There's no compile-time checking of the pathname. This
           is OK for a one-off (after all, we have to spell it
           correctly at least once), but many of these constant
           strings appear throughout the code.
      
      This patch introduces a series of functions to "memoize"
      these strings, which are essentially globals for the
      lifetime of the program. We compute the value once, take
      ownership of the buffer, and return the cached value for
      subsequent calls.  cache.h provides a helper macro for
      defining these functions as one-liners, and defines a few
      common ones for global use.
      
      Using a macro is a little bit gross, but it does nicely
      document the purpose of the functions. If we need to touch
      them all later (e.g., because we learned how to change the
      git_dir variable at runtime, and need to invalidate all of
      the stored values), it will be much easier to have the
      complete list.
      
      Note that the shared-global functions have separate, manual
      declarations. We could do something clever with the macros
      (e.g., expand it to a declaration in some places, and a
      declaration _and_ a definition in path.c). But there aren't
      that many, and it's probably better to stay away from
      too-magical macros.
      
      Likewise, if we abandon the C preprocessor in favor of
      generating these with a script, we could get much fancier.
      E.g., normalizing "FOO/BAR-BAZ" into "git_path_foo_bar_baz".
      But the small amount of saved typing is probably not worth
      the resulting confusion to readers who want to grep for the
      function's definition.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      f932729c
    • M
      b4fb09e4
  4. 30 6月, 2015 1 次提交
    • J
      convert "enum date_mode" into a struct · a5481a6c
      Jeff King 提交于
      In preparation for adding date modes that may carry extra
      information beyond the mode itself, this patch converts the
      date_mode enum into a struct.
      
      Most of the conversion is fairly straightforward; we pass
      the struct as a pointer and dereference the type field where
      necessary. Locations that declare a date_mode can use a "{}"
      constructor.  However, the tricky case is where we use the
      enum labels as constants, like:
      
        show_date(t, tz, DATE_NORMAL);
      
      Ideally we could say:
      
        show_date(t, tz, &{ DATE_NORMAL });
      
      but of course C does not allow that. Likewise, we cannot
      cast the constant to a struct, because we need to pass an
      actual address. Our options are basically:
      
        1. Manually add a "struct date_mode d = { DATE_NORMAL }"
           definition to each caller, and pass "&d". This makes
           the callers uglier, because they sometimes do not even
           have their own scope (e.g., they are inside a switch
           statement).
      
        2. Provide a pre-made global "date_normal" struct that can
           be passed by address. We'd also need "date_rfc2822",
           "date_iso8601", and so forth. But at least the ugliness
           is defined in one place.
      
        3. Provide a wrapper that generates the correct struct on
           the fly. The big downside is that we end up pointing to
           a single global, which makes our wrapper non-reentrant.
           But show_date is already not reentrant, so it does not
           matter.
      
      This patch implements 3, along with a minor macro to keep
      the size of the callers sane.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      a5481a6c
  5. 07 5月, 2015 1 次提交
  6. 24 3月, 2015 1 次提交
  7. 13 3月, 2015 1 次提交
  8. 18 2月, 2015 2 次提交
  9. 27 1月, 2015 1 次提交
    • M
      commit: reword --author error message · 1044b1f6
      Michael J Gruber 提交于
      If an --author argument is specified but does not contain a '>' then git tries
      to find the argument within the existing authors; and gives the error
      message "No existing author found with '%s'" if there is no match.
      
      This is confusing for users who try to specify a valid complete author
      name.
      
      Rename the error message to make it clearer that the failure has two
      reasons in this case.
      
      (This codepath is touched only when we know already that the argument
      cannot be a completely wellformed author ident.)
      Signed-off-by: NMichael J Gruber <git@drmicha.warpmail.net>
      Helped-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      1044b1f6
  10. 15 1月, 2015 1 次提交
  11. 14 1月, 2015 1 次提交
  12. 12 12月, 2014 2 次提交
    • J
      commit: always populate GIT_AUTHOR_* variables · c83a5099
      Jeff King 提交于
      To figure out the author ident for a commit, we call
      determine_author_info(). This function collects information
      from the environment, other commits (in the case of
      "--amend" or "-c/-C"), and the "--author" option. It then
      uses fmt_ident to generate the final ident string that goes
      into the commit object. fmt_ident is therefore responsible
      for any quality or validation checks on what is allowed to
      go into a commit.
      
      Before returning, though, we call split_ident_line on the
      result, and feed the individual components to hooks via the
      GIT_AUTHOR_* variables. Furthermore, we do extra validation
      by feeding the split to sane_ident_split(), which is pickier
      than fmt_ident (in particular, it will complain about an empty
      email field).  If this parsing or validation fails, we skip
      updating the environment variables.
      
      This is bad, because it means that hooks may silently see a
      different ident than what we are putting into the commit. We
      should drop the extra sane_ident_split checks entirely, and
      take whatever fmt_ident has fed us (and what will go into
      the commit object).
      
      If parsing fails, we should actually abort here rather than
      continuing (and feeding the hooks bogus data). However,
      split_ident_line should never fail here. The ident was just
      generated by fmt_ident, so we know that it's sane. We can
      use assert_split_ident to double-check this.
      
      Note that we also teach that assertion to check that we
      found a date (it always should, but until now, no caller
      cared whether we found a date or not). Checking the return
      value of sane_ident_split is enough to ensure we have the
      name/email pointers set, and checking date_begin is enough
      to know that all of the date/tz variables are set.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      c83a5099
    • J
      commit: loosen ident checks when generating template · fac90838
      Jeff King 提交于
      When we generate the commit-message template, we try to
      report an author or committer ident that will be of interest
      to the user: an author that does not match the committer, or
      a committer that was auto-configured.
      
      When doing so, if we encounter what we consider to be a
      bogus ident, we immediately die. This is a bad idea, because
      our use of the idents here is purely informational.  Any
      ident rules should be enforced elsewhere, because commits
      that do not invoke the editor will not even hit this code
      path (e.g., "git commit -mfoo" would work, but "git commit"
      would not). So at best, we are redundant with other checks,
      and at worse, we actively prevent commits that should
      otherwise be allowed.
      
      We should therefore do the minimal parsing we can to get a
      value and not do any validation (i.e., drop the call to
      sane_ident_split()).
      
      In theory we could notice when even our minimal parsing
      fails to work, and do the sane thing for each check (e.g.,
      if we have an author but can't parse the committer, assume
      they are different and print the author). But we can
      actually simplify this even further.
      
      We know that the author and committer strings we are parsing
      have been generated by us earlier in the program, and
      therefore they must be parseable. We could just call
      split_ident_line without even checking its return value,
      knowing that it will put _something_ in the name/mail
      fields. Of course, to protect ourselves against future
      changes to the code, it makes sense to turn this into an
      assert, so we are not surprised if our assumption fails.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      fac90838
  13. 02 12月, 2014 1 次提交
  14. 11 11月, 2014 1 次提交
  15. 29 10月, 2014 2 次提交
    • J
      merge & sequencer: turn "Conflicts:" hint into a comment · 261f315b
      Junio C Hamano 提交于
      Just like other hints such as "Changes to be committed" we show in
      the editor to remind the committer what paths were involved in the
      resulting commit to help improving their log message, this section
      is merely a reminder.
      
      Traditionally, it was not made into comments primarily because it
      has to be generated outside the wt-status infrastructure, and also
      because it was meant as a bit stronger reminder than the others
      (i.e. explaining how you resolved conflicts is much more important
      than mentioning what you did to every paths involved in the commit).
      
      But that still does not make this hint a part of the log message
      proper, and not showing it as a comment is inviting mistakes.
      
      Note that we still notice "Conflicts:" followed by list of indented
      pathnames as an old-style cruft and insert a new Signed-off-by:
      before it.  This is so that "commit --amend -s" adds the new S-o-b
      at the right place when used on an older commit.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      261f315b
    • J
      builtin/commit.c: extract ignore_non_trailer() helper function · 073bd75e
      Junio C Hamano 提交于
      Extract a helper function from prepare_to_commit() to determine
      where to place a new Signed-off-by: line, which is essentially the
      true "end" of the log message, ignoring the trailing "Conflicts:"
      line and everything below it.
      
      The detection _should_ make sure the "Conflicts:" line it finds is
      truly the conflict hint block by checking everything that follows is
      a HT indented pathname to avoid false positive, but this logic will
      be revamped in a later patch to ignore comments and blanks anyway,
      so it is left as-is in this step.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      073bd75e
  16. 16 10月, 2014 2 次提交
  17. 15 10月, 2014 2 次提交
    • J
      color_parse: do not mention variable name in error message · f6c5a296
      Jeff King 提交于
      Originally the color-parsing function was used only for
      config variables. It made sense to pass the variable name so
      that the die() message could be something like:
      
        $ git -c color.branch.plain=bogus branch
        fatal: bad color value 'bogus' for variable 'color.branch.plain'
      
      These days we call it in other contexts, and the resulting
      error messages are a little confusing:
      
        $ git log --pretty='%C(bogus)'
        fatal: bad color value 'bogus' for variable '--pretty format'
      
        $ git config --get-color foo.bar bogus
        fatal: bad color value 'bogus' for variable 'command line'
      
      This patch teaches color_parse to complain only about the
      value, and then return an error code. Config callers can
      then propagate that up to the config parser, which mentions
      the variable name. Other callers can provide a custom
      message. After this patch these three cases now look like:
      
        $ git -c color.branch.plain=bogus branch
        error: invalid color value: bogus
        fatal: unable to parse 'color.branch.plain' from command-line config
      
        $ git log --pretty='%C(bogus)'
        error: invalid color value: bogus
        fatal: unable to parse --pretty format
      
        $ git config --get-color foo.bar bogus
        error: invalid color value: bogus
        fatal: unable to parse default color value
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      f6c5a296
    • J
      pass config slots as pointers instead of offsets · 8852117a
      Jonathan Nieder 提交于
      Many config-parsing helpers, like parse_branch_color_slot,
      take the name of a config variable and an offset to the
      "slot" name (e.g., "color.branch.plain" is passed along with
      "13" to effectively pass "plain"). This is leftover from the
      time that these functions would die() on error, and would
      want the full variable name for error reporting.
      
      These days they do not use the full variable name at all.
      Passing a single pointer to the slot name is more natural,
      and lets us more easily adjust the callers to use skip_prefix
      to avoid manually writing offset numbers.
      
      This is effectively a continuation of 9e1a5ebe, which did the
      same for parse_diff_color_slot. This patch covers all of the
      remaining similar constructs.
      Signed-off-by: NJonathan Nieder <jrnieder@gmail.com>
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      8852117a
  18. 08 10月, 2014 1 次提交
  19. 02 10月, 2014 3 次提交
  20. 04 9月, 2014 1 次提交
  21. 03 9月, 2014 1 次提交
  22. 30 8月, 2014 2 次提交
    • J
      determine_author_info(): copy getenv output · f4ef5173
      Jeff King 提交于
      When figuring out the author name for a commit, we may end
      up either pointing to const storage from getenv("GIT_AUTHOR_*"),
      or to newly allocated storage based on an existing commit or
      the --author option.
      
      Using const pointers to getenv's return has two problems:
      
        1. It is not guaranteed that the return value from getenv
           remains valid across multiple calls.
      
        2. We do not know whether to free the values at the end,
           so we just leak them.
      
      We can solve both by duplicating the string returned by
      getenv().
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      f4ef5173
    • J
      determine_author_info(): reuse parsing functions · f0f9662a
      Jeff King 提交于
      Rather than parsing the header manually to find the "author"
      field, and then parsing its sub-parts, let's use
      find_commit_header and split_ident_line. This is shorter and
      easier to read, and should do a more careful parsing job.
      
      For example, the current parser could find the end-of-email
      right-bracket across a newline (for a malformed commit), and
      calculate a bogus gigantic length for the date (by using
      "eol - rb").
      
      As a bonus, this also plugs a memory leak when we pull the
      date field from an existing commit (we still leak the name
      and email buffers, which will be fixed in a later commit).
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      f0f9662a
  23. 28 8月, 2014 1 次提交
    • J
      date: use strbufs in date-formatting functions · c33ddc2e
      Jeff King 提交于
      Many of the date functions write into fixed-size buffers.
      This is a minor pain, as we have to take special
      precautions, and frequently end up copying the result into a
      strbuf or heap-allocated buffer anyway (for which we
      sometimes use strcpy!).
      
      Let's instead teach parse_date, datestamp, etc to write to a
      strbuf. The obvious downside is that we might need to
      perform a heap allocation where we otherwise would not need
      to. However, it turns out that the only two new allocations
      required are:
      
        1. In test-date.c, where we don't care about efficiency.
      
        2. In determine_author_info, which is not performance
           critical (and where the use of a strbuf will help later
           refactoring).
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      c33ddc2e
  24. 21 8月, 2014 1 次提交
  25. 13 8月, 2014 1 次提交
  26. 26 7月, 2014 1 次提交
  27. 22 7月, 2014 1 次提交
  28. 18 7月, 2014 1 次提交
  29. 15 7月, 2014 1 次提交
  30. 21 6月, 2014 1 次提交
    • J
      refactor skip_prefix to return a boolean · cf4fff57
      Jeff King 提交于
      The skip_prefix() function returns a pointer to the content
      past the prefix, or NULL if the prefix was not found. While
      this is nice and simple, in practice it makes it hard to use
      for two reasons:
      
        1. When you want to conditionally skip or keep the string
           as-is, you have to introduce a temporary variable.
           For example:
      
             tmp = skip_prefix(buf, "foo");
             if (tmp)
      	       buf = tmp;
      
        2. It is verbose to check the outcome in a conditional, as
           you need extra parentheses to silence compiler
           warnings. For example:
      
             if ((cp = skip_prefix(buf, "foo"))
      	       /* do something with cp */
      
      Both of these make it harder to use for long if-chains, and
      we tend to use starts_with() instead. However, the first line
      of "do something" is often to then skip forward in buf past
      the prefix, either using a magic constant or with an extra
      strlen(3) (which is generally computed at compile time, but
      means we are repeating ourselves).
      
      This patch refactors skip_prefix() to return a simple boolean,
      and to provide the pointer value as an out-parameter. If the
      prefix is not found, the out-parameter is untouched. This
      lets you write:
      
        if (skip_prefix(arg, "foo ", &arg))
      	  do_foo(arg);
        else if (skip_prefix(arg, "bar ", &arg))
      	  do_bar(arg);
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      cf4fff57
  31. 14 6月, 2014 1 次提交