Changeset b0916a4160dd…
Parent d0975634cee1…
by Na'Tosha Bard <natosha@unity3d.com>
Changes to 3 files · Browse files at b0916a4160dd Showing diff from parent d0975634cee1 Diff from another changeset...
@@ -356,7 +356,7 @@ store = basestore._open_store(repo)
return store.verify(revs, contents=contents)
-def revert_bfiles(ui, repo):
+def revert_bfiles(ui, repo, file_list=None):
wlock = repo.wlock()
try:
bfdirstate = bfutil.open_bfdirstate(ui, repo)
@@ -368,21 +368,31 @@ at = 0
updated = 0
for bfile in bfiles:
- if not os.path.exists(repo.wjoin(bfutil.standin(bfile))):
- bfdirstate.remove(bfile)
- continue
- if os.path.exists(repo.wjoin(bfutil.standin(os.path.join(bfile + '.orig')))):
- shutil.copyfile(repo.wjoin(bfile), repo.wjoin(bfile + '.orig'))
- at += 1
- expectedhash = repo[None][bfutil.standin(bfile)].data().strip()
- mode = os.stat(repo.wjoin(bfutil.standin(bfile))).st_mode
- if not os.path.exists(repo.wjoin(bfile)) or expectedhash != bfutil.hashfile(repo.wjoin(bfile)):
- path = bfutil.find_file(repo, expectedhash)
- if path is None:
- toget.append((bfile, expectedhash))
- else:
- util.makedirs(os.path.dirname(repo.wjoin(bfile)))
- shutil.copy(path, repo.wjoin(bfile))
+ if file_list == None or bfile in file_list:
+ if not os.path.exists(repo.wjoin(bfutil.standin(bfile))):
+ bfdirstate.remove(bfile)
+ continue
+ if os.path.exists(repo.wjoin(bfutil.standin(os.path.join(bfile + '.orig')))):
+ shutil.copyfile(repo.wjoin(bfile), repo.wjoin(bfile + '.orig'))
+ at += 1
+ expectedhash = repo[None][bfutil.standin(bfile)].data().strip()
+ mode = os.stat(repo.wjoin(bfutil.standin(bfile))).st_mode
+ if not os.path.exists(repo.wjoin(bfile)) or expectedhash != bfutil.hashfile(repo.wjoin(bfile)):
+ path = bfutil.find_file(repo, expectedhash)
+ if path is None:
+ toget.append((bfile, expectedhash))
+ else:
+ util.makedirs(os.path.dirname(repo.wjoin(bfile)))
+ shutil.copy(path, repo.wjoin(bfile))
+ os.chmod(repo.wjoin(bfile), mode)
+ updated += 1
+ if bfutil.standin(bfile) not in repo['.']:
+ bfdirstate.add(bfutil.unixpath(bfile))
+ elif expectedhash == repo['.'][bfutil.standin(bfile)].data().strip():
+ bfdirstate.normal(bfutil.unixpath(bfile))
+ else:
+ bfutil.dirstate_normaldirty(bfdirstate, bfutil.unixpath(bfile))
+ elif os.path.exists(repo.wjoin(bfile)) and mode != os.stat(repo.wjoin(bfile)).st_mode:
os.chmod(repo.wjoin(bfile), mode)
updated += 1
if bfutil.standin(bfile) not in repo['.']:
@@ -391,15 +401,6 @@ bfdirstate.normal(bfutil.unixpath(bfile))
else:
bfutil.dirstate_normaldirty(bfdirstate, bfutil.unixpath(bfile))
- elif os.path.exists(repo.wjoin(bfile)) and mode != os.stat(repo.wjoin(bfile)).st_mode:
- os.chmod(repo.wjoin(bfile), mode)
- updated += 1
- if bfutil.standin(bfile) not in repo['.']:
- bfdirstate.add(bfutil.unixpath(bfile))
- elif expectedhash == repo['.'][bfutil.standin(bfile)].data().strip():
- bfdirstate.normal(bfutil.unixpath(bfile))
- else:
- bfutil.dirstate_normaldirty(bfdirstate, bfutil.unixpath(bfile))
if toget:
store = basestore._open_store(repo)
@@ -420,24 +421,25 @@
removed = 0
for bfile in bfdirstate:
- if not os.path.exists(repo.wjoin(bfutil.standin(bfile))):
- if os.path.exists(repo.wjoin(bfile)):
- os.unlink(repo.wjoin(bfile))
- removed += 1
- if bfutil.standin(bfile) in repo['.']:
- bfdirstate.remove(bfutil.unixpath(bfile))
- else:
- bfdirstate.forget(bfutil.unixpath(bfile))
- else:
- state = repo.dirstate[bfutil.standin(bfile)]
- if state == 'n':
- bfdirstate.normal(bfile)
- elif state == 'r':
- bfdirstate.remove(bfile)
- elif state == 'a':
- bfdirstate.add(bfile)
- elif state == '?':
- bfdirstate.forget(bfile)
+ if file_list == None or bfile in file_list:
+ if not os.path.exists(repo.wjoin(bfutil.standin(bfile))):
+ if os.path.exists(repo.wjoin(bfile)):
+ os.unlink(repo.wjoin(bfile))
+ removed += 1
+ if bfutil.standin(bfile) in repo['.']:
+ bfdirstate.remove(bfutil.unixpath(bfile))
+ else:
+ bfdirstate.forget(bfutil.unixpath(bfile))
+ else:
+ state = repo.dirstate[bfutil.standin(bfile)]
+ if state == 'n':
+ bfdirstate.normal(bfile)
+ elif state == 'r':
+ bfdirstate.remove(bfile)
+ elif state == 'a':
+ bfdirstate.add(bfile)
+ elif state == '?':
+ bfdirstate.forget(bfile)
bfdirstate.write()
finally:
wlock.release()
|
@@ -211,3 +211,34 @@ ? b2.txt.orig
? n2.txt.orig
''')
+# Test that modifying a normal file and a bfile, then reverting the normal file,
+# does not alter the bfile
+os.chdir('..')
+os.mkdir('repo2')
+os.chdir('repo2')
+hgt.hg(['init', '-q'])
+hgt.writefile('n1', 'n1')
+hgt.hg(['add', 'n1'])
+hgt.hg(['commit', '-m', 'added normal file'])
+hgt.writefile('b1', 'b1')
+hgt.hg(['add', '--bf', 'b1'])
+hgt.hg(['commit', '-m', 'added bfile'])
+hgt.writefile('n1', 'n11')
+hgt.writefile('b1', 'b11')
+hgt.hg(['revert', 'n1'])
+hgt.asserttrue(hgt.readfile('b1') == 'b11', 'file chnaged')
+# Test that modifying 2 bfiles and reverting one of the bfiles, does not alter the
+# second bfile
+os.chdir('..')
+os.mkdir('repo3')
+hgt.hg(['init', '-q'])
+hgt.writefile('b1', 'b1')
+hgt.hg(['add', '--bf', 'b1'])
+hgt.hg(['commit', '-m', 'added first bfile'])
+hgt.writefile('b2', 'b2')
+hgt.hg(['add', '--bf', 'b2'])
+hgt.hg(['commit', '-m', 'added second bfile'])
+hgt.writefile('b1', 'b11')
+hgt.writefile('b2', 'b22')
+hgt.hg(['revert', 'b1'])
+hgt.asserttrue(hgt.readfile('b2') == 'b22', 'file chnaged')
|
Loading...