git-p4: avoid syncing duplicate changes
PATCH 1/1 git-p4: avoid syncing duplicate changes
When a particular changeset affects multiple depot paths, it will appear multiple times in the output of "p4 changes". Filter out the duplicates to avoid the extra empty commits that this would otherwise create.
--- contrib/fast-import/git-p4 | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
contrib/fast-import/git-p4 +3 -2
@@ -444,8 +444,9 @@ def p4ChangesForPaths(depotPaths, changeRange): changes = [] for line in output: - changeNum = line.split(" ")[1] - changes.append(int(changeNum)) + changeNum = int(line.split(" ")[1]) + if changeNum not in changes: + changes.append(changeNum) changes.sort() return changes
Signature · 1 line
1.6.0.6
Quoted 15 lines · On Wednesday 28 January 2009 Pete Wyckoff, wrote:
When a particular changeset affects multiple depot paths, it will appear multiple times in the output of "p4 changes". Filter out the duplicates to avoid the extra empty commits that this would otherwise create.
Signed-off-by Pete Wyckoff <[email protected]>--- contrib/fast-import/git-p4 | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)contrib/fast-import/git-p4 +0
-0
contrib/fast-import/git-p4 def p4ChangesForPaths(depotPaths, changeRange): · line 449
Quoted 8 lines
contrib/fast-import/git-p4 +3
-2@@ -444,8 +444,9 @@ def p4ChangesForPaths(depotPaths, changeRange): changes = [] for line in output: - changeNum = line.split(" ")[1] - changes.append(int(changeNum)) + changeNum = int(line.split(" ")[1]) + if changeNum not in changes: + changes.append(changeNum)
Hmm, isn't this a potentially quadratic operation?
I agree about the problem in general though.
Simon
PATCH v2 1/1 git-p4: avoid syncing duplicate changes
When a particular changeset affects multiple depot paths, it will appear multiple times in the output of "p4 changes". Filter out the duplicates to avoid the extra empty commits that this otherwise would create.
---
Switched to a dictionary to avoid the quadratic behavior, as pointed out by Simon.
contrib/fast-import/git-p4 | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-)
contrib/fast-import/git-p4 +6 -5
@@ -442,13 +442,14 @@ def p4ChangesForPaths(depotPaths, changeRange): output = p4_read_pipe_lines("changes " + ' '.join (["%s...%s" % (p, changeRange) for p in depotPaths])) - changes = [] + changes = {} for line in output: - changeNum = line.split(" ")[1] - changes.append(int(changeNum)) + changeNum = int(line.split(" ")[1]) + changes[changeNum] = True - changes.sort() - return changes + changelist = changes.keys() + changelist.sort() + return changelist class Command: def __init__(self):
Signature · 1 line
1.6.0.6
Quoted 6 lines · On Wednesday 18 February 2009 Pete Wyckoff, wrote:
When a particular changeset affects multiple depot paths, it will appear multiple times in the output of "p4 changes". Filter out the duplicates to avoid the extra empty commits that this otherwise would create.
Signed-off-by Pete Wyckoff <[email protected]>
Nice patch, thanks :)
Simon
contrib/fast-import/git-p4 def p4ChangesForPaths(depotPaths, changeRange): · line 442
Quoted 12 lines
Switched to a dictionary to avoid the quadratic behavior, as pointed out by Simon.
contrib/fast-import/git-p4 | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-)contrib/fast-import/git-p4 +0
-0@@ -442,13 +442,14 @@ def p4ChangesForPaths(depotPaths, changeRange): output = p4_read_pipe_lines("changes " + ' '.join (["%s...%s" % (p,
changeRange)
contrib/fast-import/git-p4 def p4ChangesForPaths(depotPaths, changeRange): · line 443
Quoted 1 line
contrib/fast-import/git-p4 +0
-0for p in
depotPaths]))
Quoted 21 lines
contrib/fast-import/git-p4 +6
-5- changes = [] + changes = {} for line in output: - changeNum = line.split(" ")[1] - changes.append(int(changeNum)) + changeNum = int(line.split(" ")[1]) + changes[changeNum] = True - changes.sort() - return changes + changelist = changes.keys() + changelist.sort() + return changelist class Command: def __init__(self):Signature · 1 line
1.6.0.6