mercurial/cmdutil.py
changeset 24306 6ddc86eedc3b
parent 24301 18b5b2c9d921
child 24309 fefcafda10b8
equal deleted inserted replaced
24305:867c3649be5d 24306:6ddc86eedc3b
   396                 pathname=None):
   396                 pathname=None):
   397 
   397 
   398     writable = mode not in ('r', 'rb')
   398     writable = mode not in ('r', 'rb')
   399 
   399 
   400     if not pat or pat == '-':
   400     if not pat or pat == '-':
   401         fp = writable and repo.ui.fout or repo.ui.fin
   401         if writable:
       
   402             fp = repo.ui.fout
       
   403         else:
       
   404             fp = repo.ui.fin
   402         if util.safehasattr(fp, 'fileno'):
   405         if util.safehasattr(fp, 'fileno'):
   403             return os.fdopen(os.dup(fp.fileno()), mode)
   406             return os.fdopen(os.dup(fp.fileno()), mode)
   404         else:
   407         else:
   405             # if this fp can't be duped properly, return
   408             # if this fp can't be duped properly, return
   406             # a dummy object that can be closed
   409             # a dummy object that can be closed
   472     dryrun = opts.get("dry_run")
   475     dryrun = opts.get("dry_run")
   473     wctx = repo[None]
   476     wctx = repo[None]
   474 
   477 
   475     def walkpat(pat):
   478     def walkpat(pat):
   476         srcs = []
   479         srcs = []
   477         badstates = after and '?' or '?r'
   480         if after:
       
   481             badstates = '?'
       
   482         else:
       
   483             badstates = '?r'
   478         m = scmutil.match(repo[None], [pat], opts, globbed=True)
   484         m = scmutil.match(repo[None], [pat], opts, globbed=True)
   479         for abs in repo.walk(m):
   485         for abs in repo.walk(m):
   480             state = repo.dirstate[abs]
   486             state = repo.dirstate[abs]
   481             rel = m.rel(abs)
   487             rel = m.rel(abs)
   482             exact = m.exact(abs)
   488             exact = m.exact(abs)
   691     runargs=None, appendpid=False):
   697     runargs=None, appendpid=False):
   692     '''Run a command as a service.'''
   698     '''Run a command as a service.'''
   693 
   699 
   694     def writepid(pid):
   700     def writepid(pid):
   695         if opts['pid_file']:
   701         if opts['pid_file']:
   696             mode = appendpid and 'a' or 'w'
   702             if appendpid:
       
   703                 mode = 'a'
       
   704             else:
       
   705                 mode = 'w'
   697             fp = open(opts['pid_file'], mode)
   706             fp = open(opts['pid_file'], mode)
   698             fp.write(str(pid) + '\n')
   707             fp.write(str(pid) + '\n')
   699             fp.close()
   708             fp.close()
   700 
   709 
   701     if opts['daemon'] and not opts['daemon_pipefds']:
   710     if opts['daemon'] and not opts['daemon_pipefds']:
   927         node = ctx.node()
   936         node = ctx.node()
   928         parents = [p.node() for p in ctx.parents() if p]
   937         parents = [p.node() for p in ctx.parents() if p]
   929         branch = ctx.branch()
   938         branch = ctx.branch()
   930         if switch_parent:
   939         if switch_parent:
   931             parents.reverse()
   940             parents.reverse()
   932         prev = (parents and parents[0]) or nullid
   941 
       
   942         if parents:
       
   943             prev = parents[0]
       
   944         else:
       
   945             prev = nullid
   933 
   946 
   934         shouldclose = False
   947         shouldclose = False
   935         if not fp and len(template) > 0:
   948         if not fp and len(template) > 0:
   936             desc_lines = ctx.description().rstrip().split('\n')
   949             desc_lines = ctx.description().rstrip().split('\n')
   937             desc = desc_lines[0]    #Commit always has a first line.
   950             desc = desc_lines[0]    #Commit always has a first line.
  1065             return
  1078             return
  1066 
  1079 
  1067         log = self.repo.changelog
  1080         log = self.repo.changelog
  1068         date = util.datestr(ctx.date())
  1081         date = util.datestr(ctx.date())
  1069 
  1082 
  1070         hexfunc = self.ui.debugflag and hex or short
  1083         if self.ui.debugflag:
       
  1084             hexfunc = hex
       
  1085         else:
       
  1086             hexfunc = short
  1071 
  1087 
  1072         parents = [(p, hexfunc(log.node(p)))
  1088         parents = [(p, hexfunc(log.node(p)))
  1073                    for p in self._meaningful_parentrevs(log, rev)]
  1089                    for p in self._meaningful_parentrevs(log, rev)]
  1074 
  1090 
  1075         # i18n: column positioning for "hg log"
  1091         # i18n: column positioning for "hg log"
  1864         }
  1880         }
  1865 
  1881 
  1866     opts = dict(opts)
  1882     opts = dict(opts)
  1867     # follow or not follow?
  1883     # follow or not follow?
  1868     follow = opts.get('follow') or opts.get('follow_first')
  1884     follow = opts.get('follow') or opts.get('follow_first')
  1869     followfirst = opts.get('follow_first') and 1 or 0
  1885     if opts.get('follow_first'):
       
  1886         followfirst = 1
       
  1887     else:
       
  1888         followfirst = 0
  1870     # --follow with FILE behaviour depends on revs...
  1889     # --follow with FILE behaviour depends on revs...
  1871     it = iter(revs)
  1890     it = iter(revs)
  1872     startrev = it.next()
  1891     startrev = it.next()
  1873     try:
  1892     try:
  1874         followdescendants = startrev < it.next()
  1893         followdescendants = startrev < it.next()