[PATCH 13/15] git-tracker: use write-tree/commit-tree/update-ref

Johannes Berg <[email protected]>
Newsgroups org.kernel.vger.backports
Message-ID <20200221095437.8699e29264b8.I370ee81ce341d4db00a2e5193efe3c697f944121@changeid>
From: Johannes Berg <[email protected]>

This gives us more flexibility, so we can create pretend
merge commits later.

Signed-off-by: Johannes Berg <[email protected]>
---
 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..60d4abaa7a0d 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.