D12125: transaction: do not rely on a global variable to post_finalize file

2022-01-31 Thread marmoute (Pierre-Yves David)
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  We can just add a new argument to the `addfilegenerator` function. This is 
more
  explicit and therefor clearer and less error prone.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12125

AFFECTED FILES
  mercurial/bookmarks.py
  mercurial/dirstate.py
  mercurial/transaction.py
  tests/testlib/crash_transaction_late.py

CHANGE DETAILS

diff --git a/tests/testlib/crash_transaction_late.py 
b/tests/testlib/crash_transaction_late.py
--- a/tests/testlib/crash_transaction_late.py
+++ b/tests/testlib/crash_transaction_late.py
@@ -9,7 +9,6 @@
 
 from mercurial import (
 error,
-transaction,
 )
 
 
@@ -18,14 +17,15 @@
 
 
 def reposetup(ui, repo):
-
-transaction.postfinalizegenerators.add(b'late-abort')
-
 class LateAbortRepo(repo.__class__):
 def transaction(self, *args, **kwargs):
 tr = super(LateAbortRepo, self).transaction(*args, **kwargs)
 tr.addfilegenerator(
-b'late-abort', [b'late-abort'], abort, order=999
+b'late-abort',
+[b'late-abort'],
+abort,
+order=999,
+post_finalize=True,
 )
 return tr
 
diff --git a/mercurial/transaction.py b/mercurial/transaction.py
--- a/mercurial/transaction.py
+++ b/mercurial/transaction.py
@@ -25,16 +25,6 @@
 
 version = 2
 
-# These are the file generators that should only be executed after the
-# finalizers are done, since they rely on the output of the finalizers (like
-# the changelog having been written).
-postfinalizegenerators = {
-b'bookmarks',
-b'dirstate-0-key-pre',
-b'dirstate-1-main',
-b'dirstate-2-key-post',
-}
-
 GEN_GROUP_ALL = b'all'
 GEN_GROUP_PRE_FINALIZE = b'prefinalize'
 GEN_GROUP_POST_FINALIZE = b'postfinalize'
@@ -335,7 +325,13 @@
 
 @active
 def addfilegenerator(
-self, genid, filenames, genfunc, order=0, location=b''
+self,
+genid,
+filenames,
+genfunc,
+order=0,
+location=b'',
+post_finalize=False,
 ):
 """add a function to generates some files at transaction commit
 
@@ -358,10 +354,14 @@
 The `location` arguments may be used to indicate the files are located
 outside of the the standard directory for transaction. It should match
 one of the key of the `transaction.vfsmap` dictionary.
+
+The `post_finalize` argument can be set to `True` for file generation
+that must be run after the transaction has been finalized.
 """
 # For now, we are unable to do proper backup and restore of custom vfs
 # but for bookmarks that are handled outside this mechanism.
-self._filegenerators[genid] = (order, filenames, genfunc, location)
+entry = (order, filenames, genfunc, location, post_finalize)
+self._filegenerators[genid] = entry
 
 @active
 def removefilegenerator(self, genid):
@@ -381,13 +381,12 @@
 
 for id, entry in sorted(pycompat.iteritems(self._filegenerators)):
 any = True
-order, filenames, genfunc, location = entry
+order, filenames, genfunc, location, post_finalize = entry
 
 # for generation at closing, check if it's before or after finalize
-is_post = id in postfinalizegenerators
-if skip_post and is_post:
+if skip_post and post_finalize:
 continue
-elif skip_pre and not is_post:
+elif skip_pre and not post_finalize:
 continue
 
 vfs = self._vfsmap[location]
diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -730,12 +730,14 @@
 (self._filename_tk,),
 lambda f: self._write_tracked_key(tr, f),
 location=b'plain',
+post_finalize=True,
 )
 tr.addfilegenerator(
 b'dirstate-1-main',
 (self._filename,),
 lambda f: self._writedirstate(tr, f),
 location=b'plain',
+post_finalize=True,
 )
 if write_key:
 tr.addfilegenerator(
@@ -743,6 +745,7 @@
 (self._filename_tk,),
 lambda f: self._write_tracked_key(tr, f),
 location=b'plain',
+post_finalize=True,
 )
 return
 
@@ -1425,6 +1428,7 @@
 (self._filename,),
 lambda f: self._writedirstate(tr, f),
 location=b'plain',
+post_finalize=True,
 )
 
 # ensure that pending file written above is unlinked at
diff --git 

[PATCH 1 of 2] revlog: extract entry byte offsets into named constants

2022-01-31 Thread pacien via Mercurial-devel
# HG changeset patch
# User pacien 
# Date 1643198916 -3600
#  Wed Jan 26 13:08:36 2022 +0100
# Node ID 92eaf2a7d355c27f04ea3bc90019723c0e643475
# Parent  3b6b43a7ace4bf9059c44ef81b630d15986e08ca
# EXP-Topic cl2-cext-prep
revlog: extract entry byte offsets into named constants

Labelling the fields pointed by the given offsets shared by revlog v1 and v2.

diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -136,6 +136,20 @@
 static const long format_v1 = 1; /* Internal only, could be any number */
 static const long format_v2 = 2; /* Internal only, could be any number */
 
