##// END OF EJS Templates
subrepo: extract preprocess of repo.commit() to free function...
Yuya Nishihara -
r35018:5c6b96b8 stable
parent child Browse files
Show More
@@ -1845,58 +1845,8 b' class localrepository(object):'
1845 1845 status.modified.extend(status.clean) # mq may commit clean files
1846 1846
1847 1847 # check subrepos
1848 subs = []
1849 commitsubs = set()
1850 newstate = wctx.substate.copy()
1851 # only manage subrepos and .hgsubstate if .hgsub is present
1852 if '.hgsub' in wctx:
1853 # we'll decide whether to track this ourselves, thanks
1854 for c in status.modified, status.added, status.removed:
1855 if '.hgsubstate' in c:
1856 c.remove('.hgsubstate')
1857
1858 # compare current state to last committed state
1859 # build new substate based on last committed state
1860 oldstate = wctx.p1().substate
1861 for s in sorted(newstate.keys()):
1862 if not match(s):
1863 # ignore working copy, use old state if present
1864 if s in oldstate:
1865 newstate[s] = oldstate[s]
1866 continue
1867 if not force:
1868 raise error.Abort(
1869 _("commit with new subrepo %s excluded") % s)
1870 dirtyreason = wctx.sub(s).dirtyreason(True)
1871 if dirtyreason:
1872 if not self.ui.configbool('ui', 'commitsubrepos'):
1873 raise error.Abort(dirtyreason,
1874 hint=_("use --subrepos for recursive commit"))
1875 subs.append(s)
1876 commitsubs.add(s)
1877 else:
1878 bs = wctx.sub(s).basestate()
1879 newstate[s] = (newstate[s][0], bs, newstate[s][2])
1880 if oldstate.get(s, (None, None, None))[1] != bs:
1881 subs.append(s)
1882
1883 # check for removed subrepos
1884 for p in wctx.parents():
1885 r = [s for s in p.substate if s not in newstate]
1886 subs += [s for s in r if match(s)]
1887 if subs:
1888 if (not match('.hgsub') and
1889 '.hgsub' in (wctx.modified() + wctx.added())):
1890 raise error.Abort(
1891 _("can't commit subrepos without .hgsub"))
1892 status.modified.insert(0, '.hgsubstate')
1893
1894 elif '.hgsub' in status.removed:
1895 # clean up .hgsubstate when .hgsub is removed
1896 if ('.hgsubstate' in wctx and
1897 '.hgsubstate' not in (status.modified + status.added +
1898 status.removed)):
1899 status.removed.insert(0, '.hgsubstate')
1848 subs, commitsubs, newstate = subrepo.precommit(
1849 self.ui, wctx, status, match, force=force)
1900 1850
1901 1851 # make sure all explicit patterns are matched
1902 1852 if not force:
@@ -293,6 +293,71 b' def submerge(repo, wctx, mctx, actx, ove'
293 293 writestate(repo, sm)
294 294 return sm
295 295
296 def precommit(ui, wctx, status, match, force=False):
297 """Calculate .hgsubstate changes that should be applied before committing
298
299 Returns (subs, commitsubs, newstate) where
300 - subs: changed subrepos (including dirty ones)
301 - commitsubs: dirty subrepos which the caller needs to commit recursively
302 - newstate: new state dict which the caller must write to .hgsubstate
303
304 This also updates the given status argument.
305 """
306 subs = []
307 commitsubs = set()
308 newstate = wctx.substate.copy()
309
310 # only manage subrepos and .hgsubstate if .hgsub is present
311 if '.hgsub' in wctx:
312 # we'll decide whether to track this ourselves, thanks
313 for c in status.modified, status.added, status.removed:
314 if '.hgsubstate' in c:
315 c.remove('.hgsubstate')
316
317 # compare current state to last committed state
318 # build new substate based on last committed state
319 oldstate = wctx.p1().substate
320 for s in sorted(newstate.keys()):
321 if not match(s):
322 # ignore working copy, use old state if present
323 if s in oldstate:
324 newstate[s] = oldstate[s]
325 continue
326 if not force:
327 raise error.Abort(
328 _("commit with new subrepo %s excluded") % s)
329 dirtyreason = wctx.sub(s).dirtyreason(True)
330 if dirtyreason:
331 if not ui.configbool('ui', 'commitsubrepos'):
332 raise error.Abort(dirtyreason,
333 hint=_("use --subrepos for recursive commit"))
334 subs.append(s)
335 commitsubs.add(s)
336 else:
337 bs = wctx.sub(s).basestate()
338 newstate[s] = (newstate[s][0], bs, newstate[s][2])
339 if oldstate.get(s, (None, None, None))[1] != bs:
340 subs.append(s)
341
342 # check for removed subrepos
343 for p in wctx.parents():
344 r = [s for s in p.substate if s not in newstate]
345 subs += [s for s in r if match(s)]
346 if subs:
347 if (not match('.hgsub') and
348 '.hgsub' in (wctx.modified() + wctx.added())):
349 raise error.Abort(_("can't commit subrepos without .hgsub"))
350 status.modified.insert(0, '.hgsubstate')
351
352 elif '.hgsub' in status.removed:
353 # clean up .hgsubstate when .hgsub is removed
354 if ('.hgsubstate' in wctx and
355 '.hgsubstate' not in (status.modified + status.added +
356 status.removed)):
357 status.removed.insert(0, '.hgsubstate')
358
359 return subs, commitsubs, newstate
360
296 361 def _updateprompt(ui, sub, dirty, local, remote):
297 362 if dirty:
298 363 msg = (_(' subrepository sources for %s differ\n'
General Comments 0
You need to be logged in to leave comments. Login now