mercurial/commands.py
changeset 2920 ef8ee4477019
parent 2907 b70740aefa4d
parent 2908 3848488244fc
child 2922 773c5b82d052
equal deleted inserted replaced
2907:b70740aefa4d 2920:ef8ee4477019
   181             matches = filter(matchfn, changefiles)
   181             matches = filter(matchfn, changefiles)
   182             if matches:
   182             if matches:
   183                 fncache[rev] = matches
   183                 fncache[rev] = matches
   184                 wanted[rev] = 1
   184                 wanted[rev] = 1
   185 
   185 
   186     class followfilter:
   186     def iterate():
   187         def __init__(self, onlyfirst=False):
   187         class followfilter:
   188             self.startrev = -1
   188             def __init__(self, onlyfirst=False):
   189             self.roots = []
   189                 self.startrev = -1
   190             self.onlyfirst = onlyfirst
   190                 self.roots = []
   191 
   191                 self.onlyfirst = onlyfirst
   192         def match(self, rev):
   192 
   193             def realparents(rev):
   193             def match(self, rev):
   194                 if self.onlyfirst:
   194                 def realparents(rev):
   195                     return repo.changelog.parentrevs(rev)[0:1]
   195                     if self.onlyfirst:
       
   196                         return repo.changelog.parentrevs(rev)[0:1]
       
   197                     else:
       
   198                         return filter(lambda x: x != -1, repo.changelog.parentrevs(rev))
       
   199 
       
   200                 if self.startrev == -1:
       
   201                     self.startrev = rev
       
   202                     return True
       
   203 
       
   204                 if rev > self.startrev:
       
   205                     # forward: all descendants
       
   206                     if not self.roots:
       
   207                         self.roots.append(self.startrev)
       
   208                     for parent in realparents(rev):
       
   209                         if parent in self.roots:
       
   210                             self.roots.append(rev)
       
   211                             return True
   196                 else:
   212                 else:
   197                     return filter(lambda x: x != -1, repo.changelog.parentrevs(rev))
   213                     # backwards: all parents
   198 
   214                     if not self.roots:
   199             if self.startrev == -1:
   215                         self.roots.extend(realparents(self.startrev))
   200                 self.startrev = rev
   216                     if rev in self.roots:
   201                 return True
   217                         self.roots.remove(rev)
   202 
   218                         self.roots.extend(realparents(rev))
   203             if rev > self.startrev:
       
   204                 # forward: all descendants
       
   205                 if not self.roots:
       
   206                     self.roots.append(self.startrev)
       
   207                 for parent in realparents(rev):
       
   208                     if parent in self.roots:
       
   209                         self.roots.append(rev)
       
   210                         return True
   219                         return True
   211             else:
   220 
   212                 # backwards: all parents
   221                 return False
   213                 if not self.roots:
   222 
   214                     self.roots.extend(realparents(self.startrev))
       
   215                 if rev in self.roots:
       
   216                     self.roots.remove(rev)
       
   217                     self.roots.extend(realparents(rev))
       
   218                     return True
       
   219 
       
   220             return False
       
   221 
       
   222     # it might be worthwhile to do this in the iterator if the rev range
       
   223     # is descending and the prune args are all within that range
       
   224     for rev in opts.get('prune', ()):
       
   225         rev = repo.changelog.rev(repo.lookup(rev))
       
   226         ff = followfilter()
       
   227         stop = min(revs[0], revs[-1])
       
   228         for x in range(rev, stop-1, -1):
       
   229             if ff.match(x) and wanted.has_key(x):
       
   230                 del wanted[x]
       
   231 
       
   232     def iterate():
       
   233         if follow and not files:
   223         if follow and not files:
   234             ff = followfilter(onlyfirst=opts.get('follow_first'))
   224             ff = followfilter(onlyfirst=opts.get('follow_first'))
   235             def want(rev):
   225             def want(rev):
   236                 if ff.match(rev) and rev in wanted:
   226                 if rev not in wanted:
   237                     return True
   227                     return False
   238                 return False
   228                 return ff.match(rev)
   239         else:
   229         else:
   240             def want(rev):
   230             def want(rev):
   241                 return rev in wanted
   231                 return rev in wanted
   242 
   232 
   243         for i, window in increasing_windows(0, len(revs)):
   233         for i, window in increasing_windows(0, len(revs)):
  1345     node1, node2 = revpair(ui, repo, opts['rev'])
  1335     node1, node2 = revpair(ui, repo, opts['rev'])
  1346 
  1336 
  1347     fns, matchfn, anypats = cmdutil.matchpats(repo, pats, opts)
  1337     fns, matchfn, anypats = cmdutil.matchpats(repo, pats, opts)
  1348 
  1338 
  1349     patch.diff(repo, node1, node2, fns, match=matchfn,
  1339     patch.diff(repo, node1, node2, fns, match=matchfn,
  1350                opts=ui.diffopts(opts))
  1340                opts=patch.diffopts(ui, opts))
  1351 
  1341 
  1352 def export(ui, repo, *changesets, **opts):
  1342 def export(ui, repo, *changesets, **opts):
  1353     """dump the header and diffs for one or more changesets
  1343     """dump the header and diffs for one or more changesets
  1354 
  1344 
  1355     Print the changeset header and diffs for one or more revisions.
  1345     Print the changeset header and diffs for one or more revisions.
  1382     if len(revs) > 1:
  1372     if len(revs) > 1:
  1383         ui.note(_('exporting patches:\n'))
  1373         ui.note(_('exporting patches:\n'))
  1384     else:
  1374     else:
  1385         ui.note(_('exporting patch:\n'))
  1375         ui.note(_('exporting patch:\n'))
  1386     patch.export(repo, map(repo.lookup, revs), template=opts['output'],
  1376     patch.export(repo, map(repo.lookup, revs), template=opts['output'],
  1387                  switch_parent=opts['switch_parent'], opts=ui.diffopts(opts))
  1377                  switch_parent=opts['switch_parent'],
       
  1378                  opts=patch.diffopts(ui, opts))
  1388 
  1379 
  1389 def forget(ui, repo, *pats, **opts):
  1380 def forget(ui, repo, *pats, **opts):
  1390     """don't add the specified files on the next commit (DEPRECATED)
  1381     """don't add the specified files on the next commit (DEPRECATED)
  1391 
  1382 
  1392     (DEPRECATED)
  1383     (DEPRECATED)
  1679             else:
  1670             else:
  1680                 # launch the editor
  1671                 # launch the editor
  1681                 message = None
  1672                 message = None
  1682             ui.debug(_('message:\n%s\n') % message)
  1673             ui.debug(_('message:\n%s\n') % message)
  1683 
  1674 
  1684             files, fuzz = patch.patch(tmpname, ui, strip=strip, cwd=repo.root)
  1675             files = patch.patch(strip, tmpname, ui, cwd=repo.root)
  1685             removes = []
  1676             removes = []
  1686             if len(files) > 0:
  1677             if len(files) > 0:
  1687                 cfiles = files.keys()
  1678                 cfiles = files.keys()
  1688                 copies = []
  1679                 copies = []
  1689                 copts = {'after': False, 'force': False}
  1680                 copts = {'after': False, 'force': False}
  1967 
  1958 
  1968     Merge the contents of the current working directory and the
  1959     Merge the contents of the current working directory and the
  1969     requested revision. Files that changed between either parent are
  1960     requested revision. Files that changed between either parent are
  1970     marked as changed for the next commit and a commit must be
  1961     marked as changed for the next commit and a commit must be
  1971     performed before any further updates are allowed.
  1962     performed before any further updates are allowed.
  1972 
  1963     """
  1973     If no revision is specified, the working directory's parent is a
  1964 
  1974     head revision, and the repository contains exactly one other head,
  1965     node = _lookup(repo, node, branch)
  1975     the other head is merged with by default.  Otherwise, an explicit
       
  1976     revision to merge with must be provided.
       
  1977     """
       
  1978 
       
  1979     if node:
       
  1980         node = _lookup(repo, node, branch)
       
  1981     else:
       
  1982         heads = repo.heads()
       
  1983         if len(heads) > 2:
       
  1984             raise util.Abort(_('repo has %d heads - '
       
  1985                                'please merge with an explicit rev') %
       
  1986                              len(heads))
       
  1987         if len(heads) == 1:
       
  1988             raise util.Abort(_('there is nothing to merge - '
       
  1989                                'use "hg update" instead'))
       
  1990         parent = repo.dirstate.parents()[0]
       
  1991         if parent not in heads:
       
  1992             raise util.Abort(_('working dir not at a head rev - '
       
  1993                                'use "hg update" or merge with an explicit rev'))
       
  1994         node = parent == heads[0] and heads[-1] or heads[0]
       
  1995     return hg.merge(repo, node, force=force)
  1966     return hg.merge(repo, node, force=force)
  1996 
  1967 
  1997 def outgoing(ui, repo, dest=None, **opts):
  1968 def outgoing(ui, repo, dest=None, **opts):
  1998     """show changesets not found in destination
  1969     """show changesets not found in destination
  1999 
  1970 
  2895         (diff,
  2866         (diff,
  2896          [('r', 'rev', [], _('revision')),
  2867          [('r', 'rev', [], _('revision')),
  2897           ('a', 'text', None, _('treat all files as text')),
  2868           ('a', 'text', None, _('treat all files as text')),
  2898           ('p', 'show-function', None,
  2869           ('p', 'show-function', None,
  2899            _('show which function each change is in')),
  2870            _('show which function each change is in')),
  2900           ('g', 'git', None, _('use git extended diff format')),
       
  2901           ('w', 'ignore-all-space', None,
  2871           ('w', 'ignore-all-space', None,
  2902            _('ignore white space when comparing lines')),
  2872            _('ignore white space when comparing lines')),
  2903           ('b', 'ignore-space-change', None,
  2873           ('b', 'ignore-space-change', None,
  2904            _('ignore changes in the amount of white space')),
  2874            _('ignore changes in the amount of white space')),
  2905           ('B', 'ignore-blank-lines', None,
  2875           ('B', 'ignore-blank-lines', None,
  2995           ('r', 'rev', [], _('show the specified revision or range')),
  2965           ('r', 'rev', [], _('show the specified revision or range')),
  2996           ('M', 'no-merges', None, _('do not show merges')),
  2966           ('M', 'no-merges', None, _('do not show merges')),
  2997           ('', 'style', '', _('display using template map file')),
  2967           ('', 'style', '', _('display using template map file')),
  2998           ('m', 'only-merges', None, _('show only merges')),
  2968           ('m', 'only-merges', None, _('show only merges')),
  2999           ('p', 'patch', None, _('show patch')),
  2969           ('p', 'patch', None, _('show patch')),
  3000           ('P', 'prune', [], _('do not display revision or any of its ancestors')),
       
  3001           ('', 'template', '', _('display with template')),
  2970           ('', 'template', '', _('display with template')),
  3002           ('I', 'include', [], _('include names matching the given patterns')),
  2971           ('I', 'include', [], _('include names matching the given patterns')),
  3003           ('X', 'exclude', [], _('exclude names matching the given patterns'))],
  2972           ('X', 'exclude', [], _('exclude names matching the given patterns'))],
  3004          _('hg log [OPTION]... [FILE]')),
  2973          _('hg log [OPTION]... [FILE]')),
  3005     "manifest": (manifest, [], _('hg manifest [REV]')),
  2974     "manifest": (manifest, [], _('hg manifest [REV]')),