comparison repair.py @ 62:c82a8743fd48

taking notes on how to merge
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Thu, 14 Dec 2023 00:13:19 +0000
parents bc1acb1416ab
children 721bd7a04efb
comparison
equal deleted inserted replaced
61:19262b15a099 62:c82a8743fd48
11 for l in lines: 11 for l in lines:
12 ll = lisparser.get_ast(lisparser.normalize_str(l))[0] 12 ll = lisparser.get_ast(lisparser.normalize_str(l))[0]
13 k = ll.pop(0) 13 k = ll.pop(0)
14 n = ll.pop(0) 14 n = ll.pop(0)
15 t = ll.pop(0) 15 t = ll.pop(0)
16 pp = dict((a[0],a[1:]) for a in ll.pop(0)) if ll else None 16 if ll:
17 pp = ll.pop(0)
18 if pp[0] == '(':
19 pp = dict((a[0],a[1:]) for a in pp)
20 # Otherwise only "nil", I think, so pass through
21 else:
22 pp = None
17 res[eval(k)]=(n, t, pp, ll) 23 res[eval(k)]=(n, t, pp, ll)
18 return res 24 return res
19 25
26 # alist fields are: group, rank, read, marks, method, params
27
20 def p2l(pl, f, top = False): 28 def p2l(pl, f, top = False):
21 if isinstance(pl,list) or isinstance(pl,tuple): 29 if isinstance(pl,list) or isinstance(pl,tuple):
22 if len(pl) == 0: 30 if len(pl) == 0:
23 f.write('nil') 31 f.write('nil')
24 else: 32 else:
42 else: 50 else:
43 f.write('(' if top else '((') 51 f.write('(' if top else '((')
44 space = True 52 space = True
45 if top: 53 if top:
46 f.write('"%s"'%k) 54 f.write('"%s"'%k)
55 for e in v[:3]: # v is [n, t, pp, ll], pp may be None
56 if e:
57 f.write(' ')
58 p2l(e,f)
59 # ll may be empty
60 for e in v[3]:
61 if e:
62 f.write(' ')
63 p2l(e,f)
47 else: 64 else:
48 f.write(k) 65 f.write(k)
49 for e in v: 66 for e in v:
50 if e:
51 # 4th tuple, from tail of original (ref 'll' in alist), may be empty
52 f.write(' ') 67 f.write(' ')
53 p2l(e,f) 68 p2l(e,f)
54 f.write(')') 69 f.write(')')
55 if top: 70 if top:
56 f.write('\n))\n') 71 f.write('\n))\n')
62 else: 77 else:
63 try: 78 try:
64 int(pl) 79 int(pl)
65 f.write(pl) 80 f.write(pl)
66 except ValueError: 81 except ValueError:
67 f.write('"%s"'%pl) 82 f.write(pl)
68 else: 83 else:
69 f.write(pl) 84 f.write(pl)
85
86 def merge(gnus, mail):
87 '''
88 rank, read, marks, method, params
89
90 read is everything that is unmarked (nothing in left column)
91 marks.seen is everything that has ever been looked it and not DELETED
92 marks.tick is a !, marks.forward is F, marks.reply is A.
93
94 rank: deeper in gnus wins
95 read: if unequal
96 if mail is nil, use gnus
97 otherwise use mail
98 marks: merge unseen keys, unequal values for same key prefer gnus
99 EXCEPT bogus, w3c-ac-forum, handle by hand
100 method: change "ht" to "nnml+ht", flag anything else
101 params: TBD
102
103 Comparison tool:
104
105 export P='\(nil\|(\(\([0-9]\+\|([^)]*)\) \?\)*)\)'
106 paste <(cat shared) <(fgrep -f shared mail/alist.fixed | sed 's/ \([0-9]\) '"$P $P/ \1 \2 \5 /g" | cut -f 3) <(fgrep -f shared gnus/alist.fixed | sed 's/ \([0-9]\) '"$P $P/ \1 \2 \5 /g" | cut -f 3) | { IFS=' ' ; while read gn g m; do if [ "$g" != "$m" ]; then printf "=----%s------\n%s\n%s\n" "$gn" "$g" "$m"; fi; done ; } | less
107
108 Watch out for tabs!
109 To look for overlap, change 2nd \n in printf to \t
110
111 '''