All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johannes Sixt <j.sixt@viscovery.net>
To: Klas Lindberg <klas.lindberg@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: Create a new commit from patches without using any worktree?
Date: Wed, 27 Oct 2010 11:07:54 +0200	[thread overview]
Message-ID: <4CC7EBEA.9070804@viscovery.net> (raw)
In-Reply-To: <AANLkTi=Xi13_0+bC-TVRP3uVDmGWVdM3a708=SSzCR88@mail.gmail.com>

Am 10/27/2010 3:49, schrieb Klas Lindberg:
> Is there any way to record a new commit based on contents in a patch
> without going through a worktree?

This script may be a starter. It takes a commit on the command line
instead of a patch, but it processes that commit as a patch ("diff-tree -p"),
so the script should be easy to adapt.

-- Hannes

-- 8< --
#!/bin/sh

OPTIONS_SPEC="\
git post to-ref [from-rev]
--
"
. git-sh-setup

while test $# != 0
do
	case "$1" in
	--)	shift; break;;
	-*)	usage;;
	*)	break;;
	esac
	shift
done

FROM=$(git rev-parse --verify --symbolic-full-name "$1") || exit
shift
if test $# = 0; then
	set -- HEAD
fi
test $# = 1 || usage

# populate a temporary index
tmpidx=$GIT_DIR/index-post-$$
git read-tree --index-output="$tmpidx" "$FROM" || exit
GIT_INDEX_FILE=$tmpidx
export GIT_INDEX_FILE
trap 'rm -f "$tmpidx"' 0 1 2 15

git diff-tree -p -M -C "$@" | git apply --cached || exit

newtree=$(git write-tree) &&
newrev=$(
	eval "$(get_author_ident_from_commit "$1")"
	git-cat-file commit "$1" | sed -e '1,/^$/d' |
	git commit-tree $newtree -p "$FROM"
) || exit

if git check-ref-format "$FROM"
then
	set_reflog_action post
	subject=$(git log --no-walk --pretty=%s "$newrev") &&
	git update-ref -m "$GIT_REFLOG_ACTION: $subject" "$FROM" $newrev || exit
fi
if test -z "$GIT_QUIET"
then
	git rev-list -1 --oneline $newrev
fi

  parent reply	other threads:[~2010-10-27  9:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-27  1:49 Create a new commit from patches without using any worktree? Klas Lindberg
2010-10-27  2:58 ` Jonathan Nieder
2010-10-27  9:07 ` Johannes Sixt [this message]
2010-10-27 10:28   ` Bert Wesarg
2010-10-27 15:20   ` Klas Lindberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4CC7EBEA.9070804@viscovery.net \
    --to=j.sixt@viscovery.net \
    --cc=git@vger.kernel.org \
    --cc=klas.lindberg@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.