Merge pull request #566 from luckytyphlosion/master

Refactor .gitattributes and .gitignore
This commit is contained in:
luckytyphlosion 2018-09-23 14:14:54 -04:00 committed by GitHub
commit c323f9ddd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 131 additions and 101 deletions

41
.gitattributes vendored
View File

@ -1,11 +1,34 @@
# No monkey business with line endings # Auto detect text files and perform LF normalization
* -text * text eol=lf
# hexdump binary files # Explicitly declare text files you want to always be normalized and converted
*.png binary diff=hex # to native line endings on checkout.
*.lz binary diff=hex
# files part of the build
*.asm text
*.pal text
*.link text
*.txt text
# extra files
*.awk text
*.c text
*.h text
*.md text
*.py text
*.sh text
*.sha1 text
# Denote all files that are truly binary and should not be modified.
*.png binary diff=hex
*.lz.* binary diff=hex
*.bin binary diff=hex
*.blk binary diff=hex
*.rle binary diff=hex
*.attrmap binary diff=hex
*.tilemap binary diff=hex
# these are generated but just in case
*.lz binary diff=hex
*.2bpp binary diff=hex *.2bpp binary diff=hex
*.1bpp binary diff=hex *.1bpp binary diff=hex
*.bin binary diff=hex
*.blk binary diff=hex

5
.gitignore vendored
View File

