Petr Onderka has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/81664


Change subject: Fix and refactoring of previous commit
......................................................................

Fix and refactoring of previous commit

Change-Id: I620885fa4032d3711ec1b8e9fd281c704c659062
---
M DumpObjects/DumpRevision.cpp
1 file changed, 11 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/dumps/incremental 
refs/changes/64/81664/1

diff --git a/DumpObjects/DumpRevision.cpp b/DumpObjects/DumpRevision.cpp
index 1178153..1873a0a 100644
--- a/DumpObjects/DumpRevision.cpp
+++ b/DumpObjects/DumpRevision.cpp
@@ -241,13 +241,14 @@
     return result;
 }
 
+const std::uint8_t rawSha1Length = 20;
+const std::uint8_t base36Sha1Length = 31;
+
 std::string convertFromBase36(const std::string& input)
 {
-    const std::uint8_t expectedLength = 20;
+    auto result = baseConvert(input, 36, 256, rawSha1Length);
 
-    auto result = baseConvert(input, 36, 256, expectedLength);
-
-    if (result.length() != expectedLength)
+    if (result.length() != rawSha1Length)
         throw DumpException();
 
     std::reverse(result.begin(), result.end());
@@ -260,11 +261,9 @@
 {
     std::reverse(input.begin(), input.end());
 
-    const std::uint8_t expectedLength = 31;
+    auto result =  baseConvert(input, 256, 36, base36Sha1Length);
 
-    auto result =  baseConvert(input, 256, 36, expectedLength);
-
-    if (result.length() != expectedLength)
+    if (result.length() != base36Sha1Length)
         throw DumpException();
 
     return result;
@@ -291,9 +290,9 @@
     if (!HasFlag(revision.Flags, RevisionFlags::TextDeleted))
     {
         std::string rawSha1;
-        rawSha1.reserve(20);
+        rawSha1.reserve(rawSha1Length);
 
-        for (int i = 0; i < 20; i++)
+        for (int i = 0; i < rawSha1Length; i++)
             rawSha1.push_back(DumpTraits<char>::Read(stream));
 
         revision.Sha1 = convertToBase36(rawSha1);
@@ -332,7 +331,7 @@
     if (!HasFlag(revision.Flags, RevisionFlags::TextDeleted))
     {
         auto convertedSha1 = convertFromBase36(revision.Sha1);
-        for (int i = 0; i < 20; i++)
+        for (int i = 0; i < rawSha1Length; i++)
             WriteValue(stream, convertedSha1[i]);
 
         if (withText)
@@ -358,7 +357,7 @@
         result += ValueSize(modelFormatId);
     if (!HasFlag(revision.Flags, RevisionFlags::TextDeleted))
     {
-        result += ValueSize(revision.Sha1);
+        result += rawSha1Length;
 
         if (withText)
             result += ValueSize(textLength) + textLength;

-- 
To view, visit https://gerrit.wikimedia.org/r/81664
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I620885fa4032d3711ec1b8e9fd281c704c659062
Gerrit-PatchSet: 1
Gerrit-Project: operations/dumps/incremental
Gerrit-Branch: gsoc
Gerrit-Owner: Petr Onderka <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to