git-watchtower 2.1.8 → 2.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/git/branch.js +17 -10
package/package.json
CHANGED
package/src/git/branch.js
CHANGED
|
@@ -97,7 +97,12 @@ async function getAllBranches(options = {}) {
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
const branchList = [];
|
|
100
|
-
|
|
100
|
+
// O(1) lookup by name. The Map stores the same object references
|
|
101
|
+
// pushed into branchList, so mutating an entry through the Map (when
|
|
102
|
+
// a remote ref matches a local ref) updates the array entry too.
|
|
103
|
+
// Replaces the previous `branchList.find()` per-remote-ref scan,
|
|
104
|
+
// which was O(n²) and noticeable on large monorepos.
|
|
105
|
+
const branchByName = new Map();
|
|
101
106
|
|
|
102
107
|
// Get local branches
|
|
103
108
|
// Use \x1f (Unit Separator) as delimiter since | can appear in commit subjects
|
|
@@ -111,9 +116,8 @@ async function getAllBranches(options = {}) {
|
|
|
111
116
|
for (const line of localResult.stdout.split('\n').filter(Boolean)) {
|
|
112
117
|
const [name, dateStr, commit, ...subjectParts] = line.split(delimiter);
|
|
113
118
|
const subject = subjectParts.join(delimiter);
|
|
114
|
-
if (!
|
|
115
|
-
|
|
116
|
-
branchList.push({
|
|
119
|
+
if (!branchByName.has(name) && isValidBranchName(name)) {
|
|
120
|
+
const branch = {
|
|
117
121
|
name,
|
|
118
122
|
commit,
|
|
119
123
|
subject: subject || '',
|
|
@@ -121,7 +125,9 @@ async function getAllBranches(options = {}) {
|
|
|
121
125
|
isLocal: true,
|
|
122
126
|
hasRemote: false,
|
|
123
127
|
hasUpdates: false,
|
|
124
|
-
}
|
|
128
|
+
};
|
|
129
|
+
branchByName.set(name, branch);
|
|
130
|
+
branchList.push(branch);
|
|
125
131
|
}
|
|
126
132
|
}
|
|
127
133
|
}
|
|
@@ -142,7 +148,7 @@ async function getAllBranches(options = {}) {
|
|
|
142
148
|
if (name === 'HEAD') continue;
|
|
143
149
|
if (!isValidBranchName(name)) continue;
|
|
144
150
|
|
|
145
|
-
const existing = /** @type {Branch|undefined} */ (
|
|
151
|
+
const existing = /** @type {Branch|undefined} */ (branchByName.get(name));
|
|
146
152
|
if (existing) {
|
|
147
153
|
existing.hasRemote = true;
|
|
148
154
|
existing.remoteCommit = commit;
|
|
@@ -154,9 +160,8 @@ async function getAllBranches(options = {}) {
|
|
|
154
160
|
existing.date = new Date(dateStr);
|
|
155
161
|
existing.subject = subject || existing.subject;
|
|
156
162
|
}
|
|
157
|
-
} else
|
|
158
|
-
|
|
159
|
-
branchList.push({
|
|
163
|
+
} else {
|
|
164
|
+
const branch = {
|
|
160
165
|
name,
|
|
161
166
|
commit,
|
|
162
167
|
subject: subject || '',
|
|
@@ -164,7 +169,9 @@ async function getAllBranches(options = {}) {
|
|
|
164
169
|
isLocal: false,
|
|
165
170
|
hasRemote: true,
|
|
166
171
|
hasUpdates: false,
|
|
167
|
-
}
|
|
172
|
+
};
|
|
173
|
+
branchByName.set(name, branch);
|
|
174
|
+
branchList.push(branch);
|
|
168
175
|
}
|
|
169
176
|
}
|
|
170
177
|
}
|