Updates tools to include mapmerge hooks and merge drivers, plus more (#18034)

* bumps tools to modern versions, adds DMM merge driver hooks for automatic map merging

* mapping guidelines update

* Update .github/CONTRIBUTING.md

Co-authored-by: AffectedArc07 <25063394+AffectedArc07@users.noreply.github.com>

* aa review

* these somehow got ignored? force adding

* Apply suggestions from code review

Co-authored-by: AffectedArc07 <25063394+AffectedArc07@users.noreply.github.com>
This commit is contained in:
S34N
2022-06-21 23:53:19 +01:00
committed by GitHub
parent 727b299d33
commit 4f5c3376e3
53 changed files with 1089 additions and 2465 deletions

View File

@@ -1,10 +1,10 @@
#!/usr/bin/env python3
import os
import pygit2
import dmm
from mapmerge import merge_map
import os, sys, pygit2
from . import dmm
from .mapmerge import merge_map
def main(repo):
def main(repo, *, use_workdir=False):
if repo.index.conflicts:
print("You need to resolve merge conflicts first.")
return 1
@@ -16,12 +16,21 @@ def main(repo):
except KeyError:
pass
target_statuses = pygit2.GIT_STATUS_INDEX_MODIFIED | pygit2.GIT_STATUS_INDEX_NEW
skip_to_file_statuses = pygit2.GIT_STATUS_WT_DELETED | pygit2.GIT_STATUS_WT_MODIFIED
if use_workdir:
target_statuses |= pygit2.GIT_STATUS_WT_MODIFIED | pygit2.GIT_STATUS_WT_NEW
skip_to_file_statuses &= ~pygit2.GIT_STATUS_WT_MODIFIED
changed = 0
for path, status in repo.status().items():
if path.endswith(".dmm") and (status & (pygit2.GIT_STATUS_INDEX_MODIFIED | pygit2.GIT_STATUS_INDEX_NEW)):
if path.endswith(".dmm") and (status & target_statuses):
# read the index
index_entry = repo.index[path]
index_map = dmm.DMM.from_bytes(repo[index_entry.id].read_raw())
if use_workdir:
index_map = dmm.DMM.from_file(os.path.join(repo.workdir, path))
else:
index_map = dmm.DMM.from_bytes(repo[index_entry.id].read_raw())
try:
head_blob = repo[repo[repo.head.target].tree[path].id]
@@ -32,7 +41,7 @@ def main(repo):
merged_map = index_map
else:
# Entry in HEAD, merge the index over it
print(f"Merging map: {path}", flush=True)
print(f"Converting map: {path}", flush=True)
assert not (status & pygit2.GIT_STATUS_INDEX_NEW)
head_map = dmm.DMM.from_bytes(head_blob.read_raw())
merged_map = merge_map(index_map, head_map)
@@ -43,15 +52,16 @@ def main(repo):
changed += 1
# write to the working directory if that's clean
if status & (pygit2.GIT_STATUS_WT_DELETED | pygit2.GIT_STATUS_WT_MODIFIED):
if status & skip_to_file_statuses:
print(f"Warning: {path} has unindexed changes, not overwriting them")
else:
merged_map.to_file(os.path.join(repo.workdir, path))
if changed:
repo.index.write()
print(f"Merged {changed} maps.")
return 0
if __name__ == '__main__':
exit(main(pygit2.Repository(pygit2.discover_repository(os.getcwd()))))
repo = pygit2.Repository(pygit2.discover_repository(os.getcwd()))
exit(main(repo, use_workdir='--use-workdir' in sys.argv))