1. 05 8月, 2015 38 次提交
    • P
      builtin-am: support and auto-detect mercurial patches · 94cd175c
      Paul Tan 提交于
      Since 0cfd1120 (am: preliminary support for hg patches, 2011-08-29),
      git-am.sh could convert mercurial patches to an RFC2822 mail patch
      suitable for parsing with git-mailinfo, and queue them in the state
      directory for application.
      
      Since 15ced753 (git-am foreign patch support: autodetect some patch
      formats, 2009-05-27), git-am.sh was able to auto-detect mercurial
      patches by checking if the file begins with the line:
      
      	# HG changeset patch
      
      Re-implement the above in builtin/am.c.
      Helped-by: NStefan Beller <sbeller@google.com>
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      94cd175c
    • P
      builtin-am: support and auto-detect StGit series files · 336108c1
      Paul Tan 提交于
      Since c574e683 (git-am foreign patch support: StGIT support, 2009-05-27),
      git-am.sh is able to read a single StGit series file and, for each StGit
      patch listed in the file, convert the StGit patch into a RFC2822 mail
      patch suitable for parsing with git-mailinfo, and queue them in the
      state directory for applying.
      
      Since 15ced753 (git-am foreign patch support: autodetect some patch
      formats, 2009-05-27), git-am.sh is able to auto-detect StGit series
      files by checking to see if the file starts with the string:
      
      	# This series applies on GIT commit
      
      Re-implement the above in builtin/am.c.
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      336108c1
    • P
      builtin-am: support and auto-detect StGit patches · 5ae41c79
      Paul Tan 提交于
      Since c574e683 (git-am foreign patch support: StGIT support, 2009-05-27),
      git-am.sh supported converting StGit patches into RFC2822 mail patches
      that can be parsed with git-mailinfo.
      
      Implement this by introducing two functions in builtin/am.c:
      stgit_patch_to_mail() and split_mail_conv().
      
      stgit_patch_to_mail() is a callback function for split_mail_conv(), and
      contains the logic for converting an StGit patch into an RFC2822 mail
      patch.
      
      split_mail_conv() implements the logic to go through each file in the
      `paths` list, reading from stdin where specified, and calls the callback
      function to write the converted patch to the corresponding output file
      in the state directory. This interface should be generic enough to
      support other foreign patch formats in the future.
      
      Since 15ced753 (git-am foreign patch support: autodetect some patch
      formats, 2009-05-27), git-am.sh is able to auto-detect StGit patches.
      Re-implement this in builtin/am.c.
      Helped-by: NEric Sunshine <sunshine@sunshineco.com>
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      5ae41c79
    • P
      builtin-am: rerere support · f1cb96d6
      Paul Tan 提交于
      git-am.sh will call git-rerere at the following events:
      
      * "git rerere" when a three-way merge fails to record the conflicted
        automerge results. Since 8389b52b (git-rerere: reuse recorded resolve.,
        2006-01-28)
      
        * Since cb6020bb (Teach --[no-]rerere-autoupdate option to merge,
          revert and friends, 2009-12-04), git-am.sh supports the
          --[no-]rerere-autoupdate option as well, and would pass it to
          git-rerere.
      
      * "git rerere" when --resolved, to record the hand resolution. Since
        f131dd49 (rerere: record (or avoid misrecording) resolved, skipped or
        aborted rebase/am, 2006-12-08)
      
      * "git rerere clear" when --skip-ing. Since f131dd49 (rerere: record (or
        avoid misrecording) resolved, skipped or aborted rebase/am,
        2006-12-08)
      
      * "git rerere clear" when --abort-ing. Since 3e5057a8 (git am --abort,
        2008-07-16)
      
      Re-implement the above in builtin/am.c.
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      f1cb96d6
    • P
      builtin-am: invoke post-applypatch hook · 7088f807
      Paul Tan 提交于
      Since d1c5f2a4 (Add git-am, applymbox replacement., 2005-10-07),
      git-am.sh will invoke the post-applypatch hook after the patch is
      applied and a commit is made. The exit code of the hook is ignored.
      
      Re-implement this in builtin/am.c.
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      7088f807
    • P
      builtin-am: invoke pre-applypatch hook · 6c24c5c0
      Paul Tan 提交于
      Since d1c5f2a4 (Add git-am, applymbox replacement., 2005-10-07),
      git-am.sg will invoke the pre-applypatch hook after applying the patch
      to the index, but before a commit is made. Should the hook exit with a
      non-zero status, git am will exit.
      
      Re-implement this in builtin/am.c.
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      6c24c5c0
    • P
      builtin-am: invoke applypatch-msg hook · b8803d8f
      Paul Tan 提交于
      Since d1c5f2a4 (Add git-am, applymbox replacement., 2005-10-07),
      git-am.sh will invoke the applypatch-msg hooks just after extracting the
      patch message. If the applypatch-msg hook exits with a non-zero status,
      git-am.sh abort before even applying the patch to the index.
      
      Re-implement this in builtin/am.c.
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      b8803d8f
    • P
      builtin-am: support automatic notes copying · 88b291fe
      Paul Tan 提交于
      Since eb2151bb (rebase: support automatic notes copying, 2010-03-12),
      git-am.sh supported automatic notes copying in --rebasing mode by
      invoking "git notes copy" once it has finished applying all the patches.
      
      Re-implement this feature in builtin/am.c.
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      88b291fe
    • P
      builtin-am: invoke post-rewrite hook · 13b97ea5
      Paul Tan 提交于
      Since 96e19488 (rebase: invoke post-rewrite hook, 2010-03-12), git-am.sh
      will invoke the post-rewrite hook after it successfully finishes
      applying all the queued patches.
      
      To do this, when parsing a mail to extract its patch and metadata, in
      --rebasing mode git-am.sh will also store the original commit ID in the
      $state_dir/original-commit file. Once it applies and commits the patch,
      the original commit ID, and the new commit ID, will be appended to the
      $state_dir/rewritten file.
      
      Once all of the queued mail have been processed, git-am.sh will then
      invoke the post-rewrite hook with the contents of the
      $state_dir/rewritten file.
      
      Re-implement this in builtin/am.c.
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      13b97ea5
    • P
      builtin-am: implement -S/--gpg-sign, commit.gpgsign · 7e35dacb
      Paul Tan 提交于
      Since 3b4e395f (am: add the --gpg-sign option, 2014-02-01), git-am.sh
      supported the --gpg-sign option, and would pass it to git-commit-tree,
      thus GPG-signing the commit object.
      
      Re-implement this option in builtin/am.c.
      
      git-commit-tree would also sign the commit by default if the
      commit.gpgsign setting is true. Since we do not run commit-tree, we
      re-implement this behavior by handling the commit.gpgsign setting
      ourselves.
      Helped-by: NStefan Beller <sbeller@google.com>
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      7e35dacb
    • P
      builtin-am: implement --committer-date-is-author-date · 0cd4bcba
      Paul Tan 提交于
      Since 3f01ad66 (am: Add --committer-date-is-author-date option,
      2009-01-22), git-am.sh implemented the --committer-date-is-author-date
      option, which tells git-am to use the timestamp recorded in the email
      message as both author and committer date.
      
      Re-implement this option in builtin/am.c.
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      0cd4bcba
    • P
      builtin-am: implement --ignore-date · f07adb62
      Paul Tan 提交于
      Since a79ec62d (git-am: Add --ignore-date option, 2009-01-24), git-am.sh
      supported the --ignore-date option, and would use the current timestamp
      instead of the one provided in the patch if the option was set.
      
      Re-implement this option in builtin/am.c.
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      f07adb62
    • P
      builtin-am: pass git-apply's options to git-apply · 257e8cec
      Paul Tan 提交于
      git-am.sh recognizes some of git-apply's options, and would pass them to
      git-apply:
      
      * --whitespace, since 8c31cb82 (git-am: --whitespace=x option.,
        2006-02-28)
      
      * -C, since 67dad687 (add -C[NUM] to git-am, 2007-02-08)
      
      * -p, since 2092a1fe (Teach git-am to pass -p option down to git-apply,
        2007-02-11)
      
      * --directory, since b47dfe9e (git-am: add --directory=<dir> option,
        2009-01-11)
      
      * --reject, since b80da424 (git-am: implement --reject option passed to
        git-apply, 2009-01-23)
      
      * --ignore-space-change, --ignore-whitespace, since 86c91f91 (git apply:
        option to ignore whitespace differences, 2009-08-04)
      
      * --exclude, since 77e9e496 (am: pass exclude down to apply, 2011-08-03)
      
      * --include, since 58725efd (am: support --include option, 2012-03-28)
      
      * --reject, since b80da424 (git-am: implement --reject option passed to
        git-apply, 2009-01-23)
      
      Re-implement support for these options in builtin/am.c.
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      257e8cec
    • P
      builtin-am: implement --[no-]scissors · 9b646617
      Paul Tan 提交于
      Since 017678b4 (am/mailinfo: Disable scissors processing by default,
      2009-08-26), git-am supported the --[no-]scissors option, passing it to
      git-mailinfo.
      
      Re-implement support for this option in builtin/am.c.
      
      Since the default setting of --scissors in git-mailinfo can be
      configured with mailinfo.scissors (and perhaps through other settings in
      the future), to be safe we make an explicit distinction between
      SCISSORS_UNSET, SCISSORS_TRUE and SCISSORS_FALSE.
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      9b646617
    • P
      builtin-am: support --keep-cr, am.keepcr · 5d123a40
      Paul Tan 提交于
      Since ad2c9280 (git-am: Add command line parameter `--keep-cr` passing it
      to git-mailsplit, 2010-02-27), git-am.sh supported the --keep-cr option
      and would pass it to git-mailsplit.
      
      Since e80d4cbe (git-am: Add am.keepcr and --no-keep-cr to override it,
      2010-02-27), git-am.sh supported the am.keepcr config setting, which
      controls whether --keep-cr is on by default.
      
      Re-implement the above in builtin/am.c.
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      5d123a40
    • P
      builtin-am: implement --[no-]message-id, am.messageid · 702cbaad
      Paul Tan 提交于
      Since a078f732 (git-am: add --message-id/--no-message-id, 2014-11-25),
      git-am.sh supported the --[no-]message-id options, and the
      "am.messageid" setting which specifies the default option.
      
      --[no-]message-id tells git-am whether or not the -m option should be
      passed to git-mailinfo.
      
      Re-implement this option in builtin/am.c.
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      702cbaad
    • P
      builtin-am: implement -k/--keep, --keep-non-patch · 4f1b6961
      Paul Tan 提交于
      Since d1c5f2a4 (Add git-am, applymbox replacement., 2005-10-07),
      git-am.sh supported the -k/--keep option to pass the -k option to
      git-mailsplit.
      
      Since f7e5ea17 (am: learn passing -b to mailinfo, 2012-01-16), git-am.sh
      supported the --keep-non-patch option to pass the -b option to
      git-mailsplit.
      
      Re-implement these two options in builtin/am.c.
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      4f1b6961
    • P
      builtin-am: implement -u/--utf8 · ef7ee16d
      Paul Tan 提交于
      Since d1c5f2a4 (Add git-am, applymbox replacement., 2005-10-07),
      git-am.sh supported the -u,--utf8 option. If set, the -u option will be
      passed to git-mailinfo to re-code the commit log message and authorship
      in the charset specified by i18n.commitencoding. If unset, the -n option
      will be passed to git-mailinfo, which disables the re-encoding.
      
      Since d84029b6 (--utf8 is now default for 'git-am', 2007-01-08), --utf8
      is specified by default in git-am.sh.
      
      Re-implement the above in builtin/am.c.
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      ef7ee16d
    • P
      builtin-am: handle stray state directory · 6d42ac29
      Paul Tan 提交于
      Should git-am terminate unexpectedly between the point where the state
      directory is created, but the "next" and "last" files are not written
      yet, a stray state directory will be left behind.
      
      As such, since b141f3c9 (am: handle stray $dotest directory, 2013-06-15),
      git-am.sh explicitly recognizes such a stray directory, and allows the
      user to remove it with am --abort.
      
      Re-implement this feature in builtin/am.c.
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      6d42ac29
    • P
      builtin-am: bypass git-mailinfo when --rebasing · df2760a5
      Paul Tan 提交于
      Since 5e835cac (rebase: do not munge commit log message, 2008-04-16),
      git am --rebasing no longer gets the commit log message from the patch,
      but reads it directly from the commit identified by the "From " header
      line.
      
      Since 43c23251 (am: use get_author_ident_from_commit instead of mailinfo
      when rebasing, 2010-06-16), git am --rebasing also gets the author name,
      email and date directly from the commit.
      
      Since 0fbb95dc (am: don't call mailinfo if $rebasing, 2012-06-26), git am
      --rebasing does not use git-mailinfo to get the patch body, but rather
      generates it directly from the commit itself.
      
      The above 3 commits introduced a separate parse_mail() code path in
      git-am.sh's --rebasing mode that bypasses git-mailinfo. Re-implement
      this code path in builtin/am.c as parse_mail_rebase().
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      df2760a5
    • P
      builtin-am: implement --rebasing mode · 35bdcc59
      Paul Tan 提交于
      Since 3041c324 (am: --rebasing, 2008-03-04), git-am.sh supported the
      --rebasing option, which is used internally by git-rebase to tell git-am
      that it is being used for its purpose. It would create the empty file
      $state_dir/rebasing to help "completion" scripts tell if the ongoing
      operation is am or rebase.
      
      As of 0fbb95dc (am: don't call mailinfo if $rebasing, 2012-06-26),
      --rebasing also implies --3way as well.
      
      Since a1549e10 (am: return control to caller, for housekeeping,
      2013-05-12), git-am.sh would only clean up the state directory when it
      is not --rebasing, instead deferring cleanup to git-rebase.sh.
      
      Re-implement the above in builtin/am.c.
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      35bdcc59
    • P
      builtin-am: implement --3way · 84f3de28
      Paul Tan 提交于
      Since d1c5f2a4 (Add git-am, applymbox replacement., 2005-10-07),
      git-am.sh supported the --3way option, and if set, would attempt to do a
      3-way merge if the initial patch application fails.
      
      Since 5d86861c (am -3: list the paths that needed 3-way fallback,
      2012-03-28), in a 3-way merge git-am.sh would list the paths that needed
      3-way fallback, so that the user can review them more carefully to spot
      mismerges.
      
      Re-implement the above in builtin/am.c.
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      84f3de28
    • P
      builtin-am: implement -s/--signoff · eb898b83
      Paul Tan 提交于
      Since d1c5f2a4 (Add git-am, applymbox replacement., 2005-10-07), git-am
      supported the --signoff option which will append a signoff at the end of
      the commit messsage. Re-implement this feature in parse_mail() by
      calling append_signoff() if the option is set.
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      eb898b83
    • P
      builtin-am: exit with user friendly message on failure · 2d83109a
      Paul Tan 提交于
      Since ced9456a (Give the user a hint for how to continue in the case that
      git-am fails because it requires user intervention, 2006-05-02), git-am
      prints additional information on how the user can re-invoke git-am to
      resume patch application after resolving the failure. Re-implement this
      through the die_user_resolve() function.
      
      Since cc120056 (Make git rebase interactive help match documentation.,
      2006-05-13), git-am supports the --resolvemsg option which is used by
      git-rebase to override the message printed out when git-am fails.
      Re-implement this option.
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      2d83109a
    • P
      builtin-am: implement -q/--quiet · 5d28cf78
      Paul Tan 提交于
      Since 0e987a12 (am, rebase: teach quiet option, 2009-06-16), git-am
      supported the --quiet option, and when told to be quiet, would only
      speak on failure. Re-implement this by introducing the say() function,
      which works like fprintf_ln(), but would only write to the stream when
      state->quiet is false.
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      5d28cf78
    • P
      builtin-am: reject patches when there's a session in progress · 8d185503
      Paul Tan 提交于
      Since d1c5f2a4 (Add git-am, applymbox replacement., 2005-10-07), git-am
      would error out if the user gave it mbox(s) on the command-line, but
      there was a session in progress.
      
      Since c95b1389 (Fix git-am safety checks, 2006-09-15), git-am would
      detect if the user attempted to feed it a mbox via stdin, by checking if
      stdin is not a tty and there is no resume command given.
      
      Re-implement the above two safety checks.
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      8d185503
    • P
      builtin-am: implement --abort · 33388a71
      Paul Tan 提交于
      Since 3e5057a8 (git am --abort, 2008-07-16), git-am supported the --abort
      option that will rewind HEAD back to the original commit. Re-implement
      this through am_abort().
      
      Since 7b3b7e37 (am --abort: keep unrelated commits since the last failure
      and warn, 2010-12-21), to prevent commits made since the last failure
      from being lost, git-am will not rewind HEAD back to the original
      commit if HEAD moved since the last failure. Re-implement this through
      safe_to_abort().
      Helped-by: NStefan Beller <sbeller@google.com>
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      33388a71
    • P
      builtin-am: implement --skip · 9990080c
      Paul Tan 提交于
      Since d1c5f2a4 (Add git-am, applymbox replacement., 2005-10-07), git-am
      supported resuming from a failed patch application by skipping the
      current patch. Re-implement this feature by introducing am_skip().
      Helped-by: NStefan Beller <sbeller@google.com>
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      9990080c
    • P
      builtin-am: don't parse mail when resuming · 8c7b1563
      Paul Tan 提交于
      Since 271440e3 (git-am: make it easier after fixing up an unapplicable
      patch., 2005-10-25), when "git am" is run again after being paused, the
      current mail message will not be re-parsed, but instead the contents of
      the state directory's patch, msg and author-script files will be used
      as-is instead.
      
      Re-implement this in builtin/am.c.
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      8c7b1563
    • P
      builtin-am: implement --resolved/--continue · 240bfd2d
      Paul Tan 提交于
      Since 0c15cc92 (git-am: --resolved., 2005-11-16), git-am supported
      resuming from a failed patch application. The user will manually apply
      the patch, and the run git am --resolved which will then commit the
      resulting index. Re-implement this feature by introducing am_resolve().
      
      Since it makes no sense for the user to run am --resolved when there is
      no session in progress, we error out in this case.
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      240bfd2d
    • P
      builtin-am: refuse to apply patches if index is dirty · 32a5fcbf
      Paul Tan 提交于
      Since d1c5f2a4 (Add git-am, applymbox replacement., 2005-10-07), git-am
      will refuse to apply patches if the index is dirty. Re-implement this
      behavior in builtin/am.c.
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      32a5fcbf
    • P
      builtin-am: implement committing applied patch · c9e8d960
      Paul Tan 提交于
      Implement do_commit(), which commits the index which contains the
      results of applying the patch, along with the extracted commit message
      and authorship information.
      
      Since 29b67543 (am: remove rebase-apply directory before gc, 2010-02-22),
      git gc --auto is also invoked to pack the loose objects that are created
      from making the commits.
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      c9e8d960
    • P
      builtin-am: apply patch with git-apply · 38a824fe
      Paul Tan 提交于
      Implement applying the patch to the index using git-apply.
      
      If a file is unchanged but stat-dirty, git-apply may erroneously fail to
      apply patches, thinking that they conflict with a dirty working tree.
      
      As such, since 2a6f08ac (am: refresh the index at start and --resolved,
      2011-08-15), git-am will refresh the index before applying patches.
      Re-implement this behavior.
      Helped-by: NJunio C Hamano <gitster@pobox.com>
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      38a824fe
    • P
      builtin-am: extract patch and commit info with git-mailinfo · 3e20dcf3
      Paul Tan 提交于
      For the purpose of applying the patch and committing the results,
      implement extracting the patch data, commit message and authorship from
      an e-mail message using git-mailinfo.
      
      git-mailinfo is run as a separate process, but ideally in the future,
      we should be be able to access its functionality directly without
      spawning a new process.
      Helped-by: NJunio C Hamano <gitster@pobox.com>
      Helped-by: NJeff King <peff@peff.net>
      Helped-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      3e20dcf3
    • P
      builtin-am: auto-detect mbox patches · c29807b2
      Paul Tan 提交于
      Since 15ced753 (git-am foreign patch support: autodetect some patch
      formats, 2009-05-27), git-am.sh is able to autodetect mbox, stgit and
      mercurial patches through heuristics.
      
      Re-implement support for autodetecting mbox/maildir files in
      builtin/am.c.
      
      RFC 2822 requires that lines are terminated by "\r\n". To support this,
      implement strbuf_getline_crlf(), which will remove both '\n' and "\r\n"
      from the end of the line.
      Helped-by: NJunio C Hamano <gitster@pobox.com>
      Helped-by: NEric Sunshine <sunshine@sunshineco.com>
      Helped-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      c29807b2
    • P
      builtin-am: split out mbox/maildir patches with git-mailsplit · 11c2177f
      Paul Tan 提交于
      git-am.sh supports mbox, stgit and mercurial patches. Re-implement
      support for splitting out mbox/maildirs using git-mailsplit, while also
      implementing the framework required to support other patch formats in
      the future.
      
      Re-implement support for the --patch-format option (since a5a6755a
      (git-am foreign patch support: introduce patch_format, 2009-05-27)) to
      allow the user to choose between the different patch formats.
      Helped-by: NJunio C Hamano <gitster@pobox.com>
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      11c2177f
    • P
      builtin-am: implement patch queue mechanism · 8c3bd9e2
      Paul Tan 提交于
      git-am applies a series of patches. If the process terminates
      abnormally, we want to be able to resume applying the series of patches.
      This requires the session state to be saved in a persistent location.
      
      Implement the mechanism of a "patch queue", represented by 2 integers --
      the index of the current patch we are applying and the index of the last
      patch, as well as its lifecycle through the following functions:
      
      * am_setup(), which will set up the state directory
        $GIT_DIR/rebase-apply. As such, even if the process exits abnormally,
        the last-known state will still persist.
      
      * am_load(), which is called if there is an am session in
        progress, to load the last known state from the state directory so we
        can resume applying patches.
      
      * am_run(), which will do the actual patch application. After applying a
        patch, it calls am_next() to increment the current patch index. The
        logic for applying and committing a patch is not implemented yet.
      
      * am_destroy(), which is finally called when we successfully applied all
        the patches in the queue, to clean up by removing the state directory
        and its contents.
      Helped-by: NJunio C Hamano <gitster@pobox.com>
      Helped-by: NStefan Beller <sbeller@google.com>
      Helped-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      8c3bd9e2
    • P
      builtin-am: implement skeletal builtin am · 73c2779f
      Paul Tan 提交于
      For the purpose of rewriting git-am.sh into a C builtin, implement a
      skeletal builtin/am.c that redirects to $GIT_EXEC_PATH/git-am if the
      environment variable _GIT_USE_BUILTIN_AM is not defined. Since in the
      Makefile git-am.sh takes precedence over builtin/am.c,
      $GIT_EXEC_PATH/git-am will contain the shell script git-am.sh, and thus
      this allows us to fall back on the functional git-am.sh when running the
      test suite for tests that depend on a working git-am implementation.
      
      Since git-am.sh cannot handle any environment modifications by
      setup_git_directory(), "am" is declared with no setup flags in git.c. On
      the other hand, to re-implement git-am.sh in builtin/am.c, we need to
      run all the git dir and work tree setup logic that git.c typically does
      for us. As such, we work around this temporarily by copying the logic in
      git.c's run_builtin(), which is roughly:
      
      	prefix = setup_git_directory();
      	trace_repo_setup(prefix);
      	setup_work_tree();
      
      This redirection should be removed when all the features of git-am.sh
      have been re-implemented in builtin/am.c.
      Helped-by: NJunio C Hamano <gitster@pobox.com>
      Signed-off-by: NPaul Tan <pyokagan@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      73c2779f