Commit Graph

15 Commits

Author SHA1 Message Date
Adam Simpkins
5afbd505ef clib: clean up include guards in the C/C++ header files
Summary:
Clean up the include guards to be more consistent and unique.

Some files used include guards like "KEY_H" and "STORE_H" which were not very
unique, and are more likely to collide with definitions provided by header
files from other projects.  Some of the py-*.h files were missing include
guards altogether.

This corresponds to Facebook diff D5588670.

Test Plan: Confirmed the code still builds and passes tests.

Reviewers: #fbhgext, quark

Reviewed By: #fbhgext, quark

Differential Revision: https://phab.mercurial-scm.org/D508
2017-08-25 16:46:07 -07:00
Adam Simpkins
ecb0fd2dd7 clib: update C/C++ copyright statements to pass lint checks
Summary:
Update the copyright headers in most of the C/C++ code consistently use the
GPLv2 copyright message.  This allows these files to pass Facebook's internal
C/C++ linters.

Some of the files in fbcode/scm/hgext/cstore/ appear to have actually been
copied from the hg-crew repository, and were not originally authored by
Facebook.  I have not modified the copyright statements in these files:

- cstore/bitmanipulation.h
- cstore/compat.h
- cstore/mpatch.h
- cstore/mpatch.c

I also have not modified any of the cfastmanifest code.

This corresponds to Facebook diff D5588677.

Test Plan:
Confirmed that Facebook's C++ linters no longer complain about the copyright
messages.

Reviewers: #fbhgext, quark

Reviewed By: #fbhgext, quark

Differential Revision: https://phab.mercurial-scm.org/D507
2017-08-25 16:46:07 -07:00
Adam Simpkins
b67af2812c clib: simplify include paths in C extensions
Summary:
Convert the C and C++ files in cdatapack, clib, cstore, and ctreemanifest
to always include files from the root of fb-hgext.  This simplifies the build
process by no long requiring a variety of separate include directories to be
specified on the compiler command line.

This will also make it easier to re-use these extensions in other projects
with different build systems.

This corresponds to the Facebook diff D5588676.

Test Plan: Confirmed that "make local" succeeds from a clean build.

Reviewers: #fbhgext, quark

Reviewed By: #fbhgext, quark

Differential Revision: https://phab.mercurial-scm.org/D505
2017-08-25 16:46:07 -07:00
Adam Simpkins
d76e68c663 sha1: allow selecting SHA-1 library at build time
Summary:
Add a #define which allows selecting between the sha1collisiondetection and
openssl SHA-1 implementations at build time.

For now setup.py always uses sha1collisiondetection, but we have some other
internal build environments where we will likely default to OpenSSL's SHA-1
implementation instead.

Test Plan: Confirmed the code builds and passes tests.

Reviewers: #fbhgext, ryanmce

Reviewed By: #fbhgext, ryanmce

Differential Revision: https://phab.mercurial-scm.org/D285
2017-08-22 19:09:07 -07:00
Adam Simpkins
8f31b2b18e sha1: use the real SHA-1 algorithm
Summary:
The sha1collisiondetection library by default performs its own "safe-hash"
algorithm, which is not actually the same as the normal SHA-1 algorithm.
For most inputs the output will be the actual SHA-1 hash, but if the input
happens to contain one of several known SHA-1 disturbance vectors this code
returns an alternate "safe-hash" output instead.

This updates the code to explicitly disable "safe-hash" mode and collision
detection, so that we always get actual SHA-1 hashes.

Test Plan: Ran the unit tests.

Reviewers: #fbhgext, ryanmce

Reviewed By: #fbhgext, ryanmce

Differential Revision: https://phab.mercurial-scm.org/D284
2017-08-22 19:09:07 -07:00
Adam Simpkins
2fe96efe2c sha1: update to the stable-v1.0.3 release of sha1collisiondetection
Summary:
Update the code to the stable-v1.0.3 release of sha1collisiondetection, and
include the upstream README file as well.

Test Plan: Confirmed the code builds and passes tests.

Reviewers: #fbhgext, ryanmce

Reviewed By: #fbhgext, ryanmce

Differential Revision: https://phab.mercurial-scm.org/D283
2017-08-22 19:09:07 -07:00
Adam Simpkins
5977867b68 sha1: provide wrapper functions around the SHA-1 implementation
Summary:
Add a clib/sha1.h file with SHA-1 utility functions that hide the details of
the underlying SHA-1 implementation being used.  This will make it easier in
the future if we want to use the faster SHA-1 implementation from OpenSSL if it
is available, but fall back to the sha1collisiondetection library if it is not
available.

Test Plan: Confirmed the code builds and passes unit tests.

Reviewers: #fbhgext, ryanmce

Reviewed By: #fbhgext, ryanmce

Differential Revision: https://phab.mercurial-scm.org/D282
2017-08-22 19:09:07 -07:00
Adam Simpkins
d5440b15c4 sha1: move the sha1collisiondetection code to third-party
Summary:
Move the third-party sha1collisiondetection code from clib/sha1 to
third-party/sha1dc.  This helps isolate third-party code from our own
internally developed code.

This also updates the code to use the same include paths and library names as
used by the sha1collisiondetection's upstream Makefile, which would be needed
to link against a version of sha1collisiondetection installed locally.

Test Plan:
Confirmed "make local" succeeds.

All of the tests pass, except for test-check-commit-hg, which complains about
the fact that some of this third-party code contains multiple empty lines in a
row.  It doesn't seem straightforward to update test-check-commit to ignore
this third-party code, but these test failures shouldn't affect any future
commits.

