mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 15:27:13 +03:00
Implement file mode logic for repo converter
Summary: Up until now, we haven't been setting file modes for the files we're putting into hg. This seems like it might be related to some of the problems we're seeing in changes relating to symlinks. This commit adds mode tracking to try to fix that. It also adds unit tests to test the underlying mode conversion functions in gitutil to check our logic. Reviewed By: tchebb Differential Revision: D18409701 fbshipit-source-id: c5c3a90e12bd7115e24024a912f175484efe8a90
This commit is contained in:
parent
2fbe60fea6
commit
3fb8264cf4
@ -28,8 +28,14 @@ class gitutil(object):
|
||||
OBJECT_TYPE_BLOB = "blob"
|
||||
|
||||
FILE_MODE_MASK_LINK = 0o020000
|
||||
FILE_MODE_MASK_GLOBAL_EXEC = 0o000100
|
||||
FILE_MODE_MASK_USER_EXEC = 0o000001
|
||||
FILE_MODE_MASK_EXEC_GLOBAL = 0o000100
|
||||
FILE_MODE_MASK_EXEC_GROUP = 0o000010
|
||||
FILE_MODE_MASK_EXEC_USER = 0o000001
|
||||
FILE_MODE_MASK_EXEC_COMBINED = (
|
||||
FILE_MODE_MASK_EXEC_GLOBAL
|
||||
| FILE_MODE_MASK_EXEC_GROUP
|
||||
| FILE_MODE_MASK_EXEC_USER
|
||||
)
|
||||
|
||||
GIT_FILE_STATUS_ADDED = "A"
|
||||
GIT_FILE_STATUS_COPIED = "C"
|
||||
@ -65,9 +71,9 @@ class gitutil(object):
|
||||
|
||||
@classmethod
|
||||
def isexecfilemode(cls, mode):
|
||||
return (
|
||||
mode & (cls.FILE_MODE_MASK_GLOBAL_EXEC | cls.FILE_MODE_MASK_USER_EXEC)
|
||||
) > 0
|
||||
# Git's docs say that files can either be 644 or 755, but we're checking all of
|
||||
# the bits out of an abundance of caution
|
||||
return (mode & cls.FILE_MODE_MASK_EXEC_COMBINED) > 0
|
||||
|
||||
@classmethod
|
||||
def iscopystatus(cls, status):
|
||||
@ -741,6 +747,7 @@ class repo_source(common.converter_source):
|
||||
self.objecthashprojectindex = {}
|
||||
self.filecache = {}
|
||||
self._difftreecache = {}
|
||||
self._filemodecache = {}
|
||||
|
||||
def before(self):
|
||||
"""See converter_source.before"""
|
||||
@ -814,7 +821,8 @@ class repo_source(common.converter_source):
|
||||
self.filecache.pop(self.filecache.keys()[0])
|
||||
self.filecache[(name, rev)] = filebytes
|
||||
|
||||
mode = "" # TODO
|
||||
gitfilemode = self._filemodecache[rev]
|
||||
mode = gitutil.getfilemodestr(gitfilemode)
|
||||
|
||||
return filebytes, mode
|
||||
|
||||
@ -868,6 +876,7 @@ class repo_source(common.converter_source):
|
||||
filediff["source"]["hash"]
|
||||
] = projectpath
|
||||
self.objecthashprojectindex[filediff["dest"]["hash"]] = projectpath
|
||||
self._filemodecache[filediff["dest"]["hash"]] = filediff["dest"]["mode"]
|
||||
|
||||
pathprefix = {
|
||||
self.VARIANT_ROOTED: "",
|
||||
|
@ -17,6 +17,17 @@ def draft(test_func):
|
||||
class gitutiltest(unittest.TestCase):
|
||||
"""Unit tests for the gitutil helper class of the repo converter"""
|
||||
|
||||
def test_getfilemodestr(self):
|
||||
mode = gitutil.getfilemodestr(int("000644", 8))
|
||||
self.assertEqual("", mode)
|
||||
|
||||
mode = gitutil.getfilemodestr(int("100755", 8))
|
||||
self.assertEqual("x", mode)
|
||||
|
||||
mode = gitutil.getfilemodestr(int("120000", 8))
|
||||
self.assertEqual("l", mode)
|
||||
|
||||
|
||||
def test_parsedifftree_readable(self):
|
||||
difftree_string = """1fd915b9c1fcf3803383432ede29fc4d686fdb44
|
||||
:100644 100644 b02a70992e734985768e839281932c315fafb21d a268f9d1a620a9f438d014376f72bcf413eea6d8 M\tlibc/arch-arm/bionic/__bionic_clone.S
|
||||
|
Loading…
Reference in New Issue
Block a user