Merge lp:~mwhudson/merge-o-matic/exec-bits into lp:merge-o-matic

Proposed by Michael Hudson-Doyle
Status: Merged
Approved by: Steve Langasek
Approved revision: 318
Merged at revision: 317
Proposed branch: lp:~mwhudson/merge-o-matic/exec-bits
Merge into: lp:merge-o-matic
Diff against target: 73 lines (+33/-19)
1 file modified
produce-merges.py (+33/-19)
To merge this branch: bzr merge lp:~mwhudson/merge-o-matic/exec-bits
Reviewer Review Type Date Requested Status
Steve Langasek Approve
Review via email: mp+355396@code.launchpad.net

Commit message

Fix the thing where merged files lose their exec bit.

To post a comment you must log in.
Revision history for this message
Steve Langasek (vorlon) :
review: Needs Fixing
lp:~mwhudson/merge-o-matic/exec-bits updated
318. By Michael Hudson-Doyle

review feedback

Revision history for this message
Steve Langasek (vorlon) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'produce-merges.py'
2--- produce-merges.py 2016-11-18 21:42:52 +0000
3+++ produce-merges.py 2018-09-20 08:52:05 +0000
4@@ -588,36 +588,50 @@
5 dest = "%s/%s" % (merged_dir, filename)
6 ensure(dest)
7
8- with open(dest, "w") as output:
9+ left = "%s/%s" % (left_dir, filename)
10+ right = "%s/%s" % (right_dir, filename)
11+ base = "%s/%s" % (base_dir, filename)
12+
13+ left_stat = os.stat(left)
14+ right_stat = os.stat(right)
15+ base_stat = os.stat(base)
16+
17+ # Preserve execute bit on merged file. This all ignores the distinction
18+ # between the ugo exec bits because it's hard to think of a reason we
19+ # should.
20+ mode = 0o644
21+ if stat.S_IMODE(base_stat) & 0o111:
22+ # If base was executable and both left and right are, make output
23+ # executable.
24+ if stat.S_IMODE(right_stat) & stat.S_IMODE(left_stat) & 0o111:
25+ mode |= 0o111
26+ else:
27+ # Alternatively, if base was not executable and either of left and right
28+ # are, make output executable.
29+ if (stat.S_IMODE(right_stat) | stat.S_IMODE(left_stat)) & 0o111:
30+ mode |= 0o111
31+
32+ with open(dest, "w", mode) as output:
33 status = shell.run(("diff3", "-E", "-m",
34- "-L", left_name, "%s/%s" % (left_dir, filename),
35- "-L", "BASE", "%s/%s" % (base_dir, filename),
36- "-L", right_name, "%s/%s" % (right_dir, filename)),
37+ "-L", left_name, left,
38+ "-L", "BASE", base,
39+ "-L", right_name, right),
40 stdout=output, okstatus=(0,1,2))
41
42 if status != 0:
43 if not tree.exists(dest) or os.stat(dest).st_size == 0:
44 # Probably binary
45- if same_file(os.stat("%s/%s" % (left_dir, filename)), left_dir,
46- os.stat("%s/%s" % (right_dir, filename)), right_dir,
47- filename):
48+ if same_file(left_stat, left_dir, right_stat, right_dir, filename):
49 logging.debug("binary files are the same: %s", filename)
50- tree.copyfile("%s/%s" % (left_dir, filename),
51- "%s/%s" % (merged_dir, filename))
52- elif same_file(os.stat("%s/%s" % (base_dir, filename)), base_dir,
53- os.stat("%s/%s" % (left_dir, filename)), left_dir,
54- filename):
55+ tree.copyfile(left, dest)
56+ elif same_file(base_stat, base_dir, left_stat, left_dir, filename):
57 logging.debug("preserving binary change in %s: %s",
58 right_distro, filename)
59- tree.copyfile("%s/%s" % (right_dir, filename),
60- "%s/%s" % (merged_dir, filename))
61- elif same_file(os.stat("%s/%s" % (base_dir, filename)), base_dir,
62- os.stat("%s/%s" % (right_dir, filename)), right_dir,
63- filename):
64+ tree.copyfile(right, dest)
65+ elif same_file(base_stat, base_dir, right_stat, right_dir, filename):
66 logging.debug("preserving binary change in %s: %s",
67 left_distro, filename)
68- tree.copyfile("%s/%s" % (left_dir, filename),
69- "%s/%s" % (merged_dir, filename))
70+ tree.copyfile(left, dest)
71 else:
72 logging.debug("binary file conflict: %s", filename)
73 conflict_file(left_dir, left_distro, right_dir, right_distro,

Subscribers

People subscribed via source and target branches

to status/vote changes: