Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcery refactored master branch #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Aug 11, 2023

Branch master refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from ia-kobos August 11, 2023 15:24
if not d or len(d) == 0:
return None
else:
return d
return None if not d or len(d) == 0 else d
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function git_dir refactored with the following changes:

Comment on lines -194 to +192
else:
sys.stderr.write(msg + "\n")
sys.exit(1)
sys.stderr.write(msg + "\n")
sys.exit(1)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function die refactored with the following changes:

Comment on lines -205 to +201
choices = set(m.group(1) for m in re.finditer(r"\[(.)\]", prompt_text))
choices = {m.group(1) for m in re.finditer(r"\[(.)\]", prompt_text)}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function prompt refactored with the following changes:

Comment on lines -308 to +312
else:
try:
path.decode('ascii')
except:
path = path.decode(encoding, errors='replace')
if verbose:
print('Path with non-ASCII characters detected. Used {} to decode: {}'.format(encoding, path))
return path
try:
path.decode('ascii')
except:
path = path.decode(encoding, errors='replace')
if verbose:
print(
f'Path with non-ASCII characters detected. Used {encoding} to decode: {path}'
)
return path
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function decode_path refactored with the following changes:

Comment on lines -323 to +320
for p in param:
args.append(p)
args.extend(iter(param))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function run_git_hook refactored with the following changes:

Comment on lines -678 to +663
else:
type_base, type_mods = split_p4_type(p4_type(file))
return p4_keywords_regexp_for_type(type_base, type_mods)
type_base, type_mods = split_p4_type(p4_type(file))
return p4_keywords_regexp_for_type(type_base, type_mods)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function p4_keywords_regexp_for_file refactored with the following changes:

Comment on lines -695 to +678
p4Type = p4Type[0:-1]
p4Type = p4Type[:-1]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function setP4ExecBit refactored with the following changes:

Comment on lines -704 to +690
match = re.match(".*\((.+)\)( \*exclusive\*)?\r?$", result)
if match:
return match.group(1)
if match := re.match(".*\((.+)\)( \*exclusive\*)?\r?$", result):
return match[1]
else:
die("Could not determine file type for %s (result: '%s')" % (file, result))
die(f"Could not determine file type for {file} (result: '{result}')")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function getP4OpenedType refactored with the following changes:

Comment on lines -718 to +700
for l in p4CmdList(["labels"] + ["%s..." % p for p in depotPaths]):
for l in p4CmdList(["labels"] + [f"{p}..." for p in depotPaths]):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function getP4Labels refactored with the following changes:

Comment on lines -762 to +744
match = _diff_tree_pattern.match(entry)
if match:
if match := _diff_tree_pattern.match(entry):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function parseDiffTreeEntry refactored with the following changes:

Comment on lines -854 to +839
if key in p4KeysContainingNonUtf8Chars() or \
key in p4KeysContainingBinaryData() or \
p4KeyContainsFilePaths(key):
return False
return True
return (
key not in p4KeysContainingNonUtf8Chars()
and key not in p4KeysContainingBinaryData()
and not p4KeyContainsFilePaths(key)
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function p4KeyWhichCanBeDirectlyDecoded refactored with the following changes:

Comment on lines -866 to +847
sys.stderr.write("Opening pipe: {}\n".format(' '.join(cmd)))
sys.stderr.write(f"Opening pipe: {' '.join(cmd)}\n")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function p4CmdList refactored with the following changes:

Comment on lines -944 to +923
result.update(entry)
result |= entry
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function p4Cmd refactored with the following changes:

Comment on lines -951 to +930
depotPathLong = depotPath + "..."
depotPathLong = f"{depotPath}..."
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function p4Where refactored with the following changes:

Comment on lines -1026 to +1005
assignments = m.group(1).split(':')
assignments = m[1].split(':')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function extractSettingsGitLog refactored with the following changes:

Comment on lines -1470 to +1425
assert False, "Method 'generatePointer' required in " + self.__class__.__name__
assert False, f"Method 'generatePointer' required in {self.__class__.__name__}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function LargeFileSystem.generatePointer refactored with the following changes:

Comment on lines -1476 to +1431
assert False, "Method 'pushFile' required in " + self.__class__.__name__
assert False, f"Method 'pushFile' required in {self.__class__.__name__}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function LargeFileSystem.pushFile refactored with the following changes:

Comment on lines -1481 to +1440
[relPath.endswith('.' + e) for e in gitConfigList('git-p4.largeFileExtensions')],
False
[
relPath.endswith(f'.{e}')
for e in gitConfigList('git-p4.largeFileExtensions')
],
False,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function LargeFileSystem.hasLargeFileExtension refactored with the following changes:

Comment on lines -1555 to +1513
pointerContents = 'pointer-' + content
pointerContents = f'pointer-{content}'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function MockLFS.generatePointer refactored with the following changes:

Comment on lines -1588 to +1547
['git', 'lfs', 'pointer', '--file=' + contentFile],
stdout=subprocess.PIPE
['git', 'lfs', 'pointer', f'--file={contentFile}'],
stdout=subprocess.PIPE,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function GitLFS.generatePointer refactored with the following changes:

Comment on lines -1652 to +1613
if relPath == '.gitattributes':
self.baseGitAttributes = contents
return (git_mode, self.generateGitAttributes())
else:
if relPath != '.gitattributes':
return LargeFileSystem.processContent(self, git_mode, relPath, contents)
self.baseGitAttributes = contents
return (git_mode, self.generateGitAttributes())
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function GitLFS.processContent refactored with the following changes:

Comment on lines -1694 to +1651
if not p4User or p4User != me:
return False
else:
return True
return bool(p4User and p4User == me)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function P4UserMap.p4UserIsMe refactored with the following changes:

Comment on lines -1701 to +1655
return home + "/.gitp4-usercache.txt"
return f"{home}/.gitp4-usercache.txt"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function P4UserMap.getUserCacheFilename refactored with the following changes:

Comment on lines -1728 to +1682
fulluser = fullname + " <" + email + ">"
fulluser = f"{fullname} <{email}>"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function P4UserMap.getUserMapFromPerforceServer refactored with the following changes:

Comment on lines -1744 to +1699
cache = open(self.getUserCacheFilename(), 'rb')
lines = cache.readlines()
cache.close()
with open(self.getUserCacheFilename(), 'rb') as cache:
lines = cache.readlines()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function P4UserMap.loadUserMapFromCache refactored with the following changes:

Comment on lines -2094 to +2042
system(["sh", "-c", ('%s "$@"' % editor), editor, template_file])
system(["sh", "-c", f'{editor} "$@"', editor, template_file])
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function P4Submit.edit_template refactored with the following changes:

Comment on lines -2115 to +2066
diff = ""
for editedFile in editedFiles:
diff += p4_read_pipe(['diff', '-du',
wildcard_encode(editedFile)])

diff = "".join(
p4_read_pipe(['diff', '-du', wildcard_encode(editedFile)])
for editedFile in editedFiles
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function P4Submit.get_diff_description refactored with the following changes:

mark = dict()
mark = {}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 38-75 refactored with the following changes:

Comment on lines -62 to +76
env = ''
elems = re.compile('(.*?)\s+<(.*)>').match(user)
if elems:
env += 'export GIT_AUTHOR_NAME="%s" ;' % elems.group(1)
env += 'export GIT_COMMITTER_NAME="%s" ;' % elems.group(1)
env += 'export GIT_AUTHOR_EMAIL="%s" ;' % elems.group(2)
env += 'export GIT_COMMITTER_EMAIL="%s" ;' % elems.group(2)
else:
env += 'export GIT_AUTHOR_NAME="%s" ;' % user
env += 'export GIT_COMMITTER_NAME="%s" ;' % user
env += 'export GIT_AUTHOR_EMAIL= ;'
env += 'export GIT_COMMITTER_EMAIL= ;'

env += 'export GIT_AUTHOR_DATE="%s" ;' % date
env += 'export GIT_COMMITTER_DATE="%s" ;' % date
return env
env = ''
if elems := re.compile('(.*?)\s+<(.*)>').match(user):
env += f'export GIT_AUTHOR_NAME="{elems[1]}" ;'
env += f'export GIT_COMMITTER_NAME="{elems[1]}" ;'
env += f'export GIT_AUTHOR_EMAIL="{elems[2]}" ;'
env += f'export GIT_COMMITTER_EMAIL="{elems[2]}" ;'
else:
env += f'export GIT_AUTHOR_NAME="{user}" ;'
env += f'export GIT_COMMITTER_NAME="{user}" ;'
env += 'export GIT_AUTHOR_EMAIL= ;'
env += 'export GIT_COMMITTER_EMAIL= ;'

env += f'export GIT_AUTHOR_DATE="{date}" ;'
env += f'export GIT_COMMITTER_DATE="{date}" ;'
return env
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function getgitenv refactored with the following changes:

Comment on lines -127 to +146
hgchildren[str(cset)] = ()
prnts = os.popen('hg log -r %d --template "{parents}"' % cset).read().strip().split(' ')
prnts = map(lambda x: x[:x.find(':')], prnts)
if prnts[0] != '':
parent = prnts[0].strip()
else:
parent = str(cset - 1)
hgchildren[parent] += ( str(cset), )
if len(prnts) > 1:
mparent = prnts[1].strip()
hgchildren[mparent] += ( str(cset), )
else:
mparent = None

hgparents[str(cset)] = (parent, mparent)

if mparent:
hgchildren[str(cset)] = ()
prnts = os.popen('hg log -r %d --template "{parents}"' % cset).read().strip().split(' ')
prnts = map(lambda x: x[:x.find(':')], prnts)
parent = prnts[0].strip() if prnts[0] != '' else str(cset - 1)
hgchildren[parent] += ( str(cset), )
if len(prnts) > 1:
mparent = prnts[1].strip()
hgchildren[mparent] += ( str(cset), )
else:
mparent = None

hgparents[str(cset)] = (parent, mparent)

if mparent:
# For merge changesets, take either one, preferably the 'master' branch
if hgbranch[mparent] == 'master':
hgbranch[str(cset)] = 'master'
else:
hgbranch[str(cset)] = hgbranch[parent]
else:
# Normal changesets
# For first children, take the parent branch, for the others create a new branch
if hgchildren[parent][0] == str(cset):
hgbranch[str(cset)] = hgbranch[parent]
else:
hgbranch[str(cset)] = "branch-" + str(cset)
hgbranch[str(cset)] = ('master' if hgbranch[mparent] == 'master' else
hgbranch[parent])
elif hgchildren[parent][0] == str(cset):
hgbranch[str(cset)] = hgbranch[parent]
else:
hgbranch[str(cset)] = f"branch-{str(cset)}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 127-242 refactored with the following changes:

This removes the following comments ( why? ):

# For first children, take the parent branch, for the others create a new branch
# Normal changesets

@what-the-diff
Copy link

what-the-diff bot commented Aug 11, 2023

PR Summary

  • Refactoring the file import-zips.py
    The variable 'mark' was updated to start as an empty dictionary. Added code to update the 'commit_time' using the maximum value between 'commit_time' and 'info.date_time'. Made several improvements in the areas of the code that print lines or write data, providing more detailed and updated output.

  • Refactoring the file hg-to-git.py
    The function 'getgitenv(user, date)' has been updated for better efficiency using the walrus operator. Furthermore, the way we create a new branch or switch to an existing one has seen some improvements. Other commands such as the ones used for file management, committing changes, handling tags, deleting branches, and showing information, are now using a more efficient string formatting method, making our code more modern and maintainable. A new line of code has been added to update the version control system's data, which will keep our version history more accurate.

Benefits of this PR include greater efficiency, improved maintainability, and a more accurate version control history.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants