-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add python 3 versions of PT python scripts (#2930)
Co-authored-by: Raymond Luong <[email protected]>
- Loading branch information
1 parent
6f3e06b
commit 53fa502
Showing
2 changed files
with
63 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,80 @@ | ||
# Mercurial extension to provide the 'hg changedChapter' command | ||
|
||
"""command to list all changesets which changed the specified chapter""" | ||
'''command to list all changesets which changed the specified chapter''' | ||
|
||
from mercurial import commands, registrar | ||
from mercurial.i18n import _ | ||
|
||
from mercurial.node import short | ||
import re | ||
|
||
cmdtable = {} | ||
command = registrar.command(cmdtable) | ||
|
||
|
||
@command( | ||
"changedChapter", | ||
[("c", "chap", "", _("show revision changing the chapter"))] + commands.globalopts, | ||
_("hg changedChapter [-c CHAPTER] [FILE]"), | ||
) | ||
@command(b'changedChapter', | ||
[(b'c', b'chap', b'', _(b'show revision changing the chapter'))] + commands.globalopts, | ||
_(b'hg changedChapter [-c CHAPTER] [FILE]')) | ||
def changedChapter(ui, repo, file_=None, **opts): | ||
parts = opts.get("chap").split(".") | ||
parts = opts.get('chap').split(b'.') | ||
chapter = parts[0] | ||
if len(parts[1].split("-")) == 2: | ||
(v1, v2) = parts[1].split("-") | ||
if len(parts[1].split(b'-')) == 2: | ||
(v1, v2) = parts[1].split(b'-') | ||
else: | ||
# verse bridges present, just look for changed chapter text | ||
v1 = "" | ||
v2 = "" | ||
|
||
fl = repo.file(file_) # get filelog | ||
|
||
lastVerseText = "" # track verse text seen | ||
|
||
v1 = b'' | ||
v2 = b'' | ||
|
||
fl = repo.file(file_) # get filelog | ||
lastVerseText = b'' # track verse text seen | ||
|
||
for rev in fl: | ||
bookText = fl.revision(fl.node(rev)) | ||
chapterText = getChapter(chapter, bookText) | ||
if chapterText == "": | ||
continue | ||
|
||
if v1 != "": | ||
bookText = fl.revision(fl.node(rev)) | ||
chapterText = getChapter(chapter, bookText) | ||
if chapterText == b'': continue | ||
|
||
if v1 != b'': | ||
verseText = getVerses(v1, v2, chapterText) | ||
else: | ||
verseText = chapterText | ||
|
||
if verseText == lastVerseText: | ||
continue | ||
|
||
if verseText == lastVerseText: continue | ||
lastVerseText = verseText | ||
|
||
ui.write(str(int(fl.linkrev(rev))) + "\r\n") | ||
ui.write(str(int(fl.linkrev(rev))).encode() + b'\r\n') | ||
ui.flush() | ||
|
||
|
||
# Extract the text of the specificed chapter from the text of the book | ||
|
||
|
||
def getChapter(chapter, text): | ||
parts = re.split(r"(\\c\s+\S+)", text) | ||
parts = re.split(b'(\\\\c\\s+\\S+)', text) | ||
i = findIndex(parts, chapter) | ||
if i == -1: | ||
return "" | ||
|
||
if chapter == "1": | ||
return parts[i - 1] + parts[i] + parts[i + 1] | ||
|
||
return parts[i] + parts[i + 1] | ||
|
||
if i == -1: return b'' | ||
|
||
if chapter == b'1': | ||
return parts[i-1] + parts[i] + parts[i+1] | ||
|
||
return parts[i] + parts[i+1] | ||
|
||
def getVerses(v1, v2, text): | ||
parts = re.split(r"(\\v\s+\S+)", text) | ||
parts = re.split(b'(\\\\v\\s+\\S+)', text) | ||
i = findIndex(parts, v1) | ||
if i == -1: | ||
return text | ||
if i == -1: return text | ||
j = findIndex(parts, v2) | ||
if j == -1: | ||
return text | ||
|
||
result = "" | ||
if j == -1: return text | ||
|
||
result = b'' | ||
if i == 1: | ||
result = parts[0] | ||
|
||
while i <= j: | ||
result += parts[i] + parts[i + 1] | ||
result += parts[i] + parts[i+1] | ||
i = i + 2 | ||
|
||
return result | ||
|
||
|
||
|
||
def findIndex(parts, match): | ||
for i in range(1, len(parts), 2): | ||
pieces = parts[i].split() | ||
if pieces[1] == match: | ||
return i | ||
|
||
return -1 |