okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
5af104b51
main
1# merge_sel.py BASE_OUT NEW_OUT OLD_REV NEW_REV: 3-way merge into sycl/ of the files upstream changed OLD_REV..NEW_REV 2import re ,subprocess ,sys ,os ,shutil 3B ,N ,old ,new = sys .argv [1 :5 ] 4pat = re .compile (r"\b([A-Za-z0-9_]+)_([0-9a-f]{6})\b" ) 5H = lambda t :pat .sub (lambda m :m .group (1 )+ "_HASH" ,t ) 6def hashes (t ): 7m = {} 8for a ,h in pat .findall (t ):m .setdefault (a ,set ()).add (h ) 9return {a :next (iter (v ))for a ,v in m .items ()if len (v )== 1 } 10changed = subprocess .check_output (["git" ,"diff" ,"--name-only" ,old ,new ,"--" ,"src" ,"include" ],text = True ).split () 11HAND = {"src/core/mtp.cpp" ,"src/core/verify.cpp" ,"src/ngram/ple_reader.cpp" ,"src/kernels/native_expert_parity.cpp" } 12for f in changed : 13rel = f [:- 3 ]+ ".dp.cpp" if f .endswith (".cu" )else f 14pf = "sycl/" + rel 15if f in HAND : 16if not os .path .exists (pf ):"HAND-MISSING" ,f );continue 17open ("/tmp/_b" ,"w" ).write (subprocess .check_output (["git" ,"show" ,f" { old } : { f } " ],text = True )) 18open ("/tmp/_n" ,"w" ).write (subprocess .check_output (["git" ,"show" ,f" { new } : { f } " ],text = True )) 19r = subprocess .run (["git" ,"merge-file" ,"-L" ,"port" ,"-L" ,"base" ,"-L" ,"new" ,pf ,"/tmp/_b" ,"/tmp/_n" ]).returncode 20"HAND" ,"MERGED" if r == 0 else f"CONFLICT { r } " ,rel );continue 21bf ,nf = f" { B } / { rel } " ,f" { N } / { rel } " 22if not os .path .exists (nf ): 23"NOT-MIGRATED (original used)" if not os .path .exists (pf )else "PORT-HAS-NO-DPCT?" ,rel );continue 24nt = open (nf ).read () 25if not os .path .exists (pf ): 26os .makedirs (os .path .dirname (pf ),exist_ok = True );os .makedirs (os .path .dirname (pf ),exist_ok = True );shutil .copy (nf ,pf );"NEWCOPY" ,rel );continue 27if not os .path .exists (bf ): 28"NO-BASE (new to dpct output)" ,rel );continue 29bt = open (bf ).read () 30if H (bt )== H (nt ):"NOCHANGE-after-dpct" ,rel );continue 31pt = open (pf ).read ();ph = hashes (pt );bh = hashes (bt ) 32nt = pat .sub (lambda m :f" { m . group ( 1 ) } _ { bh [ m . group ( 1 )] } " if m .group (1 )in bh else m .group (0 ),nt ) 33canon = lambda t :pat .sub (lambda m :f" { m . group ( 1 ) } _ { ph [ m . group ( 1 )] } " if m .group (1 )in ph else m .group (0 ),t ) 34bt ,nt = canon (bt ),canon (nt ) 35open ("/tmp/_b" ,"w" ).write (bt );open ("/tmp/_n" ,"w" ).write (nt ) 36r = subprocess .run (["git" ,"merge-file" ,"-L" ,"port" ,"-L" ,"base" ,"-L" ,"new" ,pf ,"/tmp/_b" ,"/tmp/_n" ]).returncode 37"MERGED" if r == 0 else f"CONFLICT { r } " ,rel )