Skip to content

Instantly share code, notes, and snippets.

@QuLogic
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save QuLogic/ed9d5f5c4a8b0dbc794f to your computer and use it in GitHub Desktop.
Save QuLogic/ed9d5f5c4a8b0dbc794f to your computer and use it in GitHub Desktop.
proj.4 repo cleanup
#!/usr/bin/env python3
import os
import sys
try:
import github3
except ImportError:
print('Please (pip) install github3.py first.')
exit(1)
try:
import bs4
except ImportError:
print('Please (pip) install BeautifulSoup first.')
exit(1)
from bs4 import BeautifulSoup
from github3 import login
try:
token = os.environ['GH_TOKEN']
except KeyError:
print('Please set the GH_TOKEN environment variable.')
exit(1)
gh = login(token=token)
issue_count = 0
comment_count = 0
ref_count = 0
for issue in gh.iter_repo_issues('OSGeo', 'proj.4', state='all'):
issue_count += 1
soup = BeautifulSoup(issue.body_html)
for i, link in enumerate(soup.find_all(class_='commit-link')):
ref = link.text
print(issue.number, 0, i, ref)
ref_count += 1
for comment in issue.iter_comments():
comment_count += 1
soup = BeautifulSoup(comment.body_html)
for i, link in enumerate(soup.find_all(class_='commit-link')):
ref = link.text
print(issue.number, comment.id, i, ref)
ref_count += 1
print('Processed %d tickets with %d comments and found %d references.' % (
issue_count, comment_count, ref_count), file=sys.stderr)
265 104556197 0 33cad93 b0fd484
264 104556187 0 2bda6db 51c3555
263 104556065 0 2bce58d d06e4b3
263 104556089 0 2bce58d d06e4b3
262 104556022 0 8e6d15b fab753b
261 104555976 0 ae621e0 04e1540
260 104555916 0 e93df5e ef2b10f
259 104555799 0 b091686 897b545
258 104555743 0 8b0407a bd47d2f
257 104555716 0 9be27ea 5ec17d0
256 104555675 0 c85f4e1 b6db90d
255 104555501 0 c0c5486 a865692
255 104555501 1 fd3790a f8630e0
255 104555507 0 c0c5486 a865692
255 104555512 0 b7c9ba9 ff07f4d
255 104555631 0 aad7b42 3f6d7af
253 104555436 0 d479464 862c468
253 104555436 1 87d61d9 a45753c
250 104555262 0 ccdd555 98b6427
250 104555279 0 9a09f57 9c936de
250 104555283 0 9a09f57 9c936de
250 104555286 0 0da3a82 484aa69
249 0 0 f6f977e ff6b472
249 104555229 0 07c9b4d 579ac11
249 104555232 0 c62f61e 73a1f0f
248 104555200 0 9d6080b 3e6f53a
247 104555150 0 07c9b4d 579ac11
245 104554912 0 0316b17 86dea6a
245 104554955 0 8686cb1 bea351a
245 104554955 1 cc554fc 6dc2a8c
244 104554871 0 72286d6 2d0acd7
239 104554643 0 0b7f584 bd4a62f
237 104554511 0 83efb91 9bd1122
236 104554435 0 a1a596c 32b08fb
231 104554321 0 4d4a113 349048c
229 104554157 0 b899d73 f9c3e66
229 104554182 0 b899d73 f9c3e66
229 104554190 0 b899d73 f9c3e66
229 104554202 0 0d455fd 9e730d9
229 104554208 0 8ba7884 b295166
229 104554208 1 0d455fd 9e730d9
228 104554111 0 7a90771 30d531e
225 104554051 0 3ae40ca 9067fbe
225 104554051 1 5152fd6 fb9b0c6
224 104554030 0 0495da4 d889852
224 104554030 1 c6e01b1 e6a8374
223 0 0 fd3790a f8630e0
223 104554017 0 f709658 caccc26
222 104553991 0 17a27a7 f00990b
221 104553973 0 79cb780 1544f05
220 104553961 0 88cf0f4 8fb066c
219 104553904 0 3073188 bbfe2ec
219 104553904 1 fd3790a f8630e0
219 104553918 0 5d61110 9d16ee4
219 104553921 0 7dee98b 4c03b0c
217 104553855 0 99fae74 a6d9882
216 104553835 0 56afc78 9725b44
214 104553821 0 8670fe2 162566d
208 104553736 0 6ce7a66 6f6eb0d
207 104553722 0 21f39de e4ef280
204 104553669 0 6d742d4 b958c66
200 104553613 0 9aae4b0 07e3b53
199 104553586 0 30f0b51 b22c452
199 104553586 1 6ff041f f97e567
199 104553586 2 b5bb038 6c9cd0d
199 104553586 3 58760be 977bd9f
197 104553385 0 7490bd6 f1f1f9f
197 104553455 0 94f3c6e a7bbac8
197 104553512 0 98a3711 8d061d8
182 104553113 0 166024e 70e4dad
179 104553043 0 259bd19 2ed14f8
177 104552992 0 c5c383b 6112703
176 104552947 0 c7faf09 bc416d8
175 104552923 0 e5af56a e032ca4
169 104552837 0 6cbed78 178074d
168 104552822 0 8ce4a9e acadd16
167 104552812 0 6930825 3cbc9b7
160 104552762 0 8ce4a9e acadd16
157 104552635 0 bfc2cfc 1209f47
153 104552468 0 f28105e 4672937
148 104551901 0 a149ba1 3ea87ae
147 104551692 0 5164bc2 b75f02e
146 104551380 0 de14626 d33de1c
146 104551602 0 2f64094 bf5009f
145 104550883 0 75643c6 3307707
145 104551027 0 bfe20dd 9e84c05
145 104551193 0 be1196a cfe1eb9
143 104550368 0 408ca3d 4c97d90
143 104550460 0 408ca3d 4c97d90
142 104550162 0 ad78193 b52b9b9
141 104549641 0 8449cee dde549f
141 104549774 0 594913b faffa62
141 104549946 0 abe84bf 02ac444
140 104549374 0 5594fa1 5dfb1d5
139 104549191 0 8449cee dde549f
135 104548337 0 442a9e8 142dc13
133 104547904 0 1833b02 850f843
132 104547677 0 9c06ea4 33f73be
132 104547711 0 d57469a 6a350a8
131 104547560 0 9c06ea4 33f73be
130 104547374 0 b465026 df31356
128 104547075 0 d02698d c4652f8
128 104547138 0 0b7f584 bd4a62f
123 104546750 0 742844e d98ff55
122 0 0 f81d979 195e3f3
122 104546617 0 f81d979 195e3f3
122 104546731 0 05df062 d0c1fe6
116 104546292 0 09a3420 cf5c8cd
116 104546300 0 c25edbb 9ca4c10
115 104546244 0 892a9b5 3fd5db7
114 104546218 0 41f977e 3f7d516
114 104546225 0 18dc26f dea2d65
113 104546149 0 eada653 42abd11
113 104546192 0 8c2d94c d856016
112 104546134 0 b1acb15 284daac
112 104546134 1 5ccb7b0 4f86e50
112 104546134 2 476311b a32d0af
111 104546109 0 a433174 c5c96ad
111 104546109 1 1893218 d7ec98f
109 104546075 0 d9cfc80 77aac68
108 104546046 0 0d8969a ba0403e
106 104545984 0 aab380d f7bb18d
104 104545936 0 315a7e0 06896c5
100 104545847 0 0d8969a ba0403e
98 104545810 0 87a6324 8e64ca8
97 104545773 0 2e6971e 818f6a9
95 104545732 0 f4cebbb 9d0a661
94 104545709 0 569bbdc 565f820
93 104545687 0 84188bc 5c012e6
92 104545655 0 5cb2e18 98ea774
90 0 0 bfb9d21 4294bc2
88 104545594 0 e180184 67e5825
87 104545557 0 0a707d8 812c666
81 104545472 0 262595a ab034ef
70 104545172 0 fc9768b a32477f
69 104545150 0 bcd8408 c174749
66 104545090 0 a58c392 8313a5f
63 104545004 0 fc9768b a32477f
63 104545030 0 5516116 c2525b5
62 104544966 0 41f977e 3f7d516
62 104544975 0 a52e5bd 00d894d
62 104544978 0 56d471d d3753ed
61 104544935 0 b2ece1f e525ab9
56 104544773 0 eaa24a0 4e01bab
55 104544743 0 f05e791 21ad562
54 104544693 0 4b0b041 0bb9f58
52 104544588 0 e1dc2d8 a4f28e0
52 104544592 0 e1dc2d8 a4f28e0
52 104544618 0 d1e8cab a14e285
51 104544550 0 f920d40 78c72cc
50 104544531 0 000589f ad030cb
49 104544512 0 c147724 a26eedd
47 104544456 0 56d471d d3753ed
45 104544399 0 abe84bf 02ac444
41 104544247 0 8ab2a77 84d22b2
40 104544103 0 ca0b979 3a60273
40 104544171 0 705b22f 9de8a9b
39 104544014 0 ba39af6 b104cfc
33 104543729 0 6718fe0 326089e
31 104543568 0 163e82e 4582598
31 104543577 0 163e82e 4582598
31 104543577 1 fc0444e 8967873
30 104543523 0 88cad72 6c9ed6d
29 104543454 0 90495cb e89e21b
28 104543416 0 e940b2a 00a1b41
26 104543217 0 04dfe32 4f74d95
26 104543252 0 f7ff03d 839e211
24 104543025 0 8309e2f 3e1894a
24 104543054 0 92f2c60 1eeb0e7
24 104543097 0 e3d2cdf fab46ab
21 104542957 0 55fc17a a4927c2
18 104542787 0 a9d3d03 3405bf7
18 104542806 0 f81d979 195e3f3
11 104542617 0 56d471d d3753ed
10 104542552 0 18977e4 bb1b053
3 104542256 0 2266c51 2f0f94d

