Skip to content
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

Detect and propagate renames/moves instead of delete+create #576

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
47 changes: 42 additions & 5 deletions src/.depend
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ common.cmo : \
osx.cmi \
os.cmi \
name.cmi \
ubase/myMap.cmi \
fspath.cmi \
fileinfo.cmi \
features.cmi \
common.cmi
common.cmx : \
uutil.cmx \
Expand All @@ -73,8 +75,10 @@ common.cmx : \
osx.cmx \
os.cmx \
name.cmx \
ubase/myMap.cmx \
fspath.cmx \
fileinfo.cmx \
features.cmx \
common.cmi
common.cmi : \
uutil.cmi \
Expand All @@ -84,6 +88,7 @@ common.cmi : \
osx.cmi \
os.cmi \
name.cmi \
ubase/myMap.cmi \
fspath.cmi \
fileinfo.cmi
copy.cmo : \
Expand Down Expand Up @@ -628,6 +633,37 @@ main.cmx : \
remote.cmx \
ubase/prefs.cmx \
os.cmx
moves.cmo : \
uutil.cmi \
ubase/util.cmi \
update.cmi \
ubase/trace.cmi \
ubase/safelist.cmi \
props.cmi \
ubase/prefs.cmi \
path.cmi \
os.cmi \
name.cmi \
features.cmi \
common.cmi \
moves.cmi
moves.cmx : \
uutil.cmx \
ubase/util.cmx \
update.cmx \
ubase/trace.cmx \
ubase/safelist.cmx \
props.cmx \
ubase/prefs.cmx \
path.cmx \
os.cmx \
name.cmx \
features.cmx \
common.cmx \
moves.cmi
moves.cmi : \
path.cmi \
common.cmi
name.cmo : \
ubase/util.cmi \
ubase/umarshal.cmi \
Expand Down Expand Up @@ -841,6 +877,7 @@ recon.cmo : \
pred.cmi \
path.cmi \
name.cmi \
moves.cmi \
globals.cmi \
fileinfo.cmi \
common.cmi \
Expand All @@ -859,6 +896,7 @@ recon.cmx : \
pred.cmx \
path.cmx \
name.cmx \
moves.cmx \
globals.cmx \
fileinfo.cmx \
common.cmx \
Expand Down Expand Up @@ -1051,7 +1089,7 @@ test.cmo : \
ubase/prefs.cmi \
path.cmi \
os.cmi \
lwt/lwt_util.cmi \
moves.cmi \
lwt/lwt_unix.cmi \
lwt/lwt.cmi \
globals.cmi \
Expand All @@ -1075,7 +1113,7 @@ test.cmx : \
ubase/prefs.cmx \
path.cmx \
os.cmx \
lwt/lwt_util.cmx \
moves.cmx \
lwt/lwt_unix.cmx \
lwt/lwt.cmx \
globals.cmx \
Expand Down Expand Up @@ -1119,6 +1157,7 @@ transport.cmo : \
ubase/prefs.cmi \
path.cmi \
osx.cmi \
moves.cmi \
lwt/lwt_util.cmi \
lwt/lwt.cmi \
globals.cmi \
Expand All @@ -1135,6 +1174,7 @@ transport.cmx : \
ubase/prefs.cmx \
path.cmx \
osx.cmx \
moves.cmx \
lwt/lwt_util.cmx \
lwt/lwt.cmx \
globals.cmx \
Expand Down Expand Up @@ -1507,7 +1547,6 @@ update.cmo : \
osx.cmi \
os.cmi \
name.cmi \
ubase/myMap.cmi \
lwt/lwt_unix.cmi \
lwt/lwt.cmi \
lock.cmi \
Expand Down Expand Up @@ -1540,7 +1579,6 @@ update.cmx : \
osx.cmx \
os.cmx \
name.cmx \
ubase/myMap.cmx \
lwt/lwt_unix.cmx \
lwt/lwt.cmx \
lock.cmx \
Expand All @@ -1564,7 +1602,6 @@ update.cmi : \
osx.cmi \
os.cmi \
name.cmi \
ubase/myMap.cmi \
lwt/lwt.cmi \
fspath.cmi \
fileinfo.cmi \
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile.OCaml
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ OCAMLOBJS += \
props.cmo fileinfo.cmo os.cmo lock.cmo clroot.cmo common.cmo \
tree.cmo checksum.cmo transfer.cmo xferhint.cmo \
remote.cmo external.cmo negotiate.cmo globals.cmo fswatchold.cmo \
fpcache.cmo update.cmo copy.cmo stasher.cmo \
fpcache.cmo update.cmo moves.cmo copy.cmo stasher.cmo \
files.cmo sortri.cmo recon.cmo transport.cmo \
strings.cmo uicommon.cmo uitext.cmo test.cmo

Expand Down
84 changes: 73 additions & 11 deletions src/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,32 @@ let sortRoots rootList = Safelist.sort compareRoots rootList

(* ---------------------------------------------------------------------- *)

module NameMap = MyMap.Make (Name)

type archive =
| ArchiveDir of Props.t * archive NameMap.t
| ArchiveFile of Props.t * Os.fullfingerprint * Fileinfo.stamp * Osx.ressStamp
| ArchiveSymlink of string
| NoArchive

