@@ -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:
@@ -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)