Reviewers: #fbhgext, ryanmce

Reviewed By: #fbhgext, ryanmce

Differential Revision: https://phab.mercurial-scm.org/D281
2017-08-22 19:09:07 -07:00
Kostia Balytskyi
bb22e387cb cdatapack: add some windows portability
Summary:
This is a first set of changes to help `cdatapack` compile on Windows. Second
set will include adding some way of using `mman` on Windows.

Test Plan:
- `make local` on Linux, `rt`
- with some intermediary solution for `mman` this also builds on Windows 10,
  I was able to produce `cdatapack_get.exe` and `cdatapack_dump.exe`. Here's an
  example:
```
PS C:\Code\fb-hg-rpms\fb-hgext\cdatapack> .\cdatapack_get.exe 3ba0b10b8d251743a2692e042b114c1204b19d74 88dadb363234ec4fec3df85810810d6073288350

xplat/third-party/yarn/offline-mirror/smoothscroll-polyfill-0.3.5.tgz
Node                                      Delta Base                                Delta SHA1                                Delta Length
88dadb363234ec4fec3df85810810d6073288350  0000000000000000000000000000000000000000  466e6039b51cb525d70e1a5077ef81e064678eae  26057
```

Reviewers: durham, #fbhgext

Differential Revision: https://phab.mercurial-scm.org/D106
2017-07-18 03:21:28 -07:00
Jun Wu
6f5f9b9c0d convert: unify two sources and clean it up
Summary:
There are two `convert.h`. This patch unifies them and does cleanups so it's
a valid header file which could be included by multiple .c and .cpp files
and linker won't complain re-definition (by adding `static` to everything).

Besides, reformat the code so it could pass check-code. Also fix a compiler
warning about comparing an unsigned integer with a signed integer.

Test Plan: `make clean local`. It still builds.

Reviewers: durham, #mercurial, rmcelroy

Reviewed By: rmcelroy

Subscribers: mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D5113550

Signature: t1:5113550:1495565413:e399f898ac513e64af37dab5daf55cedbabfc703
2017-05-23 11:57:12 -07:00
Jun Wu
a63cbaaed1 portibility: move to clib
Summary:
It's a small C utility. It should belong to `clib` directory.

Also, `#include "../foo"` does not seem to be a good pattern. It makes
include files harder to follow and make code movement more difficult. Since
`clib` is already included in `-I` during compilation, remove `../`.

Test Plan: `make clean local`. It still builds.

Reviewers: ikostia, #mercurial, rmcelroy

Reviewed By: rmcelroy

Subscribers: mjpieters, vsutaria

Differential Revision: https://phabricator.intern.facebook.com/D5113236

Signature: t1:5113236:1495562436:e8d64083ab0417c67b63223a092470739f4c1176
2017-05-23 11:47:40 -07:00
Jun Wu
80e40da9d6 sha1: switch to new implementation
Summary:
This diff changes our code to use the new SHA1 library. See the previous diff
for why we do this.

Test Plan:
Run related tests manually:

```
$ make local PYTHON=python2
$ rt test-remotefilelog-*.t
.........................
# Ran 25 tests, 0 skipped, 0 warned, 0 failed.
$ rt test-treemanifest*.t
........
# Ran 8 tests, 0 skipped, 0 warned, 0 failed.
$ rt test-fastmanifest*.t
.........
# Ran 9 tests, 0 skipped, 0 warned, 0 failed.
```

Reviewers: #sourcecontrol, durham

Reviewed By: durham

Subscribers: mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D4945025

Signature: t1:4945025:1493154873:844e55a51ab250354fc08163e0949eed47b0a861
2017-04-25 14:53:32 -07:00
Jun Wu
76c7347a2e clib: import sha1 impl from github/cr-marcstevens/sha1collisiondetection
Summary:
This imports a SHA1 hash function implementation from
https://github.com/cr-marcstevens/sha1collisiondetection, commit hash
0572d8a302b1f62f25c1559b0de74908550ab2c3, using the MIT License.

This allows us to decouple from an external crypto library like openssl. The
new library's "safe hash" feature could also mitigate known SHA1 collisions.

test-check-code is modified accordingly to skip checking the sha1 code
without modifying them.

Test Plan: Run test-check-code.t and make sure it's not complaining.

Reviewers: #sourcecontrol, durham

Reviewed By: durham

Subscribers: ikostia, mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D4945012

Signature: t1:4945012:1493154822:be0deb451d50f3a8b6cc42addf091349bf6554f4
2017-04-25 14:53:04 -07:00
Tony Tung
2b3e7ac198 port upgrades of buffer.h into clib
Summary:
buffer.h gained the ability to deal with non-char-sized buffers when I built cdatapack.  We need to update the callers in ctreemanifest to be aware of this.  Most of this is done with macro magic.

Some functionality was dropped from cdatapack's buffer.h (macro definitions to deal with paths).  Those are moved to path_buffer.h

Test Plan:
make local && clion build.
pass cfastmanifest unit tests.

Reviewers: #fastmanifest, durham

Reviewed By: durham

Subscribers: mitrandir, mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D3780767

Signature: t1:3780767:1472255278:40a19edfd171df5804e9cdfa4444d5c6386f00e8
2016-08-26 17:14:52 -07:00
Tony Tung
2f5e85ccb8 move common code to clib
Test Plan: make local && build in clion

Reviewers: #fastmanifest, durham

Reviewed By: durham

Subscribers: mitrandir, mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D3780622

Signature: t1:3780622:1472250774:fa702d78dab39eb74c8de58c0d589ae36a2c42b3
2016-08-26 15:45:43 -07:00