let marchive_rec marchive =
Umarshal.(sum4
(prod2 Props.m (NameMap.m marchive) id id)
(prod4 Props.m Os.mfullfingerprint Fileinfo.mstamp Osx.mressStamp id id)
string unit
(function
| ArchiveDir (a, b) -> I41 (a, b)
| ArchiveFile (a, b, c, d) -> I42 (a, b, c, d)
| ArchiveSymlink a -> I43 a
| NoArchive -> I44 ())
(function
| I41 (a, b) -> ArchiveDir (a, b)
| I42 (a, b, c, d) -> ArchiveFile (a, b, c, d)
| I43 a -> ArchiveSymlink a
| I44 () -> NoArchive))

let marchive = Umarshal.rec1 marchive_rec

(* IMPORTANT!
This is the 2.51-compatible version of type [Common.prevState]. It must
always remain exactly the same as the type [Common.prevState] in version
Expand All @@ -77,11 +103,11 @@ type prevState251 =
Previous of Fileinfo.typ * Props.t251 * Os.fullfingerprint * Osx.ressStamp
| New

type prevState =
type prevState1 =
Previous of Fileinfo.typ * Props.t * Os.fullfingerprint * Osx.ressStamp
| New

let mprevState = Umarshal.(sum2
let mprevState1 = Umarshal.(sum2
(prod4 Fileinfo.mtyp Props.m Os.mfullfingerprint Osx.mressStamp id id)
unit
(function
Expand All @@ -91,6 +117,35 @@ let mprevState = Umarshal.(sum2
| I21 (a, b, c, d) -> Previous (a, b, c, d)
| I22 () -> New))

type prevState = archive

let mprevState2 = Umarshal.rec1 marchive_rec

let prev_to_old = function
| ArchiveDir (desc, _) ->
Previous (`DIRECTORY, desc, Os.fullfingerprint_dummy, Osx.ressDummy)
| ArchiveFile (desc, fp, _, ress) ->
Previous (`FILE, desc, fp, ress)
| ArchiveSymlink _ ->
Previous (`SYMLINK, Props.dummy, Os.fullfingerprint_dummy, Osx.ressDummy)
| NoArchive ->
New

let prev_of_old = function
| Previous (`DIRECTORY, desc, _, _) -> ArchiveDir (desc, NameMap.empty)
| Previous (`FILE, desc, fp, ress) -> ArchiveFile (desc, fp, NoStamp, ress)
| Previous (`SYMLINK, _, _, _) -> ArchiveSymlink ""
| Previous (`ABSENT, _, _, _)
| New -> NoArchive

let featPrevState2 = Features.register "prevState2" None

let newPrevStateType () = Features.enabled featPrevState2

let mprevState = Umarshal.(switch newPrevStateType
mprevState2 id id
mprevState1 prev_to_old prev_of_old)

(* IMPORTANT!
This is the 2.51-compatible version of type [Common.contentschange]. It
must always remain exactly the same as the type [Common.contentschange]
Expand Down Expand Up @@ -207,16 +262,16 @@ let mupdateContent, mupdateItem =
(* Compatibility conversion functions *)

let prev_to_compat251 (prev : prevState) : prevState251 =
match prev with
match prev_to_old prev with
| Previous (typ, props, fp, ress) ->
Previous (typ, Props.to_compat251 props, fp, ress)
| New -> New

let prev_of_compat251 (prev : prevState251) : prevState =
match prev with
prev_of_old (match prev with
| Previous (typ, props, fp, ress) ->
Previous (typ, Props.of_compat251 props, fp, ress)
| New -> New
| New -> New)

let change_to_compat251 (c : contentschange) : contentschange251 =
match c with
Expand Down Expand Up @@ -273,9 +328,11 @@ type status =
| `Modified
| `PropsChanged
| `Created
| `MovedOut of Path.t * replicaContent * replicaContent
| `MovedIn of Path.t * replicaContent * replicaContent
| `Unchanged ]

type replicaContent =
and replicaContent =
{ typ : Fileinfo.typ;
status : status;
desc : Props.t; (* Properties (for the UI) *)
Expand Down Expand Up @@ -335,7 +392,12 @@ let rcLength rc rc' =
if riAction rc rc' = `SetProps then
Uutil.Filesize.zero
else
snd rc.size
match rc'.status with
| `MovedIn _ ->
(* A move/rename will be reverted, count its size too *)
Uutil.Filesize.add (snd rc.size) (snd rc'.size)
| _ ->
snd rc.size

let riLength ri =
match ri.replicas with
Expand All @@ -355,17 +417,17 @@ let riLength ri =
let fileInfos ui1 ui2 =
match ui1, ui2 with
(Updates (File (desc1, ContentsUpdated (fp1, _, ress1)),
Previous (`FILE, desc2, fp2, ress2)),
ArchiveFile (desc2, fp2, _, ress2)),
NoUpdates)
| (Updates (File (desc1, ContentsUpdated (fp1, _, ress1)),
Previous (`FILE, desc2, fp2, ress2)),
ArchiveFile (desc2, fp2, _, ress2)),
Updates (File (_, ContentsSame), _))
| (NoUpdates,
Updates (File (desc2, ContentsUpdated (fp2, _, ress2)),
Previous (`FILE, desc1, fp1, ress1)))
ArchiveFile (desc1, fp1, _, ress1)))
| (Updates (File (_, ContentsSame), _),
Updates (File (desc2, ContentsUpdated (fp2, _, ress2)),
Previous (`FILE, desc1, fp1, ress1)))
ArchiveFile (desc1, fp1, _, ress1)))
| (Updates (File (desc1, ContentsUpdated (fp1, _, ress1)), _),
Updates (File (desc2, ContentsUpdated (fp2, _, ress2)), _)) ->
(desc1, fp1, ress1, desc2, fp2, ress2)
Expand Down
Loading