Angel Ezquerra committed 705cc5b

Check changes to the projrc file when executing the "incoming" command

Comments (0)

Files changed (1)

             serverlist[n] = server.lower()
     return set(serverlist)
-def transferprojrc(ui, repo, other):
+def getremoteprojrc(ui, repo, other):
+    """
+    Get the contents of a remote projrc and check that they are valid
+    This function returns a 2-element tuple:
+    - The projrc contents as a string (or None if no projrc was found)
+    - A boolean indicating whether the data is valid.
+    Note that it is possible to return (None, True), which simply means
+    that no data matching the projrc filter settings was found.
+    """
     if not repo.local():
-        return
+        return None, True
     # Get the list of repos that we are supposed to get a projrc file from
     # (i.e. the projrc "servers")
         # The pull source is not on the projrc server list
         # Note that we keep any existing local projrc file, which may have been
         # transferred from another valid server
-        return
+        return None, True
     # Get the list of remote keys that we must load from the remote projrc file
     includedkeys, excludedkeys = getallowedkeys(ui)
         # There are no remote keys to load
         projrc = {} # This ensures that any existing projrc file will be deleted
+    data = None
+    valid = True
     if 'data' in projrc:
         data = projrc['data'].decode('string-escape')
         if data.startswith("#\\\\ "):
             # the user has specified in any of its hgrc files
             data = ENCODING_CHECK + \
                 serializeconfig(c, includedkeys, excludedkeys)
+        except error.ParseError, e:
+                ui.warn(_("not saving retrieved projrc file: "
+                          "parse error at '%s' on %s\n") % e.args)
+                valid = False
+    return data, valid
-            # Compare the old projrc with the new one
+def transferprojrc(ui, repo, other):
+    data, valid = getremoteprojrc(ui, repo, other)
+    if not valid or data is None:
+        return
+    if data != "":
+        # Compare the old projrc with the new one
+        try:
             olddata = readcurrentprojrc(repo)
             if olddata != data:
                 def mustconfirm(projrcexists):
                     """Read the projrc.confirm setting.
         origupdate(dst, uprev[0])
     return src, dst
+def incoming(orig, ui, repo, srcpath, *args, **kwargs):
+    # hg.clone calls hg._update as the very last thing. We need to
+    # transfer the .hg/projrc file before this happens in order for it
+    # to take effect for things like subrepos. We do this by wrapping
+    # hg._update in our own function that just stores the target
+    # revision for later.
+    res = orig(ui, repo, srcpath, *args, **kwargs)
+    olddata = readcurrentprojrc(repo)
+    if olddata:
+        ui.note(_('searching for changes to the projrc file\n'))
+    else:
+        ui.note(_('looking for remote projrc file\n'))
+    expandedpath = ui.expandpath(srcpath)
+    other = hg.repository(ui, expandedpath)
+    data, valid = getremoteprojrc(ui, repo, other)
+    if valid:
+        # If not valid we will already have shown a warning message
+        if olddata:
+            if olddata != data:
+                ui.status(_('remote and local projrc files are different\n'))
+            else:
+                ui.note(_('no changes found to projrc file\n'))
+        elif data:
+            ui.status(_('new remote projrc file found\n'))
+    return res
 def pushprojrc(repo, key, old, new):
     return False
     extensions.wrapfunction(hg, 'clone', clone)
+    extensions.wrapfunction(hg, 'incoming', incoming)
     pushkey.register('projrc', pushprojrc, listprojrc)
 def reposetup(ui, repo):