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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/git/branch.js +17 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "git-watchtower",
3
- "version": "2.1.8",
3
+ "version": "2.1.9",
4
4
  "description": "Terminal-based Git branch monitor with activity sparklines and optional dev server with live reload",
5
5
  "main": "bin/git-watchtower.js",
6
6
  "bin": {
package/src/git/branch.js CHANGED
@@ -97,7 +97,12 @@ async function getAllBranches(options = {}) {
97
97
  }
98
98
 
99
99
  const branchList = [];
100
- const seenBranches = new Set();
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 (!seenBranches.has(name) && isValidBranchName(name)) {
115
- seenBranches.add(name);
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} */ (branchList.find((b) => b.name === name));
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 if (!seenBranches.has(name)) {
158
- seenBranches.add(name);
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
  }