D4156: narrow: add a --narrowspec flag to clone command

pulkit (Pulkit Goyal) phabricator at mercurial-scm.org
Wed Aug 22 12:40:25 EDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rHGf4d4bd8c8911: narrow: add a --narrowspec flag to clone command (authored by pulkit, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D4156?vs=10068&id=10527

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

AFFECTED FILES
  hgext/narrow/narrowcommands.py
  tests/test-narrow-clone-no-ellipsis.t
  tests/test-narrow-clone.t

CHANGE DETAILS

diff --git a/tests/test-narrow-clone.t b/tests/test-narrow-clone.t
--- a/tests/test-narrow-clone.t
+++ b/tests/test-narrow-clone.t
@@ -218,3 +218,39 @@
   dir/tests/t9
 
   $ cd ..
+
+Testing the --narrowspec flag to clone
+
+  $ cat >> narrowspecs <<EOF
+  > %include foo
+  > [include]
+  > path:dir/tests/
+  > dir/src/f12
+  > EOF
+
+  $ hg clone ssh://user@dummy/master specfile --narrowspec narrowspecs
+  reading narrowspec from '$TESTTMP/narrowspecs'
+  abort: cannot specify other files using '%include' in narrowspec
+  [255]
+
+  $ cat > narrowspecs <<EOF
+  > [include]
+  > path:dir/tests/
+  > file:dir/src/f12
+  > EOF
+
+  $ hg clone ssh://user@dummy/master specfile --narrowspec narrowspecs
+  reading narrowspec from '$TESTTMP/narrowspecs'
+  requesting all changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 21 changesets with 20 changes to 20 files
+  new changesets f93383bb3e99:26ce255d5b5d
+  updating to branch default
+  20 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ cd specfile
+  $ hg tracked
+  I path:dir/tests
+  I path:file:dir/src/f12
+  $ cd ..
diff --git a/tests/test-narrow-clone-no-ellipsis.t b/tests/test-narrow-clone-no-ellipsis.t
--- a/tests/test-narrow-clone-no-ellipsis.t
+++ b/tests/test-narrow-clone-no-ellipsis.t
@@ -123,3 +123,39 @@
   dir/src/f9
 
   $ cd ..
+
+Testing the --narrowspec flag to clone
+
+  $ cat >> narrowspecs <<EOF
+  > %include foo
+  > [include]
+  > path:dir/tests/
+  > file:dir/src/f12
+  > EOF
+
+  $ hg clone ssh://user@dummy/master specfile --narrowspec narrowspecs
+  reading narrowspec from '$TESTTMP/narrowspecs'
+  abort: cannot specify other files using '%include' in narrowspec
+  [255]
+
+  $ cat > narrowspecs <<EOF
+  > [include]
+  > path:dir/tests/
+  > file:dir/src/f12
+  > EOF
+
+  $ hg clone ssh://user@dummy/master specfile --narrowspec narrowspecs
+  reading narrowspec from '$TESTTMP/narrowspecs'
+  requesting all changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 40 changesets with 20 changes to 20 files
+  new changesets 681085829a73:26ce255d5b5d
+  updating to branch default
+  20 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ cd specfile
+  $ hg tracked
+  I path:dir/tests
+  I path:file:dir/src/f12
+  $ cd ..
diff --git a/hgext/narrow/narrowcommands.py b/hgext/narrow/narrowcommands.py
--- a/hgext/narrow/narrowcommands.py
+++ b/hgext/narrow/narrowcommands.py
@@ -7,6 +7,7 @@
 from __future__ import absolute_import
 
 import itertools
+import os
 
 from mercurial.i18n import _
 from mercurial import (
@@ -25,6 +26,7 @@
     repair,
     repository,
     repoview,
+    sparse,
     util,
 )
 
@@ -43,6 +45,8 @@
                      _("create a narrow clone of select files")))
     entry[1].append(('', 'depth', '',
                      _("limit the history fetched by distance from heads")))
+    entry[1].append(('', 'narrowspec', '',
+                     _("read narrowspecs from file")))
     # TODO(durin42): unify sparse/narrow --include/--exclude logic a bit
     if 'sparse' not in extensions.enabled():
         entry[1].append(('', 'include', [],
@@ -73,6 +77,27 @@
     opts = pycompat.byteskwargs(opts)
     wrappedextraprepare = util.nullcontextmanager()
     opts_narrow = opts['narrow']
+    narrowspecfile = opts['narrowspec']
+
+    if narrowspecfile:
+        filepath = os.path.join(pycompat.getcwd(), narrowspecfile)
+        ui.status(_("reading narrowspec from '%s'\n") % filepath)
+        try:
+            fp = open(filepath, 'rb')
+        except IOError:
+            raise error.Abort(_("file '%s' not found") % filepath)
+
+        includes, excludes, profiles = sparse.parseconfig(ui, fp.read(),
+                                                          'narrow')
+        if profiles:
+            raise error.Abort(_("cannot specify other files using '%include' in"
+                                " narrowspec"))
+
+        # narrowspec is passed so we should assume that user wants narrow clone
+        opts_narrow = True
+        opts['include'].extend(includes)
+        opts['exclude'].extend(excludes)
+
     if opts_narrow:
         def pullbundle2extraprepare_widen(orig, pullop, kwargs):
             # Create narrow spec patterns from clone flags



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


More information about the Mercurial-devel mailing list