Changeset 1441


Ignore:
Timestamp:
03/28/03 04:17:59 (20 years ago)
Author:
piso
Message:

All commands now support filenames with embedded spaces.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/j/P4.java

    r629 r1441  
    22 * P4.java
    33 *
    4  * Copyright (C) 1998-2002 Peter Graves
    5  * $Id: P4.java,v 1.6 2003-01-31 02:10:29 piso Exp $
     4 * Copyright (C) 1998-2003 Peter Graves
     5 * $Id: P4.java,v 1.7 2003-03-28 04:17:59 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    7070                    arg = file.canonicalPath();
    7171            }
    72             if (arg.indexOf(' ') >= 0) {
    73                 sb.append('"');
    74                 sb.append(arg);
    75                 sb.append('"');
    76             } else
    77                 sb.append(arg);
     72            sb.append(maybeQuote(arg));
    7873            sb.append(' ');
    7974        }
     
    117112        final String name = buffer.getFile().getName();
    118113        FastStringBuffer sb = new FastStringBuffer("p4 add ");
    119         // Enclose filename in double quotes in case it contains embedded
    120         // spaces.
    121         sb.append('"');
    122         sb.append(name);
    123         sb.append('"');
     114        sb.append(maybeQuote(name));
    124115        final String cmd = sb.toString();
    125116        final String output = command(cmd, buffer.getCurrentDirectory());
    126117        OutputBuffer buf = OutputBuffer.getOutputBuffer(output);
    127         buf.setTitle(cmd + name);
     118        buf.setTitle(cmd);
    128119        editor.makeNext(buf);
    129120        editor.activateInOtherWindow(buf);
     
    142133        buffer.setBusy(true);
    143134        editor.setWaitCursor();
    144         final String canonicalPath = file.canonicalPath();
    145135        FastStringBuffer sb = new FastStringBuffer("p4 edit ");
    146         // Enclose filename in double quotes in case it contains an embedded
    147         // space.
    148         sb.append('"');
    149         sb.append(canonicalPath);
    150         sb.append('"');
     136        sb.append(maybeQuote(file.canonicalPath()));
    151137        final String cmd = sb.toString();
    152138        Runnable commandRunnable = new Runnable() {
     
    174160        } else {
    175161            OutputBuffer buf = OutputBuffer.getOutputBuffer(output);
    176             buf.setTitle(cmd + buffer.getFile().getName());
     162            buf.setTitle(cmd);
    177163            editor.makeNext(buf);
    178164            editor.activateInOtherWindow(buf);
     
    200186        if (output == null)
    201187            return false;
    202         editCompleted(editor, buffer, "p4 edit " + file.canonicalPath(), output);
     188        FastStringBuffer sb = new FastStringBuffer("p4 edit ");
     189        sb.append(maybeQuote(file.canonicalPath()));
     190        editCompleted(editor, buffer, sb.toString(), output);
    203191        return !buffer.isReadOnly();
    204192    }
     
    222210        if (!haveP4())
    223211            return null;
    224         return command("p4 edit " + file.canonicalPath(), null);
     212        FastStringBuffer sb = new FastStringBuffer("p4 edit ");
     213        sb.append(maybeQuote(file.canonicalPath()));
     214        return command(sb.toString(), null);
    225215    }
    226216
     
    235225            return;
    236226        if (buffer.isModified()) {
    237             String prompt = "Discard changes to " + file.canonicalPath() + "?";
     227            String prompt =
     228                "Discard changes to " + maybeQuote(file.getName()) + "?";
    238229            if (!editor.confirm("Revert Buffer", prompt))
    239230                return;
    240231        }
    241         final String cmd = "p4 revert " + file.canonicalPath();
     232        final String cmd = "p4 revert " + maybeQuote(file.canonicalPath());
    242233        String output = command(cmd, null);
    243234        if (output.trim().endsWith(" - was edit, reverted")) {
     
    245236        } else {
    246237            OutputBuffer buf = OutputBuffer.getOutputBuffer(output);
    247             buf.setTitle(cmd + file.getName());
     238            buf.setTitle(cmd);
    248239            editor.makeNext(buf);
    249240            editor.activateInOtherWindow(buf);
     
    268259        final String baseCmd = "p4 diff -du ";
    269260        final String name = file.getName();
    270         final String title = baseCmd + name;
     261        final String title = baseCmd + maybeQuote(name);
    271262        boolean save = false;
    272263        if (parentBuffer.isModified()) {
     
    296287                }
    297288            }
    298             final String cmd = baseCmd + file.canonicalPath();
     289            final String cmd = baseCmd + maybeQuote(file.canonicalPath());
    299290            final String output = command(cmd, null);
    300291            DiffOutputBuffer buf = new DiffOutputBuffer(parentBuffer, output, VC_P4);
     
    831822            }
    832823            sb.append(cmd);
    833             Log.debug("P4Command.run |" + sb.toString() + "|");
    834824            shellCommand = new ShellCommand(sb.toString());
    835825            shellCommand.run();
     
    871861        return false;
    872862    }
     863
     864    // Enclose string in quotes if it contains any embedded spaces.
     865    private static String maybeQuote(String s)
     866    {
     867        if (s.indexOf(' ') < 0)
     868            return s;
     869        FastStringBuffer sb = new FastStringBuffer('"');
     870        sb.append(s);
     871        sb.append('"');
     872        return sb.toString();
     873    }
    873874}
Note: See TracChangeset for help on using the changeset viewer.