1. 18 2月, 2015 2 次提交
  2. 15 1月, 2015 1 次提交
  3. 14 1月, 2015 1 次提交
  4. 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
  5. 11 11月, 2014 1 次提交
  6. 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
  7. 16 10月, 2014 2 次提交
  8. 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
  9. 08 10月, 2014 1 次提交
  10. 02 10月, 2014 3 次提交
  11. 04 9月, 2014 1 次提交
  12. 03 9月, 2014 1 次提交
  13. 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
  14. 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
  15. 21 8月, 2014 1 次提交
  16. 13 8月, 2014 1 次提交
  17. 26 7月, 2014 1 次提交
  18. 22 7月, 2014 1 次提交
  19. 18 7月, 2014 1 次提交
  20. 15 7月, 2014 1 次提交
  21. 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
  22. 14 6月, 2014 1 次提交
  23. 13 6月, 2014 1 次提交
    • J
      commit_tree: take a pointer/len pair rather than a const strbuf · 3ffefb54
      Jeff King 提交于
      While strbufs are pretty common throughout our code, it is
      more flexible for functions to take a pointer/len pair than
      a strbuf. It's easy to turn a strbuf into such a pair (by
      dereferencing its members), but less easy to go the other
      way (you can strbuf_attach, but that has implications about
      memory ownership).
      
      This patch teaches commit_tree (and its associated callers
      and sub-functions) to take such a pair for the commit
      message rather than a strbuf.  This makes passing the buffer
      around slightly more verbose, but means we can get rid of
      some dangerous strbuf_attach calls in the next patch.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      3ffefb54
  24. 20 5月, 2014 1 次提交
  25. 08 5月, 2014 1 次提交
  26. 03 5月, 2014 3 次提交
    • J
      commit: accept more date formats for "--date" · 14ac2864
      Jeff King 提交于
      Right now we pass off the string found by "--date" straight
      to the fmt_ident function, which will use our strict
      parse_date to normalize it. However, this means obvious
      things like "--date=now" or "--date=2.days.ago" will not
      work.
      
      Instead, let's fallback to the approxidate function to
      handle this for us. Note that we must try parse_date
      ourselves first, even though approxidate will try strict
      parsing itself. The reason is that approxidate throws away
      any timezone information it sees from the strict parsing,
      and we want to preserve it. So asking for:
      
        git commit --date="@1234567890 -0700"
      
      continues to set the date in -0700, regardless of what the
      local timezone is.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      14ac2864
    • J
      commit: print "Date" line when the user has set date · b7242b8c
      Jeff King 提交于
      When we make a commit and the author is not the same as the
      committer (e.g., because you used "-c $commit" or
      "--author=$somebody"), we print the author's name and email
      in both the commit-message template and as part of the
      commit summary. This is a safety check to give the user a
      chance to confirm that we are doing what they expect.
      
      This patch brings the same safety for the "date" field,
      which may be set by "-c" or by using "--date".  Note that we
      explicitly do not set it for $GIT_AUTHOR_DATE, as it is
      probably not of interest when "git commit" is being fed its
      parameters by a script.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      b7242b8c
    • J
      commit: use split_ident_line to compare author/committer · 47010263
      Jeff King 提交于
      Instead of string-wise comparing the author/committer lines
      with their timestamps truncated, we can use split_ident_line
      and ident_cmp. These functions are more robust than our
      ad-hoc parsing, though in practice it should not matter, as
      we just generated these ident lines ourselves.
      
      However, this will also allow us easy access to the
      timestamp and tz fields in future patches.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      47010263
  27. 29 4月, 2014 1 次提交
    • J
      commit: do not complain of empty messages from -C · 076cbd63
      Jeff King 提交于
      When we pick another commit's message, we die() immediately
      if we find that it's empty and we are not going to run an
      editor (i.e., when running "-C" instead of "-c").  However,
      this check is redundant and harmful.
      
      It's redundant because we will already notice the empty
      message later, after we would have run the editor, and die
      there (just as we would for a regular, not "-C" case, where
      the user provided an empty message in the editor).
      
      It's harmful for a few reasons:
      
        1. It does not respect --allow-empty-message. As a result,
           a "git rebase -i" cannot "pick" such a commit. So you
           cannot even go back in time to fix it with a "reword"
           or "edit" instruction.
      
        2. It does not take into account other ways besides the
           editor to modify the message. For example, "git commit
           -C empty-commit -m foo" could take the author
           information from empty-commit, but add a message to it.
           There's more to do to make that work correctly (and
           right now we explicitly forbid "-C with -m"), but this
           removes one roadblock.
      
        3. The existing check is not enough to prevent segfaults.
           We try to find the "\n\n" header/body boundary in the
           commit. If it is at the end of the string (i.e., no
           body), _or_ if we cannot find it at all (i.e., a
           truncated commit object), we consider the message
           empty. With "-C", that's OK; we die in either case. But
           with "-c", we continue on, and in the case of a
           truncated commit may end up dereferencing NULL+2.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      076cbd63
  28. 18 4月, 2014 1 次提交
  29. 08 4月, 2014 1 次提交
    • J
      commit -m: commit staged submodules regardless of ignore config · c215d3d2
      Jens Lehmann 提交于
      The previous commit fixed the problem that the staged but that ignored
      submodules did not show up in the status output of the commit command and
      weren't committed afterwards either. But when commit doesn't generate the
      status output (e.g. when used in a script with '-m') the ignored submodule
      will still not be committed. This is because in that case a different code
      path is taken which calls index_differs_from() instead of calling the
      wt_status functions.
      
      Fix that by calling index_differs_from() from builtin/commit.c with a
      diff_options argument value that tells it not ignore any submodule changes
      unless the '--ignore-submodules' option is used. Even though this option
      isn't yet implemented for cmd_commit() but only for cmd_status() this
      prepares cmd_commit() to correctly handle the '--ignore-submodules' option
      later. As status and commit share the same ignore_submodule_arg variable
      this makes the code more robust against accidental breakage and documents
      how to correctly call index_differs_from().
      
      Change the expected result of the test documenting this problem from
      failure to success.
      Signed-off-by: NJens Lehmann <Jens.Lehmann@web.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      c215d3d2
  30. 01 4月, 2014 1 次提交