Skip to content
This repository was archived by the owner on Jul 1, 2023. It is now read-only.

Commit 6c31326

Browse files
committed
Initial commit
Lint clean, has boilerplate and license information, and has diff creation code from HHAST
0 parents  commit 6c31326

22 files changed

+1333
-0
lines changed

.LICENSE_HEADER.hh.txt

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
* Copyright (c) 2017-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*
8+
*/

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
vendor/
2+
*.swp
3+
*.swo
4+
.DS_Store

.hhconfig

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
assume_php=false

.travis.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
set -ex
3+
hhvm --version
4+
5+
composer install --ignore-platform-reqs
6+
7+
hh_client
8+
9+
#hhvm vendor/bin/phpunit
10+
hhvm vendor/bin/hhast-lint

.travis.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
language: php
2+
php:
3+
- hhvm
4+
- hhvm-nightly
5+
matrix:
6+
allow_failures:
7+
- php: hhvm-nightly
8+
script:
9+
- ./.travis.sh

CODE_OF_CONDUCT.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Code of Conduct
2+
3+
Facebook has adopted a Code of Conduct that we expect project participants to adhere to.
4+
Please read the [full text](https://code.fb.com/codeofconduct/)
5+
so that you can understand what actions will and will not be tolerated.

CONTRIBUTING.md

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Contributing to DiffLib
2+
3+
We want to make contributing to this project as easy and transparent as
4+
possible.
5+
6+
## Code of Conduct
7+
The code of conduct is described in [`CODE_OF_CONDUCT.md`](CODE_OF_CONDUCT.md).
8+
9+
## Our Development Process
10+
11+
We develop on master, and make releases on an as-needed basic - usually
12+
to support new HHVM releases.
13+
14+
## Pull Requests
15+
We actively welcome your pull requests.
16+
17+
1. Fork the repo and create your branch from `master`.
18+
2. If you've added code that should be tested, add tests.
19+
3. If you've changed APIs, update the documentation.
20+
4. Ensure the test suite passes.
21+
5. Make sure your code lints.
22+
6. If you haven't already, complete the Contributor License Agreement ("CLA").
23+
24+
## Contributor License Agreement ("CLA")
25+
In order to accept your pull request, we need you to submit a CLA. You only need
26+
to do this once to work on any of Facebook's open source projects.
27+
28+
Complete your CLA here: <https://code.facebook.com/cla>
29+
30+
## Issues
31+
We use GitHub issues to track public bugs. Please ensure your description is
32+
clear and has sufficient instructions to be able to reproduce the issue.
33+
34+
Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe
35+
disclosure of security bugs. In those cases, please go through the process
36+
outlined on that page and do not file a public issue.
37+
38+
## Coding Style
39+
* 2 spaces for indentation rather than tabs
40+
* 80 character line length
41+
* Match hackfmt output
42+
* Pass the configured HHAST linters
43+
44+
## License
45+
By contributing to DiffLib, you agree that your contributions will be licensed
46+
under the LICENSE file in the root directory of this source tree.

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017-present, Facebook, Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# DiffLib
2+
3+
DiffLib is a Hack library for creating and parsing diffs. Diffs can be created
4+
between any two sequences of items. Additional helpers (such as support for
5+
unified diffs, and colored diffs) are provided for string diffs.
6+
7+
Diffs are represented as a sequence of `DiffOp` operations; these can 'keep' an
8+
element (i.e. it's unchanged in both sequences), insert an element, or delete an
9+
element. For example, in a unified diff, these would be:
10+
11+
```diff
12+
DiffKeepOp
13+
- DiffDeleteOp
14+
+ DiffInsertOp
15+
```
16+
17+
String diffs are typically represented as a sequence of lines, but can also be
18+
represented as a sequence of characters, allowing intra-line diffs.
19+
20+
## Examples
21+
22+
```Hack
23+
use namespace Facebook\DiffLib;
24+
25+
function create_unified_diff(string $from, string $to): string {
26+
return DiffLib\StringDiff::lines($from, $to)->getUnifiedDiff();
27+
}
28+
29+
function create_colored_diff(string $from, string $to): string {
30+
return DiffLib\CLIColoredUnifiedDiff::create($from, $to);
31+
}
32+
33+
final class IntDiff extends DiffLib\Diff {
34+
const type TContent = int;
35+
}
36+
37+
function dump_int_diff(vec<int> $from, vec<int> $to): void {
38+
$diff = (new IntDiff($from, $to))->getDiff();
39+
foreach ($diff as $op) {
40+
if ($op is DiffLib\DiffKeepOp<_>) {
41+
\printf(" %d\n", $op->getContent());
42+
} else if ($op is DiffLib\DiffDeleteOp<_>) {
43+
\printf("- %d\n", $op->getContent());
44+
} else {
45+
$op = $op as DiffLib\DiffInsertOp<_>;
46+
printf("+ %d\n", $op->getContent());
47+
}
48+
}
49+
}
50+
51+
```
52+
53+
`dump_int_diff(vec[1, 3, 9], vec[1, 4, 9])` will produce this output:
54+
55+
```
56+
1
57+
- 3
58+
+ 4
59+
9
60+
```
61+
62+
## Requirements
63+
64+
* The current release version of HHVM
65+
66+
## Installing DiffLib
67+
68+
```
69+
composer require facebook/difflib
70+
```
71+
72+
## How DiffLib works
73+
74+
Diffs are created using Myers' diff algorithm:
75+
Myers, E.W. Algorithmica (1986) 1: 251. https://doi.org/10.1007/BF01840446
76+
77+
For more details, see [the commented implementation](src/Diff.php).
78+
79+
## Full documentation
80+
81+
- `DiffLib\Diff`: abstract base class. Needs to be subclassed to operate on
82+
any particular type.
83+
- `DiffLib\StringDiff`: final class for diffing strings, and adds support
84+
for creating unified diffs
85+
- `DiffLib\ColoredUnifiedDiff`: abstract class for rendering unified diffs.
86+
Output may be any type - for example, strings or XHP.
87+
- `DiffLib\CLIColoredUnifiedDiff`: abstract final class for rendering unified
88+
diffs to a terminal that supports color escape sequences. Provides intra-line
89+
highlighting.
90+
- `DiffLib\DiffOp`: abstract class for a diff operation. Sealed to
91+
`DiffInsertOp`, `DiffKeepOp`, and `DiffDeleteOp`.
92+
- `DiffLib\cluster()`: utility function to group together sequential operations
93+
of the same kind. Converts `vec<DiffOp<T>>` to a generally shorter number of
94+
`vec<DiffOp<vec<T>>>`
95+
96+
## License
97+
DiffLib is MIT licensed, as found in the LICENSE file.

composer.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "facebook/difflib",
3+
"license": "MIT",
4+
"require": {
5+
"hhvm/hsl": "^3.28"
6+
},
7+
"require-dev": {
8+
"hhvm/hhast": "^3.28"
9+
}
10+
}

0 commit comments

Comments
 (0)