mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Use git's path stripping when upstreaming patches.
This commit is contained in:
parent
578498ba24
commit
d9baadd3df
2 changed files with 8 additions and 24 deletions
|
@ -69,7 +69,7 @@ class GitTree(wptupdate.tree.GitTree):
|
|||
data = self.git("log", *args)
|
||||
return [self.commit_cls(self, sha1) for sha1 in data.split("\0") if sha1]
|
||||
|
||||
def import_patch(self, patch):
|
||||
def import_patch(self, patch, strip_count):
|
||||
"""Import a patch file into the tree and commit it
|
||||
|
||||
:param patch: a Patch object containing the patch to import
|
||||
|
@ -79,7 +79,7 @@ class GitTree(wptupdate.tree.GitTree):
|
|||
f.write(patch.diff)
|
||||
f.flush()
|
||||
f.seek(0)
|
||||
self.git("apply", "--index", f.name)
|
||||
self.git("apply", "--index", f.name, "-p", str(strip_count))
|
||||
self.git("commit", "-m", patch.message.text, "--author=%s" % patch.full_author)
|
||||
|
||||
def rebase(self, ref, continue_rebase=False):
|
||||
|
|
|
@ -14,32 +14,13 @@ from .github import GitHub
|
|||
|
||||
|
||||
def rewrite_patch(patch, strip_dir):
|
||||
"""Take a Patch and convert to a different repository by stripping a prefix from the
|
||||
file paths. Also rewrite the message to remove the bug number and reviewer, but add
|
||||
"""Take a Patch and rewrite the message to remove the bug number and reviewer, but add
|
||||
a bugzilla link in the summary.
|
||||
|
||||
:param patch: the Patch to convert
|
||||
:param strip_dir: the path prefix to remove
|
||||
"""
|
||||
|
||||
if not strip_dir.startswith("/"):
|
||||
strip_dir = "/%s"% strip_dir
|
||||
|
||||
new_diff = []
|
||||
line_starts = ["diff ", "+++ ", "--- "]
|
||||
for line in patch.diff.split("\n"):
|
||||
for start in line_starts:
|
||||
if line.startswith(start):
|
||||
new_diff.append(line.replace(strip_dir, "").encode("utf8"))
|
||||
break
|
||||
else:
|
||||
new_diff.append(line)
|
||||
|
||||
new_diff = "\n".join(new_diff)
|
||||
|
||||
assert new_diff != patch
|
||||
|
||||
return Patch(patch.author, patch.email, rewrite_message(patch), None, new_diff)
|
||||
return Patch(patch.author, patch.email, rewrite_message(patch), None, patch.diff)
|
||||
|
||||
def rewrite_message(patch):
|
||||
if patch.merge_message and patch.merge_message.bug:
|
||||
|
@ -223,8 +204,11 @@ class MovePatches(Step):
|
|||
self.logger.info("Moving commit %i: %s" % (i, commit.message.full_summary))
|
||||
patch = commit.export_patch(state.tests_path)
|
||||
stripped_patch = rewrite_patch(patch, strip_path)
|
||||
strip_count = strip_path.count('/')
|
||||
if strip_path[-1] != '/':
|
||||
strip_count += 1
|
||||
try:
|
||||
state.sync_tree.import_patch(stripped_patch)
|
||||
state.sync_tree.import_patch(stripped_patch, 1 + strip_count)
|
||||
except:
|
||||
print patch.diff
|
||||
raise
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue