From 52884b2999747e36baade1eeb6240a8cc19ffd2d Mon Sep 17 00:00:00 2001 From: Joe Cross Date: Sun, 12 Jun 2016 15:15:45 -0700 Subject: [PATCH 1/2] Use --allow-empty for performance gelstudios/gitfiti#32 * Improves the size of the generated file: 2365211 new-gitfiti.sh 2529001 original-gitfiti.sh * Cutting the number of executed commands in half (no more echo) * Vastly reduces the amount of gc git performs during push --- gitfiti.py | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/gitfiti.py b/gitfiti.py index b15b75b1c4..3af317d892 100755 --- a/gitfiti.py +++ b/gitfiti.py @@ -34,12 +34,12 @@ TITLE = ''' - _ __ _____ __ _ + _ __ _____ __ _ ____ _(_) /_/ __(_) /_(_) - / __ `/ / __/ /_/ / __/ / - / /_/ / / /_/ __/ / /_/ / - \__, /_/\__/_/ /_/\__/_/ -/____/ + / __ `/ / __/ /_/ / __/ / + / /_/ / / /_/ __/ / /_/ / + \__, /_/\__/_/ /_/\__/_/ +/____/ ''' @@ -153,13 +153,13 @@ def is_empty_line(line): ONEUP_STR = str_to_sprite(''' - ******* + ******* *=~~-~~=* *~~---~~* *=*****=* **-*-*-** - *-----* - ***** + *-----* + ***** ''') @@ -211,7 +211,7 @@ def retrieve_contributions_calendar(username, base_url): """retrieves the GitHub commit calendar data for a username""" base_url = base_url + 'users/' + username - try: + try: url = base_url + '/contributions' page = urlopen(url) except (HTTPError, URLError) as e: @@ -283,12 +283,10 @@ def generate_values_in_date_order(image, multiplier=1): def commit(content, commitdate): template = ( - '''echo {0} >> gitfiti\n''' - '''GIT_AUTHOR_DATE={1} GIT_COMMITTER_DATE={2} ''' - '''git commit -a -m "gitfiti" > /dev/null\n''' + '''GIT_AUTHOR_DATE={0} GIT_COMMITTER_DATE={1} ''' + '''git commit --allow-empty -m "gitfiti" > /dev/null\n''' ) - return template.format(content, commitdate.isoformat(), - commitdate.isoformat()) + return template.format(commitdate.isoformat(), commitdate.isoformat()) def fake_it(image, start_date, username, repo, git_url, offset=0, multiplier=1): @@ -380,9 +378,9 @@ def main(): if not image: image = IMAGES[image_name_fallback] else: - try: + try: image = images[image] - except: + except: image = IMAGES[image_name_fallback] start_date = get_start_date() From 7a80c1d7302f646cc7eea505c5eab79db348f9db Mon Sep 17 00:00:00 2001 From: Joe Cross Date: Sun, 12 Jun 2016 15:23:26 -0700 Subject: [PATCH 2/2] drop unused content arg from commit function --- gitfiti.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gitfiti.py b/gitfiti.py index 3af317d892..46dffcd7a1 100755 --- a/gitfiti.py +++ b/gitfiti.py @@ -281,7 +281,7 @@ def generate_values_in_date_order(image, multiplier=1): yield image[h][w] * multiplier -def commit(content, commitdate): +def commit(commitdate): template = ( '''GIT_AUTHOR_DATE={0} GIT_COMMITTER_DATE={1} ''' '''git commit --allow-empty -m "gitfiti" > /dev/null\n''' @@ -308,8 +308,8 @@ def fake_it(image, start_date, username, repo, git_url, offset=0, multiplier=1): strings = [] for value, date in zip(generate_values_in_date_order(image, multiplier), generate_next_dates(start_date, offset)): - for i in range(value): - strings.append(commit(i, date)) + for _ in range(value): + strings.append(commit(date)) return template.format(repo, ''.join(strings), git_url, username)