@ -17,6 +17,7 @@
*.sgm *.sgm
*.sav *.sav
*.rtc *.rtc
*.sn*
# rgbds extras # rgbds extras
*.map *.map
@ -39,8 +40,8 @@ pokecrystal.txt
*.2bpp *.2bpp
*.1bpp *.1bpp
*.lz *.lz
*.pal
*.animated.tilemap *.animated.tilemap
gfx/pokemon/*/bitmask.asm gfx/pokemon/*/bitmask.asm
gfx/pokemon/*/frames.asm gfx/pokemon/*/frames.asm
!gfx/pokemon/*/shiny.pal !gfx/pokemon/unown/bitmask.asm
!gfx/pokemon/unown/frames.asm

View File

@ -33,7 +33,7 @@ crystal11_obj := $(crystal_obj:.o=11.o)
### Build targets ### Build targets
.SUFFIXES: .SUFFIXES:
.PHONY: all crystal crystal11 clean compare tools .PHONY: all crystal crystal11 clean compare tools tidy
.SECONDEXPANSION: .SECONDEXPANSION:
.PRECIOUS: .PRECIOUS:
.SECONDARY: .SECONDARY:
@ -43,6 +43,12 @@ crystal: pokecrystal.gbc
crystal11: pokecrystal11.gbc crystal11: pokecrystal11.gbc
clean: clean:
rm -f $(roms) $(crystal_obj) $(crystal11_obj) $(roms:.gbc=.map) $(roms:.gbc=.sym)
find gfx \( -name "*.[12]bpp" -o -name "*.lz" -o -name "*.gbcpal" \) -delete
find gfx/pokemon -mindepth 1 ! -path "gfx/pokemon/unown/*" \( -name "bitmask.asm" -o -name "frames.asm" -o -name "front.animated.tilemap" -o -name "front.dimensions" \) -delete
$(MAKE) clean -C tools/
tidy:
rm -f $(roms) $(crystal_obj) $(crystal11_obj) $(roms:.gbc=.map) $(roms:.gbc=.sym) rm -f $(roms) $(crystal_obj) $(crystal11_obj) $(roms:.gbc=.map) $(roms:.gbc=.sym)
$(MAKE) clean -C tools/ $(MAKE) clean -C tools/

View File

@ -1,89 +1,89 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" """
Usage: python3 toc.py [-n] files.md... Usage: python3 toc.py [-n] files.md...
Replace a "## TOC" heading in a Markdown file with a table of contents, Replace a "## TOC" heading in a Markdown file with a table of contents,
generated from the other headings in the file. Supports multiple files. generated from the other headings in the file. Supports multiple files.
Headings must start with "##" signs to be detected. Headings must start with "##" signs to be detected.
""" """
import sys import sys
import re import re
from collections import namedtuple from collections import namedtuple
toc_name = 'Contents' toc_name = 'Contents'
valid_toc_headings = {'## TOC', '##TOC'} valid_toc_headings = {'## TOC', '##TOC'}
TocItem = namedtuple('TocItem', ['name', 'anchor', 'level']) TocItem = namedtuple('TocItem', ['name', 'anchor', 'level'])
punctuation_regexp = re.compile(r'[^\w\- ]+') punctuation_regexp = re.compile(r'[^\w\- ]+')
def name_to_anchor(name): def name_to_anchor(name):
# GitHub's algorithm for generating anchors from headings # GitHub's algorithm for generating anchors from headings
# https://github.com/jch/html-pipeline/blob/master/lib/html/pipeline/toc_filter.rb # https://github.com/jch/html-pipeline/blob/master/lib/html/pipeline/toc_filter.rb
anchor = name.strip().lower() # lowercase anchor = name.strip().lower() # lowercase
anchor = re.sub(punctuation_regexp, '', anchor) # remove punctuation anchor = re.sub(punctuation_regexp, '', anchor) # remove punctuation
anchor = anchor.replace(' ', '-') # replace spaces with dash anchor = anchor.replace(' ', '-') # replace spaces with dash
return anchor return anchor
def get_toc_index(lines): def get_toc_index(lines):
toc_index = None toc_index = None
for i, line in enumerate(lines): for i, line in enumerate(lines):
if line.rstrip() in valid_toc_headings: if line.rstrip() in valid_toc_headings:
toc_index = i toc_index = i
break break
return toc_index return toc_index
def get_toc_items(lines, toc_index): def get_toc_items(lines, toc_index):
for i, line in enumerate(lines): for i, line in enumerate(lines):
if i <= toc_index: if i <= toc_index:
continue continue
if line.startswith('##'): if line.startswith('##'):
name = line.lstrip('#') name = line.lstrip('#')
level = len(line) - len(name) - len('##') level = len(line) - len(name) - len('##')
name = name.strip() name = name.strip()
anchor = name_to_anchor(name) anchor = name_to_anchor(name)
yield TocItem(name, anchor, level) yield TocItem(name, anchor, level)
def toc_string(toc_items): def toc_string(toc_items):
lines = ['## %s' % toc_name, ''] lines = ['## %s' % toc_name, '']
for name, anchor, level in toc_items: for name, anchor, level in toc_items:
padding = ' ' * level padding = ' ' * level
line = '%s- [%s](#%s)' % (padding, name, anchor) line = '%s- [%s](#%s)' % (padding, name, anchor)
lines.append(line) lines.append(line)
return '\n'.join(lines) + '\n' return '\n'.join(lines) + '\n'
def add_toc(filename): def add_toc(filename):
with open(filename, 'r', encoding='utf-8') as f: with open(filename, 'r', encoding='utf-8') as f:
lines = f.readlines() lines = f.readlines()
toc_index = get_toc_index(lines) toc_index = get_toc_index(lines)
if toc_index is None: if toc_index is None:
return None # no TOC heading return None # no TOC heading
toc_items = list(get_toc_items(lines, toc_index)) toc_items = list(get_toc_items(lines, toc_index))
if not toc_items: if not toc_items:
return False # no content headings return False # no content headings
with open(filename, 'w', encoding='utf-8') as f: with open(filename, 'w', encoding='utf-8') as f:
for i, line in enumerate(lines): for i, line in enumerate(lines):
if i == toc_index: if i == toc_index:
f.write(toc_string(toc_items)) f.write(toc_string(toc_items))
else: else:
f.write(line) f.write(line)
return True # OK return True # OK
def main(): def main():
if len(sys.argv) < 2: if len(sys.argv) < 2:
print('*** ERROR: No filenames specified') print('*** ERROR: No filenames specified')
print(__doc__) print(__doc__)
exit(1) exit(1)
for filename in sys.argv[1:]: for filename in sys.argv[1:]:
print(filename) print(filename)
result = add_toc(filename) result = add_toc(filename)
if result is None: if result is None:
print('*** WARNING: No "## TOC" heading found') print('*** WARNING: No "## TOC" heading found')
elif result is False: elif result is False:
print('*** WARNING: No content headings found') print('*** WARNING: No content headings found')
else: else:
print('OK') print('OK')
if __name__ == '__main__': if __name__ == '__main__':
main() main()