lfs: remove placeholder feature

Summary:
This feature is only used for e-discovery, and we don't need to build a
new e-discovery package from eden/scm anymore. Let's remove this feature since
the monkeypatch interferes with updating the hg status paths.

Reviewed By: quark-zju

Differential Revision: D34124434

fbshipit-source-id: b41382bc1a3cfeda82e1dd2af511244ad16a9fb8
This commit is contained in:
Durham Goode 2022-02-10 14:12:00 -08:00 committed by Facebook GitHub Bot
parent 595f1307ca
commit 16af96aba7
4 changed files with 11 additions and 219 deletions

View File

@ -64,7 +64,7 @@ from edenscm.mercurial import (
)
from edenscm.mercurial.i18n import _, _x
from . import blobstore, pointer, wrapper, placeholders
from . import blobstore, pointer, wrapper
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
@ -135,12 +135,8 @@ def wrapfilelog(ui, filelog):
wrapfunction = extensions.wrapfunction
wrapfunction(filelog, "renamed", wrapper.filelogrenamed)
if ui.configbool("experimental", "lfsplaceholders"):
wrapfunction(filelog, "addrevision", placeholders.filelogaddrevision)
wrapfunction(filelog, "size", placeholders.filelogsize)
else:
wrapfunction(filelog, "addrevision", wrapper.filelogaddrevision)
wrapfunction(filelog, "size", wrapper.filelogsize)
wrapfunction(filelog, "addrevision", wrapper.filelogaddrevision)
wrapfunction(filelog, "size", wrapper.filelogsize)
def extsetup(ui):
@ -163,24 +159,12 @@ def extsetup(ui):
context.basefilectx.islfs = wrapper.filectxislfs
if ui.configbool("experimental", "lfsplaceholders"):
wrapfunction(context.basefilectx, "cmp", placeholders.filectxcmp)
wrapfunction(context.basefilectx, "isbinary", placeholders.filectxisbinary)
revlog.addflagprocessor(
revlog.REVIDX_EXTSTORED,
(
placeholders.readfromstore,
placeholders.writetostore,
wrapper.bypasscheckhash,
),
)
else:
wrapfunction(context.basefilectx, "cmp", wrapper.filectxcmp)
wrapfunction(context.basefilectx, "isbinary", wrapper.filectxisbinary)
revlog.addflagprocessor(
revlog.REVIDX_EXTSTORED,
(wrapper.readfromstore, wrapper.writetostore, wrapper.bypasscheckhash),
)
wrapfunction(context.basefilectx, "cmp", wrapper.filectxcmp)
wrapfunction(context.basefilectx, "isbinary", wrapper.filectxisbinary)
revlog.addflagprocessor(
revlog.REVIDX_EXTSTORED,
(wrapper.readfromstore, wrapper.writetostore, wrapper.bypasscheckhash),
)
wrapfunction(hg, "clonepreclose", wrapper.hgclone)
wrapfunction(hg, "postshare", wrapper.hgpostshare)

View File

@ -393,7 +393,7 @@ class _promptremote(object):
"""Prompt user to set lfs.url when accessed."""
def __init__(self, ui, url):
self.useplaceholders = ui.configbool("experimental", "lfsplaceholders")
pass
def writebatch(self, pointers, fromstore, ui=None):
self._prompt()
@ -402,8 +402,7 @@ class _promptremote(object):
self._prompt()
def _prompt(self):
if not self.useplaceholders:
raise error.Abort(_("lfs.url needs to be configured"))
raise error.Abort(_("lfs.url needs to be configured"))
_storemap = {

View File

@ -1,104 +0,0 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2.
# placeholders.py - methods wrapping core mercurial logic when lfs.lfsplaceholders is set
from __future__ import absolute_import
from edenscm.mercurial import error, filelog, revlog
from edenscm.mercurial.i18n import _
from . import pointer, wrapper
def readfromstore(self, text):
"""Return placeholder instead of actual lfs file."""
p = pointer.deserialize(text)
isbinary = bool(int(p.get("x-is-binary", 1)))
placeholder = (
"This is a placeholder for a large file\n\n"
"Original file id: %s\n"
"Original file size: %s\n"
"Original file is binary: %s\n" % (p["oid"], p.size(), isbinary)
)
# pack hg filelog metadata
hgmeta = p.hgmeta()
text = placeholder.encode("utf-8")
if hgmeta:
text = filelog.packmeta(hgmeta, text)
return (text, False)
def filectxisbinary(orig, self):
if self.islfs():
"""Placeholders are always text"""
return False
return orig(self)
def filectxcmp(orig, self, fctx):
"""returns True if text is different than fctx"""
# some fctx (ex. hg-git) is not based on basefilectx and do not have islfs
if self.islfs() and getattr(fctx, "islfs", lambda: False)():
# fast path: check LFS oid
p1 = pointer.deserialize(self.rawdata())
p2 = pointer.deserialize(fctx.rawdata())
return p1.oid() != p2.oid()
if self.islfs() or getattr(fctx, "islfs", lambda: False)():
# we can't rely on filelog hashing as the hashes don't match the reality
return self.data() != fctx.data()
return orig(self, fctx)
def filelogsize(orig, self, rev):
if wrapper._islfs(self, rev=rev):
rawtext = self.revision(rev, raw=True)
placeholder = readfromstore(self, rawtext)
return len(placeholder[0])
return orig(self, rev)
def writetostore(self, text):
raise error.Abort(_("can't write LFS files in placeholders mode"))
def filelogaddrevision(
orig,
self,
text,
transaction,
link,
p1,
p2,
cachedelta=None,
node=None,
flags=revlog.REVIDX_DEFAULT_FLAGS,
**kwds
):
threshold = self.opener.options["lfsthreshold"]
textlen = len(text)
# exclude hg rename meta from file size
meta, offset = filelog.parsemeta(text)
if offset:
textlen -= offset
if threshold and textlen > threshold:
raise error.Abort(_("can't write LFS files in placeholders mode"))
return orig(
self,
text,
transaction,
link,
p1,
p2,
cachedelta=cachedelta,
node=node,
flags=flags,
**kwds
)

View File

@ -1,87 +0,0 @@
#chg-compatible
$ setconfig experimental.allowfilepeer=True
#require no-windows
Test the lfs.placeholders config option
$ enable lfs
$ newrepo server
$ setconfig lfs.url=file://$TESTTMP/remote lfs.threshold=8
$ drawdag <<'EOS'
> B2 # B2/B2=lots_of_text
> |
> A1 # A1/A1=small
> EOS
One commit has LFS file (flag=2000)
$ hg debugfilerevision -r 'all()'
3828e4693c74: A1
A1: bin=0 lnk=0 flag=0 size=5 copied='' chain=0cfbf921b2cb
7e1c7b2cd9df: B2
B2: bin=0 lnk=0 flag=2000 size=12 copied='' chain=eacc6746870c
$ hg debuglfsupload -r 'all()'
Clone the repo
$ cd ..
$ hg clone --config experimental.lfsplaceholders=True server client
updating to branch default
2 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ cd client
$ setconfig experimental.lfsplaceholders=True
Demonstrate that placeholders are there
$ cat B2
This is a placeholder for a large file
Original file id: sha256:88cab35a00c697e745f11131c19eac3a078683dc4d06f840cb9b40aa010cb29c
Original file size: 12
Original file is binary: False
Demonstrate that non-LFS file is there
$ cat A1
small (no-eol)
Diff and status should be clean
$ hg diff
$ hg status
Committing new files should be possible only when they are below LFS treshold
$ setconfig lfs.threshold=8
$ echo "tiny" > tinyfile
$ hg commit -Aq -m tiny
$ echo "very large file" > verylargefile
$ hg commit -Aq -m verylargefile
abort: can't write LFS files in placeholders mode
[255]
$ rm verylargefile
Disable the placeholders mode
$ setconfig experimental.lfsplaceholders=False
$ setconfig lfs.url=file://$TESTTMP/remote lfs.threshold=8
Recrawling distate is neccessary
$ hg debugrebuilddirstate
File should be dirty now
$ hg diff
diff -r ad054566f884 B2
--- a/B2 Thu Jan 01 00:00:00 1970 +0000
+++ b/B2 Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +1,5 @@
-lots_of_text
\ No newline at end of file
+This is a placeholder for a large file
+
+Original file id: sha256:88cab35a00c697e745f11131c19eac3a078683dc4d06f840cb9b40aa010cb29c
+Original file size: 12
+Original file is binary: False
$ hg status
M B2
$ hg update -C .
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ cat B2
lots_of_text (no-eol)