1878
2073
if not all_versioned:
1879
2074
raise errors.PathsNotVersionedError(specific_files)
1880
2075
# -- remove redundancy in supplied specific_files to prevent over-scanning --
1881
search_specific_files = set()
1882
for path in specific_files:
1883
other_specific_files = specific_files.difference(set([path]))
1884
if not osutils.is_inside_any(other_specific_files, path):
1885
# this is a top level path, we must check it.
1886
search_specific_files.add(path)
1888
# compare source_index and target_index at or under each element of search_specific_files.
1889
# follow the following comparison table. Note that we only want to do diff operations when
1890
# the target is fdl because thats when the walkdirs logic will have exposed the pathinfo
1894
# Source | Target | disk | action
1895
# r | fdlt | | add source to search, add id path move and perform
1896
# | | | diff check on source-target
1897
# r | fdlt | a | dangling file that was present in the basis.
1899
# r | a | | add source to search
1901
# r | r | | this path is present in a non-examined tree, skip.
1902
# r | r | a | this path is present in a non-examined tree, skip.
1903
# a | fdlt | | add new id
1904
# a | fdlt | a | dangling locally added file, skip
1905
# a | a | | not present in either tree, skip
1906
# a | a | a | not present in any tree, skip
1907
# a | r | | not present in either tree at this path, skip as it
1908
# | | | may not be selected by the users list of paths.
1909
# a | r | a | not present in either tree at this path, skip as it
1910
# | | | may not be selected by the users list of paths.
1911
# fdlt | fdlt | | content in both: diff them
1912
# fdlt | fdlt | a | deleted locally, but not unversioned - show as deleted ?
1913
# fdlt | a | | unversioned: output deleted id for now
1914
# fdlt | a | a | unversioned and deleted: output deleted id
1915
# fdlt | r | | relocated in this tree, so add target to search.
1916
# | | | Dont diff, we will see an r,fd; pair when we reach
1917
# | | | this id at the other path.
1918
# fdlt | r | a | relocated in this tree, so add target to search.
1919
# | | | Dont diff, we will see an r,fd; pair when we reach
1920
# | | | this id at the other path.
1922
# for all search_indexs in each path at or under each element of
1923
# search_specific_files, if the detail is relocated: add the id, and add the
1924
# relocated path as one to search if its not searched already. If the
1925
# detail is not relocated, add the id.
1926
searched_specific_files = set()
1927
NULL_PARENT_DETAILS = dirstate.DirState.NULL_PARENT_DETAILS
1928
# Using a list so that we can access the values and change them in
1929
# nested scope. Each one is [path, file_id, entry]
1930
last_source_parent = [None, None]
1931
last_target_parent = [None, None]
2076
search_specific_files = osutils.minimum_path_selection(specific_files)
1933
2078
use_filesystem_for_exec = (sys.platform != 'win32')
1935
# Just a sentry, so that _process_entry can say that this
1936
# record is handled, but isn't interesting to process (unchanged)
1937
uninteresting = object()
1940
old_dirname_to_file_id = {}
1941
new_dirname_to_file_id = {}
1942
# TODO: jam 20070516 - Avoid the _get_entry lookup overhead by
1943
# keeping a cache of directories that we have seen.
1945
def _process_entry(entry, path_info):
1946
"""Compare an entry and real disk to generate delta information.
1948
:param path_info: top_relpath, basename, kind, lstat, abspath for
1949
the path of entry. If None, then the path is considered absent.
1950
(Perhaps we should pass in a concrete entry for this ?)
1951
Basename is returned as a utf8 string because we expect this
1952
tuple will be ignored, and don't want to take the time to
1954
:return: None if these don't match
1955
A tuple of information about the change, or
1956
the object 'uninteresting' if these match, but are
1957
basically identical.
1959
if source_index is None:
1960
source_details = NULL_PARENT_DETAILS
1962
source_details = entry[1][source_index]
1963
target_details = entry[1][target_index]
1964
target_minikind = target_details[0]
1965
if path_info is not None and target_minikind in 'fdlt':
1966
if not (target_index == 0):
1967
raise AssertionError()
1968
link_or_sha1 = state.update_entry(entry, abspath=path_info[4],
1969
stat_value=path_info[3])
1970
# The entry may have been modified by update_entry
1971
target_details = entry[1][target_index]
1972
target_minikind = target_details[0]
1975
file_id = entry[0][2]
1976
source_minikind = source_details[0]
1977
if source_minikind in 'fdltr' and target_minikind in 'fdlt':
1978
# claimed content in both: diff
1979
# r | fdlt | | add source to search, add id path move and perform
1980
# | | | diff check on source-target
1981
# r | fdlt | a | dangling file that was present in the basis.
1983
if source_minikind in 'r':
1984
# add the source to the search path to find any children it
1985
# has. TODO ? : only add if it is a container ?
1986
if not osutils.is_inside_any(searched_specific_files,
1988
search_specific_files.add(source_details[1])
1989
# generate the old path; this is needed for stating later
1991
old_path = source_details[1]
1992
old_dirname, old_basename = os.path.split(old_path)
1993
path = pathjoin(entry[0][0], entry[0][1])
1994
old_entry = state._get_entry(source_index,
1996
# update the source details variable to be the real
1998
if old_entry == (None, None):
1999
raise errors.CorruptDirstate(state._filename,
2000
"entry '%s/%s' is considered renamed from %r"
2001
" but source does not exist\n"
2002
"entry: %s" % (entry[0][0], entry[0][1], old_path, entry))
2003
source_details = old_entry[1][source_index]
2004
source_minikind = source_details[0]
2006
old_dirname = entry[0][0]
2007
old_basename = entry[0][1]
2008
old_path = path = None
2009
if path_info is None:
2010
# the file is missing on disk, show as removed.
2011
content_change = True
2015
# source and target are both versioned and disk file is present.
2016
target_kind = path_info[2]
2017
if target_kind == 'directory':
2019
old_path = path = pathjoin(old_dirname, old_basename)
2020
new_dirname_to_file_id[path] = file_id
2021
if source_minikind != 'd':
2022
content_change = True
2024
# directories have no fingerprint
2025
content_change = False
2027
elif target_kind == 'file':
2028
if source_minikind != 'f':
2029
content_change = True
2031
# We could check the size, but we already have the
2033
content_change = (link_or_sha1 != source_details[1])
2034
# Target details is updated at update_entry time
2035
if use_filesystem_for_exec:
2036
# We don't need S_ISREG here, because we are sure
2037
# we are dealing with a file.
2038
target_exec = bool(stat.S_IEXEC & path_info[3].st_mode)
2040
target_exec = target_details[3]
2041
elif target_kind == 'symlink':
2042
if source_minikind != 'l':
2043
content_change = True
2045
content_change = (link_or_sha1 != source_details[1])
2047
elif target_kind == 'tree-reference':
2048
if source_minikind != 't':
2049
content_change = True
2051
content_change = False
2054
raise Exception, "unknown kind %s" % path_info[2]
2055
if source_minikind == 'd':
2057
old_path = path = pathjoin(old_dirname, old_basename)
2058
old_dirname_to_file_id[old_path] = file_id
2059
# parent id is the entry for the path in the target tree
2060
if old_dirname == last_source_parent[0]:
2061
source_parent_id = last_source_parent[1]
2064
source_parent_id = old_dirname_to_file_id[old_dirname]
2066
source_parent_entry = state._get_entry(source_index,
2067
path_utf8=old_dirname)
2068
source_parent_id = source_parent_entry[0][2]
2069
if source_parent_id == entry[0][2]:
2070
# This is the root, so the parent is None
2071
source_parent_id = None
2073
last_source_parent[0] = old_dirname
2074
last_source_parent[1] = source_parent_id
2075
new_dirname = entry[0][0]
2076
if new_dirname == last_target_parent[0]:
2077
target_parent_id = last_target_parent[1]
2080
target_parent_id = new_dirname_to_file_id[new_dirname]
2082
# TODO: We don't always need to do the lookup, because the
2083
# parent entry will be the same as the source entry.
2084
target_parent_entry = state._get_entry(target_index,
2085
path_utf8=new_dirname)
2086
if target_parent_entry == (None, None):
2087
raise AssertionError(
2088
"Could not find target parent in wt: %s\nparent of: %s"
2089
% (new_dirname, entry))
2090
target_parent_id = target_parent_entry[0][2]
2091
if target_parent_id == entry[0][2]:
2092
# This is the root, so the parent is None
2093
target_parent_id = None
2095
last_target_parent[0] = new_dirname
2096
last_target_parent[1] = target_parent_id
2098
source_exec = source_details[3]
2099
if (include_unchanged
2101
or source_parent_id != target_parent_id
2102
or old_basename != entry[0][1]
2103
or source_exec != target_exec
2105
if old_path is None:
2106
old_path = path = pathjoin(old_dirname, old_basename)
2107
old_path_u = utf8_decode(old_path)[0]
2110
old_path_u = utf8_decode(old_path)[0]
2111
if old_path == path:
2114
path_u = utf8_decode(path)[0]
2115
source_kind = _minikind_to_kind[source_minikind]
2116
return (entry[0][2],
2117
(old_path_u, path_u),
2120
(source_parent_id, target_parent_id),
2121
(utf8_decode(old_basename)[0], utf8_decode(entry[0][1])[0]),
2122
(source_kind, target_kind),
2123
(source_exec, target_exec))
2125
return uninteresting
2126
elif source_minikind in 'a' and target_minikind in 'fdlt':
2127
# looks like a new file
2128
if path_info is not None:
2129
path = pathjoin(entry[0][0], entry[0][1])
2130
# parent id is the entry for the path in the target tree
2131
# TODO: these are the same for an entire directory: cache em.
2132
parent_id = state._get_entry(target_index,
2133
path_utf8=entry[0][0])[0][2]
2134
if parent_id == entry[0][2]:
2136
if use_filesystem_for_exec:
2137
# We need S_ISREG here, because we aren't sure if this
2140
stat.S_ISREG(path_info[3].st_mode)
2141
and stat.S_IEXEC & path_info[3].st_mode)
2143
target_exec = target_details[3]
2144
return (entry[0][2],
2145
(None, utf8_decode(path)[0]),
2149
(None, utf8_decode(entry[0][1])[0]),
2150
(None, path_info[2]),
2151
(None, target_exec))
2153
# but its not on disk: we deliberately treat this as just
2154
# never-present. (Why ?! - RBC 20070224)
2156
elif source_minikind in 'fdlt' and target_minikind in 'a':
2157
# unversioned, possibly, or possibly not deleted: we dont care.
2158
# if its still on disk, *and* theres no other entry at this
2159
# path [we dont know this in this routine at the moment -
2160
# perhaps we should change this - then it would be an unknown.
2161
old_path = pathjoin(entry[0][0], entry[0][1])
2162
# parent id is the entry for the path in the target tree
2163
parent_id = state._get_entry(source_index, path_utf8=entry[0][0])[0][2]
2164
if parent_id == entry[0][2]:
2166
return (entry[0][2],
2167
(utf8_decode(old_path)[0], None),
2171
(utf8_decode(entry[0][1])[0], None),
2172
(_minikind_to_kind[source_minikind], None),
2173
(source_details[3], None))
2174
elif source_minikind in 'fdlt' and target_minikind in 'r':
2175
# a rename; could be a true rename, or a rename inherited from
2176
# a renamed parent. TODO: handle this efficiently. Its not
2177
# common case to rename dirs though, so a correct but slow
2178
# implementation will do.
2179
if not osutils.is_inside_any(searched_specific_files, target_details[1]):
2180
search_specific_files.add(target_details[1])
2181
elif source_minikind in 'ra' and target_minikind in 'ra':
2182
# neither of the selected trees contain this file,
2183
# so skip over it. This is not currently directly tested, but
2184
# is indirectly via test_too_much.TestCommands.test_conflicts.
2187
raise AssertionError("don't know how to compare "
2188
"source_minikind=%r, target_minikind=%r"
2189
% (source_minikind, target_minikind))
2190
## import pdb;pdb.set_trace()
2193
while search_specific_files:
2194
# TODO: the pending list should be lexically sorted? the
2195
# interface doesn't require it.
2196
current_root = search_specific_files.pop()
2197
current_root_unicode = current_root.decode('utf8')
2198
searched_specific_files.add(current_root)
2199
# process the entries for this containing directory: the rest will be
2200
# found by their parents recursively.
2201
root_entries = _entries_for_path(current_root)
2202
root_abspath = self.target.abspath(current_root_unicode)
2204
root_stat = os.lstat(root_abspath)
2206
if e.errno == errno.ENOENT:
2207
# the path does not exist: let _process_entry know that.
2208
root_dir_info = None
2210
# some other random error: hand it up.
2213
root_dir_info = ('', current_root,
2214
osutils.file_kind_from_stat_mode(root_stat.st_mode), root_stat,
2216
if root_dir_info[2] == 'directory':
2217
if self.target._directory_is_tree_reference(
2218
current_root.decode('utf8')):
2219
root_dir_info = root_dir_info[:2] + \
2220
('tree-reference',) + root_dir_info[3:]
2222
if not root_entries and not root_dir_info:
2223
# this specified path is not present at all, skip it.
2225
path_handled = False
2226
for entry in root_entries:
2227
result = _process_entry(entry, root_dir_info)
2228
if result is not None:
2230
if result is not uninteresting:
2232
if want_unversioned and not path_handled and root_dir_info:
2233
new_executable = bool(
2234
stat.S_ISREG(root_dir_info[3].st_mode)
2235
and stat.S_IEXEC & root_dir_info[3].st_mode)
2237
(None, current_root_unicode),
2241
(None, splitpath(current_root_unicode)[-1]),
2242
(None, root_dir_info[2]),
2243
(None, new_executable)
2245
initial_key = (current_root, '', '')
2246
block_index, _ = state._find_block_index_from_key(initial_key)
2247
if block_index == 0:
2248
# we have processed the total root already, but because the
2249
# initial key matched it we should skip it here.
2251
if root_dir_info and root_dir_info[2] == 'tree-reference':
2252
current_dir_info = None
2254
dir_iterator = osutils._walkdirs_utf8(root_abspath, prefix=current_root)
2256
current_dir_info = dir_iterator.next()
2258
# on win32, python2.4 has e.errno == ERROR_DIRECTORY, but
2259
# python 2.5 has e.errno == EINVAL,
2260
# and e.winerror == ERROR_DIRECTORY
2261
e_winerror = getattr(e, 'winerror', None)
2262
win_errors = (ERROR_DIRECTORY, ERROR_PATH_NOT_FOUND)
2263
# there may be directories in the inventory even though
2264
# this path is not a file on disk: so mark it as end of
2266
if e.errno in (errno.ENOENT, errno.ENOTDIR, errno.EINVAL):
2267
current_dir_info = None
2268
elif (sys.platform == 'win32'
2269
and (e.errno in win_errors
2270
or e_winerror in win_errors)):
2271
current_dir_info = None
2275
if current_dir_info[0][0] == '':
2276
# remove .bzr from iteration
2277
bzr_index = bisect_left(current_dir_info[1], ('.bzr',))
2278
if current_dir_info[1][bzr_index][0] != '.bzr':
2279
raise AssertionError()
2280
del current_dir_info[1][bzr_index]
2281
# walk until both the directory listing and the versioned metadata
2283
if (block_index < len(state._dirblocks) and
2284
osutils.is_inside(current_root, state._dirblocks[block_index][0])):
2285
current_block = state._dirblocks[block_index]
2287
current_block = None
2288
while (current_dir_info is not None or
2289
current_block is not None):
2290
if (current_dir_info and current_block
2291
and current_dir_info[0][0] != current_block[0]):
2292
if cmp_by_dirs(current_dir_info[0][0], current_block[0]) < 0:
2293
# filesystem data refers to paths not covered by the dirblock.
2294
# this has two possibilities:
2295
# A) it is versioned but empty, so there is no block for it
2296
# B) it is not versioned.
2298
# if (A) then we need to recurse into it to check for
2299
# new unknown files or directories.
2300
# if (B) then we should ignore it, because we don't
2301
# recurse into unknown directories.
2303
while path_index < len(current_dir_info[1]):
2304
current_path_info = current_dir_info[1][path_index]
2305
if want_unversioned:
2306
if current_path_info[2] == 'directory':
2307
if self.target._directory_is_tree_reference(
2308
current_path_info[0].decode('utf8')):
2309
current_path_info = current_path_info[:2] + \
2310
('tree-reference',) + current_path_info[3:]
2311
new_executable = bool(
2312
stat.S_ISREG(current_path_info[3].st_mode)
2313
and stat.S_IEXEC & current_path_info[3].st_mode)
2315
(None, utf8_decode(current_path_info[0])[0]),
2319
(None, utf8_decode(current_path_info[1])[0]),
2320
(None, current_path_info[2]),
2321
(None, new_executable))
2322
# dont descend into this unversioned path if it is
2324
if current_path_info[2] in ('directory',
2326
del current_dir_info[1][path_index]
2330
# This dir info has been handled, go to the next
2332
current_dir_info = dir_iterator.next()
2333
except StopIteration:
2334
current_dir_info = None
2336
# We have a dirblock entry for this location, but there
2337
# is no filesystem path for this. This is most likely
2338
# because a directory was removed from the disk.
2339
# We don't have to report the missing directory,
2340
# because that should have already been handled, but we
2341
# need to handle all of the files that are contained
2343
for current_entry in current_block[1]:
2344
# entry referring to file not present on disk.
2345
# advance the entry only, after processing.
2346
result = _process_entry(current_entry, None)
2347
if result is not None:
2348
if result is not uninteresting:
2351
if (block_index < len(state._dirblocks) and
2352
osutils.is_inside(current_root,
2353
state._dirblocks[block_index][0])):
2354
current_block = state._dirblocks[block_index]
2356
current_block = None
2359
if current_block and entry_index < len(current_block[1]):
2360
current_entry = current_block[1][entry_index]
2362
current_entry = None
2363
advance_entry = True
2365
if current_dir_info and path_index < len(current_dir_info[1]):
2366
current_path_info = current_dir_info[1][path_index]
2367
if current_path_info[2] == 'directory':
2368
if self.target._directory_is_tree_reference(
2369
current_path_info[0].decode('utf8')):
2370
current_path_info = current_path_info[:2] + \
2371
('tree-reference',) + current_path_info[3:]
2373
current_path_info = None
2375
path_handled = False
2376
while (current_entry is not None or
2377
current_path_info is not None):
2378
if current_entry is None:
2379
# the check for path_handled when the path is adnvaced
2380
# will yield this path if needed.
2382
elif current_path_info is None:
2383
# no path is fine: the per entry code will handle it.
2384
result = _process_entry(current_entry, current_path_info)
2385
if result is not None:
2386
if result is not uninteresting:
2388
elif (current_entry[0][1] != current_path_info[1]
2389
or current_entry[1][target_index][0] in 'ar'):
2390
# The current path on disk doesn't match the dirblock
2391
# record. Either the dirblock is marked as absent, or
2392
# the file on disk is not present at all in the
2393
# dirblock. Either way, report about the dirblock
2394
# entry, and let other code handle the filesystem one.
2396
# Compare the basename for these files to determine
2398
if current_path_info[1] < current_entry[0][1]:
2399
# extra file on disk: pass for now, but only
2400
# increment the path, not the entry
2401
advance_entry = False
2403
# entry referring to file not present on disk.
2404
# advance the entry only, after processing.
2405
result = _process_entry(current_entry, None)
2406
if result is not None:
2407
if result is not uninteresting:
2409
advance_path = False
2411
result = _process_entry(current_entry, current_path_info)
2412
if result is not None:
2414
if result is not uninteresting:
2416
if advance_entry and current_entry is not None:
2418
if entry_index < len(current_block[1]):
2419
current_entry = current_block[1][entry_index]
2421
current_entry = None
2423
advance_entry = True # reset the advance flaga
2424
if advance_path and current_path_info is not None:
2425
if not path_handled:
2426
# unversioned in all regards
2427
if want_unversioned:
2428
new_executable = bool(
2429
stat.S_ISREG(current_path_info[3].st_mode)
2430
and stat.S_IEXEC & current_path_info[3].st_mode)
2432
(None, utf8_decode(current_path_info[0])[0]),
2436
(None, utf8_decode(current_path_info[1])[0]),
2437
(None, current_path_info[2]),
2438
(None, new_executable))
2439
# dont descend into this unversioned path if it is
2441
if current_path_info[2] in ('directory'):
2442
del current_dir_info[1][path_index]
2444
# dont descend the disk iterator into any tree
2446
if current_path_info[2] == 'tree-reference':
2447
del current_dir_info[1][path_index]
2450
if path_index < len(current_dir_info[1]):
2451
current_path_info = current_dir_info[1][path_index]
2452
if current_path_info[2] == 'directory':
2453
if self.target._directory_is_tree_reference(
2454
current_path_info[0].decode('utf8')):
2455
current_path_info = current_path_info[:2] + \
2456
('tree-reference',) + current_path_info[3:]
2458
current_path_info = None
2459
path_handled = False
2461
advance_path = True # reset the advance flagg.
2462
if current_block is not None:
2464
if (block_index < len(state._dirblocks) and
2465
osutils.is_inside(current_root, state._dirblocks[block_index][0])):
2466
current_block = state._dirblocks[block_index]
2468
current_block = None
2469
if current_dir_info is not None:
2471
current_dir_info = dir_iterator.next()
2472
except StopIteration:
2473
current_dir_info = None
2079
iter_changes = self.target._iter_changes(include_unchanged,
2080
use_filesystem_for_exec, search_specific_files, state,
2081
source_index, target_index, want_unversioned, self.target)
2082
return iter_changes.iter_changes()
2477
2085
def is_compatible(source, target):
2478
2086
# the target must be a dirstate working tree
2479
if not isinstance(target, WorkingTree4):
2087
if not isinstance(target, DirStateWorkingTree):
2481
# the source must be a revtreee or dirstate rev tree.
2089
# the source must be a revtree or dirstate rev tree.
2482
2090
if not isinstance(source,
2483
2091
(revisiontree.RevisionTree, DirStateRevisionTree)):
2485
2093
# the source revid must be in the target dirstate
2486
2094
if not (source._revision_id == NULL_REVISION or
2487
2095
source._revision_id in target.get_parent_ids()):
2488
# TODO: what about ghosts? it may well need to
2096
# TODO: what about ghosts? it may well need to
2489
2097
# check for them explicitly.