##// END OF EJS Templates
mq: support multiple patch queues using qqueue
Henrik Stuart -
r11229:1e701ffd default
parent child Browse files
Show More
@@ -0,0 +1,47 b''
1 #!/bin/sh
2
3 echo "[extensions]" >> $HGRCPATH
4 echo "mq=" >> $HGRCPATH
5
6 hg init foo
7 cd foo
8 echo a > a
9 hg ci -qAm a
10
11 echo %% default queue
12 hg qqueue
13
14 echo b > a
15 hg qnew -fgDU somestuff
16
17 echo %% applied patches in default queue
18 hg qap
19
20 echo %% try to change patch \(create succeeds, switch fails\)
21 hg qqueue foo --create
22 hg qqueue
23
24 echo %% empty default queue
25 hg qpop
26
27 echo %% switch queue
28 hg qqueue foo
29 hg qqueue
30
31 echo %% unapplied patches
32 hg qun
33 echo c > a
34 hg qnew -fgDU otherstuff
35
36 echo %% fail switching back
37 hg qqueue patches
38
39 echo %% fail deleting current
40 hg qqueue foo --delete
41
42 echo %% switch back and delete foo
43 hg qpop -a
44 hg qqueue patches
45 hg qqueue foo --delete
46 hg qqueue
47 cd ..
@@ -0,0 +1,23 b''
1 %% default queue
2 patches (active)
3 %% applied patches in default queue
4 somestuff
5 %% try to change patch (create succeeds, switch fails)
6 abort: patches applied - cannot set new queue active
7 foo
8 patches (active)
9 %% empty default queue
10 popping somestuff
11 patch queue now empty
12 %% switch queue
13 foo (active)
14 patches
15 %% unapplied patches
16 %% fail switching back
17 abort: patches applied - cannot set new queue active
18 %% fail deleting current
19 abort: cannot delete currently active queue
20 %% switch back and delete foo
21 popping otherstuff
22 patch queue now empty
23 patches (active)
@@ -234,7 +234,12 b' class patchheader(object):'
234 234 class queue(object):
235 235 def __init__(self, ui, path, patchdir=None):
236 236 self.basepath = path
237 self.path = patchdir or os.path.join(path, "patches")
237 try:
238 fh = open(os.path.join(path, '.queue'))
239 curpath = os.path.join(path, fh.read().rstrip())
240 except IOError:
241 curpath = os.path.join(path, 'patches')
242 self.path = patchdir or curpath
238 243 self.opener = util.opener(self.path)
239 244 self.ui = ui
240 245 self.applied_dirty = 0
@@ -2533,6 +2538,107 b' def finish(ui, repo, *revrange, **opts):'
2533 2538 q.save_dirty()
2534 2539 return 0
2535 2540
2541 def qqueue(ui, repo, name=None, **opts):
2542 '''manage multiple patch queues
2543
2544 Supports switching between different patch queues, as well as creating
2545 new patch queues and deleting existing ones.
2546
2547 Omitting a queue name or specifying -l/--list will show you the registered
2548 queues - by default the "normal" patches queue is registered. The currently
2549 active queue will be marked with "(active)".
2550
2551 To create a new queue, use -c/--create. The queue is automatically made
2552 active, except in the case where there are applied patches from the
2553 currently active queue in the repository. Then the queue will only be
2554 created and switching will fail.
2555
2556 To delete an existing queue, use --delete. You cannot delete the currently
2557 active queue.
2558 '''
2559
2560 q = repo.mq
2561
2562 _defaultqueue = 'patches'
2563 _allqueues = '.queues'
2564 _activequeue = '.queue'
2565
2566 def _getcurrent():
2567 return os.path.basename(q.path)
2568
2569 def _noqueues():
2570 try:
2571 fh = repo.opener(_allqueues, 'r')
2572 fh.close()
2573 except IOError:
2574 return True
2575
2576 return False
2577
2578 def _getqueues():
2579 current = _getcurrent()
2580
2581 try:
2582 fh = repo.opener(_allqueues, 'r')
2583 queues = [queue.strip() for queue in fh if queue.strip()]
2584 if current not in queues:
2585 queues.append(current)
2586 except IOError:
2587 queues = [_defaultqueue]
2588
2589 return sorted(queues)
2590
2591 def _setactive(name):
2592 if q.applied:
2593 raise util.Abort(_('patches applied - cannot set new queue active'))
2594
2595 fh = repo.opener(_activequeue, 'w')
2596 fh.write(name)
2597 fh.close()
2598
2599 def _addqueue(name):
2600 fh = repo.opener(_allqueues, 'a')
2601 fh.write('%s\n' % (name,))
2602 fh.close()
2603
2604 if not name or opts.get('list'):
2605 current = _getcurrent()
2606 for queue in _getqueues():
2607 ui.write('%s' % (queue,))
2608 if queue == current:
2609 ui.write(_(' (active)\n'))
2610 else:
2611 ui.write('\n')
2612 return
2613
2614 existing = _getqueues()
2615
2616 if name not in existing and opts.get('delete'):
2617 raise util.Abort(_('cannot delete queue that does not exist'))
2618 elif name not in existing and not opts.get('create'):
2619 raise util.Abort(_('use --create to create a new queue'))
2620
2621 if opts.get('create'):
2622 if _noqueues():
2623 _addqueue(_defaultqueue)
2624 _addqueue(name)
2625 _setactive(name)
2626 elif opts.get('delete'):
2627 current = _getcurrent()
2628
2629 if name == current:
2630 raise util.Abort(_('cannot delete currently active queue'))
2631
2632 fh = repo.opener('.queues.new', 'w')
2633 for queue in existing:
2634 if queue == name:
2635 continue
2636 fh.write('%s\n' % (queue,))
2637 fh.close()
2638 util.rename(repo.join('.queues.new'), repo.join(_allqueues))
2639 else:
2640 _setactive(name)
2641
2536 2642 def reposetup(ui, repo):
2537 2643 class mqrepo(repo.__class__):
2538 2644 @util.propertycache
@@ -2839,6 +2945,14 b' cmdtable = {'
2839 2945 (finish,
2840 2946 [('a', 'applied', None, _('finish all applied changesets'))],
2841 2947 _('hg qfinish [-a] [REV]...')),
2948 'qqueue':
2949 (qqueue,
2950 [
2951 ('l', 'list', False, _('list all available queues')),
2952 ('c', 'create', False, _('create new queue')),
2953 ('', 'delete', False, _('delete reference to queue')),
2954 ],
2955 _('[OPTION] [QUEUE]')),
2842 2956 }
2843 2957
2844 2958 colortable = {'qguard.negative': 'red',
@@ -49,6 +49,7 b' list of commands:'
49 49 qpop pop the current patch off the stack
50 50 qprev print the name of the previous patch
51 51 qpush push the next patch onto the stack
52 qqueue manage multiple patch queues
52 53 qrefresh update the current patch
53 54 qrename rename a patch
54 55 qselect set or print guarded patches to push
General Comments 0
You need to be logged in to leave comments. Login now