Kiln » Unity3D Unity 3D's proposed fixes and extensions to Kiln BFiles
Clone URL:  

tip Fix revert so that it works correctly for cases other than 'revert --all'. Previously all bfiles were reverted regardless of what patterns were supplied.

Changeset b0916a4160dd

Parent d0975634cee1

by Profile picture of User 496Na'Tosha Bard <natosha@unity3d.com>

Changes to 3 files · Browse files at b0916a4160dd Showing diff from parent d0975634cee1 Diff from another changeset...

 
356
357
358
359
 
360
361
362
 
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
386
387
388
 
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
 
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
441
442
443
 
356
357
358
 
359
360
361
362
 
368
369
370
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
 
401
402
403
 
 
 
 
 
 
 
 
 
404
405
406
 
421
422
423
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
@@ -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()
 
700
701
702
 
 
 
 
703
704
705
 
730
731
732
733
 
 
 
 
 
 
 
 
 
 
 
734
735
736
 
738
739
740
741
 
 
 
 
742
743
744
 
 
 
745
746
747
 
700
701
702
703
704
705
706
707
708
709
 
734
735
736
 
737
738
739
740
741
742
743
744
745
746
747
748
749
750
 
752
753
754
 
755
756
757
758
759
 
 
760
761
762
763
764
765
@@ -700,6 +700,10 @@
    return result   +# When the user calls revert, we have to be careful to not revert any changes to other +# bfiles accidentally. This means we have to keep track of the bfiles that are +# being reverted so we only pull down the necessary bfiles. +#  # Standins are only updated (to match the hash of bfiles) before commits.  # Update the standins then run the original revert (changing the matcher to hit standins  # instead of bfiles). Based on the resulting standins update the bfiles. Then return the @@ -730,7 +734,17 @@
  orig_matchfn = m.matchfn   def matchfn(f):   if bfutil.is_standin(f): - return orig_matchfn(bfutil.split_standin(f)) and (f in repo[None] or f in ctx) + # We need to keep track of what bfiles are being matched so we know which + # ones to update later (otherwise we revert changes to other bfiles + # accidentally). This is repo specific, so duckpunch the repo object to + # keep the list of bfiles for us later. + if(orig_matchfn(bfutil.split_standin(f)) and (f in repo[None] or f in ctx)): + bfiles_list = getattr(repo, "_bfiles_to_update", []) + bfiles_list.append(bfutil.split_standin(f)) + repo._bfiles_to_update = bfiles_list; + return True + else: + return False   return orig_matchfn(f)   m.matchfn = matchfn   return m @@ -738,10 +752,14 @@
  orig(ui, repo, *pats, **opts)   finally:   cmdutil.match = oldmatch - bfcommands.revert_bfiles(ui, repo) + bfiles_list = getattr(repo, "_bfiles_to_update", []) + bfcommands.revert_bfiles(ui, repo, bfiles_list) + # Empty out the bfiles list so we start fresh next time + repo._bfiles_to_update = []   for bfile in modified: - if os.path.exists(repo.wjoin(bfutil.standin(bfile))) and bfile in repo['.']: - bfutil.write_standin(repo, bfutil.standin(bfile), repo['.'][bfile].data().strip(), 'x' in repo['.'][bfile].flags()) + if bfile in bfiles_list: + if os.path.exists(repo.wjoin(bfutil.standin(bfile))) and bfile in repo['.']: + bfutil.write_standin(repo, bfutil.standin(bfile), repo['.'][bfile].data().strip(), 'x' in repo['.'][bfile].flags())   finally:   wlock.release()  
 
211
212
213
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
@@ -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')