[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    kdesdk/cervisia
From:       Christian Loose <christian.loose () hamburg ! de>
Date:       2004-12-07 22:24:34
Message-ID: 20041207222434.6A5661BAE5 () office ! kde ! org
[Download RAW message or body]

CVS commit by cloose: 

first part of fix for BR #90346:

Added a new method to normalize the CVSROOT specification for a
pserver repository. New form:

    :pserver:[user]@[host]:[port][path]

This is needed because CVS does this too while adding a new entry
to the .cvspass file. We later read this file to add not-yet-configured repositories \
to the list in the "Configure Access to Repositories" dialog. 

This can lead to duplicate entries in the list, like e.g. \
":pserver:cvs.kde.org/home/kde" and ":pserver:user@cvs.kde.org:2401/home/kde".

CCBUG: 90346


  M +52 -0     misc.cpp   1.25
  M +7 -0      misc.h   1.16


--- kdesdk/cervisia/misc.cpp  #1.24:1.25
@@ -21,4 +21,5 @@
 #include <unistd.h>
 #include <qfile.h>
+#include <qregexp.h>
 #include <qstringlist.h>
 #include <kconfig.h>
@@ -27,4 +28,6 @@
 #include <kprocess.h>
 #include <ktempfile.h>
+#include <kuser.h>
+#include <kdebug.h>
 
 #include "config.h"
@@ -32,4 +35,12 @@
 #include "progressdlg.h"
 
+// These regular expression parts aren't useful to check the validity of the
+// CVSROOT specification. They are just used to extract the different parts of it.
+static const QString userNameRegExp("([a-z0-9_][a-z0-9_-]*)?");
+static const QString passwordRegExp("(:[^@]+)?");
+static const QString hostNameRegExp("([^:/]+)");
+static const QString portRegExp("(:(\\d*))?");
+static const QString pathRegExp("(/.*)");
+
 
 static int FindWhiteSpace(const QString& str, int index)
@@ -147,4 +158,45 @@ QString Cervisia::UserName()
 
 
+QString Cervisia::NormalizeRepository(const QString& repository)
+{
+    // only :pserver: repositories
+    if( !repository.startsWith(":pserver:") )
+        return repository;
+
+    QRegExp rx(":pserver:(" + userNameRegExp + passwordRegExp + "@)?" +
+               hostNameRegExp + portRegExp + pathRegExp);
+
+    // extract username, hostname, port and path from CVSROOT
+    QString userName, hostName, port, path;
+    if( rx.search(repository) != -1 )
+    {
+        userName = rx.cap(2);
+        hostName = rx.cap(4);
+        port     = rx.cap(6);
+        path     = rx.cap(7);
+
+        kdDebug() << "NormalizeRepository(): username=" << userName << endl;
+        kdDebug() << "NormalizeRepository(): hostname=" << hostName << endl;
+        kdDebug() << "NormalizeRepository(): port    =" << port << endl;
+        kdDebug() << "NormalizeRepository(): path    =" << path << endl;
+
+        if( port.isEmpty() )
+            port = "2401";
+
+        if( userName.isEmpty() )
+            userName = KUser().loginName();
+
+        QString canonicalForm = ":pserver:" + userName + "@" + hostName +
+                                ":" + port + path;
+
+        kdDebug() << "NormalizeRepository(): canonicalForm=" << canonicalForm
+                  << endl;
+        return canonicalForm;
+    }
+    else
+        return repository;
+}
+
+
 QString joinLine(const QStringList &list)
 {

--- kdesdk/cervisia/misc.h  #1.15:1.16
@@ -38,4 +38,11 @@ bool IsValidTag(const QString& tag);
 QString UserName();
 
+/**
+ * This method makes sure that the cvsroot specification for a pserver repository \
has + * always the form:
+ *  :pserver:[user]@[host]:[port][path]
+ */
+QString NormalizeRepository(const QString& repository);
+
 }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic