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

report: improve the way it displays the diffs #16

Merged
merged 1 commit into from
Feb 14, 2025
Merged

Conversation

brunoerg
Copy link
Owner

Combine diffs by the number of line touched.

E.g.:

 {
        "filename": "src/addrman.cpp",
        "mutation_score": 0.0,
        "date": "14/02/2025 17:43:07",
        "diffs": {
            "565": [
                {
                    "id": 1,
                    "diff": "@@ -562,7 +562,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c\n         time_penalty = 0s;\n     }\n \n-    if (pinfo) {\n+        if (1==1) {\n         // periodically update nTime\n         const bool currently_online{NodeClock::now() - addr.nTime < 24h};\n         const auto update_interval{currently_online ? 1h : 24h};\n",
                    "status": "alive"
                }
            ],
            "561": [
                {
                    "id": 1,
                    "diff": "@@ -558,7 +558,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c\n     AddrInfo* pinfo = Find(addr, &nId);\n \n     // Do not set a penalty for a source's self-announcement\n-    if (addr == source) {\n+        if (1==0) {\n         time_penalty = 0s;\n     }\n \n",
                    "status": "alive"
                },
                {
                    "id": 2,
                    "diff": "@@ -558,7 +558,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c\n     AddrInfo* pinfo = Find(addr, &nId);\n \n     // Do not set a penalty for a source's self-announcement\n-    if (addr == source) {\n+        if (1==1) {\n         time_penalty = 0s;\n     }\n \n",
                    "status": "alive"
                },
                {
                    "id": 3,
                    "diff": "@@ -558,7 +558,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c\n     AddrInfo* pinfo = Find(addr, &nId);\n \n     // Do not set a penalty for a source's self-announcement\n-    if (addr == source) {\n+        if (addr != source) {\n         time_penalty = 0s;\n     }\n \n",
                    "status": "alive"
                }
            ],
            "555": [
                {
                    "id": 1,
                    "diff": "@@ -552,7 +552,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c\n     AssertLockHeld(cs);\n \n     if (!addr.IsRoutable())\n-        return false;\n+                return true;\n \n     nid_type nId;\n     AddrInfo* pinfo = Find(addr, &nId);\n",
                    "status": "alive"
                }
            ],
            "605": [
                {
                    "id": 1,
                    "diff": "@@ -602,7 +602,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c\n     if (vvNew[nUBucket][nUBucketPos] != nId) {\n         if (!fInsert) {\n             AddrInfo& infoExisting = mapInfo[vvNew[nUBucket][nUBucketPos]];\n-            if (infoExisting.IsTerrible() || (infoExisting.nRefCount > 1 && pinfo->nRefCount == 0)) {\n+                        if (infoExisting.IsTerrible() || (infoExisting.nRefCount >= 1 && pinfo->nRefCount == 0)) {\n                 // Overwrite the existing new table entry.\n                 fInsert = true;\n             }\n",
                    "status": "alive"
                },
                {
                    "id": 2,
                    "diff": "@@ -602,7 +602,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c\n     if (vvNew[nUBucket][nUBucketPos] != nId) {\n         if (!fInsert) {\n             AddrInfo& infoExisting = mapInfo[vvNew[nUBucket][nUBucketPos]];\n-            if (infoExisting.IsTerrible() || (infoExisting.nRefCount > 1 && pinfo->nRefCount == 0)) {\n+                        if (infoExisting.IsTerrible() || (infoExisting.nRefCount <= 1 && pinfo->nRefCount == 0)) {\n                 // Overwrite the existing new table entry.\n                 fInsert = true;\n             }\n",
                    "status": "alive"
                },
                {
                    "id": 3,
                    "diff": "@@ -602,7 +602,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c\n     if (vvNew[nUBucket][nUBucketPos] != nId) {\n         if (!fInsert) {\n             AddrInfo& infoExisting = mapInfo[vvNew[nUBucket][nUBucketPos]];\n-            if (infoExisting.IsTerrible() || (infoExisting.nRefCount > 1 && pinfo->nRefCount == 0)) {\n+                        if (infoExisting.IsTerrible() || (infoExisting.nRefCount > 1 || pinfo->nRefCount == 0)) {\n                 // Overwrite the existing new table entry.\n                 fInsert = true;\n             }\n",
                    "status": "alive"
                },
                {
                    "id": 4,
                    "diff": "@@ -602,7 +602,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c\n     if (vvNew[nUBucket][nUBucketPos] != nId) {\n         if (!fInsert) {\n             AddrInfo& infoExisting = mapInfo[vvNew[nUBucket][nUBucketPos]];\n-            if (infoExisting.IsTerrible() || (infoExisting.nRefCount > 1 && pinfo->nRefCount == 0)) {\n+                        if (infoExisting.IsTerrible() || (infoExisting.nRefCount < 1 && pinfo->nRefCount == 0)) {\n                 // Overwrite the existing new table entry.\n                 fInsert = true;\n             }\n",
                    "status": "alive"
                }
            ],
            "596": [
                {
                    "id": 1,
                    "diff": "@@ -593,7 +593,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c\n         }\n     } else {\n         pinfo = Create(addr, source, &nId);\n-        pinfo->nTime = std::max(NodeSeconds{0s}, pinfo->nTime - time_penalty);\n+                pinfo->nTime = std::max(NodeSeconds{0s}, pinfo->nTime + time_penalty);\n     }\n \n     int nUBucket = pinfo->GetNewBucket(nKey, source, m_netgroupman);\n",
                    "status": "alive"
                },
                {
                    "id": 2,
                    "diff": "@@ -593,7 +593,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c\n         }\n     } else {\n         pinfo = Create(addr, source, &nId);\n-        pinfo->nTime = std::max(NodeSeconds{0s}, pinfo->nTime - time_penalty);\n+                pinfo->nTime = std::min(NodeSeconds{0s}, pinfo->nTime - time_penalty);\n     }\n \n     int nUBucket = pinfo->GetNewBucket(nKey, source, m_netgroupman);\n",
                    "status": "alive"
                }
            ],
            "569": [
                {
                    "id": 1,
                    "diff": "@@ -566,7 +566,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c\n         // periodically update nTime\n         const bool currently_online{NodeClock::now() - addr.nTime < 24h};\n         const auto update_interval{currently_online ? 1h : 24h};\n-        if (pinfo->nTime < addr.nTime - update_interval - time_penalty) {\n+                if (1==0) {\n             pinfo->nTime = std::max(NodeSeconds{0s}, addr.nTime - time_penalty);\n         }\n \n",
                    "status": "alive"
                }
            ],
            "590": [
                {
                    "id": 1,
                    "diff": "@@ -587,7 +587,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c\n             return false;\n \n         // stochastic test: previous nRefCount == N: 2^N times harder to increase it\n-        if (pinfo->nRefCount > 0) {\n+                if (1==0) {\n             const int nFactor{1 << pinfo->nRefCount};\n             if (insecure_rand.randrange(nFactor) != 0) return false;\n         }\n",
                    "status": "alive"
                }
            ],
            "592": [
                {
                    "id": 1,
                    "diff": "@@ -589,7 +589,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c\n         // stochastic test: previous nRefCount == N: 2^N times harder to increase it\n         if (pinfo->nRefCount > 0) {\n             const int nFactor{1 << pinfo->nRefCount};\n-            if (insecure_rand.randrange(nFactor) != 0) return false;\n+            \n         }\n     } else {\n         pinfo = Create(addr, source, &nId);\n",
                    "status": "alive"
                }
            ],
            "602": [
                {
                    "id": 1,
                    "diff": "@@ -599,7 +599,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c\n     int nUBucket = pinfo->GetNewBucket(nKey, source, m_netgroupman);\n     int nUBucketPos = pinfo->GetBucketPosition(nKey, true, nUBucket);\n     bool fInsert = vvNew[nUBucket][nUBucketPos] == -1;\n-    if (vvNew[nUBucket][nUBucketPos] != nId) {\n+        if (1==0) {\n         if (!fInsert) {\n             AddrInfo& infoExisting = mapInfo[vvNew[nUBucket][nUBucketPos]];\n             if (infoExisting.IsTerrible() || (infoExisting.nRefCount > 1 && pinfo->nRefCount == 0)) {\n",
                    "status": "alive"
                },
                {
                    "id": 2,
                    "diff": "@@ -599,7 +599,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c\n     int nUBucket = pinfo->GetNewBucket(nKey, source, m_netgroupman);\n     int nUBucketPos = pinfo->GetBucketPosition(nKey, true, nUBucket);\n     bool fInsert = vvNew[nUBucket][nUBucketPos] == -1;\n-    if (vvNew[nUBucket][nUBucketPos] != nId) {\n+        if (vvNew[nUBucket][nUBucketPos] == nId) {\n         if (!fInsert) {\n             AddrInfo& infoExisting = mapInfo[vvNew[nUBucket][nUBucketPos]];\n             if (infoExisting.IsTerrible() || (infoExisting.nRefCount > 1 && pinfo->nRefCount == 0)) {\n",
                    "status": "alive"
                },
                {
                    "id": 3,
                    "diff": "@@ -599,7 +599,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c\n     int nUBucket = pinfo->GetNewBucket(nKey, source, m_netgroupman);\n     int nUBucketPos = pinfo->GetBucketPosition(nKey, true, nUBucket);\n     bool fInsert = vvNew[nUBucket][nUBucketPos] == -1;\n-    if (vvNew[nUBucket][nUBucketPos] != nId) {\n+        if (1==1) {\n         if (!fInsert) {\n             AddrInfo& infoExisting = mapInfo[vvNew[nUBucket][nUBucketPos]];\n             if (infoExisting.IsTerrible() || (infoExisting.nRefCount > 1 && pinfo->nRefCount == 0)) {\n",
                    "status": "alive"
                }
            ],
            "603": [
                {
                    "id": 1,
                    "diff": "@@ -600,7 +600,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c\n     int nUBucketPos = pinfo->GetBucketPosition(nKey, true, nUBucket);\n     bool fInsert = vvNew[nUBucket][nUBucketPos] == -1;\n     if (vvNew[nUBucket][nUBucketPos] != nId) {\n-        if (!fInsert) {\n+                if (1==1) {\n             AddrInfo& infoExisting = mapInfo[vvNew[nUBucket][nUBucketPos]];\n             if (infoExisting.IsTerrible() || (infoExisting.nRefCount > 1 && pinfo->nRefCount == 0)) {\n                 // Overwrite the existing new table entry.\n",
                    "status": "alive"
                },
                {
                    "id": 2,
                    "diff": "@@ -600,7 +600,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c\n     int nUBucketPos = pinfo->GetBucketPosition(nKey, true, nUBucket);\n     bool fInsert = vvNew[nUBucket][nUBucketPos] == -1;\n     if (vvNew[nUBucket][nUBucketPos] != nId) {\n-        if (!fInsert) {\n+                if (1==0) {\n             AddrInfo& infoExisting = mapInfo[vvNew[nUBucket][nUBucketPos]];\n             if (infoExisting.IsTerrible() || (infoExisting.nRefCount > 1 && pinfo->nRefCount == 0)) {\n                 // Overwrite the existing new table entry.\n",
                    "status": "alive"
                }
            ],
            "601": [
                {
                    "id": 1,
                    "diff": "@@ -598,7 +598,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c\n \n     int nUBucket = pinfo->GetNewBucket(nKey, source, m_netgroupman);\n     int nUBucketPos = pinfo->GetBucketPosition(nKey, true, nUBucket);\n-    bool fInsert = vvNew[nUBucket][nUBucketPos] == -1;\n+        bool fInsert = vvNew[nUBucket][nUBucketPos] != -1;\n     if (vvNew[nUBucket][nUBucketPos] != nId) {\n         if (!fInsert) {\n             AddrInfo& infoExisting = mapInfo[vvNew[nUBucket][nUBucketPos]];\n",
                    "status": "alive"
                }
            ],
            "600": [
                {
                    "id": 1,
                    "diff": "@@ -597,7 +597,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c\n     }\n \n     int nUBucket = pinfo->GetNewBucket(nKey, source, m_netgroupman);\n-    int nUBucketPos = pinfo->GetBucketPosition(nKey, true, nUBucket);\n+        int nUBucketPos = pinfo->GetBucketPosition(nKey, false, nUBucket);\n     bool fInsert = vvNew[nUBucket][nUBucketPos] == -1;\n     if (vvNew[nUBucket][nUBucketPos] != nId) {\n         if (!fInsert) {\n",
                    "status": "alive"
                }
            ]
        }
    }

Combine diffs by the number of line touched.
@brunoerg brunoerg merged commit 62090ed into main Feb 14, 2025
4 checks passed
@brunoerg brunoerg deleted the 2025-02-improve-json branch February 14, 2025 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant