Skip to content
This repository was archived by the owner on Sep 2, 2018. It is now read-only.

Update/fix diff #13

Merged
merged 4 commits into from
Jun 11, 2018
Merged

Update/fix diff #13

merged 4 commits into from
Jun 11, 2018

Conversation

josix
Copy link

@josix josix commented Jun 7, 2018

  • Update git show to take an arbitrary hash
  • Add current working directory to file path

josix added 2 commits June 7, 2018 22:24
* Add original_po_file_commit_hash to main func argument
* Add argument <original_po_file_commit_hash> to argv
* Avoid a path checking thrown by git show (will lead to crash)
def main(fp):
p = subprocess.Popen(['git', 'show', 'HEAD:' + fp], stdout=subprocess.PIPE)
def main(fp, original_po_commit='HEAD'):
p = subprocess.Popen(['git', 'show', '{}:'.format(original_po_commit) + fp], stdout=subprocess.PIPE)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd propose to use string formatting for both original_po_commit and fp instead of using both formatting and concatenation.

Or actually, since this is the Python 3.6 translation, why don't we use f-strings? 😎

Copy link
Author

Choose a reason for hiding this comment

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

Oh, that's right! I will update it into using f-string.

if len(sys.argv) < 2:
print('Usage: python fix_diffs.py <po_file_path>')
print('Usage: python fix_diffs.py <po_file_path> <original_po_file_commit_hash>')
Copy link
Contributor

Choose a reason for hiding this comment

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

We should mark this argument as optional through marking the variable with a pair of square brackets or something similar. And also it would be great to show the default value (which is HEAD) here in some way.

Also I'd suggest to not use the word "hash" here as it can be HEAD, HEAD~3 etc. which are not hashes but represents a commit.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for your suggestion! I've fixed it. Please check it whether proper.


fp = sys.argv[1]
output_lines = main(fp)
fp = './' + sys.argv[1]
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious about this line, can you please explain the reason behind this line of code? As far as I understand, a relative path defaults to be relative to the current directory. What is an example case you're trying to resolve with this?

Copy link
Author

Choose a reason for hiding this comment

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

I found an error when I was running the script in the subdirectory 'tutorial' (or any subdirectory like '/reference',' /howto'...etc):
(Actually, I don't know how to explain this bug in detail 😅. Maybe the image below could reveal this bug.)
2018-06-10 1 53 37

Copy link
Contributor

Choose a reason for hiding this comment

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

I see where the problem is, this is because I was passing the filename argument directly to git show, however the git object indicating the file at HEAD should be HEAD:<path> where the path argument is by default relative to the root of the git repo.

Thanks! ✨

@adrianliaw
Copy link
Contributor

@wilson8507 Thanks for contributing! I've left some comments here, it would be great if you can take a look at them 🙏

josix added 2 commits June 10, 2018 14:54
* Update argument naming
* Add exit against wrong arguments input
@josix
Copy link
Author

josix commented Jun 10, 2018

@adrianliaw I've fixed the problems mentioned above, please check it ~ Thank you!

@adrianliaw adrianliaw merged commit 00a6a12 into python-doc-tw:3.6 Jun 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants