mercurial/commands.py
changeset 33063 15a79ac823e8
parent 33055 18c2489ac96d
child 33066 a49ab7f5e7e7
equal deleted inserted replaced
33062:0a507da7d8ea 33063:15a79ac823e8
  2665     ('n', 'num', None, _('show local revision number')),
  2665     ('n', 'num', None, _('show local revision number')),
  2666     ('i', 'id', None, _('show global revision id')),
  2666     ('i', 'id', None, _('show global revision id')),
  2667     ('b', 'branch', None, _('show branch')),
  2667     ('b', 'branch', None, _('show branch')),
  2668     ('t', 'tags', None, _('show tags')),
  2668     ('t', 'tags', None, _('show tags')),
  2669     ('B', 'bookmarks', None, _('show bookmarks')),
  2669     ('B', 'bookmarks', None, _('show bookmarks')),
  2670     ] + remoteopts,
  2670     ] + remoteopts + formatteropts,
  2671     _('[-nibtB] [-r REV] [SOURCE]'),
  2671     _('[-nibtB] [-r REV] [SOURCE]'),
  2672     optionalrepo=True)
  2672     optionalrepo=True)
  2673 def identify(ui, repo, source=None, rev=None,
  2673 def identify(ui, repo, source=None, rev=None,
  2674              num=None, id=None, branch=None, tags=None, bookmarks=None, **opts):
  2674              num=None, id=None, branch=None, tags=None, bookmarks=None, **opts):
  2675     """identify the working directory or specified revision
  2675     """identify the working directory or specified revision
  2723     if source:
  2723     if source:
  2724         source, branches = hg.parseurl(ui.expandpath(source))
  2724         source, branches = hg.parseurl(ui.expandpath(source))
  2725         peer = hg.peer(repo or ui, opts, source) # only pass ui when no repo
  2725         peer = hg.peer(repo or ui, opts, source) # only pass ui when no repo
  2726         repo = peer.local()
  2726         repo = peer.local()
  2727         revs, checkout = hg.addbranchrevs(repo, peer, branches, None)
  2727         revs, checkout = hg.addbranchrevs(repo, peer, branches, None)
       
  2728 
       
  2729     fm = ui.formatter('identify', opts)
       
  2730     fm.startitem()
  2728 
  2731 
  2729     if not repo:
  2732     if not repo:
  2730         if num or branch or tags:
  2733         if num or branch or tags:
  2731             raise error.Abort(
  2734             raise error.Abort(
  2732                 _("can't query remote revision number, branch, or tags"))
  2735                 _("can't query remote revision number, branch, or tags"))
  2734             rev = revs[0]
  2737             rev = revs[0]
  2735         if not rev:
  2738         if not rev:
  2736             rev = "tip"
  2739             rev = "tip"
  2737 
  2740 
  2738         remoterev = peer.lookup(rev)
  2741         remoterev = peer.lookup(rev)
       
  2742         hexrev = hexfunc(remoterev)
  2739         if default or id:
  2743         if default or id:
  2740             output = [hexfunc(remoterev)]
  2744             output = [hexrev]
       
  2745         fm.data(id=hexrev)
  2741 
  2746 
  2742         def getbms():
  2747         def getbms():
  2743             bms = []
  2748             bms = []
  2744 
  2749 
  2745             if 'bookmarks' in peer.listkeys('namespaces'):
  2750             if 'bookmarks' in peer.listkeys('namespaces'):
  2747                 bms = [bm for bm, bmr in peer.listkeys('bookmarks').iteritems()
  2752                 bms = [bm for bm, bmr in peer.listkeys('bookmarks').iteritems()
  2748                        if bmr == hexremoterev]
  2753                        if bmr == hexremoterev]
  2749 
  2754 
  2750             return sorted(bms)
  2755             return sorted(bms)
  2751 
  2756 
       
  2757         bms = getbms()
  2752         if bookmarks:
  2758         if bookmarks:
  2753             output.extend(getbms())
  2759             output.extend(bms)
  2754         elif default and not ui.quiet:
  2760         elif default and not ui.quiet:
  2755             # multiple bookmarks for a single parent separated by '/'
  2761             # multiple bookmarks for a single parent separated by '/'
  2756             bm = '/'.join(getbms())
  2762             bm = '/'.join(bms)
  2757             if bm:
  2763             if bm:
  2758                 output.append(bm)
  2764                 output.append(bm)
       
  2765 
       
  2766         fm.data(node=hex(remoterev))
       
  2767         fm.data(bookmarks=fm.formatlist(bms, name='bookmark'))
  2759     else:
  2768     else:
  2760         ctx = scmutil.revsingle(repo, rev, None)
  2769         ctx = scmutil.revsingle(repo, rev, None)
  2761 
  2770 
  2762         if ctx.rev() is None:
  2771         if ctx.rev() is None:
  2763             ctx = repo[None]
  2772             ctx = repo[None]
  2765             taglist = []
  2774             taglist = []
  2766             for p in parents:
  2775             for p in parents:
  2767                 taglist.extend(p.tags())
  2776                 taglist.extend(p.tags())
  2768 
  2777 
  2769             changed = ""
  2778             changed = ""
  2770             if default or id or num:
  2779             if (any(repo.status())
  2771                 if (any(repo.status())
  2780                 or any(ctx.sub(s).dirty() for s in ctx.substate)):
  2772                     or any(ctx.sub(s).dirty() for s in ctx.substate)):
  2781                 changed = '+'
  2773                     changed = '+'
  2782             fm.data(changed=changed)
       
  2783 
       
  2784             hexoutput = [hexfunc(p.node()) for p in parents]
  2774             if default or id:
  2785             if default or id:
  2775                 output = ["%s%s" %
  2786                 output = ["%s%s" % ('+'.join(hexoutput), changed)]
  2776                   ('+'.join([hexfunc(p.node()) for p in parents]), changed)]
  2787             fm.data(id="%s%s" % ('+'.join(hexoutput), changed))
       
  2788 
  2777             if num:
  2789             if num:
  2778                 output.append("%s%s" %
  2790                 numoutput = ["%d" % p.rev() for p in parents]
  2779                   ('+'.join(["%d" % p.rev() for p in parents]), changed))
  2791                 output.append("%s%s" % ('+'.join(numoutput), changed))
       
  2792 
       
  2793             for i, p in enumerate(parents):
       
  2794                 fn = fm.nested('p%d' % (i + 1))
       
  2795                 fn.startitem()
       
  2796                 fn.data(rev=p.rev())
       
  2797                 fn.data(node=p.hex())
       
  2798                 fn.end()
  2780         else:
  2799         else:
       
  2800             hexoutput = hexfunc(ctx.node())
  2781             if default or id:
  2801             if default or id:
  2782                 output = [hexfunc(ctx.node())]
  2802                 output = [hexoutput]
       
  2803             fm.data(id=hexoutput)
       
  2804 
  2783             if num:
  2805             if num:
  2784                 output.append(pycompat.bytestr(ctx.rev()))
  2806                 output.append(pycompat.bytestr(ctx.rev()))
  2785             taglist = ctx.tags()
  2807             taglist = ctx.tags()
  2786 
  2808 
  2787         if default and not ui.quiet:
  2809         if default and not ui.quiet:
  2806                 output.extend(taglist)
  2828                 output.extend(taglist)
  2807 
  2829 
  2808             if bookmarks:
  2830             if bookmarks:
  2809                 output.extend(ctx.bookmarks())
  2831                 output.extend(ctx.bookmarks())
  2810 
  2832 
  2811     ui.write("%s\n" % ' '.join(output))
  2833         fm.data(node=ctx.hex())
       
  2834         fm.data(branch=ctx.branch())
       
  2835         fm.data(tags=fm.formatlist(taglist, name='tag', sep=':'))
       
  2836         fm.data(bookmarks=fm.formatlist(ctx.bookmarks(), name='bookmark'))
       
  2837 
       
  2838     fm.plain("%s\n" % ' '.join(output))
       
  2839     fm.end()
  2812 
  2840 
  2813 @command('import|patch',
  2841 @command('import|patch',
  2814     [('p', 'strip', 1,
  2842     [('p', 'strip', 1,
  2815      _('directory strip option for patch. This has the same '
  2843      _('directory strip option for patch. This has the same '
  2816        'meaning as the corresponding patch option'), _('NUM')),
  2844        'meaning as the corresponding patch option'), _('NUM')),