Skip to content

Commit

Permalink
dag: Allow passing command-line arguments to git-dag
Browse files Browse the repository at this point in the history
Signed-off-by: David Aguilar <davvid@gmail.com>
  • Loading branch information
davvid committed Oct 31, 2011
1 parent 365e9eb commit 8bc8360
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
10 changes: 9 additions & 1 deletion cola/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ def parse_args(context):
dest='git',
metavar='PATH',
default='')

if context == 'git-dag':
parser.add_option('-c', '--count',
help='Number of commits to display.',
dest='count',
type='int',
default=1000)

return parser.parse_args()


Expand Down Expand Up @@ -228,7 +236,7 @@ def main(context):
view = MainView(model)
ctl = MainController(model, view)
elif context == 'git-dag':
ctl = git_dag(model, app.activeWindow())
ctl = git_dag(model, app.activeWindow(), opts=opts, args=args)
view = ctl.view

# Install UI wrappers for command objects
Expand Down
4 changes: 3 additions & 1 deletion cola/dag/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
from cola.dag.controller import DAGController


def git_dag(model, parent):
def git_dag(model, parent, opts=None, args=None):
"""Return a pre-populated git DAG widget."""
dag = DAG(model.currentbranch, 1000)
dag.set_options(opts, args)

view = DAGView(model, dag, parent=parent)
ctl = DAGController(dag, view)
view.show()
Expand Down
22 changes: 22 additions & 0 deletions cola/dag/model.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import subprocess

import cola
from cola import core
from cola import git
Expand Down Expand Up @@ -47,18 +49,38 @@ def new(cls, sha1=None, log_entry=None):
class DAG(Observable):
ref_updated = 'ref_updated'
count_updated = 'count_updated'

def __init__(self, ref, count):
Observable.__init__(self)
self.ref = ref
self.count = count
self.overrides = {}

def set_ref(self, ref):
changed = ref != self.ref
self.ref = ref
self.notify_message_observers(self.ref_updated)
return changed

def set_count(self, count):
changed = count != self.count
self.count = count
self.notify_message_observers(self.count_updated)
return changed

def set_options(self, opts, args):
if opts is not None:
if self.set_count(opts.count):
self.overrides['count'] = opts.count

if args is not None:
ref = subprocess.list2cmdline([core.decode(a) for a in args])
if self.set_ref(ref):
self.overrides['ref'] = ref

def overridden(self, opt):
return opt in self.overrides


class Commit(object):
root_generation = 0
Expand Down
8 changes: 6 additions & 2 deletions cola/dag/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,12 @@ def apply_state(self, state):
count = state['count']
except KeyError:
return
self.dag.set_ref(ref)
self.dag.set_count(count)

if not self.dag.overridden('ref'):
self.dag.set_ref(ref)

if not self.dag.overridden('count'):
self.dag.set_count(count)

def _model_updated(self):
self.emit(SIGNAL('model_updated'))
Expand Down

0 comments on commit 8bc8360

Please sign in to comment.