Skip to content
This repository has been archived by the owner on Aug 23, 2018. It is now read-only.

Commit

Permalink
Make things work
Browse files Browse the repository at this point in the history
Fix a lot of bugs & crashes, install everything in the makefile
  • Loading branch information
nwgh committed May 17, 2011
1 parent e230756 commit 24643ec
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 17 deletions.
2 changes: 2 additions & 0 deletions Makefile
Expand Up @@ -11,3 +11,5 @@ install: all
install -d -m 0755 -o ${OWNER} ${BINDIR}/
install -m 0755 -o ${OWNER} qnew.py ${BINDIR}/git-qnew
install -m 0755 -o ${OWNER} qrefresh.py ${BINDIR}/git-qrefresh
install -m 0755 -o ${OWNER} qpush.py ${BINDIR}/git-qpush
install -m 0755 -o ${OWNER} qpop.py ${BINDIR}/git-qpop
16 changes: 11 additions & 5 deletions gitq.py
Expand Up @@ -58,7 +58,8 @@ def load_series():
base = line.strip()
pgl.config['SERIES'].append(base)

pgl.config['ACTIVE_PATCH'] = pgl.config['SERIES'][-1]
if pgl.config['SERIES']:
pgl.config['ACTIVE_PATCH'] = pgl.config['SERIES'][-1]

with file(pgl.config['UNAPPLIED_PATCHES']) as f:
for line in f:
Expand Down Expand Up @@ -96,15 +97,19 @@ def repo_has_changes():
return True
return False

def update_patch(commit_all=False, commitmsg=None, name=None, email=None):
def update_patch(commit_all=False, commitmsg=None, new=False, name=None, email=None):
"""Makes sure we've committed all our changes, and write the patch series
for this uber-patch to its patch directory
"""
patchbase = pgl.config['ACTIVE_PATCH']
if not new:
patchbase = pgl.config['ACTIVE_PATCH']
else:
patchbase = None

# Now we can go through and make our new revision of the patch
if patchbase and not commitmsg:
gitlog = subprocess.Popen(['git', 'log', '-1', '--format=%%s'],
gitlog = subprocess.Popen(['git', 'log', '-1', '--format=%s',
patchbase],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
origmsg = gitlog.stdout.readlines()[0].strip()
commitmsg = 'fixup! %s' % (origmsg,)
Expand All @@ -126,6 +131,7 @@ def update_patch(commit_all=False, commitmsg=None, name=None, email=None):
if email:
genv['GIT_AUTHOR_EMAIL'] = email
gitcommit = subprocess.Popen(args, env=genv)
gitcommit.wait()
if gitcommit.wait():
return False

return True
11 changes: 8 additions & 3 deletions qnew.py
Expand Up @@ -26,15 +26,20 @@ def main():
if not os.path.exists(pgl.config['QUEUE_SERIES']):
if not os.path.exists(pgl.config['BRANCH_QUEUE']):
if not os.path.exists(pgl.config['QUEUES']):
os.path.mkdir(pgl.config['QUEUES'])
os.path.mkdir(pgl.config['BRANCH_QUEUE'])
os.mkdir(pgl.config['QUEUES'])
os.mkdir(pgl.config['BRANCH_QUEUE'])
file(pgl.config['QUEUE_SERIES'], 'w').close()
if not os.path.exists(pgl.config['UNAPPLIED_PATCHES']):
file(pgl.config['UNAPPLIED_PATCHES'], 'w').close()
if not os.path.exists(pgl.config['SHA_NAME_MAP']):
file(pgl.config['SHA_NAME_MAP'], 'w').close()

# Make sure we don't already have a patch named like the one we want
gitq.load_series()

# Commit outstanding changes
if not gitq.update_patch(commit_all=args.all, commitmsg=args.commitmsg):
if not gitq.update_patch(commit_all=args.all, commitmsg=args.commitmsg,
new=True):
pgl.die('Nothing to make a new patch from!')

# Do this again here to figure out the base of our new patch
Expand Down
6 changes: 4 additions & 2 deletions qpop.py
Expand Up @@ -32,13 +32,15 @@ def main():
'%s~1' % (patchbase,)],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if gfp.wait():
pgl.die('Failed to pop patch')
pgl.die('Failed to save patch')

# Reset our working copy to before the patch
reset_point = '%s~1' % (patchbase,)
gitreset = subprocess.Popen(['git', 'reset', '--hard', reset_point],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
gitreset.wait()
if gitreset.wait():
shutil.rmtree(patchdir)
pgl.die('Failed to pop patch')

# Move our now-saved patch into the unapplied list and save new state
pgl.config['SERIES'] = pgl.config['SERIES'][:-1]
Expand Down
35 changes: 31 additions & 4 deletions qpush.py
@@ -1,5 +1,7 @@
#!/usr/bin/env python

import argparse
import glob
import os
import shutil
import subprocess
Expand All @@ -10,6 +12,14 @@

@pgl.main
def main():
ap = argparse.ArgumentParser(description='Apply a popped patch',
prog='git qpush')
ap.add_argument('pname', help='Name of patch', default=None)
ap.add_argument('-i', dest='interactive', help='Choose patch interactively',
default=False, action='store_true')
# TODO - handle different username/email
args = ap.parse_args()

# Make sure we have all the config we need
gitq.include_config()

Expand Down Expand Up @@ -38,16 +48,33 @@ def main():
apply_name = pgl.config['NAMES'][apply_sha]
except ValueError:
pass
elif args.pname:
if args.pname not in pgl.config['SHAS']:
pgl.die('Unknown patch: %s' % (args.pname,))
apply_name = args.pname
apply_sha = pgl.config['SHAS'][args.pname]
else:
apply_sha = pgl.config['UNAPPLIED'][-1]
apply_name = pgl.config['NAMES'][apply_sha]

# Re-apply the patch using git am
patchdir = os.path.join(pgl.config['BRANCH_QUEUE'], apply_sha)
gitam = subprocess.Popen(['git', 'am', patchdir], stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
if gitam.wait():
pgl.die('Failed to apply patches!')
if not os.path.exists(patchdir):
pgl.die('Missing patch directory for %s. Oops!' % (apply_name,))

patches = glob.glob(os.path.join(patchdir, '*.patch'))
if not patches:
pgl.die('Missing patches for %s. Oops!' % (apply_name,))

for patch in patches:
gitam = subprocess.Popen(['git', 'am', patch], stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
if gitam.wait():
gitreset = subprocess.Popen(['git', 'reset', '--hard',
pgl.config['HEAD_SHA']],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
gitreset.wait()
pgl.die('Failed to apply patches!')

# Remove saved patches directory
shutil.rmtree(patchdir)
Expand Down
5 changes: 2 additions & 3 deletions qrefresh.py
Expand Up @@ -8,9 +8,8 @@

@pgl.main
def main():
ap = argparse.ArgumentParser(description='Create a new patch',
prog='git qnew')
ap.add_argument('pname', help='Name of patch')
ap = argparse.ArgumentParser(description='Update a patch',
prog='git qrefresh')
ap.add_argument('-a', dest='all', help='Add all unstaged changes to patch',
action='store_true', default=False)
args = ap.parse_args()
Expand Down

0 comments on commit 24643ec

Please sign in to comment.