Mercurial > public > mercurial-scm > hg
comparison mercurial/merge.py @ 3121:2ef0b3aae186
merge: simplify actions with helper function
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Sun, 17 Sep 2006 21:27:30 -0500 |
parents | 1c1e59aac82a |
children | c82ea81d6850 |
comparison
equal
deleted
inserted
replaced
3120:1c1e59aac82a | 3121:2ef0b3aae186 |
---|---|
104 a, b, c = ma.execf(f), m1.execf(f), m2.execf(f) | 104 a, b, c = ma.execf(f), m1.execf(f), m2.execf(f) |
105 return ((a^b) | (a^c)) ^ a | 105 return ((a^b) | (a^c)) ^ a |
106 | 106 |
107 action = [] | 107 action = [] |
108 | 108 |
109 def act(msg, f, m, *args): | |
110 ui.debug(" %s: %s -> %s\n" % (f, msg, m)) | |
111 action.append((f, m) + args) | |
112 | |
109 # Filter manifests | 113 # Filter manifests |
110 if partial: | 114 if partial: |
111 for f in m1.keys(): | 115 for f in m1.keys(): |
112 if not partial(f): del m1[f] | 116 if not partial(f): del m1[f] |
113 for f in m2.keys(): | 117 for f in m2.keys(): |
119 # are files different? | 123 # are files different? |
120 if n != m2[f]: | 124 if n != m2[f]: |
121 a = ma.get(f, nullid) | 125 a = ma.get(f, nullid) |
122 # are both different from the ancestor? | 126 # are both different from the ancestor? |
123 if not overwrite and n != a and m2[f] != a: | 127 if not overwrite and n != a and m2[f] != a: |
124 ui.debug(_(" %s versions differ, resolve\n") % f) | 128 act("versions differ", f, "m", fmerge(f), n[:20], m2[f]) |
125 action.append((f, "m", fmerge(f), n[:20], m2[f])) | |
126 # are we clobbering? | 129 # are we clobbering? |
127 # is remote's version newer? | 130 # is remote's version newer? |
128 # or are we going back in time and clean? | 131 # or are we going back in time and clean? |
129 elif overwrite or m2[f] != a or (backwards and not n[20:]): | 132 elif overwrite or m2[f] != a or (backwards and not n[20:]): |
130 ui.debug(_(" remote %s is newer, get\n") % f) | 133 act("remote is newer", f, "g", m2.execf(f), m2[f]) |
131 action.append((f, "g", m2.execf(f), m2[f])) | |
132 # local is newer, not overwrite, check mode bits | 134 # local is newer, not overwrite, check mode bits |
133 elif fmerge(f) != m1.execf(f): | 135 elif fmerge(f) != m1.execf(f): |
134 ui.debug(_(" updating permissions for %s\n") % f) | 136 act("update permissions", f, "e", m2.execf(f)) |
135 action.append((f, "e", m2.execf(f))) | |
136 # contents same, check mode bits | 137 # contents same, check mode bits |
137 elif m1.execf(f) != m2.execf(f): | 138 elif m1.execf(f) != m2.execf(f): |
138 if overwrite or fmerge(f) != m1.execf(f): | 139 if overwrite or fmerge(f) != m1.execf(f): |
139 ui.debug(_(" updating permissions for %s\n") % f) | 140 act("update permissions", f, "e", m2.execf(f)) |
140 action.append((f, "e", m2.execf(f))) | |
141 del m2[f] | 141 del m2[f] |
142 elif f in ma: | 142 elif f in ma: |
143 if n != ma[f] and not overwrite: | 143 if n != ma[f] and not overwrite: |
144 if ui.prompt( | 144 if ui.prompt( |
145 (_(" local changed %s which remote deleted\n") % f) + | 145 (_(" local changed %s which remote deleted\n") % f) + |
146 _("(k)eep or (d)elete?"), _("[kd]"), _("k")) == _("d"): | 146 _("(k)eep or (d)elete?"), _("[kd]"), _("k")) == _("d"): |
147 action.append((f, "r")) | 147 act("prompt delete", f, "r") |
148 else: | 148 else: |
149 ui.debug(_("other deleted %s\n") % f) | 149 act("other deleted", f, "r") |
150 action.append((f, "r")) | |
151 else: | 150 else: |
152 # file is created on branch or in working directory | 151 # file is created on branch or in working directory |
153 if (overwrite and n[20:] != "u") or (backwards and not n[20:]): | 152 if (overwrite and n[20:] != "u") or (backwards and not n[20:]): |
154 ui.debug(_("remote deleted %s, clobbering\n") % f) | 153 act("remote deleted", f, "r") |
155 action.append((f, "r")) | |
156 else: | |
157 ui.debug(_("local created %s, keeping\n") % f) | |
158 | 154 |
159 for f, n in m2.iteritems(): | 155 for f, n in m2.iteritems(): |
160 if f in ma: | 156 if f in ma: |
161 if overwrite or backwards: | 157 if overwrite or backwards: |
162 ui.debug(_("local deleted %s, recreating\n") % f) | 158 act("recreating", f, "g", m2.execf(f), n) |
163 action.append((f, "g", m2.execf(f), n)) | |
164 elif n != ma[f]: | 159 elif n != ma[f]: |
165 if ui.prompt( | 160 if ui.prompt( |
166 (_("remote changed %s which local deleted\n") % f) + | 161 (_("remote changed %s which local deleted\n") % f) + |
167 _("(k)eep or (d)elete?"), _("[kd]"), _("k")) == _("k"): | 162 _("(k)eep or (d)elete?"), _("[kd]"), _("k")) == _("k"): |
168 action.append((f, "g", m2.execf(f), n)) | 163 act("prompt recreating", f, "g", m2.execf(f), n) |
169 else: | |
170 ui.debug(_("local deleted %s\n") % f) | |
171 else: | 164 else: |
172 ui.debug(_("remote created %s\n") % f) | 165 act("remote created", f, "g", m2.execf(f), n) |
173 action.append((f, "g", m2.execf(f), n)) | |
174 | 166 |
175 return action | 167 return action |
176 | 168 |
177 def applyupdates(repo, action, xp1, xp2): | 169 def applyupdates(repo, action, xp1, xp2): |
178 updated, merged, removed, unresolved = 0, 0, 0, 0 | 170 updated, merged, removed, unresolved = 0, 0, 0, 0 |