comparison hglib/client.py @ 56:9bd819da245a

client: add grep command
author Idan Kamara <idankk86@gmail.com>
date Fri, 19 Aug 2011 20:08:13 +0300
parents 5833f6ac0929
children 2657fd6fef04
comparison
equal deleted inserted replaced
55:5833f6ac0929 56:9bd819da245a
393 393
394 eh = util.reterrorhandler(args) 394 eh = util.reterrorhandler(args)
395 self.rawcommand(args, eh=eh) 395 self.rawcommand(args, eh=eh)
396 396
397 return bool(eh) 397 return bool(eh)
398
399 def grep(self, pattern, files=[], all=False, text=False, follow=False,
400 ignorecase=False, fileswithmatches=False, line=False, user=False,
401 date=False, include=None, exclude=None):
402 """
403 search for a pattern in specified files and revisions
404
405 yields (filename, revision, [line, [match status, [user, [date, [match]]]]])
406 per match depending on the given options.
407 """
408 if not isinstance(files, list):
409 files = [files]
410
411 args = cmdbuilder('grep', *[pattern] + files, all=all, a=text, f=follow,
412 i=ignorecase, l=fileswithmatches, n=line, u=user, d=date,
413 I=include, X=exclude)
414 args.append('-0')
415
416 def eh(ret, out, err):
417 if ret != 1:
418 raise error.CommandError(args, ret, out, err)
419 return ''
420
421 out = self.rawcommand(args, eh=eh).split('\0')
422
423 fieldcount = 3
424 if user:
425 fieldcount += 1
426 if date:
427 fieldcount += 1
428 if line:
429 fieldcount += 1
430 if all:
431 fieldcount += 1
432 if fileswithmatches:
433 fieldcount -= 1
434
435 return util.grouper(fieldcount, out)
398 436
399 def diff(self, files=[], revs=[], change=None, text=False, 437 def diff(self, files=[], revs=[], change=None, text=False,
400 git=False, nodates=False, showfunction=False, reverse=False, 438 git=False, nodates=False, showfunction=False, reverse=False,
401 ignoreallspace=False, ignorespacechange=False, ignoreblanklines=False, 439 ignoreallspace=False, ignorespacechange=False, ignoreblanklines=False,
402 unified=None, stat=False, subrepos=False, include=None, exclude=None): 440 unified=None, stat=False, subrepos=False, include=None, exclude=None):