Patchwork D1755: logexchange: introduce helper function to get remote path name

login
register
mail settings
Submitter phabricator
Date Dec. 25, 2017, 9:57 a.m.
Message ID <differential-rev-PHID-DREV-62bfw7l6kqi2m54hy64f-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/26429/
State Superseded
Headers show

Comments

phabricator - Dec. 25, 2017, 9:57 a.m.
pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This patch moves chunk of activepath function from hgremotenames extension
  (linktoremotenameextension) to core. Before moving rest of the part, there needs
  to be some refactoring done to schemes which will be done in as a separate
  series.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/logexchange.py
  tests/test-logexchange.t

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: mercurial-devel
phabricator - Jan. 10, 2018, 11:18 p.m.
durin42 requested changes to this revision.
durin42 added inline comments.
This revision now requires changes to proceed.

INLINE COMMENTS

> logexchange.py:109
> +    if local:
> +        rpath = getattr(remote, 'root', None)
> +        if rpath is None:

This should be cleaned up to not have all the getattr contortions that support old hg versions.

REPOSITORY
  rHG Mercurial

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

To: pulkit, #hg-reviewers, durin42
Cc: durin42, mercurial-devel
phabricator - Jan. 18, 2018, 8:02 p.m.
durin42 added inline comments.

INLINE COMMENTS

> logexchange.py:102
> +        local = remote.local()
> +    except AttributeError:
> +        pass

what's the deal with this attributeerror business? merits a comment at least

> logexchange.py:113
> +            rpath = remote._url
> +        except AttributeError:
> +            rpath = remote.url

is the attribute name here really still inconsistent in hg?

REPOSITORY
  rHG Mercurial

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

To: pulkit, #hg-reviewers, durin42
Cc: durin42, mercurial-devel
phabricator - Feb. 12, 2018, 9:57 a.m.
pulkit added a comment.


  I will like to get this series review and iterated upon early in cycle so that we can ship remotenames in the next release.

REPOSITORY
  rHG Mercurial

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

To: pulkit, #hg-reviewers, durin42
Cc: durin42, mercurial-devel

Patch

diff --git a/tests/test-logexchange.t b/tests/test-logexchange.t
--- a/tests/test-logexchange.t
+++ b/tests/test-logexchange.t
@@ -57,14 +57,14 @@ 
   $ cat .hg/logexchange/bookmarks
   0
   
-  87d6d66763085b629e6d7ed56778c79827273022\x00file:$TESTTMP/server\x00bar (esc)
-  62615734edd52f06b6fb9c2beb429e4fe30d57b8\x00file:$TESTTMP/server\x00foo (esc)
+  87d6d66763085b629e6d7ed56778c79827273022\x00$TESTTMP/server\x00bar (esc)
+  62615734edd52f06b6fb9c2beb429e4fe30d57b8\x00$TESTTMP/server\x00foo (esc)
 
   $ cat .hg/logexchange/branches
   0
   
-  ec2426147f0e39dbc9cef599b066be6035ce691d\x00file:$TESTTMP/server\x00default (esc)
-  3e1487808078543b0af6d10dadf5d46943578db0\x00file:$TESTTMP/server\x00wat (esc)
+  ec2426147f0e39dbc9cef599b066be6035ce691d\x00$TESTTMP/server\x00default (esc)
+  3e1487808078543b0af6d10dadf5d46943578db0\x00$TESTTMP/server\x00wat (esc)
 
 Making a new server
 -------------------
@@ -94,15 +94,15 @@ 
   $ cat .hg/logexchange/bookmarks
   0
   
-  62615734edd52f06b6fb9c2beb429e4fe30d57b8\x00file:$TESTTMP/server\x00foo (esc)
-  87d6d66763085b629e6d7ed56778c79827273022\x00file:$TESTTMP/server\x00bar (esc)
-  87d6d66763085b629e6d7ed56778c79827273022\x00file:$TESTTMP/server2\x00bar (esc)
-  62615734edd52f06b6fb9c2beb429e4fe30d57b8\x00file:$TESTTMP/server2\x00foo (esc)
+  62615734edd52f06b6fb9c2beb429e4fe30d57b8\x00$TESTTMP/server\x00foo (esc)
+  87d6d66763085b629e6d7ed56778c79827273022\x00$TESTTMP/server\x00bar (esc)
+  87d6d66763085b629e6d7ed56778c79827273022\x00$TESTTMP/server2\x00bar (esc)
+  62615734edd52f06b6fb9c2beb429e4fe30d57b8\x00$TESTTMP/server2\x00foo (esc)
 
   $ cat .hg/logexchange/branches
   0
   
-  3e1487808078543b0af6d10dadf5d46943578db0\x00file:$TESTTMP/server\x00wat (esc)
-  ec2426147f0e39dbc9cef599b066be6035ce691d\x00file:$TESTTMP/server\x00default (esc)
-  ec2426147f0e39dbc9cef599b066be6035ce691d\x00file:$TESTTMP/server2\x00default (esc)
-  3e1487808078543b0af6d10dadf5d46943578db0\x00file:$TESTTMP/server2\x00wat (esc)
+  3e1487808078543b0af6d10dadf5d46943578db0\x00$TESTTMP/server\x00wat (esc)
+  ec2426147f0e39dbc9cef599b066be6035ce691d\x00$TESTTMP/server\x00default (esc)
+  ec2426147f0e39dbc9cef599b066be6035ce691d\x00$TESTTMP/server2\x00default (esc)
+  3e1487808078543b0af6d10dadf5d46943578db0\x00$TESTTMP/server2\x00wat (esc)
diff --git a/mercurial/logexchange.py b/mercurial/logexchange.py
--- a/mercurial/logexchange.py
+++ b/mercurial/logexchange.py
@@ -94,14 +94,39 @@ 
     finally:
         wlock.release()
 
+def activepath(remote):
+    """returns remote path"""
+    local = None
+    try:
+        local = remote.local()
+    except AttributeError:
+        pass
+
+    # determine the remote path from the repo, if possible; else just
+    # use the string given to us
+    rpath = remote
+    if local:
+        rpath = getattr(remote, 'root', None)
+        if rpath is None:
+            # Maybe a localpeer? (hg@1ac628cd7113, 2.3)
+            rpath = getattr(getattr(remote, '_repo', None),
+                            'root', None)
+    elif not isinstance(remote, str):
+        try:
+            rpath = remote._url
+        except AttributeError:
+            rpath = remote.url
+
+    return rpath
+
 def pullremotenames(localrepo, remoterepo):
     """
     pulls bookmarks and branches information of the remote repo during a
     pull or clone operation.
     localrepo is our local repository
     remoterepo is the peer instance
     """
-    remotepath = remoterepo.url()
+    remotepath = activepath(remoterepo)
     bookmarks = remoterepo.listkeys('bookmarks')
     # on a push, we don't want to keep obsolete heads since
     # they won't show up as heads on the next pull, so we