+static const long entry_offset_high = 0;
+static const long entry_offset_offset_flags = 4;
+static const long entry_offset_comp_len = 8;
+static const long entry_offset_uncomp_len = 12;
+static const long entry_offset_base_rev = 16;
+static const long entry_offset_link_rev = 20;
+static const long entry_offset_parent_1 = 24;
+static const long entry_offset_parent_2 = 28;
+static const long entry_offset_node_id = 32;
+static const long entry_offset_sidedata_offset = 64;
+static const long entry_offset_sidedata_comp_len = 72;
+static const long entry_offset_all_comp_mode = 76;
+static const long entry_offset_padding_start = 77;
+
 static const char comp_mode_inline = 2;
 static const char rank_unknown = -1;
 
@@ -206,8 +220,8 @@
 {
const char *data = index_deref(self, rev);
 
-   ps[0] = getbe32(data + 24);
-   ps[1] = getbe32(data + 28);
+   ps[0] = getbe32(data + entry_offset_parent_1);
+   ps[1] = getbe32(data + entry_offset_parent_2);
 
/* If index file is corrupted, ps[] may point to invalid revisions. So
 * there is a risk of buffer overflow to trust them unconditionally. */
@@ -254,12 +268,12 @@
return 0;
 
data = index_deref(self, rev);
-   offset = getbe32(data + 4);
+   offset = getbe32(data + entry_offset_offset_flags);
if (rev == 0) {
/* mask out version number for the first entry */
offset &= 0x;
} else {
-   uint32_t offset_high = getbe32(data);
+   uint32_t offset_high = getbe32(data + entry_offset_high);
offset |= ((uint64_t)offset_high) << 32;
}
return (int64_t)(offset >> 16);
@@ -275,7 +289,7 @@
 
data = index_deref(self, rev);
 
-   tmp = (int)getbe32(data + 8);
+   tmp = (int)getbe32(data + entry_offset_comp_len);
if (tmp < 0) {
PyErr_Format(PyExc_OverflowError,
 "revlog entry size out of bound (%d)", tmp);
@@ -320,7 +334,7 @@
if (data == NULL)
return NULL;
 
-   offset_flags = getbe32(data + 4);
+   offset_flags = getbe32(data + entry_offset_offset_flags);
/*
 * The first entry on-disk needs the version number masked out,
 * but this doesn't apply if entries are added to an empty index.
@@ -328,17 +342,17 @@
if (self->length && pos == 0)
offset_flags &= 0x;
else {
-   uint32_t offset_high = getbe32(data);
+   uint32_t offset_high = getbe32(data + entry_offset_high);
offset_flags |= ((uint64_t)offset_high) << 32;
}
 
-   comp_len = getbe32(data + 8);
-   uncomp_len = getbe32(data + 12);
-   base_rev = getbe32(data + 16);
-   link_rev = getbe32(data + 20);
-   parent_1 = getbe32(data + 24);
-   parent_2 = getbe32(data + 28);
-   c_node_id = data + 32;
+   comp_len = getbe32(data + entry_offset_comp_len);
+   uncomp_len = getbe32(data + entry_offset_uncomp_len);
+   base_rev = getbe32(data + entry_offset_base_rev);
+   link_rev = getbe32(data + entry_offset_link_rev);
+   parent_1 = getbe32(data + entry_offset_parent_1);
+   parent_2 = getbe32(data + entry_offset_parent_2);
+   c_node_id = data + entry_offset_node_id;
 
if (self->format_version == format_v1) {
sidedata_offset = 0;
@@ -346,10 +360,12 @@
data_comp_mode = comp_mode_inline;
sidedata_comp_mode = comp_mode_inline;
} else {
-   sidedata_offset = getbe64(data + 64);
-   sidedata_comp_len = getbe32(data + 72);
-   data_comp_mode = data[76] & 3;
-   sidedata_comp_mode = ((data[76] >> 2) & 3);
+   sidedata_offset = getbe64(data + entry_offset_sidedata_offset);
+   sidedata_comp_len =
+   getbe32(data + entry_offset_sidedata_comp_len);
+   data_comp_mode = data[entry_offset_all_comp_mode] & 3;
+   sidedata_comp_mode =
+   ((data[entry_offset_all_comp_mode] >> 2) & 3);
}
 
return Py_BuildValue(tuple_format, offset_flags, comp_len, uncomp_len,
@@ -421,7 +437,7 @@
return NULL;
 
data = index_deref(self, pos);
-   return data 

[PATCH 2 of 2] revlog: split revlog v1 and revlog v2 handling

2022-01-31 Thread pacien via Mercurial-devel
# HG changeset patch
# User pacien 
# Date 1643199528 -3600
#  Wed Jan 26 13:18:48 2022 +0100
# Node ID db5ac78afd9efe541c631cbb8f3449c387dcf7c2
# Parent  92eaf2a7d355c27f04ea3bc90019723c0e643475
# EXP-Topic cl2-cext-prep
revlog: split revlog v1 and revlog v2 handling

Explicitly splitting their fields packing and unpacking makes it easier to
extend the existing C implemenation to handle the new changelog format, whose
fields and offsets are not simply a superset of the revlog.

diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -136,19 +136,29 @@
 static const long format_v1 = 1; /* Internal only, could be any number */
 static const long format_v2 = 2; /* Internal only, could be any number */
 
-static const long entry_offset_high = 0;
-static const long entry_offset_offset_flags = 4;
-static const long entry_offset_comp_len = 8;
-static const long entry_offset_uncomp_len = 12;
-static const long entry_offset_base_rev = 16;
-static const long entry_offset_link_rev = 20;
-static const long entry_offset_parent_1 = 24;
-static const long entry_offset_parent_2 = 28;
-static const long entry_offset_node_id = 32;
-static const long entry_offset_sidedata_offset = 64;
-static const long entry_offset_sidedata_comp_len = 72;
-static const long entry_offset_all_comp_mode = 76;
-static const long entry_offset_padding_start = 77;
+static const long entry_v1_offset_high = 0;
+static const long entry_v1_offset_offset_flags = 4;
+static const long entry_v1_offset_comp_len = 8;
+static const long entry_v1_offset_uncomp_len = 12;
+static const long entry_v1_offset_base_rev = 16;
+static const long entry_v1_offset_link_rev = 20;
+static const long entry_v1_offset_parent_1 = 24;
+static const long entry_v1_offset_parent_2 = 28;
+static const long entry_v1_offset_node_id = 32;
+
+static const long entry_v2_offset_high = 0;
+static const long entry_v2_offset_offset_flags = 4;
+static const long entry_v2_offset_comp_len = 8;
+static const long entry_v2_offset_uncomp_len = 12;
+static const long entry_v2_offset_base_rev = 16;
+static const long entry_v2_offset_link_rev = 20;
+static const long entry_v2_offset_parent_1 = 24;
+static const long entry_v2_offset_parent_2 = 28;
+static const long entry_v2_offset_node_id = 32;
+static const long entry_v2_offset_sidedata_offset = 64;
+static const long entry_v2_offset_sidedata_comp_len = 72;
+static const long entry_v2_offset_all_comp_mode = 76;
+static const long entry_v2_offset_padding_start = 77;
 
 static const char comp_mode_inline = 2;
 static const char rank_unknown = -1;
@@ -220,8 +230,16 @@
 {
const char *data = index_deref(self, rev);
 
-   ps[0] = getbe32(data + entry_offset_parent_1);
-   ps[1] = getbe32(data + entry_offset_parent_2);
+   if (self->format_version == format_v1) {
+   ps[0] = getbe32(data + entry_v1_offset_parent_1);
+   ps[1] = getbe32(data + entry_v1_offset_parent_2);
+   } else if (self->format_version == format_v2) {
+   ps[0] = getbe32(data + entry_v2_offset_parent_1);
+   ps[1] = getbe32(data + entry_v2_offset_parent_2);
+   } else {
+   raise_revlog_error();
+   return -1;
+   }
 
/* If index file is corrupted, ps[] may point to invalid revisions. So
 * there is a risk of buffer overflow to trust them unconditionally. */
@@ -268,14 +286,32 @@
return 0;
 
data = index_deref(self, rev);
-   offset = getbe32(data + entry_offset_offset_flags);
-   if (rev == 0) {
-   /* mask out version number for the first entry */
-   offset &= 0x;
+
+   if (self->format_version == format_v1) {
+   offset = getbe32(data + entry_v1_offset_offset_flags);
+   if (rev == 0) {
+   /* mask out version number for the first entry */
+   offset &= 0x;
+   } else {
+   uint32_t offset_high =
+   getbe32(data + entry_v1_offset_high);
+   offset |= ((uint64_t)offset_high) << 32;
+   }
+   } else if (self->format_version == format_v2) {
+   offset = getbe32(data + entry_v2_offset_offset_flags);
+   if (rev == 0) {
+   /* mask out version number for the first entry */
+   offset &= 0x;
+   } else {
+   uint32_t offset_high =
+   getbe32(data + entry_v2_offset_high);
+   offset |= ((uint64_t)offset_high) << 32;
+   }
} else {
-   uint32_t offset_high = getbe32(data + entry_offset_high);
-   offset |= ((uint64_t)offset_high) << 32;
+   raise_revlog_error();
+   return -1;
}
+
return (int64_t)(offset >> 16);
 }
 
@@ -289,7 +325,14 @@
 

[PATCH 5 of 5] rank: compute property incrementally

2022-01-31 Thread pacien via Mercurial-devel
# HG changeset patch
# User pacien 
# Date 1643367284 -3600
#  Fri Jan 28 11:54:44 2022 +0100
# Node ID 13b044b7e39299156aac33e68550b7004ad21cba
# Parent  04b7286cc3c4c7e332294183cfb87366d9748ca6
# EXP-Topic cl2-rank
rank: compute property incrementally

This replace the naive rank computation with more efficient incremental
method, avoiding computing the whole ancestor set when possible.

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -2491,7 +2491,17 @@
 # maybe the index.append should compute it when applicable instead
 rank = RANK_UNKNOWN
 if self._format_version == CHANGELOGV2:
-rank = len(list(self.ancestors([p1r, p2r], inclusive=True))) + 1
+if (p1r, p2r) == (nullrev, nullrev):
+rank = 1
+elif p1r != nullrev and p2r == nullrev:
+rank = 1 + self.fast_rank(p1r)
+elif p1r == nullrev and p2r != nullrev:
+rank = 1 + self.fast_rank(p2r)
+else:  # merge node
+# TODO: use exclusive part size from leap info when those will
+#   be available
+rank = (1 +
+  sum(1 for _ in self.ancestors([p1r, p2r], inclusive=True)))
 
 e = revlogutils.entry(
 flags=flags,
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


[PATCH 2 of 5] rank: add context and template keyword

2022-01-31 Thread pacien via Mercurial-devel
# HG changeset patch
# User Pierre-Yves David 
# Date 1643366141 -3600
#  Fri Jan 28 11:35:41 2022 +0100
# Node ID a5e1331be0ffa00772e4de07c982dfd36cd4f8c7
# Parent  ff043e0e1aacc81f8d5238f89bed5a6b355ba9cf
# EXP-Topic cl2-rank
rank: add context and template keyword

This makes the stored rank property accessible, to be expanded and printed.

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -685,6 +685,14 @@
 """Return a list of byte bookmark names."""
 return self._repo.nodebookmarks(self._node)
 
+def fast_rank(self):
+repo = self._repo
+if self._maybe_filtered:
+cl = repo.changelog
+else:
+cl = repo.unfiltered().changelog
+return cl.fast_rank(self._rev)
+
 def phase(self):
 return self._repo._phasecache.phase(self._repo, self._rev)
 
diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -304,6 +304,20 @@
 )
 
 
+@templatekeyword(b'_fast_rank', requires={b'ctx'})
+def fast_rank(context, mapping):
+"""the rank of a changeset if cached
+
+The rank of a revision is the size of sub-graph it defines as a head. In
+other words, the rank of X is the size of `ancestors(X)` (X included).
+"""
+ctx = context.resource(mapping, b'ctx')
+rank = ctx.fast_rank()
+if rank is None:
+return None
+return b"%d" % rank
+
+
 def _getfilestatus(context, mapping, listall=False):
 ctx = context.resource(mapping, b'ctx')
 revcache = context.resource(mapping, b'revcache')
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


[PATCH 4 of 5] rank: add test with golden values

2022-01-31 Thread pacien via Mercurial-devel
# HG changeset patch
# User Pierre-Yves David 
# Date 1643366733 -3600
#  Fri Jan 28 11:45:33 2022 +0100
# Node ID 04b7286cc3c4c7e332294183cfb87366d9748ca6
# Parent  2bf3d6c5b1fa4e0c2882752031e7ca934f7330c3
# EXP-Topic cl2-rank
rank: add test with golden values

This adds a regression test for the computation of the rank, using the current
values computed with the naive algorithm as the "golden" reference.

diff --git a/tests/test-rank.t b/tests/test-rank.t
--- a/tests/test-rank.t
+++ b/tests/test-rank.t
@@ -35,3 +35,188 @@
   0 1
   $ cd ..
 
+
+Build a bigger example repo
+
+  $ hg init rank-repo-generated
+  $ cd rank-repo-generated
+  $ hg debugbuilddag '.:root1+5:mp1https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


[PATCH 1 of 5] rank: naive rank property computation and retrieval

2022-01-31 Thread pacien via Mercurial-devel
# HG changeset patch
# User Pierre-Yves David 
# Date 1643365981 -3600
#  Fri Jan 28 11:33:01 2022 +0100
# Node ID ff043e0e1aacc81f8d5238f89bed5a6b355ba9cf
# Parent  4afb9627dc77264d3a8b0c9c1ccc8bff9ffd6faa
# EXP-Topic cl2-rank
rank: naive rank property computation and retrieval

This stores the rank (size of the ancestor set of a revision, including itself)
in a changelog field and allows this property to be retrieved.

The value is computed in a naive way from the definition of the rank. This will
be replaced by a more efficient version later on.

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -40,11 +40,13 @@
 COMP_MODE_DEFAULT,
 COMP_MODE_INLINE,
 COMP_MODE_PLAIN,
+ENTRY_RANK,
 FEATURES_BY_VERSION,
 FLAG_GENERALDELTA,
 FLAG_INLINE_DATA,
 INDEX_HEADER,
 KIND_CHANGELOG,
+RANK_UNKNOWN,
 REVLOGV0,
 REVLOGV1,
 REVLOGV1_FLAGS,
@@ -872,6 +874,20 @@
 
 return len(self.revision(rev, raw=False))
 
+def fast_rank(self, rev):
+"""The "rank" of the revision if available, None otherwise
+
+The rank of a revision is the size of sub-graph it defines as a head.
+In other words, the rank og X i sthe size of `ancestors(X)` (X
+included).
+
+Some variant of revlog persist this value and make it available.
+"""
+rank = self.index[rev][ENTRY_RANK]
+if rank == RANK_UNKNOWN:
+return None
+return rank
+
 def chainbase(self, rev):
 base = self._chainbasecache.get(rev)
 if base is not None:
@@ -2472,6 +2488,11 @@
 # than ones we manually add.
 sidedata_offset = 0
 
+# maybe the index.append should compute it when applicable instead
+rank = RANK_UNKNOWN
+if self._format_version == CHANGELOGV2:
+rank = len(list(self.ancestors([p1r, p2r], inclusive=True))) + 1
+
 e = revlogutils.entry(
 flags=flags,
 data_offset=offset,
@@ -2486,6 +2507,7 @@
 sidedata_offset=sidedata_offset,
 sidedata_compressed_length=len(serialized_sidedata),
 sidedata_compression_mode=sidedata_compression_mode,
+rank=rank,
 )
 
 self.index.append(e)
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


[PATCH 3 of 5] rank: add minimal test

2022-01-31 Thread pacien via Mercurial-devel
# HG changeset patch
# User pacien 
# Date 1643366718 -3600
#  Fri Jan 28 11:45:18 2022 +0100
# Node ID 2bf3d6c5b1fa4e0c2882752031e7ca934f7330c3
# Parent  a5e1331be0ffa00772e4de07c982dfd36cd4f8c7
# EXP-Topic cl2-rank
rank: add minimal test

This adds a small test checking the rank computation in the case of a merge.

diff --git a/tests/test-rank.t b/tests/test-rank.t
new file mode 100644
--- /dev/null
+++ b/tests/test-rank.t
@@ -0,0 +1,37 @@
+=
+Check that we can compute and exchange revision rank properly
+=
+
+  $ cat << EOF >> $HGRCPATH
+  > [format]
+  > exp-use-changelog-v2=enable-unstable-format-and-corrupt-my-data
+  > EOF
+
+
+Test minimal rank computation with merge
+
+  $ hg init rank-repo-minimal
+  $ cd rank-repo-minimal
+  $ touch 0
+  $ hg add 0
+  $ hg commit -m 0
+  $ touch 1
+  $ hg add 1
+  $ hg commit -m 1
+  $ hg update -r 0 >> /dev/null
+  $ touch 2
+  $ hg add 2
+  $ hg commit -m 2 >> /dev/null
+  $ hg merge -r 1 >> /dev/null
+  $ hg commit -m 3
+  $ touch 4
+  $ hg add 4
+  $ hg commit -m 4
+  $ hg log --template '{rev} {_fast_rank}\n'
+  4 5
+  3 4
+  2 2
+  1 2
+  0 1
+  $ cd ..
+
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


[Bug 6639] New: Anti-virus detects trojan malware in hg.exe

2022-01-31 Thread mercurial-bugs
https://bz.mercurial-scm.org/show_bug.cgi?id=6639

Bug ID: 6639
   Summary: Anti-virus detects trojan malware in hg.exe
   Product: Mercurial
   Version: 6.0.1
  Hardware: PC
OS: Windows
Status: UNCONFIRMED
  Severity: feature
  Priority: wish
 Component: Mercurial
  Assignee: bugzi...@mercurial-scm.org
  Reporter: salm...@mail.com
CC: mercurial-devel@mercurial-scm.org
Python Version: ---

Created attachment 2133
  --> https://bz.mercurial-scm.org/attachment.cgi?id=2133=edit
MS Windows Defender report for hg.exe version 6.0.0 and 6.0.1

Windows hg.exe is reported as a risk of being infected by a malware trojan:

Windows THREAT REPORTS:
1. virustotal.com reports threats by 2 programs on all Windows installations:
 "Trojan.Malware.300983.susgen" is detected by MaxSecure anti-virus via
virustotal.com
 "Unsafe" is detected  by Cylance anti-virus via virustotal.com

See virustotal.com report for hg.exe version 6.0.0:
https://www.virustotal.com/gui/file/5bda8e15adf530d6186b7dfaf75eafb46f5118bd9171a312381439b3fe2638e3

See virustotal.com report for hg.exe. version 6.0.1:
https://www.virustotal.com/gui/file/d54d21430cf6a2d872f0a8fb7e569ba4a7bbed195cb8945d4e2eb4ccc37e0959

3. "Threat detected: Program"Win32/Bearfoos.B!ml" by Microsoft Defender
But this  - only on one Windows system.

OS: MS Windows 10 64bit
Tested and affected Mercurial: 6.0.0, 6.0.1
Used installer for 6.0.1: mercurial-6.0.1-x64.msi

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


mercurial@48669: 87 new changesets

2022-01-31 Thread Mercurial Commits
87 new changesets in mercurial:

https://www.mercurial-scm.org/repo/hg/rev/a809f1465a76
changeset:   48583:a809f1465a76
parent:  48579:f970bc616ebc
user:Martin von Zweigbergk 
date:Thu Jan 20 13:43:43 2022 -0800
summary: filemerge: set default labels a little earlier

https://www.mercurial-scm.org/repo/hg/rev/74973a6d4e67
changeset:   48584:74973a6d4e67
user:Martin von Zweigbergk 
date:Thu Jan 20 14:13:12 2022 -0800
summary: filemerge: always define a "base" label

https://www.mercurial-scm.org/repo/hg/rev/07069fcd9a6e
changeset:   48585:07069fcd9a6e
user:Martin von Zweigbergk 
date:Thu Jan 20 14:42:50 2022 -0800
summary: filemerge: work with `simplemerge.MergeInput` in `filemerge()`

https://www.mercurial-scm.org/repo/hg/rev/fd9fe2658cda
changeset:   48586:fd9fe2658cda
user:Martin von Zweigbergk 
date:Thu Jan 20 16:16:05 2022 -0800
summary: filemerge: pass `simplemerge.MergeInput` to tool functions

https://www.mercurial-scm.org/repo/hg/rev/3c8cc987672e
changeset:   48587:3c8cc987672e
user:Martin von Zweigbergk 
date:Thu Jan 20 11:06:52 2022 -0800
summary: simplemerge: take over formatting of label from `filemerge`

https://www.mercurial-scm.org/repo/hg/rev/402a6b6173e9
changeset:   48588:402a6b6173e9
user:Martin von Zweigbergk 
date:Tue Jan 18 14:57:15 2022 -0800
summary: rebase: set custom conflict label for base commit

https://www.mercurial-scm.org/repo/hg/rev/a51c522c0064
changeset:   48589:a51c522c0064
user:Martin von Zweigbergk 
date:Tue Jan 18 15:04:55 2022 -0800
summary: merge: set custom conflict label for base commit

https://www.mercurial-scm.org/repo/hg/rev/7e503eff3c76
changeset:   48590:7e503eff3c76
user:Martin von Zweigbergk 
date:Tue Jan 18 13:23:49 2022 -0800
summary: update: set custom conflict label for base commit

https://www.mercurial-scm.org/repo/hg/rev/f1162b125991
changeset:   48591:f1162b125991
user:Martin von Zweigbergk 
date:Fri Jan 21 13:48:18 2022 -0800
summary: histedit: attempt to make merge labels more helpful

https://www.mercurial-scm.org/repo/hg/rev/bcc4820242cf
changeset:   48592:bcc4820242cf
user:Martin von Zweigbergk 
date:Fri Jan 21 13:49:11 2022 -0800
summary: shelve: attempt to make merge labels more helpful

https://www.mercurial-scm.org/repo/hg/rev/47b3fca301f8
changeset:   48593:47b3fca301f8
user:Martin von Zweigbergk 
date:Fri Jan 21 13:48:48 2022 -0800
summary: graft: attempt to make merge labels more helpful

https://www.mercurial-scm.org/repo/hg/rev/b128d21cbe8b
changeset:   48594:b128d21cbe8b
user:Martin von Zweigbergk 
date:Mon Jan 24 08:35:14 2022 -0800
summary: relnotes: add note about changed labels texts

https://www.mercurial-scm.org/repo/hg/rev/6a68350ec2ef
changeset:   48595:6a68350ec2ef
user:Pierre-Yves David 
date:Tue Jan 18 00:07:43 2022 +0100
summary: stream-clone: drop some outdated lines in test-stream-bundle-v2.t

https://www.mercurial-scm.org/repo/hg/rev/739f2ca3aa3f
changeset:   48596:739f2ca3aa3f
user:Pierre-Yves David 
date:Fri Jan 14 17:57:49 2022 +0100
summary: stream-clone: factor computation of new clone requirement out

https://www.mercurial-scm.org/repo/hg/rev/8475a1364909
changeset:   48597:8475a1364909
user:Pierre-Yves David 
date:Fri Jan 14 18:02:25 2022 +0100
summary: stream-clone: factor computation of requirement of a stream clone

https://www.mercurial-scm.org/repo/hg/rev/a6f16ec07ed7
changeset:   48598:a6f16ec07ed7
user:Pierre-Yves David 
date:Mon Jan 17 18:51:47 2022 +0100
summary: stream-clone: add a explicit test for format change during stream 
clone

https://www.mercurial-scm.org/repo/hg/rev/dfbfa802876b
changeset:   48599:dfbfa802876b
user:Pierre-Yves David 
date:Mon Jan 17 19:18:20 2022 +0100
summary: requirements: move "bookmark in store" requirements in the right 
module

https://www.mercurial-scm.org/repo/hg/rev/d9017df70135
changeset:   48600:d9017df70135
user:Pierre-Yves David 
date:Mon Jan 24 11:49:06 2022 +0100
summary: stream-clone: filter possible missing requirements using all 
supported one

https://www.mercurial-scm.org/repo/hg/rev/baddab229b86
changeset:   48601:baddab229b86
user:Pierre-Yves David 
date:Mon Jan 17 19:26:36 2022 +0100
summary: stream-clone: add a explicit set list requirements relevant to 
stream clone

https://www.mercurial-scm.org/repo/hg/rev/66b59fbb0cdd
changeset:   48602:66b59fbb0cdd
user:Pierre-Yves David 
date:Mon Jan 17 19:28:10 2022 +0100
summary: requirements: move the comment about manifestv2 in the module

https://www.mercurial-scm.org/repo/hg/rev/3a8bc0b48e51
changeset:   48603:3a8bc0b48e51
user:Pierre-Yves David 
date:Mon Jan 17 22:48:16 2022 +0100
summary: 

Re: [PATCH 5 of 5] rank: compute property incrementally

2022-01-31 Thread Pierre-Yves David


On 1/31/22 15:03, pacien wrote:

# HG changeset patch
# User pacien 
# Date 1643367284 -3600
#  Fri Jan 28 11:54:44 2022 +0100
# Node ID 13b044b7e39299156aac33e68550b7004ad21cba
# Parent  04b7286cc3c4c7e332294183cfb87366d9748ca6
# EXP-Topic cl2-rank
rank: compute property incrementally

This replace the naive rank computation with more efficient incremental
method, avoiding computing the whole ancestor set when possible.

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -2491,7 +2491,17 @@
  # maybe the index.append should compute it when applicable instead
  rank = RANK_UNKNOWN
  if self._format_version == CHANGELOGV2:
-rank = len(list(self.ancestors([p1r, p2r], inclusive=True))) + 1
+if (p1r, p2r) == (nullrev, nullrev):
+rank = 1
+elif p1r != nullrev and p2r == nullrev:
+rank = 1 + self.fast_rank(p1r)
+elif p1r == nullrev and p2r != nullrev:
+rank = 1 + self.fast_rank(p2r)
+else:  # merge node
+# TODO: use exclusive part size from leap info when those will
+#   be available
+rank = (1 +
+  sum(1 for _ in self.ancestors([p1r, p2r], inclusive=True)))



You don't need to wait for leap based traversal, you can already use 
`self.findmissing` to have more efficient computation.



--
Pierre-Yves David

___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


Re: [PATCH 3 of 5] rank: add minimal test

2022-01-31 Thread Pierre-Yves David


On 1/31/22 15:03, pacien wrote:

# HG changeset patch
# User pacien 
# Date 1643366718 -3600
#  Fri Jan 28 11:45:18 2022 +0100
# Node ID 2bf3d6c5b1fa4e0c2882752031e7ca934f7330c3
# Parent  a5e1331be0ffa00772e4de07c982dfd36cd4f8c7
# EXP-Topic cl2-rank
rank: add minimal test

This adds a small test checking the rank computation in the case of a merge.

diff --git a/tests/test-rank.t b/tests/test-rank.t
new file mode 100644
--- /dev/null
+++ b/tests/test-rank.t
@@ -0,0 +1,37 @@
+=
+Check that we can compute and exchange revision rank properly
+=
+
+  $ cat << EOF >> $HGRCPATH
+  > [format]
+  > exp-use-changelog-v2=enable-unstable-format-and-corrupt-my-data
+  > EOF
+
+
+Test minimal rank computation with merge
+
+  $ hg init rank-repo-minimal
+  $ cd rank-repo-minimal
+  $ touch 0
+  $ hg add 0
+  $ hg commit -m 0
+  $ touch 1
+  $ hg add 1
+  $ hg commit -m 1
+  $ hg update -r 0 >> /dev/null
+  $ touch 2
+  $ hg add 2
+  $ hg commit -m 2 >> /dev/null
+  $ hg merge -r 1 >> /dev/null
+  $ hg commit -m 3
+  $ touch 4
+  $ hg add 4
+  $ hg commit -m 4
+  $ hg log --template '{rev} {_fast_rank}\n'
+  4 5
+  3 4
+  2 2
+  1 2
+  0 1
+  $ cd ..



You should throw a `--graph` flag on this log call to make it easier to 
understand.


--
Pierre-Yves David

___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12124: dirstate: introduce a "tracked-key" feature

2022-01-31 Thread marmoute (Pierre-Yves David)
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  A new format variant is introduced. When used, a `tracked-key` file will be
  generated. That file will be update when the set of tracked file might have
  changed. This will be useful for external automation (e.g. build tool) to be
  notified when the set of relevant files changes.
  
  One of the motivation for this changes is to mitigate effect dirstate-v2 has 
on
  such automation. Since the dirstate file is updated much more frequently on
  dirstate-v2, monitoring update to that file is no longer a viable strategy.
  
  See the associated documentation for details about the feature
  
  To prevent older client to update the repository without updating that file, a
  new requirements is introduced.
  
  The `postfinalizegenerators` business is a bit weird, so I'll likely clean 
that
  up soon.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12124

AFFECTED FILES
  mercurial/configitems.py
  mercurial/dirstate.py
  mercurial/helptext/config.txt
  mercurial/localrepo.py
  mercurial/requirements.py
  mercurial/transaction.py
  tests/test-help.t
  tests/test-status-tracked-key.t

CHANGE DETAILS

diff --git a/tests/test-status-tracked-key.t b/tests/test-status-tracked-key.t
new file mode 100644
--- /dev/null
+++ b/tests/test-status-tracked-key.t
@@ -0,0 +1,163 @@
+==
+Test the "tracked key" feature
+==
+
+The tracked key feature provide a file that get updated when the set of tracked
+files get updated.
+
+basic setup
+
+  $ cat << EOF >> $HGRCPATH
+  > [format]
+  > exp-dirstate-tracked-key-version=1
+  > EOF
+
+  $ hg init tracked-key-test
+  $ cd tracked-key-test
+  $ hg debugbuilddag '.+10' -n
+  $ hg log -G -T '{rev} {desc} {files}\n'
+  o  10 r10 nf10
+  |
+  o  9 r9 nf9
+  |
+  o  8 r8 nf8
+  |
+  o  7 r7 nf7
+  |
+  o  6 r6 nf6
+  |
+  o  5 r5 nf5
+  |
+  o  4 r4 nf4
+  |
+  o  3 r3 nf3
+  |
+  o  2 r2 nf2
+  |
+  o  1 r1 nf1
+  |
+  o  0 r0 nf0
+  
+  $ hg up tip
+  11 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg files
+  nf0
+  nf1
+  nf10
+  nf2
+  nf3
+  nf4
+  nf5
+  nf6
+  nf7
+  nf8
+  nf9
+
+key-file exists
+---
+
+The tracked key file should exist
+
+  $ ls -1 .hg/dirstate*
+  .hg/dirstate
+  .hg/dirstate-tracked-key
+
+key-file stay the same if the tracked set is unchanged
+--
+
+(copy its content for later comparison)
+
+  $ cp .hg/dirstate-tracked-key ../key-bck
+  $ echo foo >> nf0
+  $ sleep 1
+  $ hg status
+  M nf0
+  $ diff --brief .hg/dirstate-tracked-key ../key-bck
+  $ hg revert -C nf0
+  $ sleep 1
+  $ hg status
+  $ diff --brief .hg/dirstate-tracked-key ../key-bck
+
+key-file change if the tracked set is changed manually
+--
+
+adding a file to tracking
+
+  $ cp .hg/dirstate-tracked-key ../key-bck
+  $ echo x > x
+  $ hg add x
+  $ diff --brief .hg/dirstate-tracked-key ../key-bck
+  Files .hg/dirstate-tracked-key and ../key-bck differ
+  [1]
+
+remove a file from tracking
+(forget)
+
+  $ cp .hg/dirstate-tracked-key ../key-bck
+  $ hg forget x
+  $ diff --brief .hg/dirstate-tracked-key ../key-bck
+  Files .hg/dirstate-tracked-key and ../key-bck differ
+  [1]
+
+(remove)
+
+  $ cp .hg/dirstate-tracked-key ../key-bck
+  $ hg remove nf1
+  $ diff --brief .hg/dirstate-tracked-key ../key-bck
+  Files .hg/dirstate-tracked-key and ../key-bck differ
+  [1]
+
+key-file changes on revert (when applicable)
+
+
+  $ cp .hg/dirstate-tracked-key ../key-bck
+  $ hg status
+  R nf1
+  ? x
+  $ hg revert --all
+  undeleting nf1
+  $ hg status
+  ? x
+  $ diff --brief .hg/dirstate-tracked-key ../key-bck
+  Files .hg/dirstate-tracked-key and ../key-bck differ
+  [1]
+
+
+`hg update` does affect the key-file (when needed)
+--
+
+update changing the tracked set
+
+(removing)
+
+  $ cp .hg/dirstate-tracked-key ../key-bck
+  $ hg status --rev . --rev '.#generations[-1]'
+  R nf10
+  $ hg up '.#generations[-1]'
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ diff --brief .hg/dirstate-tracked-key ../key-bck
+  Files .hg/dirstate-tracked-key and ../key-bck differ
+  [1]
+
+(adding)
+
+  $ cp .hg/dirstate-tracked-key ../key-bck
+  $ hg status --rev . --rev '.#generations[1]'
+  A nf10
+  $ hg up '.#generations[1]'
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ diff --brief .hg/dirstate-tracked-key ../key-bck
+  Files .hg/dirstate-tracked-key and ../key-bck differ
+  [1]
+
+update not affecting the tracked set
+
+  $ echo foo >> nf0
+  $ hg commit -m foo
+
+  $ cp .hg/dirstate-tracked-key ../key-bck
+  $ hg status --rev . --rev '.#generations[-1]'
+  M nf0
+  $ hg up 

D12123: dirstate: rename the filegenerator used for writing

2022-01-31 Thread marmoute (Pierre-Yves David)
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  We will need a different name in the next changesets. Changing the name is
  actually not that trivial so we do it in its own changeset.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12123

AFFECTED FILES
  mercurial/dirstate.py
  mercurial/transaction.py

CHANGE DETAILS

diff --git a/mercurial/transaction.py b/mercurial/transaction.py
--- a/mercurial/transaction.py
+++ b/mercurial/transaction.py
@@ -28,7 +28,10 @@
 # These are the file generators that should only be executed after the
 # finalizers are done, since they rely on the output of the finalizers (like
 # the changelog having been written).
-postfinalizegenerators = {b'bookmarks', b'dirstate'}
+postfinalizegenerators = {
+b'bookmarks',
+b'dirstate-1-main',
+}
 
 GEN_GROUP_ALL = b'all'
 GEN_GROUP_PRE_FINALIZE = b'prefinalize'
diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -706,7 +706,7 @@
 if tr:
 # delay writing in-memory changes out
 tr.addfilegenerator(
-b'dirstate',
+b'dirstate-1-main',
 (self._filename,),
 lambda f: self._writedirstate(tr, f),
 location=b'plain',
@@ -1374,7 +1374,7 @@
 # changes written out above, even if dirstate is never
 # changed after this
 tr.addfilegenerator(
-b'dirstate',
+b'dirstate-1-main',
 (self._filename,),
 lambda f: self._writedirstate(tr, f),
 location=b'plain',



To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12122: dirstate: use a context manager when writing the dirstate

2022-01-31 Thread marmoute (Pierre-Yves David)
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This make sure the file is closed in a timely manner.
  
  We define a lambda for the file opening. It might seems a bit overkill here 
but
  a future changeset will need to do more of those.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12122

AFFECTED FILES
  mercurial/dirstate.py

CHANGE DETAILS

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -713,8 +713,9 @@
 )
 return
 
-st = self._opener(filename, b"w", atomictemp=True, checkambig=True)
-self._writedirstate(tr, st)
+file = lambda f: self._opener(f, b"w", atomictemp=True, 
checkambig=True)
+with file(self._filename) as f:
+self._writedirstate(tr, f)
 
 def addparentchangecallback(self, category, callback):
 """add a callback to be called when the wd parents are changed



To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12121: obsolete: don't import from .node twice

2022-01-31 Thread av6 (Anton Shestakov)
av6 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  See d55b71393907 
.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12121

AFFECTED FILES
  mercurial/obsolete.py

CHANGE DETAILS

diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -73,10 +73,6 @@
 import struct
 
 from .i18n import _
-from .node import (
-bin,
-hex,
-)
 from .pycompat import getattr
 from .node import (
 bin,



To: av6, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12120: dagop: don't import nullrev from .node twice

2022-01-31 Thread av6 (Anton Shestakov)
av6 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  See 59fa3890d40a 
.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12120

AFFECTED FILES
  mercurial/dagop.py

CHANGE DETAILS

diff --git a/mercurial/dagop.py b/mercurial/dagop.py
--- a/mercurial/dagop.py
+++ b/mercurial/dagop.py
@@ -9,7 +9,6 @@
 
 import heapq
 
-from .node import nullrev
 from .thirdparty import attr
 from .node import nullrev
 from . import (



To: av6, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel