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

Implement Patch in C++ #12

Merged
merged 71 commits into from
Dec 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
1bbe2e2
Start work on C++ Patch
maxbrunsfeld Nov 1, 2016
5fba88d
Add Patch destructor
maxbrunsfeld Nov 1, 2016
95be575
Add native test for non-overlapping splices
maxbrunsfeld Nov 1, 2016
b677fbf
Add missing include path in clang_complete file
maxbrunsfeld Nov 1, 2016
223bac4
Run mocha on on JS files in npm test
maxbrunsfeld Nov 1, 2016
669a5a4
Add Patch.printDotGraph method, for debugging
maxbrunsfeld Nov 1, 2016
d9d1e2d
Make JS hunk properties camel case
maxbrunsfeld Nov 1, 2016
33aebbc
Fix bugs in native Patch.splice
maxbrunsfeld Nov 1, 2016
9d3061c
Add Patch.getHunksInNewRange
maxbrunsfeld Nov 1, 2016
2d30e56
Add test-with-debug-graph script
maxbrunsfeld Nov 1, 2016
a75e505
Add Patch.getHunksInOldRange
maxbrunsfeld Nov 2, 2016
1ec9d5a
Add Patch.translateOldPosition and .translateNewPosition
maxbrunsfeld Nov 2, 2016
ce4f907
Use NVM_PATH env var in .clang_complete file
maxbrunsfeld Nov 2, 2016
9886c95
Add segfault-handler as dev dependency
maxbrunsfeld Nov 2, 2016
0f462e1
Don't keep .clang_complete file in version control
maxbrunsfeld Nov 2, 2016
3aca0d6
Make Patch helper functions instance methods
maxbrunsfeld Nov 2, 2016
302bf1a
Add Patch serialization and deserialization methods
maxbrunsfeld Nov 3, 2016
0420180
Clean up patch serialization code
maxbrunsfeld Nov 3, 2016
6193600
Fix compiler errors on travis
maxbrunsfeld Nov 3, 2016
17451c6
Use new gcc on travis
maxbrunsfeld Nov 3, 2016
dbca25a
Add clip mode parameter to position translation
Nov 3, 2016
bce0896
Default clipMode to CLOSEST
maxbrunsfeld Nov 3, 2016
4c4bdc0
Replace translate{Old,New}Position with hunkFor{Old,New}Position
maxbrunsfeld Nov 4, 2016
bc01c99
Add appveyor.yml
maxbrunsfeld Nov 7, 2016
8665bb9
Always serialize numbers in network byte order
maxbrunsfeld Nov 7, 2016
5fd6a50
Link ws2_32 on windows
maxbrunsfeld Nov 7, 2016
f73919e
Don't run native tests on windows
maxbrunsfeld Nov 7, 2016
4c65d86
Add mergeAdjacentHunks option
Nov 7, 2016
3f8dacc
Update main to point to native Patch
maxbrunsfeld Nov 7, 2016
deaccb6
WIP: Store new text from splices
Nov 8, 2016
e7123e0
WIP - Hard-code crashing seed
maxbrunsfeld Nov 8, 2016
25dd32f
Serialize new-text field
maxbrunsfeld Nov 8, 2016
612b7c2
Handle insertions at the beginning of existing hunks when not merging
Nov 9, 2016
f655bcc
Include cstring header for memcpy
maxbrunsfeld Nov 10, 2016
5d13912
Rename TestDocument parameters: old -> deleted and new -> inserted
maxbrunsfeld Nov 10, 2016
425e340
WIP - spliceOld
maxbrunsfeld Nov 11, 2016
85eadc3
Rename Splay methods
maxbrunsfeld Nov 11, 2016
8bfdcb2
Implement spliceOld
maxbrunsfeld Nov 12, 2016
c7a3712
Enable merging adjacent hunks in randomized test
maxbrunsfeld Nov 12, 2016
a539173
Merge hunks that become adjacent after a spliceOld call
maxbrunsfeld Nov 12, 2016
c5db39b
Include nodes' pointer addresses in debug graphs
maxbrunsfeld Dec 2, 2016
8513602
Fix segfault in spliceOld when inserting next to existing insertions
maxbrunsfeld Dec 2, 2016
f19b28f
Avoid recursion when deleting Patch nodes
maxbrunsfeld Dec 2, 2016
8c43c6b
Remove parent pointers from nodes. Use a stack instead.
maxbrunsfeld Dec 2, 2016
9d1a81d
Add Patch.getHunkCount() method
maxbrunsfeld Dec 2, 2016
7e9b8e5
Add Patch.rebalance()
maxbrunsfeld Dec 2, 2016
bdbf078
Get native test passing again
maxbrunsfeld Dec 7, 2016
d07e602
Start work on tracking old text in patch
maxbrunsfeld Dec 7, 2016
06ed8cb
Use unique_ptr for nodes' old and new text
maxbrunsfeld Dec 7, 2016
ce307a1
Store text in a vector<uint16_t>
maxbrunsfeld Dec 7, 2016
3ac09f2
Start work on handling splices with old text that overlap existing hunks
maxbrunsfeld Dec 8, 2016
396139f
Splice with old text in randomized test
maxbrunsfeld Dec 8, 2016
28d327d
Handle splices with old text that overlap existing hunks
maxbrunsfeld Dec 8, 2016
d3715da
Clean up ComputeOldText
maxbrunsfeld Dec 8, 2016
a85ca50
Make PatchWrapper constructor take a Patch
maxbrunsfeld Dec 8, 2016
703bcef
Add Patch.compose
Dec 8, 2016
442a9ed
Perform fewer operations in random test
Dec 9, 2016
3387fda
:art:
Dec 9, 2016
4f31998
Add Patch.invert
Dec 9, 2016
fcd57cc
Test Patch.compose argument checking
Dec 9, 2016
96ad5cb
Add non-enumerable legacy properties for backward compatibility
Dec 9, 2016
24fbd3e
Fix invert call in test
Dec 9, 2016
7f0a446
Remove electron-mocha dependencies
Dec 9, 2016
6e128eb
Use Node APIs to access buffer data in binding
Dec 9, 2016
8a5a53a
Remove JS implementation
Dec 9, 2016
2c709fc
Try just running test-js on Travis
Dec 9, 2016
dfb5fcb
Don't build in debug mode on Travis
Dec 9, 2016
e3b4aa5
Avoid linker errors for native tests on Linux
Dec 10, 2016
1c7e067
:art:
Dec 10, 2016
65a47e3
Require build/Debug/atom_patch if present, else use build/Release
Dec 10, 2016
a0abb61
Only override -O flag for Debug configuration on Linux
Dec 10, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
node_modules
dist
.DS_Store
build
debug.html
.clang_complete
9 changes: 8 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,12 @@ branches:

sudo: false

addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8

env:
- CC=clang CXX=clang++ npm_config_clang=1
- CC=gcc-4.8 CXX=g++-4.8
34 changes: 1 addition & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,4 @@ cd atom-patch
npm install
```

Use `npm test` or `npm run tdd` to run the test suite.

### Recompiling Patch's Flatbuffer Schema

`Patch` uses [flat buffers](https://google.github.io/flatbuffers/) to represent its serialized state. If you want to make any change to the underlying schema you have to download and compile `flatc` first:

```bash
# clone flatbuffers repository and checkout the version tested with this library
git clone https://github.com/google/flatbuffers
git checkout 959866b

# compile flatbuffers
pushd flatbuffers/build/XCode/
xcodebuild
popd
```

This will create a `flatc` executable in flatbuffers top level directory. You can recompile `src/serialization-schema.fbs` by running:

```bash
cd atom-patch
../flatbuffers/flatc -o src --js serialization-schema.fbs
```

After you do that, please make sure to to change the generated file's last line to:

```diff
// Exports for Node.js and RequireJS
- this.Serialization = Serialization;
+ module.exports = Serialization;
```

Please, note that we have included a patched version of the flatbuffers javascript library under vendor/flatbuffers.js because the original one has the same problem.
Use `npm test` to run the test suite.
15 changes: 15 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
image: Visual Studio 2015

environment:
nodejs_version: "6"

install:
- ps: Install-Product node $env:nodejs_version
- npm install

test_script:
- node --version
- npm --version
- npm run ci-windows

build: off
78 changes: 78 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"targets": [
{
"target_name": "atom_patch",
"sources": [
"src/binding.cc",
]
},
],

"variables": {
"tests": 0
},

"conditions": [
# If --tests is passed to node-gyp configure, we'll build a standalone
# executable that runs tests on the patch.
['tests != 0', {
"targets": [{
"target_name": "tests",
"type": "executable",
"cflags_cc": ["-fexceptions"],
"sources": [
"test/patch_test.cc",
"test/tests.cc",
],
"include_dirs": [
"test",
"vendor",
],
"conditions": [
['OS=="mac"', {
"xcode_settings": {
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
}
}],
# Enable debugger-friendly optimizations on Linux so we don't retain
# v8 symbols that won't be defined when linking the tests executable.
['OS=="linux"', {
'configurations': {
'Debug': {
'cflags!': [ '-O0' ],
'cflags': [ '-Og' ]
}
}
}],
]
}]
}]
],

"target_defaults": {
"cflags_cc": ["-std=c++11"],
"sources": [
"src/patch.cc",
"src/point.cc",
"src/text.cc",
],
"include_dirs": [
"src",
"<!(node -e \"require('nan')\")"
],
"conditions": [
['OS=="mac"', {
"xcode_settings": {
"OTHER_CPLUSPLUSFLAGS" : ["-std=c++11", "-stdlib=libc++"],
"OTHER_LDFLAGS": ["-stdlib=libc++"],
"MACOSX_DEPLOYMENT_TARGET": "10.9",
}
}],
['OS=="win"', {
"link_settings": {
"libraries": ["ws2_32.lib"]
}
}]
]
}
}
25 changes: 12 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"name": "atom-patch",
"version": "0.3.0",
"description": "A data structure to efficiently represent the results of applying patches.",
"main": "dist/patch.js",
"main": "./build/Release/atom_patch",
"scripts": {
"test": "mocha ./test/helpers/setup test/*",
"tdd": "electron-mocha --renderer --interactive --recursive ./test/helpers/setup test/",
"prepublish": "npm run standard && npm run clean && npm run build",
"test-native": "node-gyp rebuild --debug --tests && ./build/Debug/tests",
"test-js": "mocha ./test/helpers/setup test/*.js",
"test": "npm run test-native && npm run test-js",
"prepublish": "npm run standard",
"standard": "standard --recursive src test",
"build": "babel src --out-dir dist",
"clean": "rm -rf dist",
"ci": "npm run standard && npm run test"
"ci": "npm run standard && npm run test",
"ci-windows": "npm run standard && npm run test"
},
"repository": {
"type": "git",
Expand All @@ -25,19 +25,18 @@
"url": "https://github.com/nathansobo/atom-patch/issues"
},
"homepage": "https://github.com/nathansobo/atom-patch",
"dependencies": {
"nan": "^2.4.0"
},
"devDependencies": {
"babel": "^5.0.0",
"babel-eslint": "^4.0.5",
"chai": "^2.0.0",
"electron-mocha": "git://github.com/nathansobo/electron-mocha.git#interactive-option",
"electron-prebuilt": "^0.30.1",
"mocha": "^2.3.4",
"phonetic": "^0.1.0",
"random-seed": "^0.2.0",
"segfault-handler": "^1.0.0",
"standard": "^4.5.4"
},
"dependencies": {
"random-seed": "^0.2.0"
},
"standard": {
"parser": "babel-eslint",
"global": [
Expand Down
5 changes: 5 additions & 0 deletions script/test-with-debug-graph
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

echo '<?xml version="1.0"?>' > debug.html
echo '<style> svg { width: 100%; margin-bottom: 10px; } </style>' >> debug.html
mocha test/helpers/setup test/*.js 2> >(dot -Tsvg >> debug.html)
Loading