Show More
@@ -43,6 +43,10 b' from mercurial import (' | |||||
43 | templateutil, |
|
43 | templateutil, | |
44 | ) |
|
44 | ) | |
45 |
|
45 | |||
|
46 | from mercurial.utils import ( | |||
|
47 | stringutil, | |||
|
48 | ) | |||
|
49 | ||||
46 | if pycompat.ispy3: |
|
50 | if pycompat.ispy3: | |
47 | import collections.abc |
|
51 | import collections.abc | |
48 | mutablemapping = collections.abc.MutableMapping |
|
52 | mutablemapping = collections.abc.MutableMapping | |
@@ -343,34 +347,91 b' def remotebrancheskw(context, mapping):' | |||||
343 | return templateutil.compatlist(context, mapping, 'remotebranch', |
|
347 | return templateutil.compatlist(context, mapping, 'remotebranch', | |
344 | remotebranches, plural='remotebranches') |
|
348 | remotebranches, plural='remotebranches') | |
345 |
|
349 | |||
346 | def _revsetutil(repo, subset, x, rtypes): |
|
350 | def _revsetutil(repo, subset, x, rtypes, args): | |
347 | """utility function to return a set of revs based on the rtypes""" |
|
351 | """utility function to return a set of revs based on the rtypes""" | |
348 |
|
352 | |||
349 | revs = set() |
|
353 | revs = set() | |
350 | cl = repo.changelog |
|
354 | cl = repo.changelog | |
|
355 | literals, matchers = args | |||
|
356 | # whether arguments were passed or not | |||
|
357 | argspassed = bool(literals or matchers) | |||
351 | for rtype in rtypes: |
|
358 | for rtype in rtypes: | |
352 | if rtype in repo.names: |
|
359 | if rtype in repo.names: | |
353 | ns = repo.names[rtype] |
|
360 | ns = repo.names[rtype] | |
354 | for name in ns.listnames(repo): |
|
361 | for name in ns.listnames(repo): | |
355 | revs.update(ns.nodes(repo, name)) |
|
362 | if argspassed: | |
|
363 | if name in literals: | |||
|
364 | revs.update(ns.nodes(repo, name)) | |||
|
365 | continue | |||
|
366 | for matcher in matchers: | |||
|
367 | if matcher(name): | |||
|
368 | revs.update(ns.nodes(repo, name)) | |||
|
369 | break | |||
|
370 | else: | |||
|
371 | revs.update(ns.nodes(repo, name)) | |||
356 |
|
372 | |||
357 | results = (cl.rev(n) for n in revs if cl.hasnode(n)) |
|
373 | results = (cl.rev(n) for n in revs if cl.hasnode(n)) | |
358 | return subset & smartset.baseset(sorted(results)) |
|
374 | return subset & smartset.baseset(sorted(results)) | |
359 |
|
375 | |||
360 | @revsetpredicate('remotenames()') |
|
376 | def _parseargs(x): | |
|
377 | """parses the argument passed in revsets | |||
|
378 | ||||
|
379 | returns (literals, matchers) where, | |||
|
380 | literals is a set of literals passed by user | |||
|
381 | matchers is a list of matcher objects for patterns passed by user | |||
|
382 | """ | |||
|
383 | ||||
|
384 | # set of paths passed as literals | |||
|
385 | literals = set() | |||
|
386 | # list of matcher to match the patterns passed as names | |||
|
387 | matchers = [] | |||
|
388 | ||||
|
389 | if not x: | |||
|
390 | return literals, matchers | |||
|
391 | ||||
|
392 | args = set() | |||
|
393 | lx = revsetlang.getlist(x) | |||
|
394 | err = _('the argument must be a string') | |||
|
395 | for entry in lx: | |||
|
396 | args.add(revsetlang.getstring(entry, err)) | |||
|
397 | for p in args: | |||
|
398 | kind, pattern, matcher = stringutil.stringmatcher(p) | |||
|
399 | if kind == 'literal': | |||
|
400 | literals.add(pattern) | |||
|
401 | else: | |||
|
402 | matchers.append(matcher) | |||
|
403 | return literals, matchers | |||
|
404 | ||||
|
405 | @revsetpredicate('remotenames([name, ...])') | |||
361 | def remotenamesrevset(repo, subset, x): |
|
406 | def remotenamesrevset(repo, subset, x): | |
362 |
"""All changesets which have a remotename on them. |
|
407 | """All changesets which have a remotename on them. If paths are specified, | |
363 | revsetlang.getargs(x, 0, 0, _("remotenames takes no arguments")) |
|
408 | remotenames of those remote paths are only considered. | |
364 | return _revsetutil(repo, subset, x, ('remotebookmarks', 'remotebranches')) |
|
409 | ||
|
410 | Pattern matching is supported for `name`. See :hg:`help revisions.patterns`. | |||
|
411 | """ | |||
365 |
|
412 | |||
366 | @revsetpredicate('remotebranches()') |
|
413 | args = _parseargs(x) | |
|
414 | return _revsetutil(repo, subset, x, ('remotebookmarks', 'remotebranches'), | |||
|
415 | args) | |||
|
416 | ||||
|
417 | @revsetpredicate('remotebranches([name, ...])') | |||
367 | def remotebranchesrevset(repo, subset, x): |
|
418 | def remotebranchesrevset(repo, subset, x): | |
368 |
"""All changesets which are branch heads on remotes. |
|
419 | """All changesets which are branch heads on remotes. If paths are specified, | |
369 | revsetlang.getargs(x, 0, 0, _("remotebranches takes no arguments")) |
|
420 | only those remotes paths are considered. | |
370 | return _revsetutil(repo, subset, x, ('remotebranches',)) |
|
421 | ||
|
422 | Pattern matching is supported for `name`. See :hg:`help revisions.patterns`. | |||
|
423 | """ | |||
|
424 | ||||
|
425 | args = _parseargs(x) | |||
|
426 | return _revsetutil(repo, subset, x, ('remotebranches',), args) | |||
371 |
|
427 | |||
372 | @revsetpredicate('remotebookmarks()') |
|
428 | @revsetpredicate('remotebookmarks([name, ...])') | |
373 | def remotebmarksrevset(repo, subset, x): |
|
429 | def remotebmarksrevset(repo, subset, x): | |
374 |
"""All changesets which have bookmarks on remotes. |
|
430 | """All changesets which have bookmarks on remotes. If paths are specified, | |
375 | revsetlang.getargs(x, 0, 0, _("remotebookmarks takes no arguments")) |
|
431 | only those remote paths are considered. | |
376 | return _revsetutil(repo, subset, x, ('remotebookmarks',)) |
|
432 | ||
|
433 | Pattern matching is supported for `name`. See :hg:`help revisions.patterns`. | |||
|
434 | """ | |||
|
435 | ||||
|
436 | args = _parseargs(x) | |||
|
437 | return _revsetutil(repo, subset, x, ('remotebookmarks',), args) |
@@ -289,6 +289,7 b' Testing the revsets provided by remotena' | |||||
289 | ~ |
|
289 | ~ | |
290 |
|
290 | |||
291 | Updating to revision using hoisted name |
|
291 | Updating to revision using hoisted name | |
|
292 | --------------------------------------- | |||
292 |
|
293 | |||
293 | Deleting local bookmark to make sure we update to hoisted name only |
|
294 | Deleting local bookmark to make sure we update to hoisted name only | |
294 |
|
295 | |||
@@ -393,3 +394,187 b' After the push, default/foo should move ' | |||||
393 | default/bar 6:87d6d6676308 |
|
394 | default/bar 6:87d6d6676308 | |
394 | default/foo 8:3e1487808078 |
|
395 | default/foo 8:3e1487808078 | |
395 | * foo 8:3e1487808078 |
|
396 | * foo 8:3e1487808078 | |
|
397 | ||||
|
398 | Testing the names argument to remotenames, remotebranches and remotebookmarks revsets | |||
|
399 | -------------------------------------------------------------------------------------- | |||
|
400 | ||||
|
401 | $ cd .. | |||
|
402 | $ hg clone ssh://user@dummy/server client2 | |||
|
403 | requesting all changes | |||
|
404 | adding changesets | |||
|
405 | adding manifests | |||
|
406 | adding file changes | |||
|
407 | added 9 changesets with 9 changes to 9 files (+1 heads) | |||
|
408 | new changesets 18d04c59bb5d:3e1487808078 | |||
|
409 | updating to branch default | |||
|
410 | 8 files updated, 0 files merged, 0 files removed, 0 files unresolved | |||
|
411 | $ cd server2 | |||
|
412 | $ hg up wat | |||
|
413 | 6 files updated, 0 files merged, 0 files removed, 0 files unresolved | |||
|
414 | $ echo foo > watwat | |||
|
415 | $ hg ci -Aqm "added watwat" | |||
|
416 | $ hg bookmark bar | |||
|
417 | abort: bookmark 'bar' already exists (use -f to force) | |||
|
418 | [255] | |||
|
419 | $ hg up ec24 | |||
|
420 | 3 files updated, 0 files merged, 2 files removed, 0 files unresolved | |||
|
421 | $ echo i > i | |||
|
422 | $ hg ci -Aqm "added i" | |||
|
423 | ||||
|
424 | $ cd ../client2 | |||
|
425 | $ echo "[paths]" >> .hg/hgrc | |||
|
426 | $ echo "server2 = $TESTTMP/server2" >> .hg/hgrc | |||
|
427 | $ hg pull server2 | |||
|
428 | pulling from $TESTTMP/server2 | |||
|
429 | searching for changes | |||
|
430 | adding changesets | |||
|
431 | adding manifests | |||
|
432 | adding file changes | |||
|
433 | added 2 changesets with 2 changes to 2 files | |||
|
434 | new changesets f34adec73c21:bf433e48adea | |||
|
435 | (run 'hg update' to get a working copy) | |||
|
436 | ||||
|
437 | $ hg log -Gr 'remotenames()' -T '{rev}:{node|short} {desc}\n({remotebranches}) [{remotebookmarks}]\n\n' | |||
|
438 | o 10:bf433e48adea added i | |||
|
439 | | (server2/default) [] | |||
|
440 | | | |||
|
441 | | o 9:f34adec73c21 added watwat | |||
|
442 | | | (server2/wat) [] | |||
|
443 | | | | |||
|
444 | | o 8:3e1487808078 added bar | |||
|
445 | | : (default/wat) [default/foo] | |||
|
446 | | : | |||
|
447 | @ : 7:ec2426147f0e Added h | |||
|
448 | | : (default/default) [] | |||
|
449 | | : | |||
|
450 | o : 6:87d6d6676308 Added g | |||
|
451 | :/ () [default/bar server2/bar] | |||
|
452 | : | |||
|
453 | o 3:62615734edd5 Added d | |||
|
454 | | () [server2/foo] | |||
|
455 | ~ | |||
|
456 | ||||
|
457 | Testing for a single remote name which exists | |||
|
458 | ||||
|
459 | $ hg log -r 'remotebranches("default/wat")' -GT "{rev}:{node|short} {remotebranches}\n" | |||
|
460 | o 8:3e1487808078 default/wat | |||
|
461 | | | |||
|
462 | ~ | |||
|
463 | ||||
|
464 | $ hg log -r 'remotebookmarks("server2/foo")' -GT "{rev}:{node|short} {remotebookmarks}\n" | |||
|
465 | o 3:62615734edd5 server2/foo | |||
|
466 | | | |||
|
467 | ~ | |||
|
468 | ||||
|
469 | $ hg log -r 'remotenames("re:default")' -GT "{rev}:{node|short} {remotenames}\n" | |||
|
470 | o 10:bf433e48adea server2/default | |||
|
471 | | | |||
|
472 | | o 8:3e1487808078 default/foo default/wat | |||
|
473 | | | | |||
|
474 | | ~ | |||
|
475 | @ 7:ec2426147f0e default/default | |||
|
476 | | | |||
|
477 | o 6:87d6d6676308 default/bar server2/bar | |||
|
478 | | | |||
|
479 | ~ | |||
|
480 | ||||
|
481 | Testing for a single name which does not exists | |||
|
482 | ||||
|
483 | $ hg log -r 'remotebranches(def)' -GT "{rev}:{node|short} {remotenames}\n" | |||
|
484 | ||||
|
485 | $ hg log -r 'remotebookmarks("server3")' -GT "{rev}:{node|short} {remotenames}\n" | |||
|
486 | ||||
|
487 | $ hg log -r 'remotenames("server3")' -GT "{rev}:{node|short} {remotenames}\n" | |||
|
488 | ||||
|
489 | Testing for multiple names where all of them exists | |||
|
490 | ||||
|
491 | $ hg log -r 'remotenames("re:default", "re:server2")' -GT "{rev}:{node|short} {remotenames}\n" | |||
|
492 | o 10:bf433e48adea server2/default | |||
|
493 | | | |||
|
494 | | o 9:f34adec73c21 server2/wat | |||
|
495 | | | | |||
|
496 | | o 8:3e1487808078 default/foo default/wat | |||
|
497 | | : | |||
|
498 | @ : 7:ec2426147f0e default/default | |||
|
499 | | : | |||
|
500 | o : 6:87d6d6676308 default/bar server2/bar | |||
|
501 | :/ | |||
|
502 | o 3:62615734edd5 server2/foo | |||
|
503 | | | |||
|
504 | ~ | |||
|
505 | ||||
|
506 | $ hg log -r 'remotebranches("default/wat", "server2/wat")' -GT "{rev}:{node|short} {remotebranches}\n" | |||
|
507 | o 9:f34adec73c21 server2/wat | |||
|
508 | | | |||
|
509 | o 8:3e1487808078 default/wat | |||
|
510 | | | |||
|
511 | ~ | |||
|
512 | ||||
|
513 | $ hg log -r 'remotebookmarks("default/foo", "server2/foo")' -GT "{rev}:{node|short} {remotebookmarks}\n" | |||
|
514 | o 8:3e1487808078 default/foo | |||
|
515 | : | |||
|
516 | o 3:62615734edd5 server2/foo | |||
|
517 | | | |||
|
518 | ~ | |||
|
519 | ||||
|
520 | Testing for multipe names where some exists and some not | |||
|
521 | ||||
|
522 | $ hg log -r 'remotenames(def, "re:server2")' -GT "{rev}:{node|short} {remotenames}\n" | |||
|
523 | o 10:bf433e48adea server2/default | |||
|
524 | : | |||
|
525 | : o 9:f34adec73c21 server2/wat | |||
|
526 | : : | |||
|
527 | o : 6:87d6d6676308 default/bar server2/bar | |||
|
528 | :/ | |||
|
529 | o 3:62615734edd5 server2/foo | |||
|
530 | | | |||
|
531 | ~ | |||
|
532 | ||||
|
533 | $ hg log -r 'remotebranches("default/default", server)' -GT "{rev}:{node|short} {remotebranches}\n" | |||
|
534 | @ 7:ec2426147f0e default/default | |||
|
535 | | | |||
|
536 | ~ | |||
|
537 | ||||
|
538 | $ hg log -r 'remotebookmarks("default/foo", serv)' -GT "{rev}:{node|short} {remotebookmarks}\n" | |||
|
539 | o 8:3e1487808078 default/foo | |||
|
540 | | | |||
|
541 | ~ | |||
|
542 | ||||
|
543 | Where multiple names specified and None of them exists | |||
|
544 | ||||
|
545 | $ hg log -r 'remotenames(def, serv2)' -GT "{rev}:{node|short} {remotenames}\n" | |||
|
546 | ||||
|
547 | $ hg log -r 'remotebranches(defu, server)' -GT "{rev}:{node|short} {remotebranches}\n" | |||
|
548 | ||||
|
549 | $ hg log -r 'remotebookmarks(delt, serv)' -GT "{rev}:{node|short} {remotebookmarks}\n" | |||
|
550 | ||||
|
551 | Testing pattern matching | |||
|
552 | ||||
|
553 | $ hg log -r 'remotenames("re:def")' -GT "{rev}:{node|short} {remotenames}\n" | |||
|
554 | o 10:bf433e48adea server2/default | |||
|
555 | | | |||
|
556 | | o 8:3e1487808078 default/foo default/wat | |||
|
557 | | | | |||
|
558 | | ~ | |||
|
559 | @ 7:ec2426147f0e default/default | |||
|
560 | | | |||
|
561 | o 6:87d6d6676308 default/bar server2/bar | |||
|
562 | | | |||
|
563 | ~ | |||
|
564 | ||||
|
565 | $ hg log -r 'remotebranches("re:ser.*2")' -GT "{rev}:{node|short} {remotebranches}\n" | |||
|
566 | o 10:bf433e48adea server2/default | |||
|
567 | | | |||
|
568 | ~ | |||
|
569 | o 9:f34adec73c21 server2/wat | |||
|
570 | | | |||
|
571 | ~ | |||
|
572 | ||||
|
573 | $ hg log -r 'remotebookmarks("re:def", "re:.*2")' -GT "{rev}:{node|short} {remotebookmarks}\n" | |||
|
574 | o 8:3e1487808078 default/foo | |||
|
575 | : | |||
|
576 | : o 6:87d6d6676308 default/bar server2/bar | |||
|
577 | :/ | |||
|
578 | o 3:62615734edd5 server2/foo | |||
|
579 | | | |||
|
580 | ~ |
General Comments 0
You need to be logged in to leave comments.
Login now