Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add binary files whose filenames contain spaces into changeset #217

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

Closed
Zipher04 wants to merge 3 commits into mantisbt-plugins:master from Zipher04:master
Closed

Conversation

@Zipher04
Copy link
Contributor

@Zipher04 Zipher04 commented May 5, 2017

Update HgWeb filename match pattern. So that binary files whose filenames contain spaces could be recognized in the changeset.

test sample:
diff -r 000000000000 -r 4f849d92debe 01 foo/bar.jpg
Binary file 01 foo/bar.jpg has changed

Zipher04 added 3 commits April 25, 2017 12:20
...ames contain spaces could be recognized in the changeset.
diff -r 000000000000 -r 4f849d92debe 01 foo/bar.jpg
Binary file 01 foo/bar.jpg has changed
$t_changeset->author_email = empty($t_commit['author_email'])? '': $t_commit['author_email'];

preg_match_all('#diff[\s]*-r[\s]([^\s]*)[\s]*-r[\s]([^\s]*)[\s]([^\n]*)\n(Binary file[\s]([^\s]*)[\s]has changed|\-{3}[\s](/dev/null)?[^\t]*[^\n]*\n\+{3}[\s](/dev/null)?[^\t]*\t[^\n]*)#', $p_input, $t_matches, PREG_SET_ORDER);
preg_match_all('#diff[\s]*-r[\s]([^\s]*)[\s]*-r[\s]([^\s]*)[\s]([^\n]*)\n(Binary file[\s]([^\n]*)[\s]has changed|\-{3}[\s](/dev/null)?[^\t]*[^\n]*\n\+{3}[\s](/dev/null)?[^\t]*\t[^\n]*)#', $p_input, $t_matches, PREG_SET_ORDER);
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure whether this would actually be an issue or not (I don't use Hg), but considering that \s matches HT (9), LF (10), FF (12), CR (13), and space (32), your change actually goes beyond what the PR's description says it does (i.e. it allows more than just space), and I'm wondering if this could be problematic in some situations, e.g. with CR+LF line endings on Windows.

Copy link
Contributor Author

@Zipher04 Zipher04 May 14, 2017
edited
Loading

Choose a reason for hiding this comment

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

Sorry for the late response and thank you for point out my fault. Because I have to match Chinese characters, but I was too greedy by using ([^\n]*) only. According to PHP page, I will change it to ([\P{C}]*) and have a test.

Copy link
Member

dregad commented May 5, 2017

As a side note, when sending pull requests, could you please

  1. create a dedicated feature branch for each pull requests instead of using master (here you used the same branch as for HgWeb: replace invalid function map() by array_map() #213 , and as a result the PR includes an unrelated commit)
  2. rebase your feature branch on top of latest master, so there's no need to deal with merge commits and potential conflicts

Thanks in advance

@dregad dregad added this to the 2.1.0 milestone May 5, 2017
Copy link
Contributor Author

Zipher04 commented May 6, 2017

OK, I am not familiar with git. I used the old-fashion SVN before. But I will try out your advice next time. Thanks for the guide.

Copy link
Member

dregad commented May 6, 2017

No worries. More importantly, you have not answered #217 (comment)

Copy link
Contributor Author

I have tested \P{C} in PHP 5.6.30.

preg_match_all('#([\P{C}]*)#', '中文', $t_matches, PREG_SET_ORDER);
var_dump($t_matches);

But it cannot match the Chinese characters as I thought.
If I change the pattern to ^\n, it will do the matches.

preg_match_all('#([^\n]*)#', '中文', $t_matches, PREG_SET_ORDER);
var_dump($t_matches);

I am not sure what is wrong about the \P{C}. Maybe I should change the original patter of [^\s]* to [^\r\n\t\f\v]* in order to enable space in the file path.

By the way, the sample input file for SourceHgWeb to match the file name in the changeset is

diff -r c56b67cfe60d -r bb6504e6a338 01 中文資料夾/中文檔案.jpg
Binary file 01 中文資料夾/中文檔案.jpg has changed

Copy link
Contributor Author

According to this post, an Unicode modifier u should be appended in order to enable \P{C} to match Unicode characters.
But the \P{C} will match the \n. That is not what we need. The correct pattern should be [\p{L}\p{N}\p{S}\p{P}\p{M} ]*. The pattern [^\r\n\t\f\v]* also works in my test. And I think the later one is easier to understand. I will create a new PR for this.

Copy link
Contributor Author

@dregad
I have create a new PR #219 for this feature. Please have a look. Thank you.

@dregad dregad removed this from the 2.1.0 milestone May 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@dregad dregad dregad left review comments

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

AltStyle によって変換されたページ (->オリジナル) /