Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hg.py @ 46914:50b79f8b802d
outgoing: move filtering logic in its own function
This move code dedicated to a single purpose together and make the main code
simpler. Right when we are getting ready to make it more complex :-D
Differential Revision: https://phab.mercurial-scm.org/D10382
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 13 Apr 2021 15:13:20 +0200 |
parents | b2740c547243 |
children | efc6f6a794bd |
comparison
equal
deleted
inserted
replaced
46913:b2740c547243 | 46914:50b79f8b802d |
---|---|
1356 sub = ctx.sub(subpath) | 1356 sub = ctx.sub(subpath) |
1357 ret = min(ret, sub.outgoing(ui, dest, opts)) | 1357 ret = min(ret, sub.outgoing(ui, dest, opts)) |
1358 return ret | 1358 return ret |
1359 | 1359 |
1360 | 1360 |
1361 def _outgoing_filter(repo, revs, opts): | |
1362 """apply revision filtering/ordering option for outgoing""" | |
1363 limit = logcmdutil.getlimit(opts) | |
1364 no_merges = opts.get(b'no_merges') | |
1365 if opts.get(b'newest_first'): | |
1366 revs.reverse() | |
1367 if limit is None and not no_merges: | |
1368 for r in revs: | |
1369 yield r | |
1370 return | |
1371 | |
1372 count = 0 | |
1373 cl = repo.changelog | |
1374 for n in revs: | |
1375 if limit is not None and count >= limit: | |
1376 break | |
1377 parents = [p for p in cl.parents(n) if p != nullid] | |
1378 if no_merges and len(parents) == 2: | |
1379 continue | |
1380 count += 1 | |
1381 yield n | |
1382 | |
1383 | |
1361 def outgoing(ui, repo, dest, opts): | 1384 def outgoing(ui, repo, dest, opts): |
1362 | 1385 |
1363 limit = logcmdutil.getlimit(opts) | |
1364 o, other = _outgoing(ui, repo, dest, opts) | 1386 o, other = _outgoing(ui, repo, dest, opts) |
1365 ret = 1 | 1387 ret = 1 |
1366 try: | 1388 try: |
1367 if o: | 1389 if o: |
1368 ret = 0 | 1390 ret = 0 |
1369 | 1391 |
1370 if opts.get(b'newest_first'): | |
1371 o.reverse() | |
1372 ui.pager(b'outgoing') | 1392 ui.pager(b'outgoing') |
1373 displayer = logcmdutil.changesetdisplayer(ui, repo, opts) | 1393 displayer = logcmdutil.changesetdisplayer(ui, repo, opts) |
1374 count = 0 | 1394 for n in _outgoing_filter(repo, o, opts): |
1375 for n in o: | |
1376 if limit is not None and count >= limit: | |
1377 break | |
1378 parents = [p for p in repo.changelog.parents(n) if p != nullid] | |
1379 if opts.get(b'no_merges') and len(parents) == 2: | |
1380 continue | |
1381 count += 1 | |
1382 displayer.show(repo[n]) | 1395 displayer.show(repo[n]) |
1383 displayer.close() | 1396 displayer.close() |
1384 cmdutil.outgoinghooks(ui, repo, other, opts, o) | 1397 cmdutil.outgoinghooks(ui, repo, other, opts, o) |
1385 ret = min(ret, _outgoing_recurse(ui, repo, dest, opts)) | 1398 ret = min(ret, _outgoing_recurse(ui, repo, dest, opts)) |
1386 return ret # exit code is zero since we found outgoing changes | 1399 return ret # exit code is zero since we found outgoing changes |