This gist includes scripts used to clean up the proj.4 git repository.

  • generate_comment_refs.py determines the tickets and comments that reference to SHA1 hashes.
  • refs is a list of (ticket number, comment ID, count, commit hash) from above.
  • proj4-clean.sh clones the original repo, flattens the structure, and removes extra commits. The hashes noted in the previous step are converted to the new commit hashes.
  • newrefs is a list of (ticket number, comment ID, count, old commit hash, new commit hash) from above.
  • update_comment_refs.py takes newrefs and updates the tickets on GitHub.
#!/bin/bash
set -e
git clone git@github.com:OSGeo/proj.4.git
cd proj.4
# Mirror all branches so we don't need the remote
for remote in `git branch -r | grep -v /master`; do
git branch --track ${remote#origin/} $remote
done
git remote rm origin
# Note down locations of references in tickets
cat ../refs | while read ticket comment number ref; do
git branch t${ticket}c${comment}n${number} ${ref}
done
# Move docs/* into proj/docs/*
git filter-branch --tree-filter 'git mv -k docs/* proj/docs/' --tag-name-filter cat -- --all
git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin
# Delete docs/README.TXT about moving the documentation, which is irrelevant
git filter-branch --index-filter 'git rm --cached --ignore-unmatch proj/docs/README.TXT' --tag-name-filter cat --prune-empty -- --all
git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin
# Move proj/* to the toplevel
git filter-branch --subdirectory-filter proj --tag-name-filter cat -- --all
git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin
# Fixing some tags, so commit them using correct username
export GIT_COMMITTER_NAME='Frank Warmerdam'
export GIT_COMMITTER_EMAIL='warmerdam@pobox.com'
# Move proj_4_4_3 back one commit
GIT_COMMITTER_DATE='1083641797 +0000' git tag -f -a -m "This commit was manufactured by cvs2svn to create tag 'proj_4_4_3'." proj_4_4_3 proj_4_4_3^
# Move proj_4_4_8 to the equivalent commit on master
commit=$(git log --grep 'fixed up central meridians for all the systems with non-gm prime meridians' --format=%H)
GIT_COMMITTER_DATE='1083694822 +0000' git tag -f -a -m "This commit was manufactured by cvs2svn to create tag 'proj_4_4_8'." proj_4_4_8 $commit
# Move proj_4_6_0 back one commit
GIT_COMMITTER_DATE='1198264509 +0000' git tag -f -a -m "This commit was manufactured by cvs2svn to create tag 'proj_4_6_0'." proj_4_6_0 proj_4_6_0^
# Move proj_4_6_1 back one commit
GIT_COMMITTER_DATE='1219374019 +0000' git tag -f -a -m "This commit was manufactured by cvs2svn to create tag 'proj_4_6_1'." proj_4_6_1 proj_4_6_1^
# Note down new locations of references for tickets
cat ../refs | while read ticket comment number ref; do
branch=t${ticket}c${comment}n${number}
newref=$(git show-ref ${branch} | cut -c 1-7)
echo "${ticket} ${comment} ${number} ${ref} ${newref}" >> ../newrefs
git branch -D ${branch}
done
# Make changes public on a separate repo for now
git remote add origin git@github.com:QuLogic/proj4-clean.git
git push origin --all
git push origin --tags
265 104556197 0 33cad93
264 104556187 0 2bda6db
263 104556065 0 2bce58d
263 104556089 0 2bce58d
262 104556022 0 8e6d15b
261 104555976 0 ae621e0
260 104555916 0 e93df5e
259 104555799 0 b091686
258 104555743 0 8b0407a
257 104555716 0 9be27ea
256 104555675 0 c85f4e1
255 104555501 0 c0c5486
255 104555501 1 fd3790a
255 104555507 0 c0c5486
255 104555512 0 b7c9ba9
255 104555631 0 aad7b42
253 104555436 0 d479464
253 104555436 1 87d61d9
250 104555262 0 ccdd555
250 104555279 0 9a09f57
250 104555283 0 9a09f57
250 104555286 0 0da3a82
249 0 0 f6f977e
249 104555229 0 07c9b4d
249 104555232 0 c62f61e
248 104555200 0 9d6080b
247 104555150 0 07c9b4d
245 104554912 0 0316b17
245 104554955 0 8686cb1
245 104554955 1 cc554fc
244 104554871 0 72286d6
239 104554643 0 0b7f584
237 104554511 0 83efb91
236 104554435 0 a1a596c
231 104554321 0 4d4a113
229 104554157 0 b899d73
229 104554182 0 b899d73
229 104554190 0 b899d73
229 104554202 0 0d455fd
229 104554208 0 8ba7884
229 104554208 1 0d455fd
228 104554111 0 7a90771
225 104554051 0 3ae40ca
225 104554051 1 5152fd6
224 104554030 0 0495da4
224 104554030 1 c6e01b1
223 0 0 fd3790a
223 104554017 0 f709658
222 104553991 0 17a27a7
221 104553973 0 79cb780
220 104553961 0 88cf0f4
219 104553904 0 3073188
219 104553904 1 fd3790a
219 104553918 0 5d61110
219 104553921 0 7dee98b
217 104553855 0 99fae74
216 104553835 0 56afc78
214 104553821 0 8670fe2
208 104553736 0 6ce7a66
207 104553722 0 21f39de
204 104553669 0 6d742d4
200 104553613 0 9aae4b0
199 104553586 0 30f0b51
199 104553586 1 6ff041f
199 104553586 2 b5bb038
199 104553586 3 58760be
197 104553385 0 7490bd6
197 104553455 0 94f3c6e
197 104553512 0 98a3711
182 104553113 0 166024e
179 104553043 0 259bd19
177 104552992 0 c5c383b
176 104552947 0 c7faf09
175 104552923 0 e5af56a
169 104552837 0 6cbed78
168 104552822 0 8ce4a9e
167 104552812 0 6930825
160 104552762 0 8ce4a9e
157 104552635 0 bfc2cfc
153 104552468 0 f28105e
148 104551901 0 a149ba1
147 104551692 0 5164bc2
146 104551380 0 de14626
146 104551602 0 2f64094
145 104550883 0 75643c6
145 104551027 0 bfe20dd
145 104551193 0 be1196a
143 104550368 0 408ca3d
143 104550460 0 408ca3d
142 104550162 0 ad78193
141 104549641 0 8449cee
141 104549774 0 594913b
141 104549946 0 abe84bf
140 104549374 0 5594fa1
139 104549191 0 8449cee
135 104548337 0 442a9e8
133 104547904 0 1833b02
132 104547677 0 9c06ea4
132 104547711 0 d57469a
131 104547560 0 9c06ea4
130 104547374 0 b465026
128 104547075 0 d02698d
128 104547138 0 0b7f584
123 104546750 0 742844e
122 0 0 f81d979
122 104546617 0 f81d979
122 104546731 0 05df062
116 104546292 0 09a3420
116 104546300 0 c25edbb
115 104546244 0 892a9b5
114 104546218 0 41f977e
114 104546225 0 18dc26f
113 104546149 0 eada653
113 104546192 0 8c2d94c
112 104546134 0 b1acb15
112 104546134 1 5ccb7b0
112 104546134 2 476311b
111 104546109 0 a433174
111 104546109 1 1893218
109 104546075 0 d9cfc80
108 104546046 0 0d8969a
106 104545984 0 aab380d
104 104545936 0 315a7e0
100 104545847 0 0d8969a
98 104545810 0 87a6324
97 104545773 0 2e6971e
95 104545732 0 f4cebbb
94 104545709 0 569bbdc
93 104545687 0 84188bc
92 104545655 0 5cb2e18
90 0 0 bfb9d21
88 104545594 0 e180184
87 104545557 0 0a707d8
81 104545472 0 262595a
70 104545172 0 fc9768b
69 104545150 0 bcd8408
66 104545090 0 a58c392
63 104545004 0 fc9768b
63 104545030 0 5516116
62 104544966 0 41f977e
62 104544975 0 a52e5bd
62 104544978 0 56d471d
61 104544935 0 b2ece1f
56 104544773 0 eaa24a0
55 104544743 0 f05e791
54 104544693 0 4b0b041
52 104544588 0 e1dc2d8
52 104544592 0 e1dc2d8
52 104544618 0 d1e8cab
51 104544550 0 f920d40
50 104544531 0 000589f
49 104544512 0 c147724
47 104544456 0 56d471d
45 104544399 0 abe84bf
41 104544247 0 8ab2a77
40 104544103 0 ca0b979
40 104544171 0 705b22f
39 104544014 0 ba39af6
33 104543729 0 6718fe0
31 104543568 0 163e82e
31 104543577 0 163e82e
31 104543577 1 fc0444e
30 104543523 0 88cad72
29 104543454 0 90495cb
28 104543416 0 e940b2a
26 104543217 0 04dfe32
26 104543252 0 f7ff03d
24 104543025 0 8309e2f
24 104543054 0 92f2c60
24 104543097 0 e3d2cdf
21 104542957 0 55fc17a
18 104542787 0 a9d3d03
18 104542806 0 f81d979
11 104542617 0 56d471d
10 104542552 0 18977e4
3 104542256 0 2266c51
#!/usr/bin/env python3
from collections import defaultdict
import os
import sys
try:
import github3
except ImportError:
print('Please (pip) install github3.py first.')
exit(1)
from github3 import login
changes = defaultdict(lambda: defaultdict(list))
with open('newrefs') as f:
for line in f:
ticket, comment, num, old, new = line.split()
ticket = int(ticket)
comment = int(comment)
changes[ticket][comment].append((old, new))
try:
token = os.environ['GH_TOKEN']
except KeyError:
print('Please set the GH_TOKEN environment variable.')
exit(1)
gh = login(token=token)
ticket_count = 0
comment_count = 0
ref_count = 0
for ticket, comments in changes.items():
ticket_count += 1
print('Modifying ticket', ticket)
gh_issue = gh.issue('OSGeo', 'proj.4', ticket)
#gh_issue = gh.issue('QuLogic', 'proj4-clean', ticket)
for comment, refs in comments.items():
if comment == 0:
print('\tBody')
body = gh_issue.body
else:
comment_count += 1
print('\tComment', comment)
gh_comment = gh_issue.comment(comment)
body = gh_comment.body
for old, new in refs:
print('\t\tReplace', old, '->', new)
body = body.replace(old, new)
ref_count += 1
if comment == 0:
gh_issue.edit(body=body)
else:
# Fix authorization bug?
gh_comment._session.headers['Authorization'] = \
gh._session.headers.get('Authorization')
gh_comment.edit(body)
print('Modified %d tickets, %d comments and %d references.' % (
ticket_count, comment_count, ref_count), file=sys.stderr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment