Patchwork [STABLE] subrepo: don't write .hgsubstate lines with empty subrepo state (issue4622)

login
register
mail settings
Submitter Matt Harbison
Date April 25, 2015, 5:48 a.m.
Message ID <37cadf30f0f901b4ae4c.1429940880@Envy>
Download mbox | patch
Permalink /patch/8787/
State Accepted
Headers show

Comments

Matt Harbison - April 25, 2015, 5:48 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1429932235 14400
#      Fri Apr 24 23:23:55 2015 -0400
# Branch stable
# Node ID 37cadf30f0f901b4ae4ca20f83c1a53c029c3245
# Parent  8015a3cf13805a307b43f22d821cad4824d094ea
subrepo: don't write .hgsubstate lines with empty subrepo state (issue4622)

The '' that is used to represent the state of a not-yet-committed subrepo cannot
be written to the file, because the code that parses the file splits on ' ' and
expects two parts.

Given that the .hgsubstate file is automatically rewritten on commit, it seems
a little strange that the file is written out during a merge.
Matt Mackall - April 27, 2015, 4:33 p.m.
On Sat, 2015-04-25 at 01:48 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1429932235 14400
> #      Fri Apr 24 23:23:55 2015 -0400
> # Branch stable
> # Node ID 37cadf30f0f901b4ae4ca20f83c1a53c029c3245
> # Parent  8015a3cf13805a307b43f22d821cad4824d094ea
> subrepo: don't write .hgsubstate lines with empty subrepo state (issue4622)

Queued for stable, thanks.

Patch

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -153,7 +153,8 @@ 
 
 def writestate(repo, state):
     """rewrite .hgsubstate in (outer) repo with these subrepo states"""
-    lines = ['%s %s\n' % (state[s][1], s) for s in sorted(state)]
+    lines = ['%s %s\n' % (state[s][1], s) for s in sorted(state)
+                                                if state[s][1] != nullstate[1]]
     repo.wwrite('.hgsubstate', ''.join(lines), '')
 
 def submerge(repo, wctx, mctx, actx, overwrite):
diff --git a/tests/test-subrepo.t b/tests/test-subrepo.t
--- a/tests/test-subrepo.t
+++ b/tests/test-subrepo.t
@@ -1026,6 +1026,45 @@ 
   no changes found
   [1]
 
+Check that merge of a new subrepo doesn't write the uncommitted state to
+.hgsubstate (issue4622)
+
+  $ hg init issue1852a/addedsub
+  $ echo zzz > issue1852a/addedsub/zz.txt
+  $ hg -R issue1852a/addedsub ci -Aqm "initial ZZ"
+
+  $ hg clone issue1852a/addedsub issue1852d/addedsub
+  updating to branch default
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+  $ echo def > issue1852a/sub/repo/foo
+  $ hg -R issue1852a ci -SAm 'tweaked subrepo'
+  adding tmp/sub/repo/foo_p
+  committing subrepository sub/repo (glob)
+
+  $ echo 'addedsub = addedsub' >> issue1852d/.hgsub
+  $ echo xyz > issue1852d/sub/repo/foo
+  $ hg -R issue1852d pull -u
+  pulling from $TESTTMP/issue1852a (glob)
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 2 changes to 2 files
+   subrepository sub/repo diverged (local revision: f42d5c7504a8, remote revision: 46cd4aac504c)
+  (M)erge, keep (l)ocal or keep (r)emote? m
+  pulling subrepo sub/repo from $TESTTMP/issue1852a/sub/repo (glob)
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+   subrepository sources for sub/repo differ (glob)
+  use (l)ocal source (f42d5c7504a8) or (r)emote source (46cd4aac504c)? l
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ cat issue1852d/.hgsubstate
+  f42d5c7504a811dda50f5cf3e5e16c3330b87172 sub/repo
+
 Check status of files when none of them belong to the first
 subrepository: