Famlam
I prefer to use grep for this purpose: hg grep string_to_search -r tip
You can even use regular expressions.
BTW, I came here today to share changes which I made to FOP when I started to use it to sort things in the RU Adlist.
1. I've modified sort function to handle cases ~popup,popup (block everything including popups) and also I prefer to have third-party option first in the list.
Code: Select all
def sortfunc (option):
# For identical options, the inverse always follows the non-inverse option ($image,~image instead of $~image,image) with exception for popup filter
if option[0] == "~": return option[1:] + "{"
if option == "popup": return option + "}"
# Also let third-party will always be first in the list
if option.find("third-party") > -1: return "0" + option
return option
def filtertidy (filterin):
""" Sort the options of blocking filters and make the filter text
lower case if applicable."""
optionsplit = re.match(OPTIONPATTERN, filterin)
if not optionsplit:
# Remove unnecessary asterisks from filters without any options and return them
return removeunnecessarywildcards(filterin)
else:
# If applicable, separate and sort the filter options in addition to the filter text
filtertext = removeunnecessarywildcards(optionsplit.group(1))
optionlist = optionsplit.group(2).lower().replace("_", "-").split(",")
domainlist = []
removeentries = []
for option in optionlist:
# Detect and separate domain options
if option[0:7] == "domain=":
domainlist.extend(option[7:].split("|"))
removeentries.append(option)
elif option.strip("~") not in KNOWNOPTIONS:
print("Warning: The option \"{option}\" used on the filter \"{problemfilter}\" is not recognised by FOP".format(option = option, problemfilter = filterin))
# Sort all options other than domain alphabetically with a few exceptions
optionlist = sorted(set(filter(lambda option: option not in removeentries, optionlist)), key = sortfunc)
# If applicable, sort domain restrictions and append them to the list of options
if domainlist:
optionlist.append("domain={domainlist}".format(domainlist = "|".join(sorted(set(domainlist), key = lambda domain: domain.strip("~")))))
# Return the full filter
return "{filtertext}${options}".format(filtertext = filtertext, options = ",".join(optionlist))
Actual changes:
Code: Select all
def sortfunc (option):
# For identical options, the inverse always follows the non-inverse option ($image,~image instead of $~image,image) with exception for popup filter
if option[0] == "~": return option[1:] + "{"
if option == "popup": return option + "}"
# Also let third-party will always be first in the list
if option.find("third-party") > -1: return "0" + option
return option
and
Code: Select all
# Sort all options other than domain alphabetically with a few exceptions
optionlist = sorted(set(filter(lambda option: option not in removeentries, optionlist)), key = sortfunc)
instead of
Code: Select all
# Sort all options other than domain alphabetically
# For identical options, the inverse always follows the non-inverse option ($image,~image instead of $~image,image)
optionlist = sorted(set(filter(lambda option: option not in removeentries, optionlist)), key = lambda option: (option[1:] + "~") if option[0] == "~" else option)
2. I've extended list of commands to perform on commit to better handle situations when commits were made from different sources and merge changes automatically. I'm not sure I did it right but it works for me in most of the cases
Code: Select all
REPODEF = collections.namedtuple("repodef", "name, directory, locationoption, repodirectoryoption, checkchanges, difference, pull, checkupdate, update, merge, commit, push")
GIT = REPODEF(["git"], "./.git/", "--work-tree=", "--git-dir=", ["status", "-s", "--untracked-files=no"], ["diff"], ["pull"], ["update", "--check"], ["update"], ["merge"], ["commit", "-m"], ["push"])
HG = REPODEF(["hg"], "./.hg/", "-R", None, ["stat", "-q"], ["diff"], ["pull"], ["update", "--check"], ["update"], ["merge"], ["commit", "-m"], ["push"])
and
Code: Select all
# Allow users to abort the commit process if they do not approve of the changes
except (KeyboardInterrupt, SystemExit):
print("\nCommit aborted.")
return
print("Comment \"{comment}\" accepted.".format(comment = comment))
try:
print("\nConnecting to server. Please enter your password if required.")
# Update the server repository as required by the revision control system
for command in repository[6:]:
if command == repository.commit:
command += [comment]
command = basecommand + command
subprocess.Popen(command).communicate()
print()
except(subprocess.CalledProcessError):
print("Unexpected error with the command \"{command}\".".format(command = command))
raise subprocess.CalledProcessError("Aborting FOP.")
except(OSError):
print("Unexpected error with the command \"{command}\".".format(command = command))
raise OSError("Aborting FOP.")
print("Completed commit process successfully.")
Actual change in the second part:
Code: Select all
print("\nConnecting to server. Please enter your password if required.")
# Update the server repository as required by the revision control system
for command in repository[6:]:
if command == repository.commit:
command += [comment]
instead of
Code: Select all
# Commit the changes
command = basecommand + repository.commit + [comment]
subprocess.Popen(command).communicate()
print("\nConnecting to server. Please enter your password if required.")
# Update the server repository as required by the revision control system
for command in repository[7:]: