Show More
@@ -1,125 +1,125 b'' | |||||
1 | """implements bookmark-based branching (EXPERIMENTAL) |
|
1 | """implements bookmark-based branching (EXPERIMENTAL) | |
2 |
|
2 | |||
3 | - Disables creation of new branches (config: enable_branches=False). |
|
3 | - Disables creation of new branches (config: enable_branches=False). | |
4 | - Requires an active bookmark on commit (config: require_bookmark=True). |
|
4 | - Requires an active bookmark on commit (config: require_bookmark=True). | |
5 | - Doesn't move the active bookmark on update, only on commit. |
|
5 | - Doesn't move the active bookmark on update, only on commit. | |
6 | - Requires '--rev' for moving an existing bookmark. |
|
6 | - Requires '--rev' for moving an existing bookmark. | |
7 | - Protects special bookmarks (config: protect=@). |
|
7 | - Protects special bookmarks (config: protect=@). | |
8 |
|
8 | |||
9 | flow related commands |
|
9 | flow related commands | |
10 |
|
10 | |||
11 | :hg book NAME: create a new bookmark |
|
11 | :hg book NAME: create a new bookmark | |
12 | :hg book NAME -r REV: move bookmark to revision (fast-forward) |
|
12 | :hg book NAME -r REV: move bookmark to revision (fast-forward) | |
13 | :hg up|co NAME: switch to bookmark |
|
13 | :hg up|co NAME: switch to bookmark | |
14 | :hg push -B .: push active bookmark |
|
14 | :hg push -B .: push active bookmark | |
15 | """ |
|
15 | """ | |
16 |
|
16 | |||
17 | from mercurial.i18n import _ |
|
17 | from mercurial.i18n import _ | |
18 | from mercurial import ( |
|
18 | from mercurial import ( | |
19 | bookmarks, |
|
19 | bookmarks, | |
20 | commands, |
|
20 | commands, | |
21 | error, |
|
21 | error, | |
22 | extensions, |
|
22 | extensions, | |
23 | registrar, |
|
23 | registrar, | |
24 | ) |
|
24 | ) | |
25 |
|
25 | |||
26 | MY_NAME = b'bookflow' |
|
26 | MY_NAME = b'bookflow' | |
27 |
|
27 | |||
28 | configtable = {} |
|
28 | configtable = {} | |
29 | configitem = registrar.configitem(configtable) |
|
29 | configitem = registrar.configitem(configtable) | |
30 |
|
30 | |||
31 | configitem(MY_NAME, b'protect', [b'@']) |
|
31 | configitem(MY_NAME, b'protect', [b'@']) | |
32 | configitem(MY_NAME, b'require-bookmark', True) |
|
32 | configitem(MY_NAME, b'require-bookmark', True) | |
33 | configitem(MY_NAME, b'enable-branches', False) |
|
33 | configitem(MY_NAME, b'enable-branches', False) | |
34 |
|
34 | |||
35 | cmdtable = {} |
|
35 | cmdtable = {} | |
36 | command = registrar.command(cmdtable) |
|
36 | command = registrar.command(cmdtable) | |
37 |
|
37 | |||
38 |
|
38 | |||
39 | def commit_hook(ui, repo, **kwargs): |
|
39 | def commit_hook(ui, repo, **kwargs): | |
40 | active = repo._bookmarks.active |
|
40 | active = repo._bookmarks.active | |
41 | if active: |
|
41 | if active: | |
42 | if active in ui.configlist(MY_NAME, b'protect'): |
|
42 | if active in ui.configlist(MY_NAME, b'protect'): | |
43 | raise error.Abort( |
|
43 | raise error.Abort( | |
44 | _(b'cannot commit, bookmark %s is protected') % active |
|
44 | _(b'cannot commit, bookmark %s is protected') % active | |
45 | ) |
|
45 | ) | |
46 | if not cwd_at_bookmark(repo, active): |
|
46 | if not cwd_at_bookmark(repo, active): | |
47 | raise error.Abort( |
|
47 | raise error.Abort( | |
48 | _( |
|
48 | _( | |
49 | b'cannot commit, working directory out of sync with active bookmark' |
|
49 | b'cannot commit, working directory out of sync with active bookmark' | |
50 | ), |
|
50 | ), | |
51 | hint=_(b"run 'hg up %s'") % active, |
|
51 | hint=_(b"run 'hg up %s'") % active, | |
52 | ) |
|
52 | ) | |
53 | elif ui.configbool(MY_NAME, b'require-bookmark', True): |
|
53 | elif ui.configbool(MY_NAME, b'require-bookmark', True): | |
54 | raise error.Abort(_(b'cannot commit without an active bookmark')) |
|
54 | raise error.Abort(_(b'cannot commit without an active bookmark')) | |
55 | return 0 |
|
55 | return 0 | |
56 |
|
56 | |||
57 |
|
57 | |||
58 | def bookmarks_update(orig, repo, parents, node): |
|
58 | def bookmarks_update(orig, repo, parents, node): | |
59 | if len(parents) == 2: |
|
59 | if len(parents) == 2: | |
60 | # called during commit |
|
60 | # called during commit | |
61 | return orig(repo, parents, node) |
|
61 | return orig(repo, parents, node) | |
62 | else: |
|
62 | else: | |
63 | # called during update |
|
63 | # called during update | |
64 | return False |
|
64 | return False | |
65 |
|
65 | |||
66 |
|
66 | |||
67 | def bookmarks_addbookmarks( |
|
67 | def bookmarks_addbookmarks( | |
68 | orig, repo, tr, names, rev=None, force=False, inactive=False |
|
68 | orig, repo, tr, names, rev=None, force=False, inactive=False | |
69 | ): |
|
69 | ): | |
70 | if not rev: |
|
70 | if not rev: | |
71 | marks = repo._bookmarks |
|
71 | marks = repo._bookmarks | |
72 | for name in names: |
|
72 | for name in names: | |
73 | if name in marks: |
|
73 | if name in marks: | |
74 | raise error.Abort( |
|
74 | raise error.Abort( | |
75 | _( |
|
75 | _( | |
76 | b"bookmark %s already exists, to move use the --rev option" |
|
76 | b"bookmark %s already exists, to move use the --rev option" | |
77 | ) |
|
77 | ) | |
78 | % name |
|
78 | % name | |
79 | ) |
|
79 | ) | |
80 | return orig(repo, tr, names, rev, force, inactive) |
|
80 | return orig(repo, tr, names, rev, force, inactive) | |
81 |
|
81 | |||
82 |
|
82 | |||
83 | def commands_commit(orig, ui, repo, *args, **opts): |
|
83 | def commands_commit(orig, ui, repo, *args, **opts): | |
84 | commit_hook(ui, repo) |
|
84 | commit_hook(ui, repo) | |
85 | return orig(ui, repo, *args, **opts) |
|
85 | return orig(ui, repo, *args, **opts) | |
86 |
|
86 | |||
87 |
|
87 | |||
88 | def commands_pull(orig, ui, repo, *args, **opts): |
|
88 | def commands_pull(orig, ui, repo, *args, **opts): | |
89 | rc = orig(ui, repo, *args, **opts) |
|
89 | rc = orig(ui, repo, *args, **opts) | |
90 | active = repo._bookmarks.active |
|
90 | active = repo._bookmarks.active | |
91 | if active and not cwd_at_bookmark(repo, active): |
|
91 | if active and not cwd_at_bookmark(repo, active): | |
92 | ui.warn( |
|
92 | ui.warn( | |
93 | _( |
|
93 | _( | |
94 | b"working directory out of sync with active bookmark, run " |
|
94 | b"working directory out of sync with active bookmark, run " | |
95 | b"'hg up %s'" |
|
95 | b"'hg up %s'" | |
96 | ) |
|
96 | ) | |
97 | % active |
|
97 | % active | |
98 | ) |
|
98 | ) | |
99 | return rc |
|
99 | return rc | |
100 |
|
100 | |||
101 |
|
101 | |||
102 | def commands_branch(orig, ui, repo, label=None, **opts): |
|
102 | def commands_branch(orig, ui, repo, label=None, **opts): | |
103 | if label and not opts.get('clean') and not opts.get('rev'): |
|
103 | if label and not opts.get('clean') and not opts.get('rev'): | |
104 | raise error.Abort( |
|
104 | raise error.Abort( | |
105 | _( |
|
105 | _( | |
106 | b"creating named branches is disabled and you should use bookmarks" |
|
106 | b"creating named branches is disabled and you should use bookmarks" | |
107 | ), |
|
107 | ), | |
108 | hint=b"see 'hg help bookflow'", |
|
108 | hint=b"see 'hg help bookflow'", | |
109 | ) |
|
109 | ) | |
110 | return orig(ui, repo, label, **opts) |
|
110 | return orig(ui, repo, label, **opts) | |
111 |
|
111 | |||
112 |
|
112 | |||
113 | def cwd_at_bookmark(repo, mark): |
|
113 | def cwd_at_bookmark(repo, mark): | |
114 | mark_id = repo._bookmarks[mark] |
|
114 | mark_id = repo._bookmarks[mark] | |
115 | cur_id = repo.lookup(b'.') |
|
115 | cur_id = repo.lookup(b'.') | |
116 | return cur_id == mark_id |
|
116 | return cur_id == mark_id | |
117 |
|
117 | |||
118 |
|
118 | |||
119 | def uisetup(ui): |
|
119 | def uisetup(ui): | |
120 |
extensions.wrapfunction(bookmarks, |
|
120 | extensions.wrapfunction(bookmarks, 'update', bookmarks_update) | |
121 |
extensions.wrapfunction(bookmarks, |
|
121 | extensions.wrapfunction(bookmarks, 'addbookmarks', bookmarks_addbookmarks) | |
122 | extensions.wrapcommand(commands.table, b'commit', commands_commit) |
|
122 | extensions.wrapcommand(commands.table, b'commit', commands_commit) | |
123 | extensions.wrapcommand(commands.table, b'pull', commands_pull) |
|
123 | extensions.wrapcommand(commands.table, b'pull', commands_pull) | |
124 | if not ui.configbool(MY_NAME, b'enable-branches'): |
|
124 | if not ui.configbool(MY_NAME, b'enable-branches'): | |
125 | extensions.wrapcommand(commands.table, b'branch', commands_branch) |
|
125 | extensions.wrapcommand(commands.table, b'branch', commands_branch) |
General Comments 0
You need to be logged in to leave comments.
Login now