From: Johannes Berg <johannes@sipsolutions.net>
To: backports@vger.kernel.org
Cc: Johannes Berg <johannes.berg@intel.com>
Subject: [PATCH v2] git-tracker: use write-tree/commit-tree/update-ref
Date: Fri, 21 Feb 2020 10:07:50 +0100 [thread overview]
Message-ID: <20200221100750.61538df8b501.I370ee81ce341d4db00a2e5193efe3c697f944121@changeid> (raw)
From: Johannes Berg <johannes.berg@intel.com>
This gives us more flexibility, so we can create pretend
merge commits later.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
v2:
* use -F - (two arguments) instead of -F- to make it
compatible with ancient git
---
devel/git-tracker.py | 4 +++-
lib/bpgit.py | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/devel/git-tracker.py b/devel/git-tracker.py
index 1cb26ec82eb0..7e55fa5ccb8e 100755
--- a/devel/git-tracker.py
+++ b/devel/git-tracker.py
@@ -104,6 +104,7 @@ def handle_commit(args, msg, branch, treename, kernelobjdir, tmpdir, wgitdir, ba
else:
git.reset(opts=['-q'], tree=wdir)
+ parents = [git.rev_parse('HEAD', tree=wdir)]
if not failure or commit_failure:
if append_shortlog:
files = []
@@ -136,7 +137,8 @@ def handle_commit(args, msg, branch, treename, kernelobjdir, tmpdir, wgitdir, ba
if not have_changeid:
msg += 'Change-Id: I%s\n' % hashlib.sha1(msg).hexdigest()
- git.commit(msg, tree=wdir, env=env, opts=['-q', '--allow-empty'])
+ treeid = git.write_tree(tree=wdir)
+ git.commit_tree(treeid, msg, parents, tree=wdir, env=env)
git.push(opts=['-f', '-q', 'origin', branch], tree=wdir)
os.rename(os.path.join(wdir, '.git'), wgitdir)
finally:
diff --git a/lib/bpgit.py b/lib/bpgit.py
index ff5f4a0c95b3..c80647465778 100644
--- a/lib/bpgit.py
+++ b/lib/bpgit.py
@@ -255,6 +255,40 @@ def add(fn, tree=None):
process.wait()
_check(process)
+def write_tree(tree=None):
+ process = subprocess.Popen(['git', 'write-tree'], stdout=subprocess.PIPE,
+ close_fds=True, universal_newlines=True, cwd=tree)
+ stdout = process.communicate()[0]
+ process.wait()
+ _check(process)
+ sha = stdout.strip()
+ if not _sha_re.match(sha):
+ raise SHAError()
+ return sha
+
+def commit_tree(treeid, msg, parents, env=None, tree=None):
+ if env is None:
+ env = {}
+ opts = []
+ for p in parents:
+ opts.extend(['-p', p])
+ stdin = tempfile.NamedTemporaryFile(mode='wr')
+ stdin.write(msg)
+ stdin.seek(0)
+ process = subprocess.Popen(['git', 'commit-tree', '-F', '-', treeid] + opts,
+ stdin=stdin.file, universal_newlines=True,
+ stdout=subprocess.PIPE, env=env, cwd=tree)
+ stdout = process.communicate()[0]
+ process.wait()
+ _check(process)
+ sha = stdout.strip()
+ if not _sha_re.match(sha):
+ raise SHAError()
+ process = subprocess.Popen(['git', 'update-ref', 'HEAD', sha], cwd=tree)
+ process.wait()
+ _check(process)
+ return sha
+
def commit(msg, tree=None, env = {}, opts=[]):
stdin = tempfile.NamedTemporaryFile(mode='wr')
stdin.write(msg)
--
2.24.1
--
To unsubscribe from this list: send the line "unsubscribe backports" in
reply other threads:[~2020-02-21 9:07 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20200221100750.61538df8b501.I370ee81ce341d4db00a2e5193efe3c697f944121@changeid \
--to=johannes@sipsolutions.net \
--cc=backports@vger.kernel.org \
--cc=johannes.berg@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).