mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2025-12-20 07:12:55 +00:00
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:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user