1. 01 9月, 2012 1 次提交
    • J
      split_ident_line(): make best effort when parsing author/committer line · e27ddb64
      Junio C Hamano 提交于
      Commits made by ancient version of Git allowed committer without
      human readable name, like this (00213b17c in the kernel history):
      
          tree 6947dba41f8b0e7fe7bccd41a4840d6de6a27079
          parent 352dd1df32e672be4cff71132eb9c06a257872fe
          author Petr Baudis <pasky@ucw.cz> 1135223044 +0100
          committer  <sam@mars.ravnborg.org> 1136151043 +0100
      
          kconfig: Remove support for lxdialog --checklist
      
          ...
      Signed-off-by: NPetr Baudis <pasky@suse.cz>
      Signed-off-by: NSam Ravnborg <sam@ravnborg.org>
      
      When fed such a commit, --format='%ci' fails to parse it, and gives
      back an empty string.  Update the split_ident_line() to be a bit
      more lenient when parsing, but make sure the caller that wants to
      pick up sane value from its return value does its own validation.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      e27ddb64
  2. 25 5月, 2012 5 次提交
    • J
      ident: reject bogus email addresses with IDENT_STRICT · 8c5b1ae1
      Jeff King 提交于
      If we come up with a hostname like "foo.(none)" because the
      user's machine is not fully qualified, we should reject this
      in strict mode (e.g., when we are making a commit object),
      just as we reject an empty gecos username.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      8c5b1ae1
    • J
      ident: rename IDENT_ERROR_ON_NO_NAME to IDENT_STRICT · f9bc573f
      Jeff King 提交于
      Callers who ask for ERROR_ON_NO_NAME are not so much
      concerned that the name will be blank (because, after all,
      we will fall back to using the username), but rather it is a
      check to make sure that low-quality identities do not end up
      in things like commit messages or emails (whereas it is OK
      for them to end up in things like reflogs).
      
      When future commits add more quality checks on the identity,
      each of these callers would want to use those checks, too.
      Rather than modify each of them later to add a new flag,
      let's refactor the flag.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      f9bc573f
    • J
      ident: let callers omit name with fmt_indent · c15e1987
      Jeff King 提交于
      Most callers want to see all of "$name <$email> $date", but
      a few want only limited parts, omitting the date, or even
      the name. We already have IDENT_NO_DATE to handle the date
      part, but there's not a good option for getting just the
      email. Callers have to done one of:
      
        1. Call ident_default_email; this does not respect
           environment variables, nor does it promise to trim
           whitespace or other crud from the result.
      
        2. Call git_{committer,author}_info; this returns the name
           and email, leaving the caller to parse out the wanted
           bits.
      
      This patch adds IDENT_NO_NAME; it stops short of adding
      IDENT_NO_EMAIL, as no callers want it (nor are likely to),
      and it complicates the error handling of the function.
      
      When no name is requested, the angle brackets (<>) around
      the email address are also omitted.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      c15e1987
    • J
      ident: refactor NO_DATE flag in fmt_ident · 359b27ad
      Jeff King 提交于
      As a short-hand, we extract this flag into the local
      variable "name_addr_only". It's more accurate to simply
      negate this and refer to it as "want_date", which will be
      less confusing when we add more NO_* flags.
      
      While we're touching this part of the code, let's move the
      call to ident_default_date() only when we are actually going
      to use it, not when we have NO_DATE set, or when we get a
      date from the environment.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      359b27ad
    • J
      ident: reword empty ident error message · b00f6cfc
      Jeff King 提交于
      There's on point in printing the name, since it is by
      definition the empty string if we have reached this code
      path. Instead, let's be more clear that we are complaining
      about the empty name, but still show the email address that
      it is attached to (since that may provide some context to
      the user).
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      b00f6cfc
  3. 23 5月, 2012 12 次提交
    • J
      fix off-by-one error in split_ident_line · d9955fd6
      Jeff King 提交于
      Commit 4b340cfa split the logic to parse an ident line out of
      pretty.c's format_person_part. But in doing so, it
      accidentally introduced an off-by-one error that caused it
      to think that single-character names were invalid.
      
      This manifested itself as the "%an" format failing to show
      anything at all for a single-character name.
      Reported-by: NBrian Turner <bturner@atlassian.com>
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      d9955fd6
    • J
      ident: trim whitespace from default name/email · be641abd
      Jeff King 提交于
      Usually these values get fed to fmt_ident, which will trim
      any cruft anyway, but there are a few code paths which use
      them directly. Let's clean them up for the benefit of those
      callers. Furthermore, fmt_ident will look at the pre-trimmed
      value and decide whether to invoke ERROR_ON_NO_NAME; this
      check can be fooled by a name consisting only of spaces.
      
      Note that we only bother to clean up when we are pulling the
      information from gecos or from system files. Any other value
      comes from a config file, where we will have cleaned up
      accidental whitespace already.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      be641abd
    • J
      ident: use a dynamic strbuf in fmt_ident · c96f0c8d
      Jeff King 提交于
      Now that we accept arbitrary-sized names and email
      addresses, the only remaining limit is in the actual
      formatting of the names into a buffer. The current limit is
      1000 characters, which is not likely to be reached, but
      using a strbuf is one less error condition we have to worry
      about.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      c96f0c8d
    • J
      ident: use full dns names to generate email addresses · f8254d32
      Jeff King 提交于
      When we construct an email address from the username and
      hostname, we generate the host part of the email with this
      procedure:
      
        1. add the result of gethostname
      
        2. if it has a dot, ok, it's fully qualified
      
        3. if not, then look up the unqualified hostname via
           gethostbyname; take the domain name of the result and
           append it to the hostname
      
      Step 3 can actually produce a bogus result, as the name
      returned by gethostbyname may not be related to the hostname
      we fed it (e.g., consider a machine "foo" with names
      "foo.one.example.com" and "bar.two.example.com"; we may have
      the latter returned and generate the bogus name
      "foo.two.example.com").
      
      This patch simply uses the full hostname returned by
      gethostbyname. In the common case that the first part is the
      same as the unqualified hostname, the behavior is identical.
      And in the case that it is not the same, we are much more
      likely to be generating a valid name.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      f8254d32
    • J
      ident: report passwd errors with a more friendly message · 2f705875
      Jeff King 提交于
      When getpwuid fails, we give a cute but cryptic message.
      While it makes sense if you know that getpwuid or identity
      functions are being called, this code is triggered behind
      the scenes by quite a few git commands these days (e.g.,
      receive-pack on a remote server might use it for a reflog;
      the current message is hard to distinguish from an
      authentication error).  Let's switch to something that gives
      a little more context.
      
      While we're at it, we can factor out all of the
      cut-and-pastes of the "you don't exist" message into a
      wrapper function. Rather than provide xgetpwuid, let's make
      it even more specific to just getting the passwd entry for
      the current uid. That's the only way we use getpwuid anyway,
      and it lets us make an even more specific error message.
      
      The current message also fails to mention errno. While the
      usual cause for getpwuid failing is that the user does not
      exist, mentioning errno makes it easier to diagnose these
      problems.  Note that POSIX specifies that errno remain
      untouched if the passwd entry does not exist (but will be
      set on actual errors), whereas some systems will return
      ENOENT or similar for a missing entry. We handle both cases
      in our wrapper.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      2f705875
    • J
      drop length limitations on gecos-derived names and emails · 8587ead7
      Jeff King 提交于
      When we pull the user's name from the GECOS field of the
      passwd file (or generate an email address based on their
      username and hostname), we put the result into a
      static buffer. While it's extremely unlikely that anybody
      ever hit these limits (after all, in such a case their
      parents must have hated them), we still had to deal with the
      error cases in our code.
      
      Converting these static buffers to strbufs lets us simplify
      the code and drop some error messages from the documentation
      that have confused some users.
      
      The conversion is mostly mechanical: replace string copies
      with strbuf equivalents, and access the strbuf.buf directly.
      There are a few exceptions:
      
        - copy_gecos and copy_email are the big winners in code
          reduction (since they no longer have to manage the
          string length manually)
      
        - git_ident_config wants to replace old versions of
          the default name (e.g., if we read the config multiple
          times), so it must reset+add to the strbuf instead of
          just adding
      
      Note that there is still one length limitation: the
      gethostname interface requires us to provide a static
      buffer, so we arbitrarily choose 1024 bytes for the
      hostname.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      8587ead7
    • J
      ident: don't write fallback username into git_default_name · 060d4bb3
      Jeff King 提交于
      The fmt_ident function gets a flag that tells us whether to
      die if the name field is blank. If it is blank and we don't
      die, then we fall back to the username from the passwd file.
      
      The current code writes the value into git_default_name.
      However, that's not necessarily correct, as the empty value
      might have come from git_default_name, or it might have been
      passed in.  This leads to two potential problems:
      
        1. If we are overriding an empty name in the passed-in
           value, then we may be overwriting a perfectly good name
           (from gitconfig or gecos) in the git_default_name
           buffer. Later calls to fmt_ident will end up using the
           fallback name, even though a better name was available.
      
        2. If we override an empty gecos name, we end up with the
           fallback name in git_default_name. A later call that
           uses IDENT_ERROR_ON_NO_NAME will see the fallback name
           and think that it is a good name, instead of producing
           an error. In other words, a blank gecos name would
           cause an error with this code:
      
             git_committer_info(IDENT_ERROR_ON_NO_NAME);
      
           but not this:
      
             git_committer_info(0);
             git_committer_info(IDENT_ERROR_ON_NO_NAME);
      
           because in the latter case, the first call has polluted
           the name buffer.
      
      Instead, let's make the fallback a per-invocation variable.
      We can just use the pw->pw_name string directly, since it
      only needs to persist through the rest of the function (and
      we don't do any other getpwent calls).
      
      Note that while this solves (1) for future invocations of
      fmt_indent, the current invocation might use the fallback
      when it could in theory load a better value from
      git_default_name. However, by not passing
      IDENT_ERROR_ON_NO_NAME, the caller is indicating that it
      does not care too much about the name, anyway, so we don't
      bother; this is primarily about protecting future callers
      who do care.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      060d4bb3
    • J
      fmt_ident: drop IDENT_WARN_ON_NO_NAME code · b9f0ac17
      Jeff King 提交于
      There are no more callers who want this, so we can drop it.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      b9f0ac17
    • J
      ident: trim trailing newline from /etc/mailname · 132f4b6c
      Jeff King 提交于
      We use fgets to read the /etc/mailname file, which means we
      will typically end up with an extra newline in our
      git_default_email. Most of the time this doesn't matter, as
      fmt_ident will skip it as cruft, but there is one code path
      that accesses it directly (in http-push.c:lock_remote).
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      132f4b6c
    • J
      move git_default_* variables to ident.c · 2d4b4fce
      Jeff King 提交于
      There's no reason anybody outside of ident.c should access
      these directly (they should use the new accessors which make
      sure the variables are initialized), so we can make them
      file-scope statics.
      
      While we're at it, move user_ident_explicitly_given into
      ident.c; while still globally visible, it makes more sense
      to reside with the ident code.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      2d4b4fce
    • J
      move identity config parsing to ident.c · 9597921b
      Jeff King 提交于
      There's no reason for this to be in config, except that once
      upon a time all of the config parsing was there. It makes
      more sense to keep the ident code together.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      9597921b
    • J
      ident: split setup_ident into separate functions · bcb2b004
      Jeff King 提交于
      This function sets up the default name, email, and date, and
      is not publicly available. Let's split it into three public
      functions so that callers can get just the parts they need.
      
      While we're at it, let's change the interface to simple
      accessors. The original function was called only by fmt_ident,
      and contained logic for "if we already have some other
      value, don't load the default" which properly belongs in
      fmt_ident.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      bcb2b004
  4. 11 3月, 2012 1 次提交
    • J
      ident.c: add split_ident_line() to parse formatted ident line · 4b340cfa
      Junio C Hamano 提交于
      The commit formatting logic format_person_part() in pretty.c
      implements the logic to split an author/committer ident line into
      its parts, intermixed with logic to compute its output using these
      piece it computes.
      
      Separate the former out to a helper function split_ident_line() so
      that other codepath can use the same logic, and rewrite the function
      using the helper function.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      4b340cfa
  5. 07 10月, 2011 1 次提交
    • J
      ident: do not retrieve default ident when unnecessary · d855e4d3
      Jonathan Nieder 提交于
      Avoid a getpwuid() call (which contacts the network if the password
      database is not local), read of /etc/mailname, gethostname() call, and
      reverse DNS lookup if the user has already chosen a name and email
      through configuration, the environment, or the command line.
      
      This should slightly speed up commands like "git commit".  More
      importantly, it improves error reporting when computation of the
      default ident string does not go smoothly.  For example, after
      detecting a problem (e.g., "warning: cannot open /etc/mailname:
      Permission denied") in retrieving the default committer identity:
      
      	touch /etc/mailname;	# as root
      	chmod -r /etc/mailname;	# as root
      	git commit -m 'test commit'
      
      you can squelch the warning while waiting for your sysadmin to fix the
      permissions problem.
      
      	echo '[user] email = me@example.com' >>~/.gitconfig
      Inspired-by: NJohannes Sixt <j6t@kdgb.org>
      Signed-off-by: NJonathan Nieder <jrnieder@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      d855e4d3
  6. 04 10月, 2011 1 次提交
    • J
      ident: check /etc/mailname if email is unknown · 8a55caa8
      Jonathan Nieder 提交于
      Before falling back to gethostname(), check /etc/mailname if
      GIT_AUTHOR_EMAIL is not set in the environment or through config
      files.  Only fall back if /etc/mailname cannot be opened or read.
      
      The /etc/mailname convention comes from Debian policy section 11.6
      ("mail transport, delivery and user agents"), though maybe it could be
      useful sometimes on other machines, too.  The lack of this support was
      noticed by various people in different ways:
      
       - Ian observed that git was choosing the address
         'ian@anarres.relativity.greenend.org.uk' rather than
         'ian@davenant.greenend.org.uk' as it should have done.
      
       - Jonathan noticed that operations like "git commit" were needlessly
         slow when using a resolver that was slow to handle reverse DNS
         lookups.
      
      Alas, after this patch, if /etc/mailname is set up and the [user] name
      and email configuration aren't, the committer email will not provide a
      charming reminder of which machine commits were made on any more.  But
      I think it's worth it.
      
      Mechanics: the functionality of reading mailname goes in its own
      function, so people who care about other distros can easily add an
      implementation to a similar location without making copy_email() too
      long and losing clarity.  While at it, we split out the fallback
      default logic that does gethostname(), too (rearranging it a little
      and adding a check for errors from gethostname while at it).
      
      Based on a patch by Gerrit Pape <pape@smarden.org>.
      Requested-by: NIan Jackson <ijackson@chiark.greenend.org.uk>
      Signed-off-by: NJonathan Nieder <jrnieder@gmail.com>
      Improved-by: NJunio C Hamano <gitster@pobox.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      8a55caa8
  7. 20 5月, 2011 1 次提交
  8. 18 5月, 2011 1 次提交
  9. 21 12月, 2010 1 次提交
    • J
      ident: die on bogus date format · 4579bb41
      Jeff King 提交于
      If the user gives "git commit --date=foobar", we silently
      ignore the --date flag. We should note the error.
      
      This patch puts the fix at the lowest level of fmt_ident,
      which means it also handles GIT_AUTHOR_DATE=foobar, as well.
      
      There are two down-sides to this approach:
      
        1. Technically this breaks somebody doing something like
           "git commit --date=now", which happened to work because
           bogus data is the same as "now". Though we do
           explicitly handle the empty string, so anybody passing
           an empty variable through the environment will still
           work.
      
           If the error is too much, perhaps it can be downgraded
           to a warning?
      
        2. The error checking happens _after_ the commit message
           is written, which can be annoying to the user. We can
           put explicit checks closer to the beginning of
           git-commit, but that feels a little hack-ish; suddenly
           git-commit has to care about how fmt_ident works. Maybe
           we could simply call fmt_ident earlier?
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      4579bb41
  10. 20 1月, 2010 1 次提交
  11. 18 1月, 2010 2 次提交
  12. 11 1月, 2010 2 次提交
  13. 08 1月, 2010 1 次提交
  14. 14 11月, 2009 1 次提交
  15. 03 12月, 2008 1 次提交
    • L
      Add backslash to list of 'crud' characters in real name · d404bf02
      Linus Torvalds 提交于
      We remove crud characters at the beginning and end of real-names so that
      when we see email addresses like
      
      	From: "David S. Miller" <davem@davemloft.net>
      
      we drop the quotes around the name when we parse that and split it up into
      name and email.
      
      However, the list of crud characters was basically just a random list of
      common things that are found around names, and it didn't contain the
      backslash character that some insane scripts seem to use when quoting
      things. So now the kernel has a number of authors listed like
      
      	Author: \"Rafael J. Wysocki\ <rjw@sisk.pl>
      
      because the author name had started out as
      
      	From: \"Rafael J. Wysocki\" <rjw@sisk.pl>
      
      and the only "crud" character we noticed and removed was the final
      double-quote at the end.
      
      We should probably do better quote removal from names anyway, but this is
      the minimal obvious patch.
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      d404bf02
  16. 31 7月, 2008 1 次提交
  17. 07 5月, 2008 1 次提交
  18. 09 3月, 2008 1 次提交
  19. 04 1月, 2008 1 次提交
  20. 09 12月, 2007 1 次提交
    • J
      Re-fix "builtin-commit: fix --signoff" · 774751a8
      Junio C Hamano 提交于
      An earlier fix to the said commit was incomplete; it mixed up the
      meaning of the flag parameter passed to the internal fmt_ident()
      function, so this corrects it.
      
      git_author_info() and git_committer_info() can be told to issue a
      warning when no usable user information is found, and optionally can be
      told to error out.  Operations that actually use the information to
      record a new commit or a tag will still error out, but the caller to
      leave reflog record will just silently use bogus user information.
      
      Not warning on misconfigured user information while writing a reflog
      entry is somewhat debatable, but it is probably nicer to the users to
      silently let it pass, because the only information you are losing is who
      checked out the branch.
      
       * git_author_info() and git_committer_info() used to take 1 (positive
         int) to error out with a warning on misconfiguration; this is now
         signalled with a symbolic constant IDENT_ERROR_ON_NO_NAME.
      
       * These functions used to take -1 (negative int) to warn but continue;
         this is now signalled with a symbolic constant IDENT_WARN_ON_NO_NAME.
      
       * fmt_ident() function implements the above error reporting behaviour
         common to git_author_info() and git_committer_info().  A symbolic
         constant IDENT_NO_DATE can be or'ed in to the flag parameter to make
         it return only the "Name <email@address.xz>".
      
       * fmt_name() is a thin wrapper around fmt_ident() that always passes
         IDENT_ERROR_ON_NO_NAME and IDENT_NO_DATE.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      774751a8
  21. 07 12月, 2007 1 次提交
  22. 05 12月, 2007 1 次提交
  23. 03 12月, 2007 1 次提交